[IOT-1558] Add notification provider for windows. 31/15931/9
authorKIM JungYong <jyong2.kim@samsung.com>
Fri, 23 Dec 2016 08:44:56 +0000 (17:44 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 30 Dec 2016 06:49:46 +0000 (06:49 +0000)
Building of notification provider service is enabled for windows.
And sample application building is enabled for windows.

Improvement:https://jira.iotivity.org/browse/IOT-1558
Change-Id: I3069982e3b25d789edc4e5394c44f9cc6926091c
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15931
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
22 files changed:
service/notification/SConscript
service/notification/examples/SConscript
service/notification/examples/linux/SConscript
service/notification/examples/linux/notificationconsumer.c
service/notification/examples/linux/notificationprovider.c
service/notification/examples/windows/SConscript [deleted file]
service/notification/examples/windows/notificationconsumer.c [deleted file]
service/notification/src/common/NSConstants.h
service/notification/src/consumer/NSConsumerScheduler.c
service/notification/src/provider/NSProviderCallbackResponse.c
service/notification/src/provider/NSProviderDiscovery.c
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderMemoryCache.c
service/notification/src/provider/NSProviderMemoryCache.h
service/notification/src/provider/NSProviderNotification.c
service/notification/src/provider/NSProviderScheduler.c
service/notification/src/provider/NSProviderScheduler.h
service/notification/src/provider/NSProviderSubscription.c
service/notification/src/provider/NSProviderTopic.c
service/notification/src/provider/NSProviderTopic.h
service/notification/src/provider/NSSemaphore_windows.c [new file with mode: 0644]
service/notification/src/provider/NSSemaphore_windows.h [new file with mode: 0644]

index 2e13072..d53608a 100755 (executable)
@@ -116,28 +116,28 @@ notification_consumer_src = [
 notification_consumer_env.UserInstallTargetHeader('include/NSConsumerInterface.h',\
     'service/notification', 'NSConsumerInterface.h')
 
+notification_provider_src = [
+    env.Glob('src/provider/*.c'), env.Glob('src/common/*.c')]
+notification_provider_env.UserInstallTargetHeader('include/NSProviderInterface.h',\
+    'service/notification', 'NSProviderInterface.h')
+
+consumersdk = notification_consumer_env.StaticLibrary('notification_consumer', notification_consumer_src)
+notification_consumer_env.InstallTarget(consumersdk, 'libnotification_consumer')
+notification_consumer_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer')
+
+providersdk = notification_provider_env.StaticLibrary('notification_provider', notification_provider_src)
+notification_provider_env.InstallTarget(providersdk, 'libnotification_provider')
+notification_provider_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
+
 if target_os not in ['windows', 'winrt', 'msys_nt']:
-    notification_provider_src = [
-        env.Glob('src/provider/*.c'), env.Glob('src/common/*.c')]
-    notification_provider_env.UserInstallTargetHeader('include/NSProviderInterface.h',\
-        'service/notification', 'NSProviderInterface.h')
-        
     providersdk = notification_provider_env.SharedLibrary('notification_provider', notification_provider_src)
     notification_provider_env.InstallTarget(providersdk, 'libnotification_provider')
     notification_provider_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
-    
-    providersdk = notification_provider_env.StaticLibrary('notification_provider', notification_provider_src)
-    notification_provider_env.InstallTarget(providersdk, 'libnotification_provider')
-    notification_provider_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
 
     consumersdk = notification_consumer_env.SharedLibrary('notification_consumer', notification_consumer_src)
     notification_consumer_env.InstallTarget(consumersdk, 'libnotification_consumer')
     notification_consumer_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer')
 
-consumersdk = notification_consumer_env.StaticLibrary('notification_consumer', notification_consumer_src)
-notification_consumer_env.InstallTarget(consumersdk, 'libnotification_consumer')
-notification_consumer_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer')
-
 # Go to build Unit test
 if target_os == 'linux':
     SConscript('unittest/SConscript')
index 5da73de..c9d00b9 100644 (file)
@@ -4,9 +4,7 @@
 Import('env')
 
 target_os = env.get('TARGET_OS')
-if target_os == 'linux':
+if target_os in ['linux', 'windows', 'winrt', 'msys_nt']:
     SConscript('linux/SConscript')
 elif target_os == 'android':
     SConscript('android/SConscript')
-elif target_os == 'windows':
-    SConscript('windows/SConscript')
\ No newline at end of file
index 1368366..2df59a0 100644 (file)
@@ -20,50 +20,51 @@ notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/resou
 notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/connectivity/api'])
 
 notification_sample_env.PrependUnique(LIBS = [
-       'octbstack',
-       'oc_logger',
-       'connectivity_abstraction',
-       'libcoap'
-       ])
-
+    'oc_logger',
+    'connectivity_abstraction',
+    'coap'
+    ])
+    
 if target_os not in ['windows', 'winrt']:
-       notification_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+    notification_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
 
 if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
-       notification_sample_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
+    notification_sample_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
 
 if target_os == 'linux':
-       notification_sample_env.AppendUnique(LIBS = ['pthread'])
+    notification_sample_env.AppendUnique(LIBS = ['pthread'])
 
 if target_os == 'android':
-       notification_sample_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       notification_sample_env.AppendUnique(LIBS = ['gnustl_shared','log'])
-
-       if not env.get('RELEASE'):
-               notification_sample_env.AppendUnique(LIBS = ['log'])
-
-notification_sample_consumer_src = 'notificationconsumer.c'
-notification_sample_provider_src = 'notificationprovider.c'
+    notification_sample_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+    notification_sample_env.AppendUnique(LIBS = ['gnustl_shared','log'])
+
+    if not env.get('RELEASE'):
+        notification_sample_env.AppendUnique(LIBS = ['log'])
+        
+if target_os in ['windows', 'winrt']:
+    notification_sample_env.AppendUnique(CPPDEFINES = ['SYSTEM_WINDOWS'])
+    notification_sample_env.PrependUnique(LIBS = ['mswsock', 'ws2_32', 'iphlpapi', 'ole32', 'bcrypt', 'Crypt32'])
+    notification_sample_env.PrependUnique(LIBS = ['octbstack_static', 'ocsrm'])
+else:
+    notification_sample_env.PrependUnique(LIBS = ['octbstack'])
 
 if env.get('WITH_CLOUD') == True:
-       notification_sample_env.AppendUnique(CPPPATH = ['../../src/consumer'])
-        notification_sample_env.AppendUnique(CPPPATH = ['../../src/provider'])
-       notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+    notification_sample_env.AppendUnique(CPPPATH = ['../../src/consumer'])
+    notification_sample_env.AppendUnique(CPPPATH = ['../../src/provider'])
+    notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
-        providerCloudConnectorObj = notification_sample_env.Object('cloud_connector.c')
-        consumerCloudConnectorObj = notification_sample_env.Object('cloud_connector.c')
+    cloudConnectorObj = notification_sample_env.Object('cloud_connector.c')
 
-        #PROVIDER_CLOUD = File('cloud_connector.c')
-        #notification_sample_provider_src = ['notificationprovider.c', PROVIDER_CLOUD]
-        notification_sample_provider_src = ['notificationprovider.c', providerCloudConnectorObj]
-       #CONSUMER_CLOUD = File('cloud_connector.c')
-       #notification_sample_consumer_src = ['notificationconsumer.c', CONSUMER_CLOUD]
-        notification_sample_consumer_src = ['notificationconsumer.c', consumerCloudConnectorObj]
+    notification_sample_consumer_src = ['notificationconsumer.c', cloudConnectorObj]
+    notification_sample_provider_src = ['notificationprovider.c', cloudConnectorObj]
+else:
+    notification_sample_consumer_src = 'notificationconsumer.c'
+    notification_sample_provider_src = 'notificationprovider.c'
 
 if env.get('WITH_TCP') == True:
-       notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
-       if env.get('SECURED') == '1':
-               notification_sample_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
+    notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
+if env.get('SECURED') == '1':
+    notification_sample_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
 
 with_mq = env.get('WITH_MQ')
 if 'SUB' in with_mq:
@@ -82,15 +83,14 @@ if 'BROKER' in with_mq:
 # Source files and Targets
 ######################################################################
 notification_sample_provider_env = notification_sample_env.Clone()
-notification_sample_provider_env.AppendUnique(LIBS = 'libnotification_provider')
+notification_sample_provider_env.AppendUnique(LIBS = 'notification_provider')
 notificationprovider = notification_sample_provider_env.Program('notificationprovider', notification_sample_provider_src)
 i_notificationprovider = notification_sample_provider_env.Install(env.get('BUILD_DIR'), notificationprovider)
 
 notification_sample_consumer_env = notification_sample_env.Clone()
