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,
80 const CAConnectivityType_t connectivityType,CARemoteEndpoint_t **remoteEndpoint)
82 OIC_LOG_V(DEBUG, TAG, "CACreateRemoteEndpoint");
84 CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, connectivityType);
86 *remoteEndpoint = remote;
89 return CA_STATUS_FAILED;
94 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
96 OIC_LOG_V(DEBUG, TAG, "CADestroyRemoteEndpoint");
98 CADestroyRemoteEndpointInternal(rep);
101 CAResult_t CAGenerateToken(CAToken_t *token)
103 OIC_LOG_V(DEBUG, TAG, "CAGenerateToken");
105 return CAGenerateTokenInternal(token);
108 void CADestroyToken(CAToken_t token)
110 OIC_LOG_V(DEBUG, TAG, "CADestroyToken");
112 CADestroyTokenInternal(token);
115 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
117 OIC_LOG_V(DEBUG, TAG, "CAGetNetworkInformation");
119 return CAGetNetworkInformationInternal(info, size);
122 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token)
124 OIC_LOG_V(DEBUG, TAG, "CAFindResource");
126 return CADetachMessageResourceUri(resourceUri, token, NULL, 0);
130 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo)
132 OIC_LOG_V(DEBUG, TAG, "CASendGetRequest");
134 return CADetachRequestMessage(object, requestInfo);
137 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
138 const CARequestInfo_t *requestInfo)
140 OIC_LOG_V(DEBUG, TAG, "CASendRequestToAll");
142 return CADetachRequestToAllMessage(object, requestInfo);
145 CAResult_t CASendNotification(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
147 OIC_LOG_V(DEBUG, TAG, "CASendNotification");
149 return CADetachResponseMessage(object, responseInfo);
153 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
155 OIC_LOG_V(DEBUG, TAG, "CASendResponse");
157 return CADetachResponseMessage(object, responseInfo);
161 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
162 CAHeaderOption_t *options, uint8_t numOptions)
164 OIC_LOG_V(DEBUG, TAG, "CAAdvertiseResource");
166 return CADetachMessageResourceUri(resourceUri, token, options, numOptions);
170 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
172 OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
174 if (!(interestedNetwork & 0xf))
176 return CA_NOT_SUPPORTED;
180 if (interestedNetwork & CA_ETHERNET)
182 res = CAAddNetworkType(CA_ETHERNET);
183 if (res != CA_STATUS_OK)
189 if (interestedNetwork & CA_WIFI)
191 res = CAAddNetworkType(CA_WIFI);
192 if (res != CA_STATUS_OK)
198 if (interestedNetwork & CA_EDR)
200 res = CAAddNetworkType(CA_EDR);
201 if (res != CA_STATUS_OK)
207 if (interestedNetwork & CA_LE)
209 res = CAAddNetworkType(CA_LE);
210 if (res != CA_STATUS_OK)
219 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
221 OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
223 if (!(nonInterestedNetwork & 0xf))
225 return CA_NOT_SUPPORTED;
230 if (nonInterestedNetwork & CA_ETHERNET)
232 res = CARemoveNetworkType(CA_ETHERNET);
233 if (res != CA_STATUS_OK)
239 if (nonInterestedNetwork & CA_WIFI)
241 res = CARemoveNetworkType(CA_WIFI);
242 if (res != CA_STATUS_OK)
248 if (nonInterestedNetwork & CA_EDR)
250 res = CARemoveNetworkType(CA_EDR);
251 if (res != CA_STATUS_OK)
257 if (nonInterestedNetwork & CA_LE)
259 res = CARemoveNetworkType(CA_LE);
260 if (res != CA_STATUS_OK)
269 CAResult_t CAHandleRequestResponse()
271 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponse");
273 CAHandleRequestResponseCallbacks();