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 ******************************************************************/
26 #include "cainterface.h"
27 #include "camessagehandler.h"
28 #include "caremotehandler.h"
29 #include "cainterfacecontroller.h"
30 #include "caprotocolmessage.h"
33 #include "config.h" /* for coap protocol */
35 #include "uthreadpool.h" /* for thread pool */
36 #include "caqueueingthread.h"
37 #include "caretransmission.h"
39 #include "oic_malloc.h"
44 #define MEMORY_ALLOC_CHECK(arg) { if (arg == NULL) {OIC_LOG_V(DEBUG, TAG, "memory error"); \
45 goto memory_error_exit;} }
47 #define MAX_THREAD_POOL_SIZE 20
51 SEND_TYPE_MULTICAST = 0, SEND_TYPE_UNICAST
56 CASendDataType_t type;
57 CARemoteEndpoint_t *remoteEndpoint;
58 CARequestInfo_t *requestInfo;
59 CAResponseInfo_t *responseInfo;
60 CAHeaderOption_t *options;
65 static u_thread_pool_t gThreadPoolHandle = NULL;
67 // message handler main thread
68 static CAQueueingThread_t gSendThread;
69 static CAQueueingThread_t gReceiveThread;
71 static CARetransmission_t gRetransmissionContext;
74 static CARequestCallback gRequestHandler = NULL;
75 static CAResponseCallback gResponseHandler = NULL;
77 static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, void *pdu, uint32_t size)
79 CARemoteEndpoint_t* ep = CACloneRemoteEndpoint(endpoint);
82 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
86 CAResponseInfo_t* resInfo = (CAResponseInfo_t*) OICMalloc(sizeof(CAResponseInfo_t));
90 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
91 CADestroyRemoteEndpointInternal(ep);
94 memset(resInfo, 0, sizeof(CAResponseInfo_t));
96 CAMessageType_t type = CAGetMessageTypeFromPduBinaryData(pdu, size);
97 uint16_t messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
99 resInfo->result = CA_RETRANSMIT_TIMEOUT;
100 resInfo->info.type = type;
101 resInfo->info.messageId = messageId;
103 CAData_t *cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
106 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
107 CADestroyRemoteEndpointInternal(ep);
111 memset(cadata, 0, sizeof(CAData_t));
113 cadata->type = SEND_TYPE_UNICAST;
114 cadata->remoteEndpoint = ep;
115 cadata->requestInfo = NULL;
116 cadata->responseInfo = resInfo;
118 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
121 static void CADataDestroyer(void *data, uint32_t size)
123 CAData_t *cadata = (CAData_t *) data;
130 if (cadata->remoteEndpoint != NULL)
132 CADestroyRemoteEndpointInternal((CARemoteEndpoint_t *)cadata->remoteEndpoint);
135 if (cadata->requestInfo != NULL)
137 CADestroyRequestInfoInternal((CARequestInfo_t *)cadata->requestInfo);
140 if (cadata->responseInfo != NULL)
142 CADestroyResponseInfoInternal((CAResponseInfo_t *)cadata->responseInfo);
145 if (cadata->options != NULL)
147 OICFree(cadata->options);
153 static void CAReceiveThreadProcess(void *threadData)
155 // Currently not supported
156 // This will be enabled when RI supports multi threading
157 #ifndef SINGLE_HANDLE
158 CAData_t *data = (CAData_t *) threadData;
162 OIC_LOG(DEBUG, TAG, "thread data error!!");
166 // parse the data and call the callbacks.
169 CARemoteEndpoint_t *rep = (CARemoteEndpoint_t *)(data->remoteEndpoint);
174 if (data->requestInfo != NULL)
178 gRequestHandler(rep, data->requestInfo);
182 if (data->responseInfo != NULL)
184 if (gResponseHandler)
186 gResponseHandler(rep, data->responseInfo);
192 static void CASendThreadProcess(void *threadData)
194 CAData_t *data = (CAData_t *) threadData;
198 OIC_LOG(DEBUG, TAG, "thread data error!!");
202 if (NULL == data->remoteEndpoint)
204 OIC_LOG(DEBUG, TAG, "remoteEndpoint is null");
208 CAResult_t res = CA_STATUS_FAILED;
210 CASendDataType_t type = data->type;
212 if (type == SEND_TYPE_UNICAST)
214 coap_pdu_t *pdu = NULL;
216 if (data->requestInfo != NULL)
218 OIC_LOG_V(DEBUG, TAG, "requestInfo is available..");
220 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
221 data->requestInfo->method,
222 data->requestInfo->info);
224 else if (data->responseInfo != NULL)
226 OIC_LOG_V(DEBUG, TAG, "responseInfo is available..");
228 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
229 data->responseInfo->result,
230 data->responseInfo->info);
234 OIC_LOG(DEBUG, TAG, "request info, response info is empty");
237 // interface controller function call.
240 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
242 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
244 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
246 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
248 OIC_LOG_V(DEBUG, TAG, "PDU Maker - token : %s", pdu->hdr->token);
250 OIC_LOG_V(DEBUG, TAG, "PDU Maker - buffer data : %s", pdu->hdr);
252 res = CASendUnicastData(data->remoteEndpoint, pdu->hdr, pdu->length);
254 // for retransmission
255 CARetransmissionSentData(&gRetransmissionContext, data->remoteEndpoint, pdu->hdr,
258 coap_delete_pdu(pdu);
261 else if (type == SEND_TYPE_MULTICAST)
263 OIC_LOG(DEBUG, TAG, "both requestInfo & responseInfo is not available");
265 coap_pdu_t *pdu = NULL;
267 memset(&info, 0, sizeof(CAInfo_t));
269 info.options = data->options;
270 info.numOptions = data->numOptions;
271 info.token = data->requestInfo->info.token;
272 info.type = data->requestInfo->info.type;
274 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri, CA_GET, info);
278 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
280 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
282 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
284 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
286 OIC_LOG_V(DEBUG, TAG, "PDU Maker - token : %s", pdu->hdr->token);
288 OIC_LOG_V(DEBUG, TAG, "PDU Maker - buffer data : %s", pdu->hdr);
290 res = CASendMulticastData(pdu->hdr, pdu->length);
291 coap_delete_pdu(pdu);
295 OIC_LOG_V(DEBUG, TAG, " Result :%d", res);
298 static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
301 OIC_LOG(DEBUG, TAG, "receivedPacketCallback in message handler!!");
305 OIC_LOG(DEBUG, TAG, "received data is null");
310 uint32_t code = CA_NOT_FOUND;
312 OIC_LOG_V(DEBUG, TAG, "data : %s", data);
313 pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
318 OIC_LOG(DEBUG, TAG, "pdu is null");
322 char uri[CA_MAX_URI_LENGTH] =
325 if (code == CA_GET || code == CA_POST || code == CA_PUT || code == CA_DELETE)
327 CARequestInfo_t *ReqInfo;
328 ReqInfo = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
331 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
332 coap_delete_pdu(pdu);
335 memset(ReqInfo, 0, sizeof(CARequestInfo_t));
336 CAGetRequestInfoFromPdu(pdu, ReqInfo, uri);
338 if (NULL != ReqInfo->info.options)
341 for (i = 0; i < ReqInfo->info.numOptions; i++)
343 OIC_LOG_V(DEBUG, TAG, "Request- optionID: %d", ReqInfo->info.options[i].optionID);
345 OIC_LOG_V(DEBUG, TAG, "Request- list: %s", ReqInfo->info.options[i].optionData);
349 if (NULL != ReqInfo->info.payload)
351 OIC_LOG_V(DEBUG, TAG, "Request- payload: %s", ReqInfo->info.payload);
353 OIC_LOG_V(DEBUG, TAG, "Request- code: %d", ReqInfo->method);
354 OIC_LOG_V(DEBUG, TAG, "Request- token : %s", ReqInfo->info.token);
355 OIC_LOG_V(DEBUG, TAG, "Request- msgID: %d", ReqInfo->info.messageId);
357 if (NULL != endpoint)
359 endpoint->resourceUri = (char *) OICMalloc(strlen(uri) + 1);
360 if (endpoint->resourceUri == NULL)
362 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
364 coap_delete_pdu(pdu);
367 memset(endpoint->resourceUri, 0, strlen(uri) + 1);
368 memcpy(endpoint->resourceUri, uri, strlen(uri));
369 OIC_LOG_V(DEBUG, TAG, "added resource URI : %s", endpoint->resourceUri);
371 // store the data at queue.
372 CAData_t *cadata = NULL;
373 cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
376 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
377 if (endpoint != NULL && endpoint->resourceUri != NULL)
378 OICFree(endpoint->resourceUri);
380 coap_delete_pdu(pdu);
383 memset(cadata, 0, sizeof(CAData_t));
385 cadata->type = SEND_TYPE_UNICAST;
386 cadata->remoteEndpoint = endpoint;
387 cadata->requestInfo = ReqInfo;
388 cadata->responseInfo = NULL;
389 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
393 CAResponseInfo_t *ResInfo;
394 ResInfo = (CAResponseInfo_t *) OICMalloc(sizeof(CAResponseInfo_t));
397 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
398 coap_delete_pdu(pdu);
401 memset(ResInfo, 0, sizeof(CAResponseInfo_t));
402 CAGetResponseInfoFromPdu(pdu, ResInfo, uri);
404 if (NULL != ResInfo->info.options)
407 for (i = 0; i < ResInfo->info.numOptions; i++)
409 OIC_LOG_V(DEBUG, TAG, "Response- optionID: %d", ResInfo->info.options[i].optionID);
411 OIC_LOG_V(DEBUG, TAG, "Response- list: %s", ResInfo->info.options[i].optionData);
413 if (NULL != ResInfo->info.payload)
415 OIC_LOG_V(DEBUG, TAG, "Response- payload: %s", ResInfo->info.payload);
416 } OIC_LOG_V(DEBUG, TAG, "Response- code: %d", ResInfo->result);
419 if (NULL != endpoint)
421 endpoint->resourceUri = (char *) OICMalloc(strlen(uri) + 1);
422 if (endpoint->resourceUri == NULL)
424 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
426 coap_delete_pdu(pdu);
429 memset(endpoint->resourceUri, 0, strlen(uri) + 1);
430 memcpy(endpoint->resourceUri, uri, strlen(uri));
431 OIC_LOG_V(DEBUG, TAG, "added resource URI : %s", endpoint->resourceUri);
434 // store the data at queue.
435 CAData_t *cadata = NULL;
436 cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
439 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
440 if (endpoint != NULL && endpoint->resourceUri != NULL)
441 OICFree(endpoint->resourceUri);
443 coap_delete_pdu(pdu);
446 memset(cadata, 0, sizeof(CAData_t));
448 cadata->type = SEND_TYPE_UNICAST;
449 cadata->remoteEndpoint = endpoint;
450 cadata->requestInfo = NULL;
451 cadata->responseInfo = ResInfo;
453 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
455 // for retransmission
456 CARetransmissionReceivedData(&gRetransmissionContext, endpoint, pdu->hdr, pdu->length);
461 coap_delete_pdu(pdu);
465 static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
467 OIC_LOG(DEBUG, TAG, "networkChangeCallback in message handler!!");
469 OIC_LOG_V(DEBUG, TAG, "Changed Network Status: %d", status);
472 void CAHandleRequestResponseCallbacks()
474 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks IN");
477 // parse the data and call the callbacks.
481 u_mutex_lock(gReceiveThread.threadMutex);
483 u_queue_message_t *item = u_queue_get_element(gReceiveThread.dataQueue);
485 u_mutex_unlock(gReceiveThread.threadMutex);
491 void *msg = item->msg;
497 CAData_t *td = (CAData_t *) msg;
498 CARemoteEndpoint_t *rep = td->remoteEndpoint;
503 if (td->requestInfo != NULL)
507 gRequestHandler(rep, td->requestInfo);
510 if (NULL != td->requestInfo->info.options)
512 OICFree(td->requestInfo->info.options);
515 if (NULL != td->requestInfo->info.payload)
517 OICFree(td->requestInfo->info.payload);
520 if (NULL != td->requestInfo->info.token)
522 OICFree(td->requestInfo->info.token);
524 OICFree(td->requestInfo);
527 if (td->responseInfo != NULL)
529 if (gResponseHandler)
531 gResponseHandler(rep, td->responseInfo);
534 if (NULL != td->responseInfo->info.options)
536 OICFree(td->responseInfo->info.options);
539 if (NULL != td->responseInfo->info.payload)
541 OICFree(td->responseInfo->info.payload);
544 if (NULL != td->responseInfo->info.token)
546 OICFree(td->responseInfo->info.token);
548 OICFree(td->responseInfo);
551 if (NULL != rep->resourceUri)
553 OICFree(rep->resourceUri);
560 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks OUT");
563 CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object,
564 const CARequestInfo_t *request)
566 OIC_LOG_V(DEBUG, TAG, "CADetachRequestMessage");
568 if (object == NULL || request == NULL)
570 return CA_STATUS_FAILED;
573 CARemoteEndpoint_t *remoteEndpoint = NULL;
574 CARequestInfo_t *requestInfo = NULL;
576 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
577 MEMORY_ALLOC_CHECK(data);
580 memset(data, 0, sizeof(CAData_t));
582 // clone remote endpoint
584 remoteEndpoint = CACloneRemoteEndpoint(object);
585 MEMORY_ALLOC_CHECK(remoteEndpoint);
587 // clone request info
588 requestInfo = CACloneRequestInfo(request);
589 MEMORY_ALLOC_CHECK(requestInfo);
592 data->type = SEND_TYPE_UNICAST;
593 data->remoteEndpoint = remoteEndpoint;
594 data->requestInfo = requestInfo;
595 data->responseInfo = NULL;
598 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
602 // memory error label.
605 CADestroyRemoteEndpointInternal(remoteEndpoint);
607 CADestroyRequestInfoInternal(requestInfo);
614 return CA_MEMORY_ALLOC_FAILED;
617 CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
618 const CARequestInfo_t *request)
621 OIC_LOG_V(DEBUG, TAG, "CADetachRequestToAllMessage");
624 if (object == NULL || request == NULL)
626 return CA_STATUS_FAILED;
629 CARemoteEndpoint_t *remoteEndpoint = NULL;
630 CARequestInfo_t *requestInfo = NULL;
632 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
633 MEMORY_ALLOC_CHECK(data);
636 memset(data, 0, sizeof(CAData_t));
639 memset(&addr, 0, sizeof(CAAddress_t));
640 remoteEndpoint = CACreateRemoteEndpointInternal(object->resourceUri, addr,
641 object->connectivityType);
643 // clone request info
644 requestInfo = CACloneRequestInfo(request);
645 MEMORY_ALLOC_CHECK(requestInfo);
648 data->type = SEND_TYPE_MULTICAST;
649 data->remoteEndpoint = remoteEndpoint;
650 data->requestInfo = requestInfo;
651 data->responseInfo = NULL;
654 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
658 // memory error label.
661 CADestroyRemoteEndpointInternal(remoteEndpoint);
663 CADestroyRequestInfoInternal(requestInfo);
670 return CA_MEMORY_ALLOC_FAILED;
673 CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
674 const CAResponseInfo_t *response)
676 OIC_LOG_V(DEBUG, TAG, "CADetachResponseMessage");
678 if (object == NULL || response == NULL)
680 return CA_STATUS_FAILED;
683 CARemoteEndpoint_t *remoteEndpoint = NULL;
684 CAResponseInfo_t *responseInfo = NULL;
686 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
687 MEMORY_ALLOC_CHECK(data);
690 memset(data, 0, sizeof(CAData_t));
692 // clone remote endpoint
693 remoteEndpoint = CACloneRemoteEndpoint(object);
694 MEMORY_ALLOC_CHECK(remoteEndpoint);
696 // clone response info
697 responseInfo = CACloneResponseInfo(response);
698 MEMORY_ALLOC_CHECK(responseInfo);
701 data->type = SEND_TYPE_UNICAST;
702 data->remoteEndpoint = remoteEndpoint;
703 data->requestInfo = NULL;
704 data->responseInfo = responseInfo;
707 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
711 // memory error label.
714 CADestroyRemoteEndpointInternal(remoteEndpoint);
716 CADestroyResponseInfoInternal(responseInfo);
723 return CA_MEMORY_ALLOC_FAILED;
726 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
727 const CAHeaderOption_t *options, uint8_t numOptions)
729 if (resourceUri == NULL)
731 return CA_STATUS_FAILED;
733 CARequestInfo_t *ReqInfo = NULL;
734 CAToken_t tempToken = NULL;
735 CARemoteEndpoint_t *remoteEndpoint = NULL;
737 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
738 MEMORY_ALLOC_CHECK(data);
741 memset(data, 0, sizeof(CAData_t));
744 memset(&addr, 0, sizeof(CAAddress_t));
745 remoteEndpoint = CACreateRemoteEndpointInternal(resourceUri, addr,
746 CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE);
748 // create request info
749 ReqInfo = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
750 MEMORY_ALLOC_CHECK(ReqInfo);
751 memset(ReqInfo, 0, sizeof(CARequestInfo_t));
756 int32_t len = strlen(token);
757 tempToken = (char *) OICMalloc(sizeof(char) * (len + 1));
758 MEMORY_ALLOC_CHECK(tempToken);
759 memset(tempToken, 0, sizeof(char) * (len + 1));
760 strncpy(tempToken, token, len);
763 // save request info data
764 ReqInfo->method = CA_GET;
765 ReqInfo->info.token = tempToken;
766 ReqInfo->info.type = CA_MSG_NONCONFIRM;
768 data->type = SEND_TYPE_MULTICAST;
769 data->remoteEndpoint = remoteEndpoint;
770 data->requestInfo = ReqInfo;
772 data->responseInfo = NULL;
773 data->options = NULL;
774 data->numOptions = 0;
776 if (options != NULL && numOptions > 0)
779 CAHeaderOption_t *temp = (CAHeaderOption_t *) OICMalloc(
780 sizeof(CAHeaderOption_t) * numOptions);
782 MEMORY_ALLOC_CHECK(temp);
784 memset(temp, 0, sizeof(CAHeaderOption_t) * numOptions);
785 memcpy(temp, options, sizeof(CAHeaderOption_t) * numOptions);
787 data->options = temp;
788 data->numOptions = numOptions;
792 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
796 // memory error label.
799 CADestroyRemoteEndpointInternal(remoteEndpoint);
801 if (tempToken != NULL)
816 return CA_MEMORY_ALLOC_FAILED;
819 void CASetRequestResponseCallbacks(CARequestCallback ReqHandler,
820 CAResponseCallback RespHandler)
822 OIC_LOG_V(DEBUG, TAG, "set request, response handler callback.");
824 gRequestHandler = ReqHandler;
825 gResponseHandler = RespHandler;
828 CAResult_t CAInitializeMessageHandler()
830 OIC_LOG(DEBUG, TAG, "CAInitializeMessageHandler - Entry");
831 CASetPacketReceivedCallback(CAReceivedPacketCallback);
833 CASetNetworkChangeCallback(CANetworkChangedCallback);
835 // create thread pool
837 res = u_thread_pool_init(MAX_THREAD_POOL_SIZE, &gThreadPoolHandle);
839 if (res != CA_STATUS_OK)
841 OIC_LOG_V(DEBUG, TAG, "thread pool initialize error.");
845 // send thread initialize
846 CAQueueingThreadInitialize(&gSendThread, gThreadPoolHandle, CASendThreadProcess,
850 res = CAQueueingThreadStart(&gSendThread);
852 if (res != CA_STATUS_OK)
854 OIC_LOG_V(DEBUG, TAG, "thread start error(send thread).");
858 // receive thread initialize
859 CAQueueingThreadInitialize(&gReceiveThread, gThreadPoolHandle, CAReceiveThreadProcess,
862 #ifndef SINGLE_HANDLE// This will be enabled when RI supports multi threading
863 // start receive thread
864 res = CAQueueingThreadStart(&gReceiveThread);
866 if (res != CA_STATUS_OK)
868 OIC_LOG_V(DEBUG, TAG, "thread start error(receive thread).");
873 // retransmission initialize
874 CARetransmissionInitialize(&gRetransmissionContext, gThreadPoolHandle, CASendUnicastData,
875 CATimeoutCallback, NULL);
877 // start retransmission
878 res = CARetransmissionStart(&gRetransmissionContext);
880 if (res != CA_STATUS_OK)
882 OIC_LOG_V(DEBUG, TAG, "thread start error(retransmission thread).");
886 // initialize interface adapters by controller
887 CAInitializeAdapters(gThreadPoolHandle);
892 void CATerminateMessageHandler()
894 // terminate interface adapters by controller
895 CATerminateAdapters();
897 // stop retransmission
898 if(gRetransmissionContext.threadMutex != NULL) {
899 CARetransmissionStop(&gRetransmissionContext);
900 CARetransmissionDestroy(&gRetransmissionContext);
904 // delete thread data
905 if(gSendThread.threadMutex != NULL) {
906 CAQueueingThreadStop(&gSendThread);
907 CAQueueingThreadDestroy(&gSendThread);
911 // delete thread data
912 if(gReceiveThread.threadMutex != NULL) {
913 #ifndef SINGLE_HANDLE// This will be enabled when RI supports multi threading
914 // CAQueueingThreadStop(&gReceiveThread);
916 CAQueueingThreadDestroy(&gReceiveThread);
919 // destroy thread pool
920 if(gThreadPoolHandle != NULL) {
921 u_thread_pool_free(gThreadPoolHandle);
922 gThreadPoolHandle = NULL;
925 OIC_LOG_V(DEBUG, TAG, "message handler termination is complete!");