Fix bug for callback as seperated thread. 93/11493/4
authorKIM JungYong <jyong2.kim@samsung.com>
Wed, 7 Sep 2016 06:55:02 +0000 (15:55 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 8 Sep 2016 07:55:58 +0000 (07:55 +0000)
Problem: It is degined that consumer service executes
     the registered callback function in different thread
But, the registered callback function for ProviderChanged event
      is called in same thread.

Fix: Separate the thread for this callback function execution
     from main thread

Change-Id: Ic4c9edce1c058a7e04aa7a38fad8f66f2e586d3d
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11493
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/consumer/NSConsumerCommon.c

index bc80124..13524bc 100644 (file)
@@ -117,9 +117,36 @@ void NSSetProviderChangedCb(NSProviderStateCallback cb)
     *(NSGetProviderChangedCb()) = cb;
 }
 
+typedef struct
+{
+    NSProvider * provider;
+    NSProviderState state;
+} NSProviderChangedData;
+
+void * NSProviderChangedFunc(void * obj)
+{
+    NSProviderChangedData * data = (NSProviderChangedData *) obj;
+    (*(NSGetProviderChangedCb()))(data->provider, data->state);
+    NSOICFree(data);
+    return NULL;
+}
+
 void NSProviderChanged(NSProvider * provider, NSProviderState response)
 {
-    (*(NSGetProviderChangedCb()))(provider, response);
+    NS_VERIFY_NOT_NULL_V(provider);
+
+    NSProvider * retProvider = NSCopyProvider((NSProvider_internal *) provider);
+    NS_VERIFY_NOT_NULL_V(retProvider);
+
+    NSProviderChangedData * data =
+            (NSProviderChangedData *)OICMalloc(sizeof(NSProviderChangedData));
+    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(data, NSRemoveProvider(retProvider));
+
+    data->provider = retProvider;
+    data->state = response;
+
+    NSConsumerThread * thread = NSThreadInit(NSProviderChangedFunc, (void *) data);
+    NS_VERIFY_NOT_NULL_V(thread);
 }
 
 NSSyncInfoReceivedCallback * NSGetBoneNotificationSyncCb()