-notification_sample_consumer_env.AppendUnique(LIBS = 'libnotification_consumer')
+notification_sample_consumer_env.AppendUnique(LIBS = 'notification_consumer')
 notificationconsumer = notification_sample_consumer_env.Program('notificationconsumer', notification_sample_consumer_src)
 i_notificationprovider = notification_sample_consumer_env.Install(env.get('BUILD_DIR'), notificationconsumer)
 
 if env.get('WITH_CLOUD') == True:
-        Export('providerCloudConnectorObj')
-        Export('consumerCloudConnectorObj')
+        Export('cloudConnectorObj')
index 8c14cd3..b26c648 100644 (file)
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include <stdio.h>
-#include <unistd.h>
 #include <string.h>
-#include "pthread.h"
+#include "octhread.h"
 
 #include "ocstack.h"
 #include "NSCommon.h"
 #include "NSConsumerInterface.h"
 
+#ifdef SYSTEM_WINDOWS
+#include "win_sleep.h"
+#else
+#include <unistd.h>
+#endif
+
 #ifdef WITH_CLOUD
 #include "NSConstants.h"
 #include "oic_malloc.h"
@@ -49,7 +54,7 @@ NSTopicLL * g_topicLL = NULL;
 FILE* server_fopen(const char *path, const char *mode)
 {
     (void)path;
-    return fopen("oic_ns_provider_db.dat", mode);
+    return fopen("oic_ns_consumer_db.dat", mode);
 }
 
 void printProviderTopicList(NSTopicLL * topics)
