From fcb8ca269fa8fcf181e4dca0ede150e3c2e5fdcf Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Wed, 7 Sep 2016 15:55:02 +0900 Subject: [PATCH] Fix bug for callback as seperated thread. 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/11493 Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../notification/src/consumer/NSConsumerCommon.c | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/service/notification/src/consumer/NSConsumerCommon.c b/service/notification/src/consumer/NSConsumerCommon.c index bc80124..13524bc 100644 --- a/service/notification/src/consumer/NSConsumerCommon.c +++ b/service/notification/src/consumer/NSConsumerCommon.c @@ -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() -- 2.7.4