/**
* Callback to provide the status of the network change to CA layer.
*/
-static CANetworkChangeCallback g_networkCallback = NULL;
+static CAAdapterChangeCallback g_networkCallback = NULL;
+
+/**
+ * Callback to provide the status of the connection change to CA layer.
+ */
+static CAConnectionChangeCallback g_connectionCallback = NULL;
/**
* bleAddress of the local adapter. Value will be initialized to zero,
/**
* Register network change notification callback.
*
- * @param[in] netCallback CANetworkChangeCallback callback which will
- * be set for the change in network.
+ * @param[in] netCallback CAAdapterChangeCallback callback which will
+ * be set for the change in adapter.
+ * @param[in] connCallback CAConnectionChangeCallback callback which will
+ * be set for the change in connection.
*
* @return 0 on success otherwise a positive error value.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_FAILED Operation failed.
*
*/
-static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
+static CAResult_t CALERegisterNetworkNotifications(CAAdapterChangeCallback netCallback,
+ CAConnectionChangeCallback connCallback);
/**
* Set the thread pool handle which is required for spawning new
CAResult_t result = CAStopLEGattServer();
ca_mutex_lock(g_bleServerSendDataMutex);
- if (CA_STATUS_OK != result)
+ if (CA_STATUS_OK == result)
{
result = CAQueueingThreadStop(g_bleServerSendQueueHandle);
}
CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback reqRespCallback,
- CANetworkChangeCallback netCallback,
+ CAAdapterChangeCallback netCallback,
+ CAConnectionChangeCallback connCallback,
CAErrorHandleCallback errorCallback,
ca_thread_pool_t handle)
{
VERIFY_NON_NULL(registerCallback, CALEADAPTER_TAG, "RegisterConnectivity callback is null");
VERIFY_NON_NULL(reqRespCallback, CALEADAPTER_TAG, "PacketReceived Callback is null");
VERIFY_NON_NULL(netCallback, CALEADAPTER_TAG, "NetworkChange Callback is null");
+ VERIFY_NON_NULL(connCallback, CALEADAPTER_TAG, "ConnectionChange Callback is null");
CAResult_t result = CA_STATUS_OK;
result = CAInitLEAdapterMutex();
OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitializeLENetworkMonitor() failed");
return CA_STATUS_FAILED;
}
- CAInitializeLEAdapter(handle);
+ CAInitializeLEAdapter();
CASetLEClientThreadPoolHandle(handle);
CASetBLEClientErrorHandleCallback(CALEErrorHandler);
CASetBLEServerErrorHandleCallback(CALEErrorHandler);
- CALERegisterNetworkNotifications(netCallback);
+ CALERegisterNetworkNotifications(netCallback, connCallback);
g_errorHandler = errorCallback;
CASetLEReqRespServerCallback(NULL);
CASetLEReqRespClientCallback(NULL);
- CALERegisterNetworkNotifications(NULL);
+ CALERegisterNetworkNotifications(NULL, NULL);
CASetLEReqRespAdapterCallback(NULL);
CATerminateLENetworkMonitor();
OIC_LOG(DEBUG,
CALEADAPTER_TAG,
"Listen Server will be started once BT Adapter is enabled");
+ result = CA_STATUS_OK;
}
}
else
OIC_LOG(DEBUG,
CALEADAPTER_TAG,
"Discovery Server will be started once BT Adapter is enabled");
+ result = CA_STATUS_OK;
}
}
else
return CA_STATUS_OK;
}
-static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+static CAResult_t CALERegisterNetworkNotifications(CAAdapterChangeCallback netCallback,
+ CAConnectionChangeCallback connCallback)
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
ca_mutex_lock(g_bleNetworkCbMutex);
g_networkCallback = netCallback;
+ g_connectionCallback = connCallback;
ca_mutex_unlock(g_bleNetworkCbMutex);
CAResult_t res = CA_STATUS_OK;
if (netCallback)
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
}
-
- res = CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCb);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, CALEADAPTER_TAG, "CALEConnectionStateChangedCb failed!");
- }
}
else
{
}
}
+ if (g_connectionCallback)
+ {
+ res = CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCb);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLENWConnectionStateChangedCb failed!");
+ }
+ }
+
OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
return res;
}
#endif
}
+ CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE };
+ OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), address);
+
+ ca_mutex_lock(g_bleNetworkCbMutex);
+ if (g_connectionCallback)
+ {
+ g_connectionCallback(&localEndpoint, isConnected);
+ }
+ ca_mutex_unlock(g_bleNetworkCbMutex);
+
OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
}
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN - CALEDeviceStateChangedCb");
- VERIFY_NON_NULL_VOID(g_localBLEAddress, CALEADAPTER_TAG, "g_localBLEAddress is null");
- CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE };
-
- ca_mutex_lock(g_bleLocalAddressMutex);
- OICStrcpy(localEndpoint.addr,
- sizeof(localEndpoint.addr),
- g_localBLEAddress);
- ca_mutex_unlock(g_bleLocalAddressMutex);
-
if (CA_ADAPTER_ENABLED == adapter_state)
{
ca_mutex_lock(g_bleIsServerMutex);
ca_mutex_lock(g_bleNetworkCbMutex);
if (NULL != g_networkCallback)
{
- g_networkCallback(&localEndpoint, adapter_state);
+ g_networkCallback(CA_ADAPTER_GATT_BTLE, adapter_state);
}
else
{
static void CALERemoveReceiveQueueData(u_arraylist_t *dataInfoList, const char* address)
{
- OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALERemoveSendQueueData");
+ OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALERemoveReceiveQueueData");
VERIFY_NON_NULL_VOID(dataInfoList, CALEADAPTER_TAG, "dataInfoList");
VERIFY_NON_NULL_VOID(address, CALEADAPTER_TAG, "address");