@@ -137,7 +142,7 @@ void input(char * buffer)
 int main(void)
 {
     bool isExit = false;
-    pthread_t OCThread = NULL;
+    oc_thread OCThread = NULL;
 
     printf("start Iotivity\n");
 
@@ -156,7 +161,8 @@ int main(void)
     cfg.messageCb = onNotificationPosted;
     cfg.syncInfoCb = onNotificationSync;
 
-    pthread_create(&OCThread, NULL, OCProcessThread, NULL);
+    OCThreadResult_t ret = oc_thread_new(&OCThread, OCProcessThread, NULL);
+    printf("create thread result : %d\n", ret);
 
     printf("start notification consumer service\n");
     while (!isExit)
index 221013a..e0cf6d0 100644 (file)
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <ctype.h>
 
 #include "NSProviderInterface.h"
 #include "NSCommon.h"
 #include "logger.h"
 #include "octypes.h"
-#include "pthread.h"
+#include "octhread.h"
 #include "oic_string.h"
 #include "oic_malloc.h"
 #include "ocstack.h"
 
+#ifdef SYSTEM_WINDOWS
+#include "win_sleep.h"
+#else
+#include <unistd.h>
+#endif
+
 #define TAG "NSProviderExample"
 
 #ifdef WITH_CLOUD
@@ -155,7 +160,7 @@ void input(char * buffer)
 int main()
 {
     int num;
-    pthread_t processThread;
+    oc_thread processThread;
 
     printf("NSStartProvider()\n\n");
 
@@ -169,7 +174,8 @@ int main()
         return 0;
     }
 
-    pthread_create(&processThread, NULL, OCProcessThread, unlink);
+    OCThreadResult_t ret = oc_thread_new(&processThread, OCProcessThread, unlink);
+    printf("create thread result : %d\n", ret);
 
     while (!isExit)
     {
diff --git a/service/notification/examples/windows/SConscript b/service/notification/examples/windows/SConscript
deleted file mode 100644 (file)
index ee9ebfb..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-##
-# Notification build script
-##
-
-Import('env')
-
-lib_env = env.Clone()
-SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
-notification_sample_env = lib_env.Clone()
-
-target_os = env.get('TARGET_OS')
-rd_mode = env.get('RD_MODE')
-######################################################################
-# Build flags
-######################################################################
-notification_sample_env.AppendUnique(CPPPATH = ['../../include'])
-notification_sample_env.AppendUnique(CPPPATH = ['../../src/common'])
-notification_sample_env.AppendUnique(CPPPATH = ['../../src/provider'])
-notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/stack/include'])
-notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/resource-directory/include'])
-notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/connectivity/api'])
-
-if lib_env.get('SECURED') == '1':
-    notification_sample_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto', 'tinydtls'])
-
-notification_sample_env.PrependUnique(LIBS = [
-       'octbstack_static',
-       'oc_logger',
-       'connectivity_abstraction',
-       'coap',
-       'ocsrm'
-       ])
-
-notification_sample_env.PrependUnique(LIBS = ['mswsock', 'ws2_32', 'iphlpapi', 'ole32', 'bcrypt', 'Crypt32'])
-
-notification_sample_consumer_src = 'notificationconsumer.c'
-
-if env.get('WITH_TCP') == True:
-       notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
-if env.get('SECURED') == '1':
-       notification_sample_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
-
-if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
-       notification_sample_env.AppendUnique(LIBS = ['resource_directory'])
-
-####################################################################
-# Source files and Targets
-######################################################################
-
-notification_sample_consumer_env = notification_sample_env.Clone()
-notification_sample_consumer_env.AppendUnique(LIBS = 'notification_consumer')
-notificationconsumer = notification_sample_consumer_env.Program('notificationconsumer', notification_sample_consumer_src)
-i_notificationconsumer = notification_sample_consumer_env.Install(env.get('BUILD_DIR'), notificationconsumer)
-
diff --git a/service/notification/examples/windows/notificationconsumer.c b/service/notification/examples/windows/notificationconsumer.c
deleted file mode 100644 (file)
index 0c34f3b..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-//******************************************************************
-//
-// 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 <stdio.h>
-#include <string.h>
-#include "octhread.h"
-
-#include "ocstack.h"
-#include "NSCommon.h"
-#include "NSConsumerInterface.h"
-
-#ifdef SYSTEM_WINDOWS
-#include <unistd.h>
-#else
-#include "win_sleep.h"
-#endif
-
-#ifdef WITH_CLOUD
-#include "NSConstants.h"
-#include "oic_malloc.h"
-#include "cloud_connector.h"
-
-#define CLOUD_CONTEXT_VALUE 0x99
-
-char CLOUD_ADDRESS[100];
-char CLOUD_AUTH_PROVIDER[100];
-char CLOUD_AUTH_CODE[100];
-char CLOUD_UID[100];
-char CLOUD_ACCESS_TOKEN[100];
-#endif
-
-
-NSProvider * g_provider = NULL;
-NSTopicLL * g_topicLL = NULL;
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-    (void)path;
-    return fopen("oic_ns_provider_db.dat", mode);
-}
-
-void printProviderTopicList(NSTopicLL * topics)
-{
-    printf("printProviderTopicList\n");
-    if (topics)
-    {
-        NSTopicLL * iter = topics;
-        while (iter)
-        {
-            printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
-            iter = iter->next;
-        }
-    }
-}
-
-void onProviderChanged(NSProvider * provider, NSProviderState response)
-{
-    printf("Provider changed: %d\n", response);
-    printf("subscribed provider Id : %s\n", provider->providerId);
-
-    if (response == NS_DISCOVERED)
-    {
-        printf("notification resource discovered\n");
-        printf("subscribe result %d\n", NSSubscribe(provider->providerId));
-        printf("startSubscribing\n");
-    }
-
-    else if (response == NS_TOPIC)
-    {
-        printf ("Provider Topic Updated\n");
-        g_topicLL = NSConsumerGetTopicList(provider->providerId);
-        printProviderTopicList(g_topicLL);
-        g_provider = provider;
-    }
-}
-
-void onNotificationPosted(NSMessage * notification)
-{
-    printf("id : %lld\n", (long long int)notification->messageId);
-    printf("title : %s\n", notification->title);
-    printf("content : %s\n", notification->contentText);
-    printf("source : %s\n", notification->sourceName);
-    if (notification->topic && strlen(notification->topic) > 0)
-    {
-        printf("topic : %s\n", notification->topic);
-    }
-    NSConsumerSendSyncInfo(notification->providerId, notification->messageId, NS_SYNC_READ);
-}
-
-void onNotificationSync(NSSyncInfo * sync)
-{
-    printf("Sync ID : %lld\n", (long long int)sync->messageId);
-    printf("Sync STATE : %d\n", sync->state);
-}
-
-void* OCProcessThread(void * ptr)
-{
-    (void) ptr;
-
-    while (true)
-    {
-        if(OCProcess() != OC_STACK_OK)
-        {
-            OCStop();
-            break;
-        }
-    }
-
-    return NULL;
-}
-
-void input(char * buffer)
-{
-    char ch;
-    int i = 0;
-
-    while( (ch = getchar()) != '\n' && i < 100)
-        buffer[i++] = ch;
-
-    buffer[i] = '\0';
-}
-
-int main(void)
-{
-    bool isExit = false;
-    oc_thread OCThread = NULL;
-
-    printf("start Iotivity\n");
-
-    // open oic_db
-    static OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink};
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit1(OC_CLIENT_SERVER, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
-    {
-        printf("OCInit fail\n");
-        return 0;
-    }
-
-    NSConsumerConfig cfg;
-    cfg.changedCb = onProviderChanged;
-    cfg.messageCb = onNotificationPosted;
-    cfg.syncInfoCb = onNotificationSync;
-
-    OCThreadResult_t ret = oc_thread_new(&OCThread, OCProcessThread, NULL);
-    printf("create thread result : %d\n", ret);
-
-    printf("start notification consumer service\n");
-    while (!isExit)
-    {
-        int num = 0;
-        char dummy = '\0';
-
-        printf("1. Start Consumer\n");
-        printf("2. Stop Consumer\n");
-        printf("3. Get Topics\n");
-        printf("4. Select Topics\n");
-        printf("5. Cancel select Topics\n");
-        printf("0. Exit\n");
-#ifdef WITH_CLOUD
-        printf("21. Enable Remote Service (after login)\n");
-        printf("31. Cloud Signup\n");
-        printf("32. Cloud Login\n");
-        printf("33. Cloud Logout\n");
-#endif
-
-        printf("Input: ");
-
-        if(scanf("%d", &num) == EOF)
-        {
-            printf("Fail to input num\n");
-        }
-        fflush(stdin);
-
-        if(scanf("%c", &dummy) == EOF)
-        {
-            printf("Fail to input dummy\n");
-        }
-        fflush(stdin);
-
-        switch (num)
-        {
-            case 1:
-                printf("1. Start Consumer\n");
-                NSStartConsumer(cfg);
-                break;
-            case 2:
-                printf("2. Stop Consumer");
-                NSStopConsumer();
-                break;
-            case 3:
-                printf("3. Get Topics\n");
-                if(g_provider)
-                {
-                    g_topicLL = NSConsumerGetTopicList(g_provider->providerId);
-                    printProviderTopicList(g_topicLL);
-                }
-                break;
-            case 4:
-                printf("4. Select Topics\n");
-
-                if (g_provider && g_topicLL)
-                {
-                    NSTopicLL * iter = g_topicLL;
-                    int i = 0;
-                    while (iter)
-                    {
-                        iter->state = (i++)%2;
-                        iter = iter->next;
-                    }
-                    NSResult ret = NSConsumerUpdateTopicList(g_provider->providerId, g_topicLL);
-                    if (ret == NS_OK)
-                    {
-                        printProviderTopicList(g_topicLL);
-                    }
-                    else
-                    {
-                        printf("Update fail\n");
-                    }
-                }
-                break;
-            case 5:
-                printf("5. Cancel select Topics\n");
-                NSTopicLL * iter = g_topicLL;
-                while (iter)
-                {
-                    iter->state = NS_TOPIC_UNSUBSCRIBED;
-                    iter = iter->next;
-                }
-
-                NSResult ret = NSConsumerUpdateTopicList(g_provider->providerId, g_topicLL);
-                if (ret != NS_OK)
-                {
-                    printf("Cancel select topic fail\n");
-                }
-                break;
-            case 0:
-                printf("0. Exit");
-                isExit = true;
-                break;
-#ifdef WITH_CLOUD
-            case 21:
-                printf("Enable Remote Service");
-                if(!IsCloudLoggedin())
-                {
-                    printf("Cloud Login required");
-                    break;
-                }
-                NSConsumerEnableRemoteService(CLOUD_ADDRESS);
-                break;
-            case 31:
-                printf("Remote Server Address: ");
-                input(CLOUD_ADDRESS);
-
-                printf("Auth Provider(eg. github): ");
-                input(CLOUD_AUTH_PROVIDER);
-
-                printf("Auth Code: ");
-                input(CLOUD_AUTH_CODE);
-
-                OCCloudSignup(CLOUD_ADDRESS, OCGetServerInstanceIDString(),
-                    CLOUD_AUTH_PROVIDER, CLOUD_AUTH_CODE, CloudSignupCallback);
-                printf("OCCloudSignup requested");
-                break;
-            case 32:
-                printf("Remote Server Address: ");
-                input(CLOUD_ADDRESS);
-
-                printf("UID: ");
-                input(CLOUD_UID);
-
-                printf("ACCESS_TOKEN: ");
-                input(CLOUD_ACCESS_TOKEN);
-
-                OCCloudLogin(CLOUD_ADDRESS, CLOUD_UID, OCGetServerInstanceIDString(),
-                    CLOUD_ACCESS_TOKEN, CloudLoginoutCallback);
-                printf("OCCloudLogin requested");
-                break;
-            case 33:
-                OCCloudLogout(CLOUD_ADDRESS, CloudLoginoutCallback);
-                printf("OCCloudLogin requested");
-                break;
-#endif
-            default:
-                break;
-        }
-    }
-    return 0;
-}
-
index 0175234..a7316d9 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef _NS_CONSTANTS_H_
 #define _NS_CONSTANTS_H_
 
-#define __PRINTLOG 0
+#define __PRINTLOG 1
 #define __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
 
 #include "logger.h"
 #define NS_ATTIRBUTE_MQ_TOPICLIST "topiclist"
 #endif
 
+#ifdef SYSTEM_WINDOWS
+#define NS_FUNCTION __FUNCTION__
+#else
+#define NS_FUNCTION __func__
+#endif
+
 #define NS_VERIFY_NOT_NULL_V(obj) \
     { \
         if ((obj) == NULL) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
+            NS_LOG_V(ERROR, "%s : %s is null", NS_FUNCTION, #obj); \
             return; \
         } \
     }
     { \
         if ((obj) == NULL) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
+            NS_LOG_V(ERROR, "%s : %s is null", NS_FUNCTION, #obj); \
             return (retVal); \
         } \
     }
     { \
         if ((obj) == NULL) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
+            NS_LOG_V(ERROR, "%s : %s is null", NS_FUNCTION, #obj); \
             NS_LOG(ERROR, "execute deletion"); \
             func; \
             return; \
     { \
         if ((obj) == NULL) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
+            NS_LOG_V(ERROR, "%s : %s is null", NS_FUNCTION, #obj); \
             NS_LOG(ERROR, "execute deletion"); \
             func; \
             return (retVal); \
         bool _ret = (obj); \
         if ( _ret != true) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
+            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", NS_FUNCTION, #obj, _ret); \
             return; \
         } \
     }
         bool _ret = (obj); \
         if ( _ret != true) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
+            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", NS_FUNCTION, #obj, _ret); \
             return (retVal); \
         } \
     }
         bool _ret = (obj); \
         if ( _ret != true) \
         { \
-            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
+            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", NS_FUNCTION, #obj, _ret); \
             func; \
             return (retVal); \
         } \
         { \
             OICFree((obj)); \
             (obj) = NULL; \
-            NS_LOG_V(DEBUG, "%s : %s Removed", __func__, #obj); \
+            NS_LOG_V(DEBUG, "%s : %s Removed", NS_FUNCTION, #obj); \
         } \
     }
 
index 049a8d4..9fb9121 100644 (file)
@@ -151,6 +151,7 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
     {
         if (!queue)
         {
+            usleep(2000);
             queue = *(NSGetMsgHandleQueue());
             continue;
         }
index 6c60c04..59a2f38 100644 (file)
 #include "NSProviderCallbackResponse.h"\r
 #include "oic_malloc.h"\r
 #include "oic_string.h"\r
-#include "cautilinterface.h"\r
 #include "NSProviderSystem.h"\r
 #include "oic_time.h"\r
 \r
+#ifdef SYSTEM_WINDOWS\r
+#include "NSSemaphore_windows.h"\r
+#endif\r
+\r
 static NSSubscribeRequestCallback g_subscribeRequestCb = NULL;\r
 static NSProviderSyncInfoCallback g_syncCb = NULL;\r
 \r
-pthread_mutex_t nsInitMutex;\r
+oc_mutex nsInitMutex;\r
 \r
 void NSRegisterSubscribeRequestCb(NSSubscribeRequestCallback subscribeRequestCb)\r
 {\r
@@ -74,7 +77,7 @@ void * NSCallbackResponseSchedule(void * ptr)
     while (NSIsRunning[CALLBACK_RESPONSE_SCHEDULER])\r
     {\r
         sem_wait(&NSSemaphore[CALLBACK_RESPONSE_SCHEDULER]);\r
-        pthread_mutex_lock(&NSMutex[CALLBACK_RESPONSE_SCHEDULER]);\r
+        oc_mutex_lock(NSMutex[CALLBACK_RESPONSE_SCHEDULER]);\r
 \r
         if (NSHeadMsg[CALLBACK_RESPONSE_SCHEDULER] != NULL)\r
         {\r
@@ -120,7 +123,7 @@ void * NSCallbackResponseSchedule(void * ptr)
             OICFree(node);\r
         }\r
 \r
-        pthread_mutex_unlock(&NSMutex[CALLBACK_RESPONSE_SCHEDULER]);\r
+        oc_mutex_unlock(NSMutex[CALLBACK_RESPONSE_SCHEDULER]);\r
     }\r
 \r
     NS_LOG(DEBUG, "Destroy NSResponseSchedule");\r
index 2ff973b..f6eee01 100644 (file)
 \r
 #include "NSProviderDiscovery.h"\r
 \r
+#ifdef SYSTEM_WINDOWS\r
+#include "NSSemaphore_windows.h"\r
+#endif\r
+\r
 NSResult NSStartPresence()\r
 {\r
     NS_LOG(DEBUG, "NSStartPresence()");\r
@@ -58,7 +62,7 @@ void * NSDiscoverySchedule(void * ptr)
     while (NSIsRunning[DISCOVERY_SCHEDULER])\r
     {\r
         sem_wait(&NSSemaphore[DISCOVERY_SCHEDULER]);\r
-        pthread_mutex_lock(&NSMutex[DISCOVERY_SCHEDULER]);\r
+        oc_mutex_lock(NSMutex[DISCOVERY_SCHEDULER]);\r
 \r
         if (NSHeadMsg[DISCOVERY_SCHEDULER] != NULL)\r
         {\r
@@ -92,7 +96,7 @@ void * NSDiscoverySchedule(void * ptr)
             OICFree(node);\r
         }\r
 \r
-        pthread_mutex_unlock(&NSMutex[DISCOVERY_SCHEDULER]);\r
+        oc_mutex_unlock(NSMutex[DISCOVERY_SCHEDULER]);\r
     }\r
 \r
     NS_LOG(DEBUG, "Destroy NSDiscoverySchedule");\r
index 83fa73b..a9448b5 100644 (file)
 #include "cautilinterface.h"
 #include "NSProviderSystem.h"
 #include "oic_time.h"
+#include "octhread.h"
+
+#ifndef SYSTEM_WINDOWS
 #include <pthread.h>
 
+typedef struct
+{
+    pthread_mutex_t mutex;
+} oc_mutex_ns_internal;
+#endif
+
 bool initProvider = false;
 
-pthread_mutex_t nsInitMutex;
-pthread_cond_t nstopicCond;
+oc_mutex nsInitMutex;
+oc_cond nstopicCond;
 
 void initializeMutex()
 {
-    static pthread_mutex_t initMutex = PTHREAD_MUTEX_INITIALIZER;
+    static oc_mutex initMutex = NULL;
+    if (initMutex == NULL)
+    {
+        initMutex = oc_mutex_new();
+    }
     nsInitMutex = initMutex;
 }
 
@@ -48,10 +61,25 @@ 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);
+#ifdef SYSTEM_WINDOWS
+    NSCacheMutex = oc_mutex_new();
+#else
+    oc_mutex_ns_internal * mutexInfo
+        = (oc_mutex_ns_internal *) OICMalloc(sizeof(oc_mutex_ns_internal));
+    if (!mutexInfo)
+    {
+        NS_LOG(ERROR, "Cache mutex Create fail");
+    }
+    pthread_mutexattr_t attr;
+    pthread_mutexattr_init(&attr);
+    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+    pthread_mutex_init(&(mutexInfo->mutex), &attr);
+    pthread_mutexattr_destroy(&attr);
+
+    NSCacheMutex = (oc_mutex) mutexInfo;
+#endif
+
+    nstopicCond = oc_cond_new();
 
     NSInitSubscriptionList();
     NSInitTopicList();
@@ -64,9 +92,8 @@ void NSDeinitailize()
     NSProviderStorageDestroy(consumerTopicList);
     NSProviderStorageDestroy(registeredTopicList);
 
-    pthread_mutex_destroy(&NSCacheMutex);
-    pthread_mutexattr_destroy(&NSCacheMutexAttr);
-    pthread_cond_destroy(&nstopicCond);
+    oc_mutex_free(NSCacheMutex);
+    oc_cond_free(nstopicCond);
 }
 
 NSResult NSStartProvider(NSProviderConfig config)
@@ -75,7 +102,7 @@ NSResult NSStartProvider(NSProviderConfig config)
 
     initializeMutex();
 
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if (!initProvider)
     {
@@ -111,7 +138,7 @@ NSResult NSStartProvider(NSProviderConfig config)
     {
         NS_LOG(DEBUG, "Already started Notification Provider");
     }
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
 
     NS_LOG(DEBUG, "NSStartProvider - OUT");
     return NS_OK;
@@ -120,7 +147,7 @@ NSResult NSStartProvider(NSProviderConfig config)
 NSResult NSStopProvider()
 {
     NS_LOG(DEBUG, "NSStopProvider - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if (initProvider)
     {
@@ -135,7 +162,7 @@ NSResult NSStopProvider()
         initProvider = false;
     }
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSStopProvider - OUT");
     return NS_OK;
 }
@@ -144,12 +171,12 @@ NSResult NSProviderEnableRemoteService(char *serverAddress)
 {
 #if (defined WITH_CLOUD && defined RD_CLIENT)
     NS_LOG(DEBUG, "NSProviderEnableRemoteService - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if (!initProvider || !serverAddress)
     {
         NS_LOG(DEBUG, "Provider service has not been started yet");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
@@ -157,7 +184,7 @@ NSResult NSProviderEnableRemoteService(char *serverAddress)
     NS_LOG(DEBUG, "Request to publish resource");
     NSPushQueue(DISCOVERY_SCHEDULER, TASK_PUBLISH_RESOURCE, serverAddress);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderEnableRemoteService - OUT");
     return NS_OK;
 #else
@@ -171,7 +198,7 @@ NSResult NSProviderDisableRemoteService(char *serverAddress)
 {
 #if (defined WITH_CLOUD && defined RD_CLIENT)
     NS_LOG(DEBUG, "NSProviderDisableRemoteService - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if (!initProvider || !serverAddress)
     {
@@ -184,7 +211,7 @@ NSResult NSProviderDisableRemoteService(char *serverAddress)
     NS_LOG(DEBUG, "Delete remote server info");
     NSDeleteRemoteServerAddress(serverAddress);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderDisableRemoteService - OUT");
     return NS_OK;
 #else
@@ -234,19 +261,19 @@ NSResult NSSendMessage(NSMessage * msg)
 {
     NS_LOG(DEBUG, "NSSendNotification - IN");
 
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if (!initProvider || msg == NULL)
     {
         NS_LOG(ERROR, "Msg is NULL");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
     NSMessage * newMsg = NSDuplicateMessage(msg);
     NSPushQueue(NOTIFICATION_SCHEDULER, TASK_SEND_NOTIFICATION, newMsg);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
 
     NS_LOG(DEBUG, "NSSendNotification - OUT");
     return NS_OK;
@@ -255,14 +282,14 @@ NSResult NSSendMessage(NSMessage * msg)
 NSResult NSProviderSendSyncInfo(uint64_t messageId, NSSyncType type)
 {
     NS_LOG(DEBUG, "NSProviderReadCheck - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     NSSyncInfo * syncInfo = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
 
     if (!initProvider || !syncInfo)
     {
         NS_LOG(ERROR, "Provider is not started");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
@@ -271,7 +298,7 @@ NSResult NSProviderSendSyncInfo(uint64_t messageId, NSSyncType type)
     syncInfo->state = type;
     NSPushQueue(NOTIFICATION_SCHEDULER, TASK_SEND_READ, syncInfo);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderReadCheck - OUT");
     return NS_OK;
 }
@@ -279,12 +306,12 @@ NSResult NSProviderSendSyncInfo(uint64_t messageId, NSSyncType type)
 NSResult NSAcceptSubscription(const char * consumerId, bool accepted)
 {
     NS_LOG(DEBUG, "NSAccept - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if(!initProvider || !consumerId || consumerId[0] == '\0' || NSGetPolicy() == NS_POLICY_CONSUMER)
     {
         NS_LOG(ERROR, "Provider is not started or consumerId is NULL or NS Policy is Consumer");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
@@ -300,7 +327,7 @@ NSResult NSAcceptSubscription(const char * consumerId, bool accepted)
         NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_DENY, newConsumerId);
     }
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSAccept - OUT");
     return NS_OK;
 }
@@ -308,13 +335,13 @@ NSResult NSAcceptSubscription(const char * consumerId, bool accepted)
 NSMessage * NSCreateMessage()
 {
     NS_LOG(DEBUG, "NSCreateMessage - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     NSMessage * msg = NSInitializeMessage();
 
     OICStrcpy(msg->providerId, UUID_STRING_SIZE, NSGetProviderInfo()->providerId);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSCreateMessage - OUT");
     return msg;
 }
@@ -322,26 +349,26 @@ NSMessage * NSCreateMessage()
 NSTopicLL * NSProviderGetConsumerTopics(const char * consumerId)
 {
     NS_LOG(DEBUG, "NSProviderGetConsumerTopics - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if(!initProvider || !consumerId || consumerId[0] == '\0')
     {
         NS_LOG(DEBUG, "Provider is not started or consumer id should be set");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NULL;
     }
 
     NSTopicSync topicSync;
     topicSync.consumerId = OICStrdup(consumerId);
     topicSync.topics = NULL;
-    topicSync.condition = &nstopicCond;
-    topicSync.mutex = &nsInitMutex;
+    topicSync.condition = nstopicCond;
+    topicSync.mutex = nsInitMutex;
 
     NSPushQueue(TOPIC_SCHEDULER, TAST_GET_CONSUMER_TOPICS, &topicSync);
-    pthread_cond_wait(topicSync.condition, &nsInitMutex);
+    oc_cond_wait(topicSync.condition, nsInitMutex);
     OICFree(topicSync.consumerId);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderGetConsumerTopics - OUT");
     return topicSync.topics;
 }
@@ -349,25 +376,25 @@ NSTopicLL * NSProviderGetConsumerTopics(const char * consumerId)
 NSTopicLL * NSProviderGetTopics()
 {
     NS_LOG(DEBUG, "NSProviderGetTopics - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if (!initProvider)
     {
         NS_LOG(ERROR, "Provider is not started");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NULL;
     }
 
     NSTopicSync topicSync;
     topicSync.consumerId = NULL;
     topicSync.topics = NULL;
-    topicSync.condition = &nstopicCond;
-    topicSync.mutex = &nsInitMutex;
+    topicSync.condition = nstopicCond;
+    topicSync.mutex = nsInitMutex;
 
     NSPushQueue(TOPIC_SCHEDULER, TASK_GET_TOPICS, &topicSync);
-    pthread_cond_wait(topicSync.condition, &nsInitMutex);
+    oc_cond_wait(topicSync.condition, nsInitMutex);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderGetTopics - OUT");
     return topicSync.topics;
 }
@@ -375,30 +402,30 @@ NSTopicLL * NSProviderGetTopics()
 NSResult NSProviderRegisterTopic(const char * topicName)
 {
     NS_LOG(DEBUG, "NSProviderAddTopics - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if(!initProvider || !topicName || topicName[0] == '\0')
     {
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         NS_LOG(DEBUG, "Provider is not started or topic Name should be set");
         return NS_FAIL;
     }
 
     NSTopicSyncResult topicSyncResult;
     topicSyncResult.topicData = (void *) OICStrdup(topicName);
-    topicSyncResult.condition = &nstopicCond;
+    topicSyncResult.condition = nstopicCond;
     topicSyncResult.result = NS_OK;
-    topicSyncResult.mutex = &nsInitMutex;
+    topicSyncResult.mutex = nsInitMutex;
 
     NSPushQueue(TOPIC_SCHEDULER, TASK_REGISTER_TOPIC, &topicSyncResult);
-    pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
+    oc_cond_wait(topicSyncResult.condition, nsInitMutex);
     if(topicSyncResult.result != NS_OK)
     {
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderAddTopics - OUT");
     return NS_OK;
 }
@@ -406,31 +433,31 @@ NSResult NSProviderRegisterTopic(const char * topicName)
 NSResult NSProviderUnregisterTopic(const char * topicName)
 {
     NS_LOG(DEBUG, "NSProviderDeleteTopics - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     if(!initProvider || !topicName || topicName[0] == '\0')
     {
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         NS_LOG(DEBUG, "Provider is not started or topic Name should be set");
         return NS_FAIL;
     }
 
     NSTopicSyncResult topicSyncResult;
     topicSyncResult.topicData = (void *) OICStrdup(topicName);
-    topicSyncResult.condition = &nstopicCond;
+    topicSyncResult.condition = nstopicCond;
     topicSyncResult.result = NS_OK;
-    topicSyncResult.mutex = &nsInitMutex;
+    topicSyncResult.mutex = nsInitMutex;
 
     NSPushQueue(TOPIC_SCHEDULER, TASK_UNREGISTER_TOPIC, &topicSyncResult);
-    pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
+    oc_cond_wait(topicSyncResult.condition, nsInitMutex);
     if (topicSyncResult.result != NS_OK)
     {
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
     OICFree(topicSyncResult.topicData);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderDeleteTopics - OUT");
     return NS_OK;
 }
@@ -438,7 +465,7 @@ NSResult NSProviderUnregisterTopic(const char * topicName)
 NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicName)
 {
     NS_LOG(DEBUG, "NSProviderSelectTopics - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     NSCacheTopicSubData * topicSubData =
             (NSCacheTopicSubData *) OICMalloc(sizeof(NSCacheTopicSubData));
@@ -449,7 +476,7 @@ NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicN
         NS_LOG(DEBUG, "provider is not started or "
                 "consumer id should be set for topic subscription or "
                 "Configuration must set to true.");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
@@ -458,14 +485,14 @@ NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicN
 
     NSTopicSyncResult topicSyncResult;
     topicSyncResult.topicData = (void *) topicSubData;
-    topicSyncResult.condition = &nstopicCond;
+    topicSyncResult.condition = nstopicCond;
     topicSyncResult.result = NS_FAIL;
-    topicSyncResult.mutex = &nsInitMutex;
+    topicSyncResult.mutex = nsInitMutex;
 
     NSPushQueue(TOPIC_SCHEDULER, TASK_SUBSCRIBE_TOPIC, (void *)&topicSyncResult);
-    pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
+    oc_cond_wait(topicSyncResult.condition, nsInitMutex);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderSelectTopics - OUT");
     return topicSyncResult.result;
 }
@@ -473,7 +500,7 @@ NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicN
 NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topicName)
 {
     NS_LOG(DEBUG, "NSProviderUnselectTopics - IN");
-    pthread_mutex_lock(&nsInitMutex);
+    oc_mutex_lock(nsInitMutex);
 
     NSCacheTopicSubData * topicSubData =
             (NSCacheTopicSubData *) OICMalloc(sizeof(NSCacheTopicSubData));
@@ -484,7 +511,7 @@ NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topi
         NS_LOG(DEBUG, "provider is not started or "
                 "consumer id should be set for topic subscription or "
                 "Configuration must set to true.");
-        pthread_mutex_unlock(&nsInitMutex);
+        oc_mutex_unlock(nsInitMutex);
         return NS_FAIL;
     }
 
@@ -493,14 +520,14 @@ NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topi
 
     NSTopicSyncResult topicSyncResult;
     topicSyncResult.topicData = (void *) topicSubData;
-    topicSyncResult.condition = &nstopicCond;
+    topicSyncResult.condition = nstopicCond;
     topicSyncResult.result = NS_FAIL;
-    topicSyncResult.mutex = &nsInitMutex;
+    topicSyncResult.mutex = nsInitMutex;
 
     NSPushQueue(TOPIC_SCHEDULER, TASK_UNSUBSCRIBE_TOPIC, (void *)&topicSyncResult);
-    pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
+    oc_cond_wait(topicSyncResult.condition, nsInitMutex);
 
-    pthread_mutex_unlock(&nsInitMutex);
+    oc_mutex_unlock(nsInitMutex);
     NS_LOG(DEBUG, "NSProviderUnselectTopics - OUT");
     return topicSyncResult.result;
 }
index de28f24..1982528 100644 (file)
@@ -21,6 +21,7 @@
 #include "NSProviderMemoryCache.h"\r
 #include <string.h>\r
 \r
+\r
 #define NS_PROVIDER_DELETE_REGISTERED_TOPIC_DATA(it, topicData, newObj) \\r
     { \\r
         if (it) \\r
             OICFree(topicData->topicName); \\r
             OICFree(topicData); \\r
             OICFree(newObj); \\r
-            pthread_mutex_unlock(&NSCacheMutex); \\r
+            oc_mutex_unlock(NSCacheMutex); \\r
             return NS_FAIL; \\r
         } \\r
     }\r
 \r
 NSCacheList * NSProviderStorageCreate()\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
     NSCacheList * newList = (NSCacheList *) OICMalloc(sizeof(NSCacheList));\r
 \r
     if (!newList)\r
     {\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NULL;\r
     }\r
 \r
     newList->head = newList->tail = NULL;\r
 \r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     NS_LOG(DEBUG, "NSCacheCreate");\r
 \r
     return newList;\r
@@ -55,7 +56,7 @@ NSCacheList * NSProviderStorageCreate()
 \r
 NSCacheElement * NSProviderStorageRead(NSCacheList * list, const char * findId)\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
 \r
     NS_LOG(DEBUG, "NSCacheRead - IN");\r
 \r
@@ -72,7 +73,7 @@ NSCacheElement * NSProviderStorageRead(NSCacheList * list, const char * findId)
         if (NSProviderCompareIdCacheData(type, iter->data, findId))\r
         {\r
             NS_LOG(DEBUG, "Found in Cache");\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return iter;\r
         }\r
 \r
@@ -81,21 +82,21 @@ NSCacheElement * NSProviderStorageRead(NSCacheList * list, const char * findId)
 \r
     NS_LOG(DEBUG, "Not found in Cache");\r
     NS_LOG(DEBUG, "NSCacheRead - OUT");\r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
 \r
     return NULL;\r
 }\r
 \r
 NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool state)\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
 \r
     NS_LOG(DEBUG, "NSCacheUpdateSubScriptionState - IN");\r
 \r
     if (id == NULL)\r
     {\r
         NS_LOG(DEBUG, "id is NULL");\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NS_ERROR;\r
     }\r
 \r
@@ -120,7 +121,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat
             itData->isWhite = state;\r
 \r
             NS_LOG(DEBUG, "Update Data - OUT");\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return NS_OK;\r
         }\r
     }\r
@@ -130,13 +131,13 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat
     }\r
 \r
     NS_LOG(DEBUG, "NSCacheUpdateSubScriptionState - OUT");\r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     return NS_ERROR;\r
 }\r
 \r
 NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj)\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
 \r
     NSCacheType type = list->cacheType;\r
 \r
@@ -145,7 +146,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj)
     if (newObj == NULL)\r
     {\r
         NS_LOG(DEBUG, "newObj is NULL - IN");\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NS_ERROR;\r
     }\r
 \r
@@ -202,7 +203,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj)
                 NS_LOG(DEBUG, "Update Data - OUT");\r
                 OICFree(subData);\r
                 OICFree(newObj);\r
-                pthread_mutex_unlock(&NSCacheMutex);\r
+                oc_mutex_unlock(NSCacheMutex);\r
                 return NS_OK;\r
             }\r
         }\r
@@ -240,13 +241,13 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj)
     {\r
         NS_LOG(DEBUG, "list->head is NULL, Insert First Data");\r
         list->head = list->tail = newObj;\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NS_OK;\r
     }\r
 \r
     list->tail = list->tail->next = newObj;\r
     NS_LOG(DEBUG, "list->head is not NULL");\r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     return NS_OK;\r
 }\r
 \r
@@ -411,7 +412,7 @@ NSResult NSProviderDeleteCacheData(NSCacheType type, void * data)
 \r
 NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId)\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
     NSCacheElement * prev = list->head;\r
     NSCacheElement * del = list->head;\r
 \r
@@ -420,7 +421,7 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId)
     if (!del)\r
     {\r
         NS_LOG(DEBUG, "list head is NULL");\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NS_FAIL;\r
     }\r
 \r
@@ -436,7 +437,7 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId)
             list->head = del->next;\r
             NSProviderDeleteCacheData(type, del->data);\r
             OICFree(del);\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return NS_OK;\r
         }\r
     }\r
@@ -455,7 +456,7 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId)
             prev->next = del->next;\r
             NSProviderDeleteCacheData(type, del->data);\r
             OICFree(del);\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return NS_OK;\r
         }\r
 \r
@@ -463,20 +464,20 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId)
         del = del->next;\r
     }\r
 \r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     return NS_FAIL;\r
 }\r
 \r
 NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList)\r
 {\r
     NS_LOG(DEBUG, "NSProviderGetTopicsCache - IN");\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
 \r
     NSCacheElement * iter = regTopicList->head;\r
 \r
     if (!iter)\r
     {\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NULL;\r
     }\r
 \r
@@ -491,7 +492,7 @@ NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList)
 \r
         if (!newTopic)\r
         {\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return NULL;\r
         }\r
 \r
