}
NSTopicSyncResult topicSyncResult;
- topicSyncResult.topicName = OICStrdup(topicName);
+ topicSyncResult.topicData = (void *) OICStrdup(topicName);
topicSyncResult.condition = &nstopicCond;
topicSyncResult.result = NS_OK;
topicSyncResult.mutex = &nsInitMutex;
}
NSTopicSyncResult topicSyncResult;
- topicSyncResult.topicName = OICStrdup(topicName);
+ topicSyncResult.topicData = (void *) OICStrdup(topicName);
topicSyncResult.condition = &nstopicCond;
topicSyncResult.result = NS_OK;
topicSyncResult.mutex = &nsInitMutex;
pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
- OICFree(topicSyncResult.topicName);
+ OICFree(topicSyncResult.topicData);
pthread_mutex_unlock(&nsInitMutex);
NS_LOG(DEBUG, "NSProviderDeleteTopics - OUT");
OICStrcpy(topicSubData->id, NS_UUID_STRING_SIZE, consumerId);
topicSubData->topicName = OICStrdup(topicName);
- NSPushQueue(TOPIC_SCHEDULER, TASK_SUBSCRIBE_TOPIC, (void *)topicSubData);
+ NSTopicSyncResult topicSyncResult;
+ topicSyncResult.topicData = (void *) topicSubData;
+ topicSyncResult.condition = &nstopicCond;
+ topicSyncResult.result = NS_FAIL;
+ topicSyncResult.mutex = &nsInitMutex;
+
+ NSPushQueue(TOPIC_SCHEDULER, TASK_SUBSCRIBE_TOPIC, (void *)&topicSyncResult);
+ pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
pthread_mutex_unlock(&nsInitMutex);
NS_LOG(DEBUG, "NSProviderSelectTopics - OUT");
- return NS_OK;
+ return topicSyncResult.result;
}
NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topicName)
OICStrcpy(topicSubData->id, NS_UUID_STRING_SIZE, consumerId);
topicSubData->topicName = OICStrdup(topicName);
- NSPushQueue(TOPIC_SCHEDULER, TASK_UNSUBSCRIBE_TOPIC, (void *)topicSubData);
+ NSTopicSyncResult topicSyncResult;
+ topicSyncResult.topicData = (void *) topicSubData;
+ topicSyncResult.condition = &nstopicCond;
+ topicSyncResult.result = NS_FAIL;
+ topicSyncResult.mutex = &nsInitMutex;
+
+ NSPushQueue(TOPIC_SCHEDULER, TASK_UNSUBSCRIBE_TOPIC, (void *)&topicSyncResult);
+ pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
pthread_mutex_unlock(&nsInitMutex);
NS_LOG(DEBUG, "NSProviderUnselectTopics - OUT");
- return NS_OK;
+ return topicSyncResult.result;
}
case TASK_SUBSCRIBE_TOPIC:\r
{\r
NS_LOG(DEBUG, "CASE TASK_SUBSCRIBE_TOPIC : ");\r
+ NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
+ pthread_mutex_lock(topicSyncResult->mutex);\r
NSCacheElement * newObj = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
- if (newObj)\r
+ NSCacheTopicSubData * subData =\r
+ (NSCacheTopicSubData *) topicSyncResult->topicData;\r
+ if (!newObj)\r
+ {\r
+ OICFree(subData->topicName);\r
+ OICFree(subData);\r
+ pthread_cond_signal(topicSyncResult->condition);\r
+ pthread_mutex_unlock(topicSyncResult->mutex);\r
+ }\r
+ else\r
{\r
- newObj->data = node->taskData;\r
- newObj->next = NULL;\r
- if (NSProviderStorageWrite(consumerTopicList, newObj) == NS_OK)\r
+ if (NSProviderStorageRead(registeredTopicList, subData->topicName))\r
{\r
- NSCacheTopicSubData * topicSubData =\r
- (NSCacheTopicSubData *) node->taskData;\r
- NSSendTopicUpdationToConsumer(topicSubData->id);\r
+ newObj->data = topicSyncResult->topicData;\r
+ newObj->next = NULL;\r
+ NSProviderStorageWrite(consumerTopicList, newObj);\r
+ NSSendTopicUpdationToConsumer(subData->id);\r
+ topicSyncResult->result = NS_OK;\r
}\r
- }
+ }\r
+ pthread_cond_signal(topicSyncResult->condition);\r
+ pthread_mutex_unlock(topicSyncResult->mutex);\r
+
}\r
break;\r
case TASK_UNSUBSCRIBE_TOPIC:\r
{\r
- NS_LOG(DEBUG, "CASE TASK_SUBSCRIBE_TOPIC : ");\r
- NSCacheTopicSubData * topicSubData = (NSCacheTopicSubData *) node->taskData;\r
- if (NSProviderDeleteConsumerTopic(consumerTopicList,\r
- (NSCacheTopicSubData *) node->taskData) == NS_OK)\r
+ NS_LOG(DEBUG, "CASE TASK_UNSUBSCRIBE_TOPIC : ");\r
+ NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
+ pthread_mutex_lock(topicSyncResult->mutex);\r
+ NSCacheTopicSubData * topicSubData =\r
+ (NSCacheTopicSubData *) topicSyncResult->topicData;\r
+ if (NSProviderDeleteConsumerTopic(consumerTopicList, topicSubData) == NS_OK)\r
{\r
NSSendTopicUpdationToConsumer(topicSubData->id);\r
+ topicSyncResult->result = NS_OK;\r
}\r
OICFree(topicSubData->topicName);\r
OICFree(topicSubData);\r
+ pthread_cond_signal(topicSyncResult->condition);\r
+ pthread_mutex_unlock(topicSyncResult->mutex);\r
+\r
}\r
break;\r
case TASK_REGISTER_TOPIC:\r
\r
pthread_mutex_lock(topicSyncResult->mutex);\r
topicSyncResult->result = NSRegisterTopic(\r
- (const char *) topicSyncResult->topicName);\r
+ (const char *) topicSyncResult->topicData);\r
pthread_cond_signal(topicSyncResult->condition);\r
pthread_mutex_unlock(topicSyncResult->mutex);\r
}\r
NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
pthread_mutex_lock(topicSyncResult->mutex);\r
topicSyncResult->result = NSUnregisterTopic(\r
- (const char *) topicSyncResult->topicName);\r
+ (const char *) topicSyncResult->topicData);\r
pthread_cond_signal(topicSyncResult->condition);\r
pthread_mutex_unlock(topicSyncResult->mutex);\r
}\r