Issue fixed about OCEntityHandlerRequest same pointer address.
[platform/upstream/iotivity.git] / service / notification / src / provider / NSProviderDiscovery.c
1 //******************************************************************\r
2 //\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.\r
4 //\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
6 //\r
7 // Licensed under the Apache License, Version 2.0 (the "License");\r
8 // you may not use this file except in compliance with the License.\r
9 // You may obtain a copy of the License at\r
10 //\r
11 //      http://www.apache.org/licenses/LICENSE-2.0\r
12 //\r
13 // Unless required by applicable law or agreed to in writing, software\r
14 // distributed under the License is distributed on an "AS IS" BASIS,\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16 // See the License for the specific language governing permissions and\r
17 // limitations under the License.\r
18 //\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
20 \r
21 #include "NSProviderDiscovery.h"\r
22 \r
23 NSResult NSStartPresence()\r
24 {\r
25     OIC_LOG(INFO, DISCOVERY_TAG, "NSStartPresence()");\r
26     NS_LOG(INFO, "NSStartPresence()");\r
27 \r
28     if (OCStartPresence(0) != OC_STACK_OK)\r
29     {\r
30         OIC_LOG(INFO, DISCOVERY_TAG, "NSStartPresence() NS_ERROR");\r
31         NS_LOG(INFO, "NSStartPresence() NS_ERROR");\r
32         return NS_ERROR;\r
33     }\r
34 \r
35     OIC_LOG(INFO, DISCOVERY_TAG, "NSStartPresence() NS_OK");\r
36     NS_LOG(INFO, "NSStartPresence() NS_OK");\r
37     return NS_OK;\r
38 }\r
39 \r
40 NSResult NSStopPresence()\r
41 {\r
42     OIC_LOG(INFO, DISCOVERY_TAG, "NSStopPresence()");\r
43     NS_LOG(INFO, "NSStopPresence()");\r
44 \r
45     if (OCStopPresence() != OC_STACK_OK)\r
46     {\r
47         OIC_LOG(INFO, DISCOVERY_TAG, "NSStopPresence() NS_ERROR");\r
48         NS_LOG(INFO, "NSStopPresence() NS_ERROR");\r
49         return NS_ERROR;\r
50     }\r
51 \r
52     OIC_LOG(INFO, DISCOVERY_TAG, "NSStopPresence() NS_OK");\r
53     NS_LOG(INFO, "NSStopPresence() NS_OK");\r
54     return NS_OK;\r
55 }\r
56 \r
57 void * NSDiscoverySchedule(void * ptr)\r
58 {\r
59     if (ptr == NULL)\r
60     {\r
61         OIC_LOG(INFO, DISCOVERY_TAG, "Create NSDiscoverySchedule\n");\r
62         NS_LOG(INFO, "Create NSDiscoverySchedule");\r
63     }\r
64 \r
65     while (NSIsRunning[DISCOVERY_SCHEDULER])\r
66     {\r
67         sem_wait(&NSSemaphore[DISCOVERY_SCHEDULER]);\r
68         pthread_mutex_lock(&NSMutex[DISCOVERY_SCHEDULER]);\r
69 \r
70         if (NSHeadMsg[DISCOVERY_SCHEDULER] != NULL)\r
71         {\r
72             NSTask *node = NSHeadMsg[DISCOVERY_SCHEDULER];\r
73             NSHeadMsg[DISCOVERY_SCHEDULER] = node->nextTask;\r
74 \r
75             switch (node->taskType)\r
76             {\r
77                 case TASK_START_PRESENCE:\r
78                     NS_LOG(INFO, "CASE TASK_START_PRESENCE : ");\r
79                     NSStartPresence();\r
80                     break;\r
81                 case TASK_STOP_PRESENCE:\r
82                     NS_LOG(INFO, "CASE TASK_STOP_PRESENCE : ");\r
83                     NSStopPresence();\r
84                     break;\r
85                 case TASK_REGISTER_RESOURCE:\r
86                     NS_LOG(INFO, "CASE TASK_REGISTER_RESOURCE : ");\r
87                     NSRegisterResource();\r
88                     break;\r
89                 default:\r
90                     break;\r
91             }\r
92 \r
93             OICFree(node);\r
94         }\r
95 \r
96         pthread_mutex_unlock(&NSMutex[DISCOVERY_SCHEDULER]);\r
97 \r
98     }\r
99     return NULL;\r
100 }\r