@@ -512,7 +513,7 @@ NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList)
         iter = iter->next;\r
     }\r
 \r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     NS_LOG(DEBUG, "NSProviderGetTopicsCache - OUT");\r
 \r
     return topics;\r
@@ -523,12 +524,12 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList,
 {\r
     NS_LOG(DEBUG, "NSProviderGetConsumerTopicsCacheData - IN");\r
 \r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
     NSTopicLL * topics = NSProviderGetTopicsCacheData(regTopicList);\r
 \r
     if (!topics)\r
     {\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NULL;\r
     }\r
 \r
@@ -561,7 +562,7 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList,
     }\r
 \r
     conTopicList->cacheType = NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME;\r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     NS_LOG(DEBUG, "NSProviderGetConsumerTopics - OUT");\r
 \r
     return topics;\r
@@ -569,11 +570,11 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList,
 \r
 bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char * topicName)\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
 \r
     if (!conTopicList || !cId || !topicName)\r
     {\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return false;\r
     }\r
 \r
@@ -585,28 +586,28 @@ bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char
 \r
         if ( (strcmp(curr->id, cId) == 0) && (strcmp(curr->topicName, topicName) == 0) )\r
         {\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return true;\r
         }\r
 \r
         iter = iter->next;\r
     }\r
 \r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     return false;\r
 }\r
 \r
 NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,\r
         NSCacheTopicSubData * topicSubData)\r
 {\r
-    pthread_mutex_lock(&NSCacheMutex);\r
+    oc_mutex_lock(NSCacheMutex);\r
 \r
     char * cId = topicSubData->id;\r
     char * topicName = topicSubData->topicName;\r
 \r
     if (!conTopicList || !cId || !topicName)\r
     {\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NS_ERROR;\r
     }\r
 \r
@@ -618,7 +619,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,
     if (!del)\r
     {\r
         NS_LOG(DEBUG, "list head is NULL");\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
+        oc_mutex_unlock(NSCacheMutex);\r
         return NS_FAIL;\r
     }\r
 \r
@@ -641,7 +642,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,
             conTopicList->head = del->next;\r
             NSProviderDeleteCacheData(type, del->data);\r
             OICFree(del);\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return NS_OK;\r
         }\r
     }\r
