From 9edd4ab2b174ed7ef5165644b043cb1f4b279f88 Mon Sep 17 00:00:00 2001 From: "jaesick.shin" Date: Tue, 19 Jul 2016 13:48:37 +0900 Subject: [PATCH] separated the scheduler interface and added callbackresponse. change NSProviderInterface -> NSProvider Added NSCallbackResponse.h and .c included that file CallbackResponseSchedule instead of interfaceSchedule. second patch included missing header file.wq Change-Id: I7cd263f31be62faf979c1dee131c0afa02125280 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/9455 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/notification/SConscript | 6 +- .../src/main/jni/notificationProvider.h | 3 +- .../examples/linux/notificationprovider.c | 3 +- .../{NSProviderInterface.h => NSProvider.h} | 0 service/notification/src/common/NSConstants.h | 2 +- .../{NSProviderInterface.c => NSProvider.c} | 102 +--------------- .../src/provider/NSProviderCallbackResponse.c | 129 +++++++++++++++++++++ .../src/provider/NSProviderCallbackResponse.h | 37 ++++++ .../src/provider/NSProviderNotification.c | 2 +- .../src/provider/NSProviderScheduler.c | 11 +- .../src/provider/NSProviderScheduler.h | 2 +- .../src/provider/NSProviderSubscription.c | 2 +- service/notification/unittest/NSProviderTest.cpp | 3 +- 13 files changed, 188 insertions(+), 114 deletions(-) rename service/notification/include/{NSProviderInterface.h => NSProvider.h} (100%) rename service/notification/src/provider/{NSProviderInterface.c => NSProvider.c} (64%) create mode 100644 service/notification/src/provider/NSProviderCallbackResponse.c create mode 100644 service/notification/src/provider/NSProviderCallbackResponse.h diff --git a/service/notification/SConscript b/service/notification/SConscript index 75397e0..2da567e 100644 --- a/service/notification/SConscript +++ b/service/notification/SConscript @@ -121,14 +121,14 @@ consumersdk = notification_env.StaticLibrary('notification_consumer', notificati notification_env.InstallTarget(consumersdk, 'libnotification_consumer') notification_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer') -notification_env.UserInstallTargetHeader('include/NSProviderInterface.h',\ - 'service/notification', 'NSProviderInterface.h') +notification_env.UserInstallTargetHeader('include/NSProvider.h',\ + 'service/notification', 'NSProvider.h') notification_env.UserInstallTargetHeader('include/NSConsumerInterface.h',\ 'service/notification', 'NSConsumerInterface.h') # Go to build Unit test # if target_os == 'linux': -# SConscript('unittest/SConscript') +#SConscript('unittest/SConscript') # Go to build sample apps SConscript('examples/SConscript') diff --git a/service/notification/android/notification-service/src/main/jni/notificationProvider.h b/service/notification/android/notification-service/src/main/jni/notificationProvider.h index ffafb5c..9d6a057 100644 --- a/service/notification/android/notification-service/src/main/jni/notificationProvider.h +++ b/service/notification/android/notification-service/src/main/jni/notificationProvider.h @@ -19,7 +19,8 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include -#include "NSProviderInterface.h" + +#include "NSProvider.h" #include "NSCommon.h" #ifndef NOTIFICATION_JNI_H diff --git a/service/notification/examples/linux/notificationprovider.c b/service/notification/examples/linux/notificationprovider.c index 94c06ce..ff7343c 100644 --- a/service/notification/examples/linux/notificationprovider.c +++ b/service/notification/examples/linux/notificationprovider.c @@ -22,8 +22,9 @@ #include #include #include + +#include "NSProvider.h" #include "NSCommon.h" -#include "NSProviderInterface.h" #include "logger.h" #include "octypes.h" #include "pthread.h" diff --git a/service/notification/include/NSProviderInterface.h b/service/notification/include/NSProvider.h similarity index 100% rename from service/notification/include/NSProviderInterface.h rename to service/notification/include/NSProvider.h diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index fc1f04a..9db4b55 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -93,7 +93,7 @@ typedef enum eConnectionState typedef enum eSchedulerType { - INTERFACE_SCHEDULER = 0, + CALLBACK_RESPONSE_SCHEDULER = 0, DISCOVERY_SCHEDULER = 1, SUBSCRIPTION_SCHEDULER = 2, NOTIFICATION_SCHEDULER = 3, diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProvider.c similarity index 64% rename from service/notification/src/provider/NSProviderInterface.c rename to service/notification/src/provider/NSProvider.c index 53baa56..511114e 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProvider.c @@ -18,11 +18,12 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#include "NSProviderInterface.h" +#include "NSProvider.h" #include "NSProviderScheduler.h" #include "NSProviderListener.h" #include "NSProviderSubscription.h" #include "NSProviderNotification.h" +#include "NSProviderCallbackResponse.h" #include "NSStorageAdapter.h" #include "NSProviderMemoryCache.h" #include "oic_malloc.h" @@ -32,8 +33,6 @@ #include "oic_time.h" bool initProvider = false; -static NSSubscribeRequestCallback g_subscribeRequestCb = NULL; -static NSProviderSyncInfoCallback g_syncCb = NULL; pthread_mutex_t nsInitMutex; @@ -43,34 +42,6 @@ void initializeMutex() nsInitMutex = initMutex; } -void NSRegisterSubscribeRequestCb(NSSubscribeRequestCallback subscribeRequestCb) -{ - NS_LOG(DEBUG, "NSRegisterSubscribeRequestCb - IN"); - g_subscribeRequestCb = subscribeRequestCb; - NS_LOG(DEBUG, "NSRegisterSubscribeRequestCb - OUT"); -} - -void NSRegisterSyncCb(NSProviderSyncInfoCallback syncCb) -{ - NS_LOG(DEBUG, "NSRegisterSyncCb - IN"); - g_syncCb = syncCb; - NS_LOG(DEBUG, "NSRegisterSyncCb - OUT"); -} - -void NSSubscribeRequestCb(NSConsumer *consumer) -{ - NS_LOG(DEBUG, "NSSubscribeRequestCb - IN"); - g_subscribeRequestCb(consumer); - NS_LOG(DEBUG, "NSSubscribeRequestCb - OUT"); -} - -void NSSyncCb(NSSyncInfo *sync) -{ - NS_LOG(DEBUG, "NSSyncCb - IN"); - g_syncCb(sync); - NS_LOG(DEBUG, "NSSyncCb - OUT"); -} - NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb, NSProviderSyncInfoCallback syncCb) { @@ -88,8 +59,8 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc NSSetSubscriptionAccessPolicy(policy); NSRegisterSubscribeRequestCb(subscribeRequestCb); NSRegisterSyncCb(syncCb); - CARegisterNetworkMonitorHandler(NSProviderAdapterStateListener, - NSProviderConnectionStateListener); + CARegisterNetworkMonitorHandler((CAAdapterStateChangedCB)NSProviderAdapterStateListener, + (CAConnectionStateChangedCB)NSProviderConnectionStateListener); NSSetList(); NSInitScheduler(); @@ -152,8 +123,6 @@ NSResult NSProviderEnableRemoteService(char *serverAddress) } NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress); - NSSetRemoteServerAddress(serverAddress); - NSPushQueue(DISCOVERY_SCHEDULER, TASK_PUBLISH_RESOURCE, serverAddress); pthread_mutex_unlock(&nsInitMutex); @@ -172,7 +141,6 @@ NSResult NSProviderDisableRemoteService(char *serverAddress) return NS_FAIL; } NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress); - NSDeleteRemoteServerAddress(serverAddress); pthread_mutex_unlock(&nsInitMutex); NS_LOG(DEBUG, "NSProviderDisableRemoteService - OUT"); @@ -253,65 +221,3 @@ NSMessage * NSCreateMessage() NS_LOG(DEBUG, "NSCreateMessage - OUT"); return msg; } - -void * NSInterfaceSchedule(void * ptr) -{ - if (ptr == NULL) - { - NS_LOG(DEBUG, "Create NSReponseSchedule"); - } - - while (NSIsRunning[INTERFACE_SCHEDULER]) - { - sem_wait(&NSSemaphore[INTERFACE_SCHEDULER]); - pthread_mutex_lock(&NSMutex[INTERFACE_SCHEDULER]); - - if (NSHeadMsg[INTERFACE_SCHEDULER] != NULL) - { - NSTask *node = NSHeadMsg[INTERFACE_SCHEDULER]; - NSHeadMsg[INTERFACE_SCHEDULER] = node->nextTask; - - switch (node->taskType) - { - case TASK_CB_SUBSCRIPTION: - { - NS_LOG(DEBUG, "CASE TASK_CB_SUBSCRIPTION : "); - - OCEntityHandlerRequest * request = (OCEntityHandlerRequest*)node->taskData; - NSConsumer * consumer = (NSConsumer *)OICMalloc(sizeof(NSConsumer)); - - char * consumerId = NSGetValueFromQuery(OICStrdup(request->query), - NS_QUERY_CONSUMER_ID); - - if(consumerId) - { - OICStrcpy(consumer->consumerId, UUID_STRING_SIZE, consumerId); - NSSubscribeRequestCb(consumer); - } - - NSFreeConsumer(consumer); - NSFreeOCEntityHandlerRequest(request); - - break; - } - case TASK_CB_SYNC: - { - NS_LOG(DEBUG, "CASE TASK_CB_SYNC : "); - NSSyncInfo * sync = (NSSyncInfo*)node->taskData; - NSSyncCb(NSDuplicateSync(sync)); - NSFreeSync(sync); - break; - } - default: - NS_LOG(DEBUG, "No Task Type"); - break; - } - OICFree(node); - } - - pthread_mutex_unlock(&NSMutex[INTERFACE_SCHEDULER]); - } - - NS_LOG(DEBUG, "Destroy NSResponseSchedule"); - return NULL; -} diff --git a/service/notification/src/provider/NSProviderCallbackResponse.c b/service/notification/src/provider/NSProviderCallbackResponse.c new file mode 100644 index 0000000..d92afd6 --- /dev/null +++ b/service/notification/src/provider/NSProviderCallbackResponse.c @@ -0,0 +1,129 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include "NSProvider.h" +#include "NSProviderScheduler.h" +#include "NSProviderListener.h" +#include "NSProviderSubscription.h" +#include "NSProviderNotification.h" +#include "NSStorageAdapter.h" +#include "NSProviderMemoryCache.h" +#include "NSProviderCallbackResponse.h" +#include "oic_malloc.h" +#include "oic_string.h" +#include "cautilinterface.h" +#include "NSProviderSystem.h" +#include "oic_time.h" + +static NSSubscribeRequestCallback g_subscribeRequestCb = NULL; +static NSProviderSyncInfoCallback g_syncCb = NULL; + +pthread_mutex_t nsInitMutex; + +void NSRegisterSubscribeRequestCb(NSSubscribeRequestCallback subscribeRequestCb) +{ + NS_LOG(DEBUG, "NSRegisterSubscribeRequestCb - IN"); + g_subscribeRequestCb = subscribeRequestCb; + NS_LOG(DEBUG, "NSRegisterSubscribeRequestCb - OUT"); +} + +void NSRegisterSyncCb(NSProviderSyncInfoCallback syncCb) +{ + NS_LOG(DEBUG, "NSRegisterSyncCb - IN"); + g_syncCb = syncCb; + NS_LOG(DEBUG, "NSRegisterSyncCb - OUT"); +} + +void NSSubscribeRequestCb(NSConsumer *consumer) +{ + NS_LOG(DEBUG, "NSSubscribeRequestCb - IN"); + g_subscribeRequestCb(consumer); + NS_LOG(DEBUG, "NSSubscribeRequestCb - OUT"); +} + +void NSSyncCb(NSSyncInfo *sync) +{ + NS_LOG(DEBUG, "NSSyncCb - IN"); + g_syncCb(sync); + NS_LOG(DEBUG, "NSSyncCb - OUT"); +} + +void * NSCallbackResponseSchedule(void * ptr) +{ + if (ptr == NULL) + { + NS_LOG(DEBUG, "Create NSReponseSchedule"); + } + + while (NSIsRunning[CALLBACK_RESPONSE_SCHEDULER]) + { + sem_wait(&NSSemaphore[CALLBACK_RESPONSE_SCHEDULER]); + pthread_mutex_lock(&NSMutex[CALLBACK_RESPONSE_SCHEDULER]); + + if (NSHeadMsg[CALLBACK_RESPONSE_SCHEDULER] != NULL) + { + NSTask *node = NSHeadMsg[CALLBACK_RESPONSE_SCHEDULER]; + NSHeadMsg[CALLBACK_RESPONSE_SCHEDULER] = node->nextTask; + + switch (node->taskType) + { + case TASK_CB_SUBSCRIPTION: + { + NS_LOG(DEBUG, "CASE TASK_CB_SUBSCRIPTION : "); + + OCEntityHandlerRequest * request = (OCEntityHandlerRequest*)node->taskData; + NSConsumer * consumer = (NSConsumer *)OICMalloc(sizeof(NSConsumer)); + + char * consumerId = NSGetValueFromQuery(OICStrdup(request->query), + NS_QUERY_CONSUMER_ID); + + if(consumerId) + { + OICStrcpy(consumer->consumerId, UUID_STRING_SIZE, consumerId); + NSSubscribeRequestCb(consumer); + } + + NSFreeConsumer(consumer); + NSFreeOCEntityHandlerRequest(request); + + break; + } + case TASK_CB_SYNC: + { + NS_LOG(DEBUG, "CASE TASK_CB_SYNC : "); + NSSyncInfo * sync = (NSSyncInfo*)node->taskData; + NSSyncCb(NSDuplicateSync(sync)); + NSFreeSync(sync); + break; + } + default: + NS_LOG(DEBUG, "No Task Type"); + break; + } + OICFree(node); + } + + pthread_mutex_unlock(&NSMutex[CALLBACK_RESPONSE_SCHEDULER]); + } + + NS_LOG(DEBUG, "Destroy NSResponseSchedule"); + return NULL; +} + diff --git a/service/notification/src/provider/NSProviderCallbackResponse.h b/service/notification/src/provider/NSProviderCallbackResponse.h new file mode 100644 index 0000000..d0d8275 --- /dev/null +++ b/service/notification/src/provider/NSProviderCallbackResponse.h @@ -0,0 +1,37 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#ifndef _NS_PROVIDER_CALLBACK_RESPONSE__H_ +#define _NS_PROVIDER_CALLBACK_RESPONSE__H_ + +#include +#include "logger.h" +#include "NSCommon.h" +#include "NSConstants.h" +#include "oic_malloc.h" +#include "NSStructs.h" +#include "NSUtil.h" + +void NSRegisterSubscribeRequestCb(NSSubscribeRequestCallback subscribeRequestCb); +void NSRegisterSyncCb(NSProviderSyncInfoCallback syncCb); +void NSSubscribeRequestCb(NSConsumer *consumer); +void NSSyncCb(NSSyncInfo *sync); + +#endif /* _NS_PROVIDER_CALLBACK_RESPONSE__H_ */ diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index a2a60f1..cc1e792 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -266,7 +266,7 @@ void * NSNotificationSchedule(void *ptr) case TASK_RECV_READ: NS_LOG(DEBUG, "CASE TASK_RECV_READ : "); NSSendSync((NSSyncInfo*) node->taskData); - NSPushQueue(INTERFACE_SCHEDULER, TASK_CB_SYNC, node->taskData); + NSPushQueue(CALLBACK_RESPONSE_SCHEDULER, TASK_CB_SYNC, node->taskData); break; default: diff --git a/service/notification/src/provider/NSProviderScheduler.c b/service/notification/src/provider/NSProviderScheduler.c index 072866c..9e9173f 100755 --- a/service/notification/src/provider/NSProviderScheduler.c +++ b/service/notification/src/provider/NSProviderScheduler.c @@ -23,13 +23,12 @@ pthread_t NSThread[THREAD_COUNT]; pthread_mutex_t NSMutex[THREAD_COUNT]; sem_t NSSemaphore[THREAD_COUNT]; -bool NSIsRunning[THREAD_COUNT] = -{ false, }; +bool NSIsRunning[THREAD_COUNT] = { false, }; NSTask* NSHeadMsg[THREAD_COUNT]; NSTask* NSTailMsg[THREAD_COUNT]; -void * NSInterfaceSchedule(void *ptr); +void * NSCallbackResponseSchedule(void *ptr); void * NSDiscoverySchedule(void *ptr); void * NSSubScriptionSchedule(void *ptr); void * NSNotificationSchedule(void *ptr); @@ -62,10 +61,10 @@ bool NSStartScheduler() switch (i) { - case INTERFACE_SCHEDULER: + case CALLBACK_RESPONSE_SCHEDULER: { NS_LOG(DEBUG, "CASE RESPONSE_SCHEDULER :"); - pthread_create(&NSThread[i], NULL, NSInterfaceSchedule, NULL); + pthread_create(&NSThread[i], NULL, NSCallbackResponseSchedule, NULL); } break; @@ -184,7 +183,7 @@ void NSFreeData(NSSchedulerType type, NSTask * task) { NS_LOG(DEBUG, "NSFreeData - IN"); - if (type == INTERFACE_SCHEDULER) + if (type == CALLBACK_RESPONSE_SCHEDULER) { switch (task->taskType) { diff --git a/service/notification/src/provider/NSProviderScheduler.h b/service/notification/src/provider/NSProviderScheduler.h index 961e193..cd3b7a9 100755 --- a/service/notification/src/provider/NSProviderScheduler.h +++ b/service/notification/src/provider/NSProviderScheduler.h @@ -42,7 +42,7 @@ extern pthread_mutex_t NSMutex[THREAD_COUNT]; extern sem_t NSSemaphore[THREAD_COUNT]; extern bool NSIsRunning[THREAD_COUNT]; -extern void * NSResponseSchedule(void *ptr); +extern void * NSCallbackResponseSchedule(void *ptr); extern void * NSDiscoverySchedule(void *ptr); extern void * NSSubScriptionSchedule(void *ptr); extern void * NSNotificationSchedule(void *ptr); diff --git a/service/notification/src/provider/NSProviderSubscription.c b/service/notification/src/provider/NSProviderSubscription.c index 361a2e8..91f0325 100644 --- a/service/notification/src/provider/NSProviderSubscription.c +++ b/service/notification/src/provider/NSProviderSubscription.c @@ -245,7 +245,7 @@ void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest) { NS_LOG(DEBUG, "NSAskAcceptanceToUser - IN"); - NSPushQueue(INTERFACE_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest); + NSPushQueue(CALLBACK_RESPONSE_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest); NS_LOG(DEBUG, "NSAskAcceptanceToUser - OUT"); } diff --git a/service/notification/unittest/NSProviderTest.cpp b/service/notification/unittest/NSProviderTest.cpp index 41c7fab..782bbc5 100644 --- a/service/notification/unittest/NSProviderTest.cpp +++ b/service/notification/unittest/NSProviderTest.cpp @@ -18,6 +18,8 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "../include/NSProvider.h" + #include #include #include @@ -29,7 +31,6 @@ #include "NSConsumerSimulator.h" #include "NSCommon.h" -#include "NSProviderInterface.h" namespace { -- 2.7.4