Merge branch 'master' into notification-service
[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     NS_LOG(DEBUG, "NSStartPresence()");\r
26 \r
27     if (OCStartPresence(0) != OC_STACK_OK)\r
28     {\r
29         NS_LOG(DEBUG, "NSStartPresence() NS_ERROR");\r
30         return NS_ERROR;\r
31     }\r
32 \r
33     NS_LOG(DEBUG, "NSStartPresence() NS_OK");\r
34     return NS_OK;\r
35 }\r
36 \r
37 NSResult NSStopPresence()\r
38 {\r
39     NS_LOG(DEBUG, "NSStopPresence()");\r
40 \r
41     if (OCStopPresence() != OC_STACK_OK)\r
42     {\r
43         NS_LOG(DEBUG, "NSStopPresence() NS_ERROR");\r
44         return NS_ERROR;\r
45     }\r
46 \r
47     NS_LOG(DEBUG, "NSStopPresence() NS_OK");\r
48     return NS_OK;\r
49 }\r
50 \r
51 void * NSDiscoverySchedule(void * ptr)\r
52 {\r
53     if (ptr == NULL)\r
54     {\r
55         NS_LOG(DEBUG, "Create NSDiscoverySchedule");\r
56     }\r
57 \r
58     while (NSIsRunning[DISCOVERY_SCHEDULER])\r
59     {\r
60         sem_wait(&NSSemaphore[DISCOVERY_SCHEDULER]);\r
61         pthread_mutex_lock(&NSMutex[DISCOVERY_SCHEDULER]);\r
62 \r
63         if (NSHeadMsg[DISCOVERY_SCHEDULER] != NULL)\r
64         {\r
65             NSTask *node = NSHeadMsg[DISCOVERY_SCHEDULER];\r
66             NSHeadMsg[DISCOVERY_SCHEDULER] = node->nextTask;\r
67 \r
68             switch (node->taskType)\r
69             {\r
70                 case TASK_START_PRESENCE:\r
71                     NS_LOG(DEBUG, "CASE TASK_START_PRESENCE : ");\r
72                     NSStartPresence();\r
73                     break;\r
74                 case TASK_STOP_PRESENCE:\r
75                     NS_LOG(DEBUG, "CASE TASK_STOP_PRESENCE : ");\r
76                     NSStopPresence();\r
77                     break;\r
78                 case TASK_REGISTER_RESOURCE:\r
79                     NS_LOG(DEBUG, "CASE TASK_REGISTER_RESOURCE : ");\r
80                     NSRegisterResource();\r
81                     break;\r
82                 case TASK_PUBLISH_RESOURCE:\r
83                     NS_LOG(DEBUG, "CASE TASK_PUBLISH_PESOURCE : ");\r
84                     NSPublishResourceToCloud((char*)node->taskData);\r
85                     break;\r
86                 default:\r
87                     break;\r
88             }\r
89 \r
90             OICFree(node);\r
91         }\r
92 \r
93         pthread_mutex_unlock(&NSMutex[DISCOVERY_SCHEDULER]);\r
94     }\r
95 \r
96     NS_LOG(DEBUG, "Destroy NSDiscoverySchedule");\r
97     return NULL;\r
98 }\r