@@ -663,7 +664,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,
             prev->next = del->next;\r
             NSProviderDeleteCacheData(type, del->data);\r
             OICFree(del);\r
-            pthread_mutex_unlock(&NSCacheMutex);\r
+            oc_mutex_unlock(NSCacheMutex);\r
             return NS_OK;\r
         }\r
 \r
@@ -671,6 +672,6 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,
         del = del->next;\r
     }\r
 \r
-    pthread_mutex_unlock(&NSCacheMutex);\r
+    oc_mutex_unlock(NSCacheMutex);\r
     return NS_FAIL;\r
 }\r
index df2733d..b26485b 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef _NS_PROVIDER_CACHEADAPTER__H_\r
 #define _NS_PROVIDER_CACHEADAPTER__H_\r
 \r
-#include <pthread.h>\r
 #include <stdbool.h>\r
 \r
 #include "NSCommon.h"\r
@@ -29,6 +28,7 @@
 #include "NSStructs.h"\r
 #include "oic_malloc.h"\r
 #include "oic_string.h"\r
+#include "octhread.h"\r
 #include "NSUtil.h"\r
 \r
 NSCacheList * NSProviderStorageCreate();\r
@@ -57,7 +57,6 @@ bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char
 NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,\r
         NSCacheTopicSubData * topicSubData);\r
 \r
