*/
static oc_mutex g_LEClientListMutex = NULL;
-/**
- * State of connect state
- */
-static bool g_LEConnectedState = false;
-
void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress)
{
VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address");
if (connected)
{
OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress);
- g_LEConnectedState = true;
char *addr = OICStrdup(remoteAddress);
oc_mutex_lock(g_LEClientListMutex);
res = CAAddLEClientInfoToList(&g_LEClientList, addr);
else
{
OIC_LOG_V(DEBUG, TAG, "Disconnected from [%s]", remoteAddress);
- g_LEConnectedState = false;
oc_mutex_lock(g_LEClientListMutex);
CARemoveLEClientInfoFromList(&g_LEClientList, remoteAddress);
oc_mutex_unlock(g_LEClientListMutex);
oc_mutex_lock(g_leCharacteristicMutex);
- if (!g_LEConnectedState)
+ oc_mutex_lock(g_LEClientListMutex);
+ if (CA_STATUS_FAILED == CAIsLEClientInfoInList(g_LEClientList, address))
{
- OIC_LOG(ERROR, TAG, "g_LEConnectedState is false");
+ OIC_LOG_V(ERROR, TAG, "%s device is not connected", address);
+ oc_mutex_unlock(g_LEClientListMutex);
oc_mutex_unlock(g_leCharacteristicMutex);
return CA_STATUS_FAILED;
}
+ oc_mutex_unlock(g_LEClientListMutex);
if (NULL == g_gattReadCharPath)
{
oc_mutex_lock(g_leCharacteristicMutex);
- if (!g_LEConnectedState)
- {
- OIC_LOG(ERROR, TAG, "g_LEConnectedState is false");
- oc_mutex_unlock(g_leCharacteristicMutex);
- return CA_STATUS_FAILED;
- }
-
if (NULL == g_gattReadCharPath)
{
OIC_LOG(ERROR, TAG, "g_gattReadCharPath is NULL");
return CA_STATUS_OK;
}
+CAResult_t CAIsLEClientInfoInList(LEClientInfoList *clientList,
+ const char *clientAddress)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ LEClientInfoList *temp = clientList;
+ while (temp)
+ {
+ if (!strcasecmp(temp->remoteAddress, clientAddress))
+ {
+ return CA_STATUS_OK;
+ }
+ temp = temp->next;
+ }
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_FAILED;
+}
+
void CARemoveLEClientInfoFromList(LEClientInfoList **clientList,
const char *clientAddress)
{
const char *clientAddress);
/**
+ * Used to check if client address is present in the list.
+ *
+ * @param[in] clientList Pointer to the ble client list which holds the info of list of
+ * clients connected by the server.
+ * @param[in] clientAddress Remote address to be searched in the client list.
+ * @return ::CA_STATUS_OK if client address is found in the list, otherwise CA_STATUS_FAILED.
+ */
+CAResult_t CAIsLEClientInfoInList(LEClientInfoList *clientList,
+ const char *clientAddress);
+
+/**
* Used to disconnect all the clients connected to the server.
*
* @param[in,out] clientList Pointer to the ble client list which holds the info of list of
goto exit;
}
+ cbData = NULL; // Client CB list entry now owns it
token = NULL; // Client CB list entry now owns it
devAddr = NULL; // Client CB list entry now owns it
resourceUri = NULL; // Client CB list entry now owns it
if (result != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCDoResource error");
+ if (NULL != cbData && NULL != cbData->cd)
+ {
+ cbData->cd(cbData->context);
+ }
FindAndDeleteClientCB(clientCB);
CADestroyToken(token);
if (handle)