API change , Retransmission Callback on expiry , remove glib source for dynamic linking
[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_singlethread.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 static void CAMessageHandler(CAToken_t token, CAResult_t res)
37 {
38     // TODO
39     // it will notify the result for the each action.
40
41 }
42
43 CAResult_t CAInitialize()
44 {
45     OIC_LOG(DEBUG, TAG, "IN");
46
47     CASetMessageHandlerCallback(CAMessageHandler);
48
49     CAResult_t res = CAInitializeMessageHandler();
50
51     if (res != CA_STATUS_OK)
52     {
53         return res;
54     }
55     OIC_LOG(DEBUG, TAG, "OUT");
56     return CA_STATUS_OK;
57 }
58
59 void CATerminate()
60 {
61     OIC_LOG(DEBUG, TAG, "IN");
62     CATerminateMessageHandler();
63     OIC_LOG(DEBUG, TAG, "OUT");
64 }
65
66 CAResult_t CAStartListeningServer()
67 {
68     return CAStartListeningServerAdapters();
69 }
70
71 CAResult_t CAStartDiscoveryServer()
72 {
73     return CAStartDiscoveryServerAdapters();
74 }
75
76 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
77 {
78     OIC_LOG(DEBUG, TAG, "IN");
79     CASetRequestResponseCallbacks(ReqHandler, RespHandler);
80     OIC_LOG(DEBUG, TAG, "OUT");
81
82     return CA_STATUS_OK;
83 }
84
85 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, 
86     const CAConnectivityType_t connectivityType,CARemoteEndpoint_t **remoteEndpoint)
87 {
88     OIC_LOG(DEBUG, TAG, "IN");
89
90     CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri,connectivityType);
91
92     *remoteEndpoint = remote;
93
94     if (remote == NULL)
95         return CA_STATUS_FAILED;
96
97     OIC_LOG(DEBUG, TAG, "OUT");
98     return CA_STATUS_OK;
99 }
100
101 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
102 {
103     CADestroyRemoteEndpointInternal(rep);
104 }
105
106 CAResult_t CAGenerateToken(CAToken_t *token)
107 {
108     return CAGenerateTokenInternal(token);
109 }
110
111 void CADestroyToken(CAToken_t token)
112 {
113     OIC_LOG(DEBUG, TAG, "IN");
114     CADestroyTokenInternal(token);
115     OIC_LOG(DEBUG, TAG, "OUT");
116 }
117
118 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
119 {
120     return CAGetNetworkInformationInternal(info, size);
121 }
122
123 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token)
124 {
125     OIC_LOG(DEBUG, TAG, "IN");
126     CAResult_t res = CADetachMessageResourceUri(resourceUri, token, NULL, 0);
127     OIC_LOG(DEBUG, TAG, "OUT");
128     return res;
129 }
130
131 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo)
132 {
133     return CADetachRequestMessage(object, requestInfo);
134 }
135
136 CAResult_t CASendNotification(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
137 {
138     return CADetachResponseMessage(object, responseInfo);
139 }
140
141 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
142 {
143     return CADetachResponseMessage(object, responseInfo);
144 }
145
146 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
147                                CAHeaderOption_t *options,
148                                uint8_t numOptions)
149 {
150     return CADetachMessageResourceUri(resourceUri, token, options, numOptions);
151 }
152
153 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
154 {
155     OIC_LOG_V(DEBUG, TAG, "Selected n/W=%d", interestedNetwork);
156
157     if (!(interestedNetwork & 0xf))
158     {
159         return CA_NOT_SUPPORTED;
160     }
161     CAResult_t res;
162
163     if (interestedNetwork & CA_ETHERNET)
164     {
165         res = CAAddNetworkType(CA_ETHERNET);
166         if (res != CA_STATUS_OK)
167         {
168             return res;
169         }
170     }
171
172     if (interestedNetwork & CA_WIFI)
173     {
174         res = CAAddNetworkType(CA_WIFI);
175         if (res != CA_STATUS_OK)
176         {
177             return res;
178         }
179     }
180
181     if (interestedNetwork & CA_EDR)
182     {
183         res = CAAddNetworkType(CA_EDR);
184         if (res != CA_STATUS_OK)
185         {
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             return res;
196         }
197     }
198     OIC_LOG(DEBUG, TAG, "OUT");
199     return CA_STATUS_OK;
200 }
201
202 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
203 {
204     OIC_LOG_V(DEBUG, TAG, "unselected n/w=%d", nonInterestedNetwork);
205
206     if (!(nonInterestedNetwork & 0xf))
207     {
208         return CA_NOT_SUPPORTED;
209     }
210
211     CAResult_t res;
212
213     if (nonInterestedNetwork & CA_ETHERNET)
214     {
215         res = CARemoveNetworkType(CA_ETHERNET);
216         if (res != CA_STATUS_OK)
217         {
218             return res;
219         }
220     }
221
222     if (nonInterestedNetwork & CA_WIFI)
223     {
224         res = CARemoveNetworkType(CA_WIFI);
225         if (res != CA_STATUS_OK)
226         {
227             return res;
228         }
229     }
230
231     if (nonInterestedNetwork & CA_EDR)
232     {
233         res = CARemoveNetworkType(CA_EDR);
234         if (res != CA_STATUS_OK)
235         {
236             return res;
237         }
238     }
239
240     if (nonInterestedNetwork & CA_LE)
241     {
242         res = CARemoveNetworkType(CA_LE);
243         if (res != CA_STATUS_OK)
244         {
245             return res;
246         }
247     }
248     OIC_LOG(DEBUG, TAG, "OUT");
249     return CA_STATUS_OK;
250 }
251
252 CAResult_t CAHandleRequestResponse()
253 {
254     CAHandleRequestResponseCallbacks();
255     return CA_STATUS_OK;
256 }
257