1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
25 #include "cainterface.h"
26 #include "caremotehandler.h"
27 #include "camessagehandler.h"
28 #include "canetworkconfigurator.h"
29 #include "cainterfacecontroller.h"
34 static void CAMessageHandler(int32_t id, CADetachErrorCode code)
38 CAResult_t CAInitialize()
40 OIC_LOG_V(DEBUG, TAG, "CAInitialize");
42 CASetMessageHandlerCallback(CAMessageHandler);
44 CAResult_t res = CAInitializeMessageHandler();
46 if (res != CA_STATUS_OK)
56 OIC_LOG_V(DEBUG, TAG, "CATerminate");
58 CATerminateMessageHandler();
61 CAResult_t CAStartListeningServer()
63 OIC_LOG_V(DEBUG, TAG, "CAStartListeningServer");
65 return CAStartListeningServerAdapters();
68 CAResult_t CAStartDiscoveryServer()
70 OIC_LOG_V(DEBUG, TAG, "CAStartDiscoveryServer");
72 return CAStartDiscoveryServerAdapters();
75 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
77 OIC_LOG_V(DEBUG, TAG, "CARegisterHandler");
79 CASetRequestResponseCallbacks(ReqHandler, RespHandler);
84 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, CARemoteEndpoint_t** remoteEndpoint)
86 OIC_LOG_V(DEBUG, TAG, "CACreateRemoteEndpoint");
88 CARemoteEndpoint_t* remote = CACreateRemoteEndpointUriInternal(uri);
90 *remoteEndpoint = remote;
93 return CA_STATUS_FAILED;
98 void CADestroyRemoteEndpoint(CARemoteEndpoint_t* rep)
100 OIC_LOG_V(DEBUG, TAG, "CADestroyRemoteEndpoint");
102 CADestroyRemoteEndpointInternal(rep);
105 CAResult_t CAGenerateToken(CAToken_t* token)
107 OIC_LOG_V(DEBUG, TAG, "CAGenerateToken");
109 return CAGenerateTokenInternal(token);
112 void CADestroyToken(CAToken_t token)
114 OIC_LOG_V(DEBUG, TAG, "CADestroyToken");
116 CADestroyTokenInternal(token);
119 CAResult_t CAGetNetworkInformation(CALocalConnectivityt_t **info, uint32_t* size)
121 OIC_LOG_V(DEBUG, TAG, "CAGetNetworkInformation");
123 return CA_NOT_SUPPORTED;
126 CAResult_t CAFindResource(const CAURI_t resourceUri)
128 OIC_LOG_V(DEBUG, TAG, "CAFindResource");
130 int32_t actionId = -1;
132 actionId = CADetachMessageResourceUri(resourceUri);
135 return CA_SEND_FAILED;
137 OIC_LOG_V(DEBUG, TAG, "action id : %d", actionId);
142 CAResult_t CASendRequest(const CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo)
144 OIC_LOG_V(DEBUG, TAG, "CASendGetRequest");
146 int32_t actionId = -1;
148 actionId = CADetachRequestMessage(object, requestInfo);
151 return CA_SEND_FAILED;
153 OIC_LOG_V(DEBUG, TAG, "action id : %d", actionId);
158 CAResult_t CASendNotification(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo)
160 OIC_LOG_V(DEBUG, TAG, "CASendNotification");
162 return CA_NOT_SUPPORTED;
165 CAResult_t CASendResponse(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo)
167 OIC_LOG_V(DEBUG, TAG, "CASendResponse");
169 int32_t actionId = -1;
171 actionId = CADetachResponseMessage(object, responseInfo);
174 return CA_SEND_FAILED;
176 OIC_LOG_V(DEBUG, TAG, "action id : %d", actionId);
181 CAResult_t CAAdvertiseResource(const CAURI_t uri, CAHeaderOption_t* options, uint8_t numOptions)
183 OIC_LOG_V(DEBUG, TAG, "CAAdvertiseResource");
185 return CA_NOT_SUPPORTED;
188 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
190 OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
192 if (!(interestedNetwork & 0xf))
194 return CA_NOT_SUPPORTED;
198 if (interestedNetwork & CA_ETHERNET)
200 res = CAAddNetworkType(CA_ETHERNET);
201 if (res != CA_STATUS_OK)
207 if (interestedNetwork & CA_WIFI)
209 res = CAAddNetworkType(CA_WIFI);
210 if (res != CA_STATUS_OK)
216 if (interestedNetwork & CA_EDR)
218 res = CAAddNetworkType(CA_EDR);
219 if (res != CA_STATUS_OK)
225 if (interestedNetwork & CA_LE)
227 res = CAAddNetworkType(CA_LE);
228 if (res != CA_STATUS_OK)
237 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
239 OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
241 if (!(nonInterestedNetwork & 0xf))
243 return CA_NOT_SUPPORTED;
248 if (nonInterestedNetwork & CA_ETHERNET)
250 res = CARemoveNetworkType(CA_ETHERNET);
251 if (res != CA_STATUS_OK)
257 if (nonInterestedNetwork & CA_WIFI)
259 res = CARemoveNetworkType(CA_WIFI);
260 if (res != CA_STATUS_OK)
266 if (nonInterestedNetwork & CA_EDR)
268 res = CARemoveNetworkType(CA_EDR);
269 if (res != CA_STATUS_OK)
275 if (nonInterestedNetwork & CA_LE)
277 res = CARemoveNetworkType(CA_LE);
278 if (res != CA_STATUS_OK)
287 CAResult_t CAHandleRequestResponse()
289 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponse");
291 CAHandleRequestResponseCallbacks();