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"
43 #define MEMORY_ALLOC_CHECK(arg) { if (arg == NULL) {OIC_LOG_V(DEBUG, TAG, "memory error"); \
44 goto memory_error_exit;} }
46 #define MAX_THREAD_POOL_SIZE 20
50 SEND_TYPE_MULTICAST = 0, SEND_TYPE_UNICAST
55 CASendDataType_t type;
56 CARemoteEndpoint_t *remoteEndpoint;
57 CARequestInfo_t *requestInfo;
58 CAResponseInfo_t *responseInfo;
59 CAHeaderOption_t *options;
64 static u_thread_pool_t gThreadPoolHandle = NULL;
66 // message handler main thread
67 static CAQueueingThread_t gSendThread;
68 static CAQueueingThread_t gReceiveThread;
70 static CARetransmission_t gRetransmissionContext;
73 static CARequestCallback gRequestHandler = NULL;
74 static CAResponseCallback gResponseHandler = NULL;
76 static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, void *pdu, uint32_t size)
78 CARemoteEndpoint_t* ep = CACloneRemoteEndpoint(endpoint);
81 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
85 CAResponseInfo_t* resInfo = (CAResponseInfo_t*) OICMalloc(sizeof(CAResponseInfo_t));
89 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
90 CADestroyRemoteEndpointInternal(ep);
93 memset(resInfo, 0, sizeof(CAResponseInfo_t));
95 CAMessageType_t type = CAGetMessageTypeFromPduBinaryData(pdu, size);
96 uint16_t messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
98 resInfo->result = CA_RETRANSMIT_TIMEOUT;
99 resInfo->info.type = type;
100 resInfo->info.messageId = messageId;
102 CAData_t *cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
105 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
106 CADestroyRemoteEndpointInternal(ep);
110 memset(cadata, 0, sizeof(CAData_t));
112 cadata->type = SEND_TYPE_UNICAST;
113 cadata->remoteEndpoint = ep;
114 cadata->requestInfo = NULL;
115 cadata->responseInfo = resInfo;
117 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
120 static void CADataDestroyer(void *data, uint32_t size)
122 CAData_t *cadata = (CAData_t *) data;
129 if (cadata->remoteEndpoint != NULL)
131 CADestroyRemoteEndpointInternal((CARemoteEndpoint_t *)cadata->remoteEndpoint);
134 if (cadata->requestInfo != NULL)
136 CADestroyRequestInfoInternal((CARequestInfo_t *)cadata->requestInfo);
139 if (cadata->responseInfo != NULL)
141 CADestroyResponseInfoInternal((CAResponseInfo_t *)cadata->responseInfo);
144 if (cadata->options != NULL)
146 OICFree(cadata->options);
152 static void CAReceiveThreadProcess(void *threadData)
154 // Currently not supported
155 // This will be enabled when RI supports multi threading
157 CAData_t *data = (CAData_t *) threadData;
161 OIC_LOG(DEBUG, TAG, "thread data error!!");
165 // parse the data and call the callbacks.
168 CARemoteEndpoint_t *rep = (CARemoteEndpoint_t *)(data->remoteEndpoint);
173 if (data->requestInfo != NULL)
177 gRequestHandler(rep, data->requestInfo);
181 if (data->responseInfo != NULL)
183 if (gResponseHandler)
185 gResponseHandler(rep, data->responseInfo);
191 static void CASendThreadProcess(void *threadData)
193 CAData_t *data = (CAData_t *) threadData;
197 OIC_LOG(DEBUG, TAG, "thread data error!!");
201 if (NULL == data->remoteEndpoint)
203 OIC_LOG(DEBUG, TAG, "remoteEndpoint is null");
207 CAResult_t res = CA_STATUS_FAILED;
209 CASendDataType_t type = data->type;
211 if (type == SEND_TYPE_UNICAST)
213 coap_pdu_t *pdu = NULL;
215 if (data->requestInfo != NULL)
217 OIC_LOG_V(DEBUG, TAG, "requestInfo is available..");
219 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
220 data->requestInfo->method,
221 data->requestInfo->info);
223 else if (data->responseInfo != NULL)
225 OIC_LOG_V(DEBUG, TAG, "responseInfo is available..");
227 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
228 data->responseInfo->result,
229 data->responseInfo->info);
233 OIC_LOG(DEBUG, TAG, "request info, response info is empty");
236 // interface controller function call.
239 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
241 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
243 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
245 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
247 OIC_LOG_V(DEBUG, TAG, "PDU Maker - token : %s", pdu->hdr->token);
249 OIC_LOG_V(DEBUG, TAG, "PDU Maker - buffer data : %s", pdu->hdr);
251 res = CASendUnicastData(data->remoteEndpoint, pdu->hdr, pdu->length);
253 // for retransmission
254 CARetransmissionSentData(&gRetransmissionContext, data->remoteEndpoint, pdu->hdr,
257 coap_delete_pdu(pdu);
260 else if (type == SEND_TYPE_MULTICAST)
262 OIC_LOG(DEBUG, TAG, "both requestInfo & responseInfo is not available");
264 coap_pdu_t *pdu = NULL;
266 memset(&info, 0, sizeof(CAInfo_t));
268 info.options = data->options;
269 info.numOptions = data->numOptions;
270 info.token = data->requestInfo->info.token;
271 info.type = data->requestInfo->info.type;
273 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri, CA_GET, info);
277 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
279 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
281 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
283 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
285 OIC_LOG_V(DEBUG, TAG, "PDU Maker - token : %s", pdu->hdr->token);
287 OIC_LOG_V(DEBUG, TAG, "PDU Maker - buffer data : %s", pdu->hdr);
289 res = CASendMulticastData(pdu->hdr, pdu->length);
290 coap_delete_pdu(pdu);
294 OIC_LOG_V(DEBUG, TAG, " Result :%d", res);
297 static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
300 OIC_LOG(DEBUG, TAG, "receivedPacketCallback in message handler!!");
304 OIC_LOG(DEBUG, TAG, "received data is null");
309 uint32_t code = CA_NOT_FOUND;
311 OIC_LOG_V(DEBUG, TAG, "data : %s", data);
312 pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
317 OIC_LOG(DEBUG, TAG, "pdu is null");
321 char uri[CA_MAX_URI_LENGTH] =
324 if (code == CA_GET || code == CA_POST || code == CA_PUT || code == CA_DELETE)
326 CARequestInfo_t *ReqInfo;
327 ReqInfo = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
330 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
331 coap_delete_pdu(pdu);
334 memset(ReqInfo, 0, sizeof(CARequestInfo_t));
335 CAGetRequestInfoFromPdu(pdu, ReqInfo, uri);
337 if (NULL != ReqInfo->info.options)
340 for (i = 0; i < ReqInfo->info.numOptions; i++)
342 OIC_LOG_V(DEBUG, TAG, "Request- optionID: %d", ReqInfo->info.options[i].optionID);
344 OIC_LOG_V(DEBUG, TAG, "Request- list: %s", ReqInfo->info.options[i].optionData);
348 if (NULL != ReqInfo->info.payload)
350 OIC_LOG_V(DEBUG, TAG, "Request- payload: %s", ReqInfo->info.payload);
352 OIC_LOG_V(DEBUG, TAG, "Request- code: %d", ReqInfo->method);
353 OIC_LOG_V(DEBUG, TAG, "Request- token : %s", ReqInfo->info.token);
355 if (NULL != endpoint)
357 endpoint->resourceUri = (char *) OICMalloc(strlen(uri) + 1);
358 if (endpoint->resourceUri == NULL)
360 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
362 coap_delete_pdu(pdu);
365 memset(endpoint->resourceUri, 0, strlen(uri) + 1);
366 memcpy(endpoint->resourceUri, uri, strlen(uri));
367 OIC_LOG_V(DEBUG, TAG, "added resource URI : %s", endpoint->resourceUri);
369 // store the data at queue.
370 CAData_t *cadata = NULL;
371 cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
374 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
375 if (endpoint != NULL && endpoint->resourceUri != NULL)
376 OICFree(endpoint->resourceUri);
378 coap_delete_pdu(pdu);
381 memset(cadata, 0, sizeof(CAData_t));
383 cadata->type = SEND_TYPE_UNICAST;
384 cadata->remoteEndpoint = endpoint;
385 cadata->requestInfo = ReqInfo;
386 cadata->responseInfo = NULL;
387 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
391 CAResponseInfo_t *ResInfo;
392 ResInfo = (CAResponseInfo_t *) OICMalloc(sizeof(CAResponseInfo_t));
395 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
396 coap_delete_pdu(pdu);
399 memset(ResInfo, 0, sizeof(CAResponseInfo_t));
400 CAGetResponseInfoFromPdu(pdu, ResInfo, uri);
402 if (NULL != ResInfo->info.options)
405 for (i = 0; i < ResInfo->info.numOptions; i++)
407 OIC_LOG_V(DEBUG, TAG, "Response- optionID: %d", ResInfo->info.options[i].optionID);
409 OIC_LOG_V(DEBUG, TAG, "Response- list: %s", ResInfo->info.options[i].optionData);
411 if (NULL != ResInfo->info.payload)
413 OIC_LOG_V(DEBUG, TAG, "Response- payload: %s", ResInfo->info.payload);
414 } OIC_LOG_V(DEBUG, TAG, "Response- code: %d", ResInfo->result);
417 if (NULL != endpoint)
419 endpoint->resourceUri = (char *) OICMalloc(strlen(uri) + 1);
420 if (endpoint->resourceUri == NULL)
422 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
424 coap_delete_pdu(pdu);
427 memset(endpoint->resourceUri, 0, strlen(uri) + 1);
428 memcpy(endpoint->resourceUri, uri, strlen(uri));
429 OIC_LOG_V(DEBUG, TAG, "added resource URI : %s", endpoint->resourceUri);
432 // store the data at queue.
433 CAData_t *cadata = NULL;
434 cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
437 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
438 if (endpoint != NULL && endpoint->resourceUri != NULL)
439 OICFree(endpoint->resourceUri);
441 coap_delete_pdu(pdu);
444 memset(cadata, 0, sizeof(CAData_t));
446 cadata->type = SEND_TYPE_UNICAST;
447 cadata->remoteEndpoint = endpoint;
448 cadata->requestInfo = NULL;
449 cadata->responseInfo = ResInfo;
451 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
453 // for retransmission
454 CARetransmissionReceivedData(&gRetransmissionContext, endpoint, pdu->hdr, pdu->length);
459 coap_delete_pdu(pdu);
463 static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
465 OIC_LOG(DEBUG, TAG, "networkChangeCallback in message handler!!");
467 OIC_LOG_V(DEBUG, TAG, "Changed Network Status: %d", status);
470 void CAHandleRequestResponseCallbacks()
472 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks IN");
474 // parse the data and call the callbacks.
478 u_mutex_lock(gReceiveThread.threadMutex);
480 u_queue_message_t *item = u_queue_get_element(gReceiveThread.dataQueue);
482 u_mutex_unlock(gReceiveThread.threadMutex);
488 void *msg = item->msg;
494 CAData_t *td = (CAData_t *) msg;
495 CARemoteEndpoint_t *rep = td->remoteEndpoint;
500 if (td->requestInfo != NULL)
504 gRequestHandler(rep, td->requestInfo);
507 if (NULL != td->requestInfo->info.options)
509 OICFree(td->requestInfo->info.options);
512 if (NULL != td->requestInfo->info.payload)
514 OICFree(td->requestInfo->info.payload);
517 if (NULL != td->requestInfo->info.token)
519 OICFree(td->requestInfo->info.token);
521 OICFree(td->requestInfo);
524 if (td->responseInfo != NULL)
526 if (gResponseHandler)
528 gResponseHandler(rep, td->responseInfo);
531 if (NULL != td->responseInfo->info.options)
533 OICFree(td->responseInfo->info.options);
536 if (NULL != td->responseInfo->info.payload)
538 OICFree(td->responseInfo->info.payload);
541 if (NULL != td->responseInfo->info.token)
543 OICFree(td->responseInfo->info.token);
545 OICFree(td->responseInfo);
548 if (NULL != rep->resourceUri)
550 OICFree(rep->resourceUri);
554 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks OUT");
557 CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object,
558 const CARequestInfo_t *request)
560 OIC_LOG_V(DEBUG, TAG, "CADetachRequestMessage");
562 if (object == NULL || request == NULL)
564 return CA_STATUS_FAILED;
567 CARemoteEndpoint_t *remoteEndpoint = NULL;
568 CARequestInfo_t *requestInfo = NULL;
570 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
571 MEMORY_ALLOC_CHECK(data);
574 memset(data, 0, sizeof(CAData_t));
576 // clone remote endpoint
578 remoteEndpoint = CACloneRemoteEndpoint(object);
579 MEMORY_ALLOC_CHECK(remoteEndpoint);
581 // clone request info
582 requestInfo = CACloneRequestInfo(request);
583 MEMORY_ALLOC_CHECK(requestInfo);
586 data->type = SEND_TYPE_UNICAST;
587 data->remoteEndpoint = remoteEndpoint;
588 data->requestInfo = requestInfo;
589 data->responseInfo = NULL;
592 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
596 // memory error label.
599 CADestroyRemoteEndpointInternal(remoteEndpoint);
601 CADestroyRequestInfoInternal(requestInfo);
608 return CA_MEMORY_ALLOC_FAILED;
611 CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
612 const CARequestInfo_t *request)
615 OIC_LOG_V(DEBUG, TAG, "CADetachRequestToAllMessage");
618 if (object == NULL || request == NULL)
620 return CA_STATUS_FAILED;
623 CARemoteEndpoint_t *remoteEndpoint = NULL;
624 CARequestInfo_t *requestInfo = NULL;
626 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
627 MEMORY_ALLOC_CHECK(data);
630 memset(data, 0, sizeof(CAData_t));
633 memset(&addr, 0, sizeof(CAAddress_t));
634 remoteEndpoint = CACreateRemoteEndpointInternal(object->resourceUri, addr,
635 object->connectivityType);
637 // clone request info
638 requestInfo = CACloneRequestInfo(request);
639 MEMORY_ALLOC_CHECK(requestInfo);
642 data->type = SEND_TYPE_MULTICAST;
643 data->remoteEndpoint = remoteEndpoint;
644 data->requestInfo = requestInfo;
645 data->responseInfo = NULL;
648 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
652 // memory error label.
655 CADestroyRemoteEndpointInternal(remoteEndpoint);
657 CADestroyRequestInfoInternal(requestInfo);
664 return CA_MEMORY_ALLOC_FAILED;
667 CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
668 const CAResponseInfo_t *response)
670 OIC_LOG_V(DEBUG, TAG, "CADetachResponseMessage");
672 if (object == NULL || response == NULL)
674 return CA_STATUS_FAILED;
677 CARemoteEndpoint_t *remoteEndpoint = NULL;
678 CAResponseInfo_t *responseInfo = NULL;
680 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
681 MEMORY_ALLOC_CHECK(data);
684 memset(data, 0, sizeof(CAData_t));
686 // clone remote endpoint
687 remoteEndpoint = CACloneRemoteEndpoint(object);
688 MEMORY_ALLOC_CHECK(remoteEndpoint);
690 // clone response info
691 responseInfo = CACloneResponseInfo(response);
692 MEMORY_ALLOC_CHECK(responseInfo);
695 data->type = SEND_TYPE_UNICAST;
696 data->remoteEndpoint = remoteEndpoint;
697 data->requestInfo = NULL;
698 data->responseInfo = responseInfo;
701 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
705 // memory error label.
708 CADestroyRemoteEndpointInternal(remoteEndpoint);
710 CADestroyResponseInfoInternal(responseInfo);
717 return CA_MEMORY_ALLOC_FAILED;
720 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
721 const CAHeaderOption_t *options, uint8_t numOptions)
723 if (resourceUri == NULL)
725 return CA_STATUS_FAILED;
727 CARequestInfo_t *ReqInfo = NULL;
728 CAToken_t tempToken = NULL;
729 CARemoteEndpoint_t *remoteEndpoint = NULL;
731 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
732 MEMORY_ALLOC_CHECK(data);
735 memset(data, 0, sizeof(CAData_t));
738 memset(&addr, 0, sizeof(CAAddress_t));
739 remoteEndpoint = CACreateRemoteEndpointInternal(resourceUri, addr,
740 CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE);
742 // create request info
743 ReqInfo = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
744 MEMORY_ALLOC_CHECK(ReqInfo);
745 memset(ReqInfo, 0, sizeof(CARequestInfo_t));
750 int32_t len = strlen(token);
751 tempToken = (char *) OICMalloc(sizeof(char) * (len + 1));
752 MEMORY_ALLOC_CHECK(tempToken);
753 memset(tempToken, 0, sizeof(char) * (len + 1));
754 strncpy(tempToken, token, len);
757 // save request info data
758 ReqInfo->method = CA_GET;
759 ReqInfo->info.token = tempToken;
760 ReqInfo->info.type = CA_MSG_NONCONFIRM;
762 data->type = SEND_TYPE_MULTICAST;
763 data->remoteEndpoint = remoteEndpoint;
764 data->requestInfo = ReqInfo;
766 data->responseInfo = NULL;
767 data->options = NULL;
768 data->numOptions = 0;
770 if (options != NULL && numOptions > 0)
773 CAHeaderOption_t *temp = (CAHeaderOption_t *) OICMalloc(
774 sizeof(CAHeaderOption_t) * numOptions);
776 MEMORY_ALLOC_CHECK(temp);
778 memset(temp, 0, sizeof(CAHeaderOption_t) * numOptions);
779 memcpy(temp, options, sizeof(CAHeaderOption_t) * numOptions);
781 data->options = temp;
782 data->numOptions = numOptions;
786 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
790 // memory error label.
793 CADestroyRemoteEndpointInternal(remoteEndpoint);
795 if (tempToken != NULL)
810 return CA_MEMORY_ALLOC_FAILED;
813 void CASetRequestResponseCallbacks(CARequestCallback ReqHandler,
814 CAResponseCallback RespHandler)
816 OIC_LOG_V(DEBUG, TAG, "set request, response handler callback.");
818 gRequestHandler = ReqHandler;
819 gResponseHandler = RespHandler;
822 CAResult_t CAInitializeMessageHandler()
824 OIC_LOG(DEBUG, TAG, "CAInitializeMessageHandler - Entry");
825 CASetPacketReceivedCallback(CAReceivedPacketCallback);
827 CASetNetworkChangeCallback(CANetworkChangedCallback);
829 // create thread pool
831 res = u_thread_pool_init(MAX_THREAD_POOL_SIZE, &gThreadPoolHandle);
833 if (res != CA_STATUS_OK)
835 OIC_LOG_V(DEBUG, TAG, "thread pool initialize error.");
839 // send thread initialize
840 CAQueueingThreadInitialize(&gSendThread, gThreadPoolHandle, CASendThreadProcess,
844 res = CAQueueingThreadStart(&gSendThread);
846 if (res != CA_STATUS_OK)
848 OIC_LOG_V(DEBUG, TAG, "thread start error(send thread).");
852 // receive thread initialize
853 CAQueueingThreadInitialize(&gReceiveThread, gThreadPoolHandle, CAReceiveThreadProcess,
856 #if 0 // This will be enabled when RI supports multi threading
857 // start receive thread
858 res = CAQueueingThreadStart(&gReceiveThread);
860 if (res != CA_STATUS_OK)
862 OIC_LOG_V(DEBUG, TAG, "thread start error(receive thread).");
867 // retransmission initialize
868 CARetransmissionInitialize(&gRetransmissionContext, gThreadPoolHandle, CASendUnicastData,
869 CATimeoutCallback, NULL);
871 // start retransmission
872 res = CARetransmissionStart(&gRetransmissionContext);
874 if (res != CA_STATUS_OK)
876 OIC_LOG_V(DEBUG, TAG, "thread start error(retransmission thread).");
880 // initialize interface adapters by controller
881 CAInitializeAdapters(gThreadPoolHandle);
886 void CATerminateMessageHandler()
888 // terminate interface adapters by controller
889 CATerminateAdapters();
891 // stop retransmission
892 if(gRetransmissionContext.threadMutex != NULL) {
893 CARetransmissionStop(&gRetransmissionContext);
894 CARetransmissionDestroy(&gRetransmissionContext);
898 // delete thread data
899 if(gSendThread.threadMutex != NULL) {
900 CAQueueingThreadStop(&gSendThread);
901 CAQueueingThreadDestroy(&gSendThread);
905 // delete thread data
906 if(gReceiveThread.threadMutex != NULL) {
907 #if 0 // This will be enabled when RI supports multi threading
908 // CAQueueingThreadStop(&gReceiveThread);
910 CAQueueingThreadDestroy(&gReceiveThread);
913 // destroy thread pool
914 if(gThreadPoolHandle != NULL) {
915 u_thread_pool_free(gThreadPoolHandle);
916 gThreadPoolHandle = NULL;
919 OIC_LOG_V(DEBUG, TAG, "message handler termination is complete!");