Merge "Merge branch 'master' into notification-service" into notification-service
[platform/upstream/iotivity.git] / service / notification / src / provider / NSProviderSystem.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 #include "NSProviderSystem.h"\r
21 \r
22 #define MAX_SERVER_ADDRESS 32\r
23 static NSConnectionState NSProviderConnectionState;\r
24 static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,};\r
25 \r
26 NSProviderInfo * providerInfo;\r
27 \r
28 void NSSetProviderConnectionState(NSConnectionState state)\r
29 {\r
30     NS_LOG(DEBUG, "NSSetProviderConnectionState");\r
31 \r
32     NSProviderConnectionState = state;\r
33 }\r
34 \r
35 NSConnectionState NSGetProviderConnectionState()\r
36 {\r
37     NS_LOG(DEBUG, "Change Connection State");\r
38 \r
39     return NSProviderConnectionState;\r
40 }\r
41 \r
42 void NSSetRemoteServerAddress(char *serverAddress)\r
43 {\r
44 \r
45     OICStrcpy(NSRemoteServerAddress, MAX_SERVER_ADDRESS, serverAddress);\r
46 }\r
47 \r
48 void NSDeleteRemoteServerAddress(char *serverAddress)\r
49 {\r
50     NS_LOG_V(DEBUG, "Delete cloud address: %s", serverAddress);\r
51 \r
52     memset(NSRemoteServerAddress, 0, MAX_SERVER_ADDRESS);\r
53 }\r
54 \r
55 bool NSIsRemoteServerAddress(char *serverAddress)\r
56 {\r
57     NS_LOG_V(DEBUG, "Check server address: %s", serverAddress);\r
58 \r
59     if(serverAddress != NULL)\r
60     {\r
61         return strstr(NSRemoteServerAddress, serverAddress);\r
62     }\r
63 \r
64     return false;\r
65 }\r
66 \r
67 void NSInitProviderInfo()\r
68 {\r
69     NS_LOG(DEBUG, "NSInitProviderInfo");\r
70 \r
71     providerInfo = (NSProviderInfo *) OICMalloc(sizeof(NSProviderInfo));\r
72     const char * generatedUuid = (char *)OCGetServerInstanceIDString();\r
73     NS_LOG_V(DEBUG, "Generate Provider ID: %s", generatedUuid);\r
74     OICStrcpy(providerInfo->providerId, strlen(generatedUuid), generatedUuid);\r
75 \r
76     providerInfo->providerName = NULL;\r
77 }\r
78 \r
79 void NSDeinitProviderInfo()\r
80 {\r
81     NS_LOG(DEBUG, "NSDeinitProviderInfo");\r
82 \r
83     if(providerInfo == NULL)\r
84     {\r
85         NS_LOG(DEBUG, "providerInfo is NULL");\r
86         return;\r
87     }\r
88 \r
89     if(providerInfo->providerName != NULL)\r
90     {\r
91         OICFree(providerInfo->providerName);\r
92         providerInfo->providerName = NULL;\r
93     }\r
94 \r
95     OICFree(providerInfo);\r
96     providerInfo = NULL;\r
97 }\r
98 \r
99 NSProviderInfo * NSGetProviderInfo()\r
100 {\r
101     NS_LOG_V(DEBUG, "ProviderInfo: %s", providerInfo->providerId);\r
102 \r
103     return providerInfo;\r
104 }\r
105 \r