#ifdef SECURED
NS_LOG(DEBUG, "Built with SECURED");
- if(!config.resourceSecurity)
+ if (!config.resourceSecurity)
{
NS_LOG(DEBUG, "Resource Security Off");
}
+
NSSetResourceSecurity(config.resourceSecurity);
#endif
NS_LOG(DEBUG, "NSStopProvider - IN");
pthread_mutex_lock(&nsInitMutex);
- if(initProvider)
+ if (initProvider)
{
+ CAUnregisterNetworkMonitorHandler((CAAdapterStateChangedCB)NSProviderAdapterStateListener,
+ (CAConnectionStateChangedCB)NSProviderConnectionStateListener);
NSPushQueue(DISCOVERY_SCHEDULER, TASK_STOP_PRESENCE, NULL);
- NSDeinitProviderInfo();
- NSUnRegisterResource();
NSRegisterSubscribeRequestCb((NSSubscribeRequestCallback)NULL);
NSRegisterSyncCb((NSProviderSyncInfoCallback)NULL);
+ NSUnRegisterResource();
+ NSDeinitProviderInfo();
NSStopScheduler();
NSDeinitailize();
NSResult NSProviderEnableRemoteService(char *serverAddress)
{
-#if(defined WITH_CLOUD && defined RD_CLIENT)
+#if (defined WITH_CLOUD)
NS_LOG(DEBUG, "NSProviderEnableRemoteService - IN");
pthread_mutex_lock(&nsInitMutex);
- if(!initProvider || !serverAddress)
+ if (!initProvider || !serverAddress)
{
NS_LOG(DEBUG, "Provider service has not been started yet");
pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
- NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress);
+
+ NS_LOG_V(INFO_PRIVATE, "Remote server address: %s", serverAddress);
NS_LOG(DEBUG, "Request to publish resource");
NSPushQueue(DISCOVERY_SCHEDULER, TASK_PUBLISH_RESOURCE, serverAddress);
#else
(void) serverAddress;
#endif
- NS_LOG_V(DEBUG, "Not logged in remote server: %s", serverAddress);
+ NS_LOG_V(INFO_PRIVATE, "Not logged in remote server: %s", serverAddress);
return NS_FAIL;
}
NSResult NSProviderDisableRemoteService(char *serverAddress)
{
-#if(defined WITH_CLOUD && defined RD_CLIENT)
+#if (defined WITH_CLOUD)
NS_LOG(DEBUG, "NSProviderDisableRemoteService - IN");
pthread_mutex_lock(&nsInitMutex);
- if(!initProvider || !serverAddress)
+ if (!initProvider || !serverAddress)
{
NS_LOG(DEBUG, "Provider service has not been started yet");
+ pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
- NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress);
+
+ NS_LOG_V(INFO_PRIVATE, "Remote server address: %s", serverAddress);
NS_LOG(DEBUG, "Delete remote server info");
NSDeleteRemoteServerAddress(serverAddress);
#else
(void) serverAddress;
#endif
- NS_LOG_V(DEBUG, "Not logged in remote server : %s", serverAddress);
+ NS_LOG_V(INFO_PRIVATE, "Not logged in remote server : %s", serverAddress);
return NS_FAIL;
}
+#ifdef WITH_MQ
+NSResult NSProviderSubscribeMQService(const char * serverAddress, const char * topicName)
+{
+ NS_LOG(DEBUG, "NSProviderSubscribeMQService - IN");
+ pthread_mutex_lock(&nsInitMutex);
+
+ if (!initProvider || !serverAddress || !topicName)
+ {
+ NS_LOG(DEBUG, "Provider service has not been started yet or set the server "
+ "address and topicName");
+ pthread_mutex_unlock(&nsInitMutex);
+ return NS_FAIL;
+ }
+
+ NSMQTopicAddress * topicAddr = (NSMQTopicAddress *)OICMalloc(sizeof(NSMQTopicAddress));
+
+ if (!topicAddr)
+ {
+ NS_LOG(DEBUG, "fail to memory allocate");
+ pthread_mutex_unlock(&nsInitMutex);
+ return NS_FAIL;
+ }
+
+ topicAddr->serverAddr = NSGetQueryAddress(serverAddress);
+ topicAddr->topicName = OICStrdup(topicName);
+
+ NS_LOG_V(DEBUG, "input Topic Name : %s", topicAddr->topicName);
+
+ NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_MQ_REQ_SUBSCRIBE, (void *) topicAddr);
+
+ pthread_mutex_unlock(&nsInitMutex);
+ NS_LOG(DEBUG, "NSProviderSubscribeMQService - OUT");
+ return NS_OK;
+}
+#endif
+
NSResult NSSendMessage(NSMessage * msg)
{
NS_LOG(DEBUG, "NSSendNotification - IN");
if (!initProvider || !syncInfo)
{
NS_LOG(ERROR, "Provider is not started");
+ NSOICFree(syncInfo);
pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
}
char * newConsumerId = OICStrdup(consumerId);
- if(accepted)
+ if (accepted)
{
NS_LOG(DEBUG, "accepted is true - ALLOW");
NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_ALLOW, newConsumerId);
NSPushQueue(TOPIC_SCHEDULER, TAST_GET_CONSUMER_TOPICS, &topicSync);
pthread_cond_wait(topicSync.condition, &nsInitMutex);
- OICFree(topicSync.consumerId);
+ NSOICFree(topicSync.consumerId);
pthread_mutex_unlock(&nsInitMutex);
NS_LOG(DEBUG, "NSProviderGetConsumerTopics - OUT");
}
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;
NSPushQueue(TOPIC_SCHEDULER, TASK_UNREGISTER_TOPIC, &topicSyncResult);
pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
- if(topicSyncResult.result != NS_OK)
+ if (topicSyncResult.result != NS_OK)
{
pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
- OICFree(topicSyncResult.topicName);
+ NSOICFree(topicSyncResult.topicData);
pthread_mutex_unlock(&nsInitMutex);
NS_LOG(DEBUG, "NSProviderDeleteTopics - OUT");
NSCacheTopicSubData * topicSubData =
(NSCacheTopicSubData *) OICMalloc(sizeof(NSCacheTopicSubData));
- if(!initProvider || !consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0'
+ if (!initProvider || !consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0'
|| !NSGetPolicy() || !topicSubData)
{
NS_LOG(DEBUG, "provider is not started or "
"consumer id should be set for topic subscription or "
"Configuration must set to true.");
+ NSOICFree(topicSubData);
+ topicSubData = NULL;
pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
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)
NSCacheTopicSubData * topicSubData =
(NSCacheTopicSubData *) OICMalloc(sizeof(NSCacheTopicSubData));
- if(!initProvider || !consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0'
+ if (!initProvider || !consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0'
|| !NSGetPolicy() || !topicSubData)
{
NS_LOG(DEBUG, "provider is not started or "
"consumer id should be set for topic subscription or "
"Configuration must set to true.");
+ NSOICFree(topicSubData);
+ topicSubData = NULL;
pthread_mutex_unlock(&nsInitMutex);
return NS_FAIL;
}
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;
}