Fix incorrect usages of OIC_LOG_V macro.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / caconnectivitymanager_singlethread.c
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdint.h>
24
25 #include "cainterface.h"
26 #include "caremotehandler.h"
27 #include "caprotocolmessage.h"
28 #include "canetworkconfigurator.h"
29 #include "logger.h"
30
31 #include "cainterfacecontroller_singlethread.h"
32 #include "camessagehandler_singlethread.h"
33
34 #define TAG "CM_ST"
35
36 CAResult_t CAInitialize()
37 {
38     OIC_LOG(DEBUG, TAG, "IN");
39
40     return CAInitializeMessageHandler();
41 }
42
43 void CATerminate()
44 {
45     OIC_LOG(DEBUG, TAG, "IN");
46     CATerminateMessageHandler();
47
48     CATerminateNetworkType();
49     OIC_LOG(DEBUG, TAG, "OUT");
50 }
51
52 CAResult_t CAStartListeningServer()
53 {
54     return CAStartListeningServerAdapters();
55 }
56
57 CAResult_t CAStartDiscoveryServer()
58 {
59     return CAStartDiscoveryServerAdapters();
60 }
61
62 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
63 {
64     OIC_LOG(DEBUG, TAG, "IN");
65     CASetRequestResponseCallbacks(ReqHandler, RespHandler);
66     OIC_LOG(DEBUG, TAG, "OUT");
67 }
68
69 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
70     const CAConnectivityType_t connectivityType,CARemoteEndpoint_t **remoteEndpoint)
71 {
72     OIC_LOG(DEBUG, TAG, "IN");
73
74     CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri,connectivityType);
75
76     if (remote == NULL)
77     {
78         OIC_LOG(ERROR, TAG, "remote endpoint is NULL");
79         return CA_STATUS_FAILED;
80     }
81
82     *remoteEndpoint = remote;
83
84     OIC_LOG(DEBUG, TAG, "OUT");
85     return CA_STATUS_OK;
86 }
87
88 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
89 {
90     CADestroyRemoteEndpointInternal(rep);
91 }
92
93 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
94 {
95     return CAGenerateTokenInternal(token, tokenLength);
96 }
97
98 void CADestroyToken(CAToken_t token)
99 {
100     OIC_LOG(DEBUG, TAG, "IN");
101     CADestroyTokenInternal(token);
102     OIC_LOG(DEBUG, TAG, "OUT");
103 }
104
105 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
106 {
107     return CAGetNetworkInformationInternal(info, size);
108 }
109
110 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength)
111 {
112     OIC_LOG(DEBUG, TAG, "IN");
113
114     return CADetachMessageResourceUri(resourceUri, token, tokenLength, NULL, 0);
115 }
116
117 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo)
118 {
119     return CADetachRequestMessage(object, requestInfo);
120 }
121
122 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
123                               const CARequestInfo_t *requestInfo)
124 {
125     OIC_LOG(DEBUG, TAG, "CASendRequestToAll");
126
127     return CADetachRequestToAllMessage(object, requestInfo);
128 }
129
130 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
131     const CAResponseInfo_t *responseInfo)
132 {
133     return CADetachResponseMessage(object, responseInfo);
134 }
135
136 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
137     const CAResponseInfo_t *responseInfo)
138 {
139     return CADetachResponseMessage(object, responseInfo);
140 }
141
142 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
143                                uint8_t tokenLength, const CAHeaderOption_t *options,
144                                const uint8_t numOptions)
145 {
146     return CADetachMessageResourceUri(resourceUri, token, tokenLength, options, numOptions);
147 }
148
149 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
150 {
151     OIC_LOG_V(DEBUG, TAG, "Selected n/W=%d", interestedNetwork);
152
153     if (!(interestedNetwork & 0xf))
154     {
155         OIC_LOG(ERROR, TAG, "not supported");
156         return CA_NOT_SUPPORTED;
157     }
158     CAResult_t res = CA_STATUS_OK;
159
160     if (interestedNetwork & CA_ETHERNET)
161     {
162         res = CAAddNetworkType(CA_ETHERNET);
163         if (res != CA_STATUS_OK)
164         {
165             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
166             return res;
167         }
168     }
169
170     if (interestedNetwork & CA_WIFI)
171     {
172         res = CAAddNetworkType(CA_WIFI);
173         if (res != CA_STATUS_OK)
174         {
175             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
176             return res;
177         }
178     }
179
180     if (interestedNetwork & CA_EDR)
181     {
182         res = CAAddNetworkType(CA_EDR);
183         if (res != CA_STATUS_OK)
184         {
185             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
186             return res;
187         }
188     }
189
190     if (interestedNetwork & CA_LE)
191     {
192         res = CAAddNetworkType(CA_LE);
193         if (res != CA_STATUS_OK)
194         {
195             OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
196             return res;
197         }
198     }
199     OIC_LOG(DEBUG, TAG, "OUT");
200     return res;
201 }
202
203 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
204 {
205     OIC_LOG_V(DEBUG, TAG, "unselected n/w=%d", nonInterestedNetwork);
206
207     if (!(nonInterestedNetwork & 0xf))
208     {
209         OIC_LOG(ERROR, TAG, "not supported");
210         return CA_NOT_SUPPORTED;
211     }
212
213     CAResult_t res = CA_STATUS_OK;
214
215     if (nonInterestedNetwork & CA_ETHERNET)
216     {
217         res = CARemoveNetworkType(CA_ETHERNET);
218         if (res != CA_STATUS_OK)
219         {
220             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
221             return res;
222         }
223     }
224
225     if (nonInterestedNetwork & CA_WIFI)
226     {
227         res = CARemoveNetworkType(CA_WIFI);
228         if (res != CA_STATUS_OK)
229         {
230             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
231             return res;
232         }
233     }
234
235     if (nonInterestedNetwork & CA_EDR)
236     {
237         res = CARemoveNetworkType(CA_EDR);
238         if (res != CA_STATUS_OK)
239         {
240             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
241             return res;
242         }
243     }
244
245     if (nonInterestedNetwork & CA_LE)
246     {
247         res = CARemoveNetworkType(CA_LE);
248         if (res != CA_STATUS_OK)
249         {
250             OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
251             return res;
252         }
253     }
254     OIC_LOG(DEBUG, TAG, "OUT");
255     return res;
256 }
257
258 CAResult_t CAHandleRequestResponse()
259 {
260     CAHandleRequestResponseCallbacks();
261     return CA_STATUS_OK;
262 }
263
264