-pthread_mutex_t NSCacheMutex;\r
-pthread_mutexattr_t NSCacheMutexAttr;\r
+oc_mutex NSCacheMutex;\r
 \r
 #endif /* _NS_PROVIDER_CACHEADAPTER__H_ */\r
index 6be4265..2d1bec9 100644 (file)
@@ -329,7 +329,7 @@ void * NSNotificationSchedule(void *ptr)
     while (NSIsRunning[NOTIFICATION_SCHEDULER])
     {
         sem_wait(&NSSemaphore[NOTIFICATION_SCHEDULER]);
-        pthread_mutex_lock(&NSMutex[NOTIFICATION_SCHEDULER]);
+        oc_mutex_lock(NSMutex[NOTIFICATION_SCHEDULER]);
 
         if (NSHeadMsg[NOTIFICATION_SCHEDULER] != NULL)
         {
@@ -363,7 +363,7 @@ void * NSNotificationSchedule(void *ptr)
             OICFree(node);
         }
 
-        pthread_mutex_unlock(&NSMutex[NOTIFICATION_SCHEDULER]);
+        oc_mutex_unlock(NSMutex[NOTIFICATION_SCHEDULER]);
     }
 
     NS_LOG(INFO, "Destroy NSNotificationSchedule");
index 7803938..dc33263 100755 (executable)
 \r
 #include "NSProviderScheduler.h"\r
 \r
