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 "caprotocolmessage.h"
29 #include "canetworkconfigurator.h"
30 #include "cainterfacecontroller.h"
35 CAResult_t CAInitialize()
37 OIC_LOG_V(DEBUG, TAG, "CAInitialize");
39 CAResult_t res = CAInitializeMessageHandler();
41 if (res != CA_STATUS_OK)
51 OIC_LOG_V(DEBUG, TAG, "CATerminate");
53 CATerminateMessageHandler();
56 CAResult_t CAStartListeningServer()
58 OIC_LOG_V(DEBUG, TAG, "CAStartListeningServer");
60 return CAStartListeningServerAdapters();
63 CAResult_t CAStartDiscoveryServer()
65 OIC_LOG_V(DEBUG, TAG, "CAStartDiscoveryServer");
67 return CAStartDiscoveryServerAdapters();
70 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
72 OIC_LOG_V(DEBUG, TAG, "CARegisterHandler");
74 CASetRequestResponseCallbacks(ReqHandler, RespHandler);
79 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, CARemoteEndpoint_t** remoteEndpoint)
81 OIC_LOG_V(DEBUG, TAG, "CACreateRemoteEndpoint");
83 CARemoteEndpoint_t* remote = CACreateRemoteEndpointUriInternal(uri);
85 *remoteEndpoint = remote;
88 return CA_STATUS_FAILED;
93 void CADestroyRemoteEndpoint(CARemoteEndpoint_t* rep)
95 OIC_LOG_V(DEBUG, TAG, "CADestroyRemoteEndpoint");
97 CADestroyRemoteEndpointInternal(rep);
100 CAResult_t CAGenerateToken(CAToken_t* token)
102 OIC_LOG_V(DEBUG, TAG, "CAGenerateToken");
104 return CAGenerateTokenInternal(token);
107 void CADestroyToken(CAToken_t token)
109 OIC_LOG_V(DEBUG, TAG, "CADestroyToken");
111 CADestroyTokenInternal(token);
114 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t* size)
116 OIC_LOG_V(DEBUG, TAG, "CAGetNetworkInformation");
118 return CAGetNetworkInformationInternal(info, size);
121 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token)
123 OIC_LOG_V(DEBUG, TAG, "CAFindResource");
125 return CADetachMessageResourceUri(resourceUri, token, NULL, 0);
129 CAResult_t CASendRequest(const CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo)
131 OIC_LOG_V(DEBUG, TAG, "CASendGetRequest");
133 return CADetachRequestMessage(object, requestInfo);
136 CAResult_t CASendNotification(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo)
138 OIC_LOG_V(DEBUG, TAG, "CASendNotification");
140 return CADetachResponseMessage(object, responseInfo);
144 CAResult_t CASendResponse(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo)
146 OIC_LOG_V(DEBUG, TAG, "CASendResponse");
148 return CADetachResponseMessage(object, responseInfo);
152 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token, CAHeaderOption_t* options,
155 OIC_LOG_V(DEBUG, TAG, "CAAdvertiseResource");
157 return CADetachMessageResourceUri(resourceUri, token, options, numOptions);
161 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
163 OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
165 if (!(interestedNetwork & 0xf))
167 return CA_NOT_SUPPORTED;
171 if (interestedNetwork & CA_ETHERNET)
173 res = CAAddNetworkType(CA_ETHERNET);
174 if (res != CA_STATUS_OK)
180 if (interestedNetwork & CA_WIFI)
182 res = CAAddNetworkType(CA_WIFI);
183 if (res != CA_STATUS_OK)
189 if (interestedNetwork & CA_EDR)
191 res = CAAddNetworkType(CA_EDR);
192 if (res != CA_STATUS_OK)
198 if (interestedNetwork & CA_LE)
200 res = CAAddNetworkType(CA_LE);
201 if (res != CA_STATUS_OK)
210 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
212 OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
214 if (!(nonInterestedNetwork & 0xf))
216 return CA_NOT_SUPPORTED;
221 if (nonInterestedNetwork & CA_ETHERNET)
223 res = CARemoveNetworkType(CA_ETHERNET);
224 if (res != CA_STATUS_OK)
230 if (nonInterestedNetwork & CA_WIFI)
232 res = CARemoveNetworkType(CA_WIFI);
233 if (res != CA_STATUS_OK)
239 if (nonInterestedNetwork & CA_EDR)
241 res = CARemoveNetworkType(CA_EDR);
242 if (res != CA_STATUS_OK)
248 if (nonInterestedNetwork & CA_LE)
250 res = CARemoveNetworkType(CA_LE);
251 if (res != CA_STATUS_OK)
260 CAResult_t CAHandleRequestResponse()
262 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponse");
264 CAHandleRequestResponseCallbacks();