#include "cautilinterface.h"
#include "NSProviderSystem.h"
#include "oic_time.h"
+#include <pthread.h>
bool initProvider = false;
pthread_mutex_t nsInitMutex;
+pthread_cond_t nstopicCond;
void initializeMutex()
{
nsInitMutex = initMutex;
}
+void NSInitialize()
+{
+ NS_LOG(DEBUG, "NSSetList - IN");
+
+ pthread_mutexattr_init(&NSCacheMutexAttr);
+ pthread_mutexattr_settype(&NSCacheMutexAttr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&NSCacheMutex, &NSCacheMutexAttr);
+ pthread_cond_init(&nstopicCond, NULL);
+
+ NSInitSubscriptionList();
+ NSInitTopicList();
+ NS_LOG(DEBUG, "NSSetList - OUT");
+}
+
+void NSDeinitailize()
+{
+ NSStorageDestroy(consumerSubList);
+ NSStorageDestroy(consumerTopicList);
+ NSStorageDestroy(registeredTopicList);
+
+ pthread_mutex_destroy(&NSCacheMutex);
+ pthread_mutexattr_destroy(&NSCacheMutexAttr);
+ pthread_cond_destroy(&nstopicCond);
+}
+
NSResult NSStartProvider(NSProviderConfig config)
{
NS_LOG(DEBUG, "NSStartProvider - IN");
CARegisterNetworkMonitorHandler((CAAdapterStateChangedCB)NSProviderAdapterStateListener,
(CAConnectionStateChangedCB)NSProviderConnectionStateListener);
- NSSetList();
+ NSInitialize();
NSInitScheduler();
NSStartScheduler();
return NS_OK;
}
-void NSSetList()
-{
- NS_LOG(DEBUG, "NSSetList - IN");
-
- pthread_mutexattr_init(&NSCacheMutexAttr);
- pthread_mutexattr_settype(&NSCacheMutexAttr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&NSCacheMutex, &NSCacheMutexAttr);
-
- NSInitSubscriptionList();
- NSInitTopicList();
- NS_LOG(DEBUG, "NSSetList - OUT");
-}
-
-void NSDestroyList()
-{
- NSStorageDestroy(consumerSubList);
- NSStorageDestroy(consumerTopicList);
- NSStorageDestroy(registeredTopicList);
-
- pthread_mutex_destroy(&NSCacheMutex);
- pthread_mutexattr_destroy(&NSCacheMutexAttr);
-}
-
NSResult NSStopProvider()
{
NS_LOG(DEBUG, "NSStopProvider - IN");
NSRegisterSubscribeRequestCb((NSSubscribeRequestCallback)NULL);
NSRegisterSyncCb((NSProviderSyncInfoCallback)NULL);
NSStopScheduler();
- NSDestroyList();
+ NSDeinitailize();
initProvider = false;
}
return NULL;
}
- NSTopicLL * topics = NSProviderGetConsumerTopicsCacheData(registeredTopicList,
- consumerTopicList, consumerId);
+ NSTopicSynchronization topics;
+ topics.consumerId = OICStrdup(consumerId);
+ topics.topics = NULL;
+ topics.condition = nstopicCond;
+
+ NSPushQueue(TOPIC_SCHEDULER, TAST_GET_CONSUMER_TOPICS, &topics);
+ pthread_cond_wait(&topics.condition, &nsInitMutex);
+ OICFree(topics.consumerId);
pthread_mutex_unlock(&nsInitMutex);
- return topics;
+ NS_LOG(DEBUG, "NSProviderGetConsumerTopics - OUT");
+ return topics.topics;
}
NSTopicLL * NSProviderGetTopics()
NS_LOG(DEBUG, "NSProviderGetTopics - IN");
pthread_mutex_lock(&nsInitMutex);
- NSTopicLL * topics = NSProviderGetTopicsCacheData(registeredTopicList);
+ NSTopicSynchronization topics;
+ topics.consumerId = NULL;
+ topics.topics = NULL;
+ topics.condition = nstopicCond;
+
+ NSPushQueue(TOPIC_SCHEDULER, TASK_GET_TOPICS, &topics);
+ pthread_cond_wait(&topics.condition, &nsInitMutex);
pthread_mutex_unlock(&nsInitMutex);
NS_LOG(DEBUG, "NSProviderGetTopics - OUT");
-
- return topics;
+ return topics.topics;
}
NSResult NSProviderRegisterTopic(const char * topicName)
#include "NSProviderTopic.h"\r
#include "oic_string.h"\r
#include "oic_malloc.h"\r
+#include <pthread.h>\r
\r
NSResult NSSendTopicUpdation();\r
\r
NSFreeOCEntityHandlerRequest((OCEntityHandlerRequest*) node->taskData);\r
}\r
break;\r
+ case TASK_GET_TOPICS:\r
+ {\r
+ NS_LOG(DEBUG, "TASK_GET_TOPICS : ");\r
+ NSTopicSynchronization * topicData = (NSTopicSynchronization *) node->taskData;\r
+ NSTopicLL * topics = NSProviderGetTopicsCacheData(registeredTopicList);\r
+ topicData->topics = topics;\r
+ pthread_cond_signal(&topicData->condition);\r
+ }\r
+ break;\r
+ case TAST_GET_CONSUMER_TOPICS:\r
+ {\r
+ NS_LOG(DEBUG, "TASK_GET_CONSUMER_TOPICS : ");\r
+ NSTopicSynchronization * topicData = (NSTopicSynchronization *) node->taskData;\r
+ NSTopicLL * topics = NSProviderGetConsumerTopicsCacheData(registeredTopicList,\r
+ consumerTopicList, topicData->consumerId);\r
+ topicData->topics = topics;\r
+ pthread_cond_signal(&topicData->condition);\r
+ }\r
+ break;\r
default:\r
break;\r
}\r