-pthread_t NSThread[THREAD_COUNT];\r
-pthread_mutex_t NSMutex[THREAD_COUNT];\r
+#include "octhread.h"\r
+\r
+oc_thread NSThread[THREAD_COUNT];\r
+oc_mutex NSMutex[THREAD_COUNT];\r
 sem_t NSSemaphore[THREAD_COUNT];\r
 bool NSIsRunning[THREAD_COUNT] = { false, };\r
 \r
@@ -42,7 +44,7 @@ bool NSInitScheduler()
 \r
     for (i = 0; i < THREAD_COUNT; i++)\r
     {\r
-        pthread_mutex_init(&NSMutex[i], NULL);\r
+        NSMutex[i] = oc_mutex_new();\r
         NSIsRunning[i] = true;\r
         sem_init(&(NSSemaphore[i]), 0, 0);\r
     }\r
@@ -58,42 +60,42 @@ bool NSStartScheduler()
 \r
     for (i = 0; i < THREAD_COUNT; i++)\r
     {\r
-        pthread_mutex_lock(&NSMutex[i]);\r
+        oc_mutex_lock(NSMutex[i]);\r
 \r
         switch (i)\r
         {\r
             case CALLBACK_RESPONSE_SCHEDULER:\r
             {\r
                 NS_LOG(DEBUG, "CASE RESPONSE_SCHEDULER :");\r
-                pthread_create(&NSThread[i], NULL, NSCallbackResponseSchedule, NULL);\r
+                oc_thread_new(& NSThread[i], NSCallbackResponseSchedule, NULL);\r
             }\r
                 break;\r
 \r
             case DISCOVERY_SCHEDULER:\r
             {\r
                 NS_LOG(DEBUG, "CASE DISCOVERY_SCHEDULER :");\r
-                pthread_create(&NSThread[i], NULL, NSDiscoverySchedule, NULL);\r
+                oc_thread_new(& NSThread[i], NSDiscoverySchedule, NULL);\r
             }\r
                 break;\r
 \r
             case SUBSCRIPTION_SCHEDULER:\r
             {\r
                 NS_LOG(DEBUG, "CASE SUBSCRIPTION_SCHEDULER :");\r
-                pthread_create(&NSThread[i], NULL, NSSubScriptionSchedule, NULL);\r
+                oc_thread_new(& NSThread[i], NSSubScriptionSchedule, NULL);\r
             }\r
                 break;\r
 \r
             case NOTIFICATION_SCHEDULER:\r
             {\r
                 NS_LOG(DEBUG, "CASE NOTIFICATION_SCHEDULER :");\r
-                pthread_create(&NSThread[i], NULL, NSNotificationSchedule, NULL);\r
+                oc_thread_new(& NSThread[i], NSNotificationSchedule, NULL);\r
             }\r
                 break;\r
 \r
             case TOPIC_SCHEDULER:\r
             {\r
                 NS_LOG(DEBUG, "CASE TOPIC_SCHEDULER :");\r
-                pthread_create(&NSThread[i], NULL, NSTopicSchedule, NULL);\r
+                oc_thread_new(& NSThread[i], NSTopicSchedule, NULL);\r
             }\r
                 break;\r
             default:\r
@@ -103,7 +105,7 @@ bool NSStartScheduler()
 \r
         NSHeadMsg[i] = NSTailMsg[i] = NULL;\r
 \r
-        pthread_mutex_unlock(&NSMutex[i]);\r
+        oc_mutex_unlock(NSMutex[i]);\r
 \r
     }\r
 \r
@@ -117,16 +119,14 @@ bool NSStopScheduler()
 \r
     for (i = THREAD_COUNT - 1; i >= 0; --i)\r
     {\r
-        int status = -1;\r
-\r
         NSIsRunning[i] = false;\r
 \r
         sem_post(&(NSSemaphore[i]));\r
-        pthread_join(NSThread[i], (void **) &status);\r
+        oc_thread_wait(NSThread[i]);\r
 \r
         NSThread[i] = 0;\r
 \r
-        pthread_mutex_lock(&NSMutex[i]);\r
+        oc_mutex_lock(NSMutex[i]);\r
 \r
         while (NSHeadMsg[i] != NULL)\r
         {\r
@@ -138,8 +138,8 @@ bool NSStopScheduler()
 \r
         NSTailMsg[i] = NSHeadMsg[i] = NULL;\r
 \r
-        pthread_mutex_unlock(&NSMutex[i]);\r
-        pthread_mutex_destroy(&NSMutex[i]);\r
+        oc_mutex_unlock(NSMutex[i]);\r
+        oc_mutex_free(NSMutex[i]);\r
     }\r
 \r
     NS_LOG(DEBUG, "NSStopScheduler - OUT");\r
@@ -155,7 +155,7 @@ void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data)
         return;\r
     }\r
 \r
-    pthread_mutex_lock(&NSMutex[schedulerType]);\r
+    oc_mutex_lock(NSMutex[schedulerType]);\r
 \r
     NS_LOG(DEBUG, "NSPushQueue - IN");\r
     NS_LOG_V(DEBUG, "NSSchedulerType = %d", schedulerType);\r
@@ -189,7 +189,7 @@ void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data)
 \r
     sem_post(&(NSSemaphore[schedulerType]));\r
     NS_LOG(DEBUG, "NSPushQueue - OUT");\r
-    pthread_mutex_unlock(&NSMutex[schedulerType]);\r
+    oc_mutex_unlock(NSMutex[schedulerType]);\r
 }\r
 \r
 void NSFreeData(NSSchedulerType type, NSTask * task)\r
index e8a4883..3472ea6 100755 (executable)
@@ -22,8 +22,6 @@
 #define _PROVIDER_SCHEDULER_H_\r
 \r
 #include <stdio.h>\r
-#include <pthread.h>\r
-#include <semaphore.h>\r
 #include <stdbool.h>\r
 #include "ocstack.h"\r
 #include "NSCommon.h"\r
 #include "logger.h"\r
 #include "oic_malloc.h"\r
 #include "oic_string.h"\r
+#include "octhread.h"\r
 #include "NSUtil.h"\r
 \r
+#ifdef SYSTEM_WINDOWS\r
+#include "NSSemaphore_windows.h"\r
+#else\r
+#include <semaphore.h>\r
+#endif\r
+\r
 extern NSTask* NSHeadMsg[THREAD_COUNT]; // Current MSG;\r
 extern NSTask* NSTailMsg[THREAD_COUNT]; // Recently MSG;\r
 \r
-extern pthread_t NSThread[THREAD_COUNT];\r
-extern pthread_mutex_t NSMutex[THREAD_COUNT];\r
+extern oc_thread NSThread[THREAD_COUNT];\r
+extern oc_mutex NSMutex[THREAD_COUNT];\r
 extern sem_t NSSemaphore[THREAD_COUNT];\r
 extern bool NSIsRunning[THREAD_COUNT];\r
 \r
index 12ef5d1..280eb6e 100644 (file)
@@ -390,7 +390,7 @@ void * NSSubScriptionSchedule(void *ptr)
     while (NSIsRunning[SUBSCRIPTION_SCHEDULER])\r
     {\r
         sem_wait(&NSSemaphore[SUBSCRIPTION_SCHEDULER]);\r
-        pthread_mutex_lock(&NSMutex[SUBSCRIPTION_SCHEDULER]);\r
+        oc_mutex_lock(NSMutex[SUBSCRIPTION_SCHEDULER]);\r
 \r
         if (NSHeadMsg[SUBSCRIPTION_SCHEDULER] != NULL)\r
         {\r
@@ -454,7 +454,7 @@ void * NSSubScriptionSchedule(void *ptr)
             OICFree(node);\r
         }\r
 \r
-        pthread_mutex_unlock(&NSMutex[SUBSCRIPTION_SCHEDULER]);\r
+        oc_mutex_unlock(NSMutex[SUBSCRIPTION_SCHEDULER]);\r
 \r
     }\r
     NS_LOG(INFO, "Destroy NSSubScriptionSchedule");\r
index 389ef25..895d25d 100644 (file)
@@ -21,7 +21,7 @@
 #include "NSProviderTopic.h"\r
 #include "oic_string.h"\r
 #include "oic_malloc.h"\r
-#include <pthread.h>\r
+#include "octhread.h"\r
 \r
 NSResult NSSendTopicUpdation();\r
 \r
@@ -440,7 +440,7 @@ void * NSTopicSchedule(void * ptr)
     while (NSIsRunning[TOPIC_SCHEDULER])\r
     {\r
         sem_wait(&NSSemaphore[TOPIC_SCHEDULER]);\r
-        pthread_mutex_lock(&NSMutex[TOPIC_SCHEDULER]);\r
+        oc_mutex_lock(NSMutex[TOPIC_SCHEDULER]);\r
 \r
         if (NSHeadMsg[TOPIC_SCHEDULER] != NULL)\r
         {\r
@@ -458,7 +458,7 @@ void * NSTopicSchedule(void * ptr)
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_SUBSCRIBE_TOPIC : ");\r
                     NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
-                    pthread_mutex_lock(topicSyncResult->mutex);\r
+                    oc_mutex_lock(topicSyncResult->mutex);\r
                     NSCacheElement * newObj = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
                     NSCacheTopicSubData * subData =\r
                             (NSCacheTopicSubData *) topicSyncResult->topicData;\r
@@ -466,8 +466,8 @@ void * NSTopicSchedule(void * ptr)
                     {\r
                         OICFree(subData->topicName);\r
                         OICFree(subData);\r
-                        pthread_cond_signal(topicSyncResult->condition);\r
-                        pthread_mutex_unlock(topicSyncResult->mutex);\r
+                        oc_cond_signal(topicSyncResult->condition);\r
+                        oc_mutex_unlock(topicSyncResult->mutex);\r
                     }\r
                     else\r
                     {\r
@@ -489,15 +489,15 @@ void * NSTopicSchedule(void * ptr)
                             OICFree(newObj);\r
                         }\r
                     }\r
-                    pthread_cond_signal(topicSyncResult->condition);\r
-                    pthread_mutex_unlock(topicSyncResult->mutex);
+                    oc_cond_signal(topicSyncResult->condition);\r
+                    oc_mutex_unlock(topicSyncResult->mutex);
                 }\r
                     break;\r
                 case TASK_UNSUBSCRIBE_TOPIC:\r
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_UNSUBSCRIBE_TOPIC : ");\r
                     NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
-                    pthread_mutex_lock(topicSyncResult->mutex);\r
+                    oc_mutex_lock(topicSyncResult->mutex);\r
                     NSCacheTopicSubData * topicSubData =\r
                             (NSCacheTopicSubData *) topicSyncResult->topicData;\r
 \r
@@ -509,8 +509,8 @@ void * NSTopicSchedule(void * ptr)
 \r
                     OICFree(topicSubData->topicName);\r
                     OICFree(topicSubData);\r
-                    pthread_cond_signal(topicSyncResult->condition);\r
-                    pthread_mutex_unlock(topicSyncResult->mutex);\r
+                    oc_cond_signal(topicSyncResult->condition);\r
+                    oc_mutex_unlock(topicSyncResult->mutex);\r
 \r
                 }\r
                     break;\r
@@ -519,22 +519,22 @@ void * NSTopicSchedule(void * ptr)
                     NS_LOG(DEBUG, "CASE TASK_ADD_TOPIC : ");\r
                     NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
 \r
-                    pthread_mutex_lock(topicSyncResult->mutex);\r
+                    oc_mutex_lock(topicSyncResult->mutex);\r
                     topicSyncResult->result = NSRegisterTopic(\r
                             (const char *) topicSyncResult->topicData);\r
-                    pthread_cond_signal(topicSyncResult->condition);\r
-                    pthread_mutex_unlock(topicSyncResult->mutex);\r
+                    oc_cond_signal(topicSyncResult->condition);\r
+                    oc_mutex_unlock(topicSyncResult->mutex);\r
                 }\r
                     break;\r
                 case TASK_UNREGISTER_TOPIC:\r
                 {\r
                     NS_LOG(DEBUG, "CASE_TASK_DELETE_TOPIC : ");\r
                     NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
-                    pthread_mutex_lock(topicSyncResult->mutex);\r
+                    oc_mutex_lock(topicSyncResult->mutex);\r
                     topicSyncResult->result = NSUnregisterTopic(\r
                             (const char *) topicSyncResult->topicData);\r
-                    pthread_cond_signal(topicSyncResult->condition);\r
-                    pthread_mutex_unlock(topicSyncResult->mutex);\r
+                    oc_cond_signal(topicSyncResult->condition);\r
+                    oc_mutex_unlock(topicSyncResult->mutex);\r
                 }\r
                     break;\r
                 case TASK_POST_TOPIC:\r
@@ -548,23 +548,23 @@ void * NSTopicSchedule(void * ptr)
                 {\r
                     NS_LOG(DEBUG, "TASK_GET_TOPICS : ");\r
                     NSTopicSync * topicSync = (NSTopicSync *) node->taskData;\r
-                    pthread_mutex_lock(topicSync->mutex);\r
+                    oc_mutex_lock(topicSync->mutex);\r
                     NSTopicLL * topics = NSProviderGetTopicsCacheData(registeredTopicList);\r
                     topicSync->topics = topics;\r
-                    pthread_cond_signal(topicSync->condition);\r
-                    pthread_mutex_unlock(topicSync->mutex);\r
+                    oc_cond_signal(topicSync->condition);\r
+                    oc_mutex_unlock(topicSync->mutex);\r
                 }\r
                     break;\r
                 case TAST_GET_CONSUMER_TOPICS:\r
                 {\r
                     NS_LOG(DEBUG, "TASK_GET_CONSUMER_TOPICS : ");\r
                     NSTopicSync * topicSync = (NSTopicSync *) node->taskData;\r
-                    pthread_mutex_lock(topicSync->mutex);\r
+                    oc_mutex_lock(topicSync->mutex);\r
                     NSTopicLL * topics = NSProviderGetConsumerTopicsCacheData(registeredTopicList,\r
                             consumerTopicList, topicSync->consumerId);\r
                     topicSync->topics = topics;\r
-                    pthread_cond_signal(topicSync->condition);\r
-                    pthread_mutex_unlock(topicSync->mutex);\r
+                    oc_cond_signal(topicSync->condition);\r
+                    oc_mutex_unlock(topicSync->mutex);\r
                 }\r
                     break;\r
                 default:\r
@@ -574,7 +574,7 @@ void * NSTopicSchedule(void * ptr)
             OICFree(node);\r
         }\r
 \r
-        pthread_mutex_unlock(&NSMutex[TOPIC_SCHEDULER]);\r
+        oc_mutex_unlock(NSMutex[TOPIC_SCHEDULER]);\r
     }\r
 \r
     NS_LOG(DEBUG, "Destroy NSTopicSchedule");\r
index f75a1f5..eb858e8 100644 (file)
 #include "NSProviderSubscription.h"\r
 \r
 typedef struct {\r
-    pthread_cond_t * condition;\r
-    pthread_mutex_t * mutex;\r
+    oc_cond condition;\r
+    oc_mutex mutex;\r
     char * consumerId;\r
     NSTopicLL * topics;\r
 } NSTopicSync;\r
 \r
 typedef struct {\r
-    pthread_cond_t * condition;\r
-    pthread_mutex_t * mutex;\r
+    oc_cond condition;\r
+    oc_mutex mutex;\r
     void * topicData;\r
     NSResult result;\r
 } NSTopicSyncResult;\r
diff --git a/service/notification/src/provider/NSSemaphore_windows.c b/service/notification/src/provider/NSSemaphore_windows.c
new file mode 100644 (file)
index 0000000..811b120
--- /dev/null
@@ -0,0 +1,56 @@
+/* ****************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+
+#ifdef SYSTEM_WINDOWS
+
+#include "NSSemaphore_windows.h"
+#include "NSConstants.h"
+#include <stdio.h>
+#include <winsock2.h>
+
+int sem_init (sem_t * sem, int pshared, unsigned int value)
+{
+    sem = (sem_t *) OICMalloc(sizeof(sem_t));
+    NS_VERIFY_NOT_NULL(sem, (int)-1);
+
+    sem->semaphore = CreateSemaphore(NULL, pshared, value, NULL);
+    NS_VERIFY_NOT_NULL(sem->semaphore, (int)-1);
+
+    return 0;
+}
+int sem_post (sem_t * sem)
+{
+    NS_VERIFY_NOT_NULL(sem, (int)-1);
+
+    ReleaseSemaphore(sem->semaphore, 1, NULL);
+
+    return 0;
+}
+int sem_wait (sem_t * sem)
+{
+    NS_VERIFY_NOT_NULL(sem, (int)-1);
+
+    WaitForSingleObject(sem->semaphore, 0L);
+
+    return 0;
+}
+
+#endif
diff --git a/service/notification/src/provider/NSSemaphore_windows.h b/service/notification/src/provider/NSSemaphore_windows.h
new file mode 100644 (file)
index 0000000..154c4e3
--- /dev/null
@@ -0,0 +1,40 @@
+/* ****************************************************************
+ *
+ * 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_SEMAPHORE_WINDOWS_H_
+#define _NS_SEMAPHORE_WINDOWS_H_
+
+#ifdef SYSTEM_WINDOWS
+#include <winsock2.h>
+
+typedef struct
+{
+    HANDLE semaphore;
+} sem_t;
+
+
+int sem_init (sem_t *__sem, int pshared, unsigned int value);
+int sem_post (sem_t *__sem);
+int sem_wait (sem_t *__sem);
+
+#endif
+
+#endif // _NS_SEMAPHORE_WINDOWS_H_