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"
40 #include "caadapterutils.h"
41 #include "canetworkconfigurator.h"
46 #define CA_MEMORY_ALLOC_CHECK(arg) { if (arg == NULL) {OIC_LOG_V(ERROR, TAG, "Out of memory"); \
47 goto memory_error_exit;} }
49 #define MAX_THREAD_POOL_SIZE 20
53 SEND_TYPE_MULTICAST = 0, SEND_TYPE_UNICAST
58 CASendDataType_t type;
59 CARemoteEndpoint_t *remoteEndpoint;
60 CARequestInfo_t *requestInfo;
61 CAResponseInfo_t *responseInfo;
62 CAHeaderOption_t *options;
67 static u_thread_pool_t g_threadPoolHandle = NULL;
69 // message handler main thread
70 static CAQueueingThread_t g_sendThread;
71 static CAQueueingThread_t g_receiveThread;
73 static CARetransmission_t g_retransmissionContext;
76 static CARequestCallback g_requestHandler = NULL;
77 static CAResponseCallback g_responseHandler = NULL;
79 static void CATimeoutCallback(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size)
81 CARemoteEndpoint_t* ep = CACloneRemoteEndpoint(endpoint);
84 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
88 CAResponseInfo_t* resInfo = (CAResponseInfo_t*) OICCalloc(1, sizeof(CAResponseInfo_t));
92 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
93 CADestroyRemoteEndpointInternal(ep);
97 CAMessageType_t type = CAGetMessageTypeFromPduBinaryData(pdu, size);
98 uint16_t messageId = CAGetMessageIdFromPduBinaryData(pdu, size);
100 resInfo->result = CA_RETRANSMIT_TIMEOUT;
101 resInfo->info.type = type;
102 resInfo->info.messageId = messageId;
104 CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
107 OIC_LOG(DEBUG, TAG, "memory allocation failed !");
108 CADestroyRemoteEndpointInternal(ep);
113 cadata->type = SEND_TYPE_UNICAST;
114 cadata->remoteEndpoint = ep;
115 cadata->requestInfo = NULL;
116 cadata->responseInfo = resInfo;
118 CAQueueingThreadAddData(&g_receiveThread, 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)
176 if (g_requestHandler)
178 g_requestHandler(rep, data->requestInfo);
182 if (data->responseInfo != NULL)
184 if (g_responseHandler)
186 g_responseHandler(rep, data->responseInfo);
192 static void CASendThreadProcess(void *threadData)
194 CAData_t *data = (CAData_t *) threadData;
198 OIC_LOG(ERROR, 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(DEBUG, TAG, "PDU Maker - token :");
250 OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr->token, pdu->hdr->token_length);
252 res = CASendUnicastData(data->remoteEndpoint, pdu->hdr, pdu->length);
254 // for retransmission
255 CARetransmissionSentData(&g_retransmissionContext, data->remoteEndpoint, pdu->hdr,
258 coap_delete_pdu(pdu);
261 else if (type == SEND_TYPE_MULTICAST)
263 coap_pdu_t *pdu = NULL;
266 info.options = data->options;
267 info.numOptions = data->numOptions;
268 info.token = data->requestInfo->info.token;
269 info.type = data->requestInfo->info.type;
271 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri, CA_GET, info);
275 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
277 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
279 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
281 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
283 OIC_LOG(DEBUG, TAG, "PDU Maker - token");
285 OIC_LOG_BUFFER(DEBUG, TAG, pdu->hdr->token, pdu->hdr->token_length);
287 res = CASendMulticastData(pdu->hdr, pdu->length);
288 coap_delete_pdu(pdu);
292 OIC_LOG_V(DEBUG, TAG, " Result :%d", res);
295 static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
298 OIC_LOG(DEBUG, TAG, "receivedPacketCallback in message handler!!");
302 OIC_LOG(DEBUG, TAG, "received data is null");
307 uint32_t code = CA_NOT_FOUND;
309 OIC_LOG_V(DEBUG, TAG, "data : %s", data);
310 pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
315 OIC_LOG(DEBUG, TAG, "pdu is null");
319 char uri[CA_MAX_URI_LENGTH] = { 0, };
320 uint32_t bufLen = CA_MAX_URI_LENGTH;
322 if (code == CA_GET || code == CA_POST || code == CA_PUT || code == CA_DELETE)
324 CARequestInfo_t *ReqInfo;
325 ReqInfo = (CARequestInfo_t *) OICCalloc(1, sizeof(CARequestInfo_t));
328 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
329 coap_delete_pdu(pdu);
330 CAAdapterFreeRemoteEndpoint(endpoint);
333 CAGetRequestInfoFromPdu(pdu, ReqInfo, uri, bufLen);
335 if (NULL != ReqInfo->info.options)
338 for (i = 0; i < ReqInfo->info.numOptions; i++)
340 OIC_LOG_V(DEBUG, TAG, "Request- optionID: %d", ReqInfo->info.options[i].optionID);
342 OIC_LOG_V(DEBUG, TAG, "Request- list: %s", ReqInfo->info.options[i].optionData);
346 if (NULL != ReqInfo->info.payload)
348 OIC_LOG_V(DEBUG, TAG, "Request- payload: %s", ReqInfo->info.payload);
350 OIC_LOG_V(DEBUG, TAG, "Request- code: %d", ReqInfo->method);
351 if (NULL != ReqInfo->info.token)
353 OIC_LOG(DEBUG, TAG, "Request- token:");
354 OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *) ReqInfo->info.token, CA_MAX_TOKEN_LEN);
357 if (NULL != endpoint)
359 endpoint->resourceUri = (char *) OICCalloc(bufLen + 1, sizeof(char));
360 if (endpoint->resourceUri == NULL)
362 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
364 coap_delete_pdu(pdu);
365 CAAdapterFreeRemoteEndpoint(endpoint);
368 memcpy(endpoint->resourceUri, uri, bufLen);
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 *) OICCalloc(1, 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);
381 CAAdapterFreeRemoteEndpoint(endpoint);
385 cadata->type = SEND_TYPE_UNICAST;
386 cadata->remoteEndpoint = endpoint;
387 cadata->requestInfo = ReqInfo;
388 cadata->responseInfo = NULL;
389 CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
393 CAResponseInfo_t *ResInfo;
394 ResInfo = (CAResponseInfo_t *) OICCalloc(1, sizeof(CAResponseInfo_t));
397 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
398 coap_delete_pdu(pdu);
399 CAAdapterFreeRemoteEndpoint(endpoint);
402 CAGetResponseInfoFromPdu(pdu, ResInfo, uri, bufLen);
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);
417 OIC_LOG_V(DEBUG, TAG, "Response- code: %d", ResInfo->result);
420 if (NULL != endpoint)
422 endpoint->resourceUri = (char *) OICCalloc(bufLen + 1, sizeof(char));
423 if (endpoint->resourceUri == NULL)
425 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
427 coap_delete_pdu(pdu);
428 CAAdapterFreeRemoteEndpoint(endpoint);
431 memcpy(endpoint->resourceUri, uri, bufLen);
432 OIC_LOG_V(DEBUG, TAG, "added resource URI : %s", endpoint->resourceUri);
435 // store the data at queue.
436 CAData_t *cadata = NULL;
437 cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
440 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
441 if (endpoint != NULL && endpoint->resourceUri != NULL)
442 OICFree(endpoint->resourceUri);
444 coap_delete_pdu(pdu);
445 CAAdapterFreeRemoteEndpoint(endpoint);
449 cadata->type = SEND_TYPE_UNICAST;
450 cadata->remoteEndpoint = endpoint;
451 cadata->requestInfo = NULL;
452 cadata->responseInfo = ResInfo;
454 CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
456 // for retransmission
457 CARetransmissionReceivedData(&g_retransmissionContext, endpoint, pdu->hdr, pdu->length);
462 coap_delete_pdu(pdu);
466 static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
468 OIC_LOG(DEBUG, TAG, "networkChangeCallback in message handler!!");
470 OIC_LOG_V(DEBUG, TAG, "Changed Network Status: %d", status);
473 void CAHandleRequestResponseCallbacks()
475 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks IN");
477 // parse the data and call the callbacks.
481 u_mutex_lock(g_receiveThread.threadMutex);
483 u_queue_message_t *item = u_queue_get_element(g_receiveThread.dataQueue);
485 u_mutex_unlock(g_receiveThread.threadMutex);
491 void *msg = item->msg;
497 CAData_t *td = (CAData_t *) msg;
498 CARemoteEndpoint_t *rep = td->remoteEndpoint;
503 if (td->requestInfo != NULL)
505 if (g_requestHandler)
507 g_requestHandler(rep, td->requestInfo);
510 OICFree(td->requestInfo->info.options);
511 OICFree(td->requestInfo->info.payload);
512 OICFree(td->requestInfo->info.token);
513 OICFree(td->requestInfo);
516 if (td->responseInfo != NULL)
518 if (g_responseHandler)
520 g_responseHandler(rep, td->responseInfo);
523 OICFree(td->responseInfo->info.options);
524 OICFree(td->responseInfo->info.payload);
525 OICFree(td->responseInfo->info.token);
526 OICFree(td->responseInfo);
529 if (NULL != rep->resourceUri)
531 OICFree(rep->resourceUri);
535 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks OUT");
538 CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object,
539 const CARequestInfo_t *request)
541 OIC_LOG_V(DEBUG, TAG, "CADetachRequestMessage");
543 if (object == NULL || request == NULL)
545 return CA_STATUS_FAILED;
548 CARemoteEndpoint_t *remoteEndpoint = NULL;
549 CARequestInfo_t *requestInfo = NULL;
551 CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
552 CA_MEMORY_ALLOC_CHECK(data);
554 // clone remote endpoint
556 remoteEndpoint = CACloneRemoteEndpoint(object);
557 CA_MEMORY_ALLOC_CHECK(remoteEndpoint);
559 // clone request info
560 requestInfo = CACloneRequestInfo(request);
561 CA_MEMORY_ALLOC_CHECK(requestInfo);
564 data->type = SEND_TYPE_UNICAST;
565 data->remoteEndpoint = remoteEndpoint;
566 data->requestInfo = requestInfo;
567 data->responseInfo = NULL;
570 CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
574 // memory error label.
577 CADestroyRemoteEndpointInternal(remoteEndpoint);
579 CADestroyRequestInfoInternal(requestInfo);
586 return CA_MEMORY_ALLOC_FAILED;
589 CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
590 const CARequestInfo_t *request)
593 OIC_LOG_V(DEBUG, TAG, "CADetachRequestToAllMessage");
596 if (object == NULL || request == NULL)
598 return CA_STATUS_FAILED;
601 CARemoteEndpoint_t *remoteEndpoint = NULL;
602 CARequestInfo_t *requestInfo = NULL;
604 CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
605 CA_MEMORY_ALLOC_CHECK(data);
608 memset(&addr, 0, sizeof(CAAddress_t));
609 remoteEndpoint = CACreateRemoteEndpointInternal(object->resourceUri, addr,
610 object->connectivityType);
612 // clone request info
613 requestInfo = CACloneRequestInfo(request);
614 CA_MEMORY_ALLOC_CHECK(requestInfo);
617 data->type = SEND_TYPE_MULTICAST;
618 data->remoteEndpoint = remoteEndpoint;
619 data->requestInfo = requestInfo;
620 data->responseInfo = NULL;
623 CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
627 // memory error label.
630 CADestroyRemoteEndpointInternal(remoteEndpoint);
632 CADestroyRequestInfoInternal(requestInfo);
639 return CA_MEMORY_ALLOC_FAILED;
642 CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
643 const CAResponseInfo_t *response)
645 OIC_LOG_V(DEBUG, TAG, "CADetachResponseMessage");
647 if (object == NULL || response == NULL)
649 return CA_STATUS_FAILED;
652 CARemoteEndpoint_t *remoteEndpoint = NULL;
653 CAResponseInfo_t *responseInfo = NULL;
655 CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
656 CA_MEMORY_ALLOC_CHECK(data);
658 // clone remote endpoint
659 remoteEndpoint = CACloneRemoteEndpoint(object);
660 CA_MEMORY_ALLOC_CHECK(remoteEndpoint);
662 // clone response info
663 responseInfo = CACloneResponseInfo(response);
664 CA_MEMORY_ALLOC_CHECK(responseInfo);
667 data->type = SEND_TYPE_UNICAST;
668 data->remoteEndpoint = remoteEndpoint;
669 data->requestInfo = NULL;
670 data->responseInfo = responseInfo;
673 CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
677 // memory error label.
680 CADestroyRemoteEndpointInternal(remoteEndpoint);
682 CADestroyResponseInfoInternal(responseInfo);
689 return CA_MEMORY_ALLOC_FAILED;
692 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
693 const CAHeaderOption_t *options,const uint8_t numOptions)
695 if (resourceUri == NULL)
697 return CA_STATUS_FAILED;
699 CARequestInfo_t *ReqInfo = NULL;
700 CAToken_t tempToken = NULL;
701 CARemoteEndpoint_t *remoteEndpoint = NULL;
703 CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
704 CA_MEMORY_ALLOC_CHECK(data);
706 CAAddress_t addr = {};
707 remoteEndpoint = CACreateRemoteEndpointInternal(resourceUri, addr,
708 CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE);
710 // create request info
711 ReqInfo = (CARequestInfo_t *) OICCalloc(1, sizeof(CARequestInfo_t));
712 CA_MEMORY_ALLOC_CHECK(ReqInfo);
717 int32_t len = strlen(token);
718 tempToken = (char *) OICCalloc((len + 1), sizeof(char));
719 CA_MEMORY_ALLOC_CHECK(tempToken);
720 strncpy(tempToken, token, len);
723 // save request info data
724 ReqInfo->method = CA_GET;
725 ReqInfo->info.token = tempToken;
726 ReqInfo->info.type = CA_MSG_NONCONFIRM;
728 data->type = SEND_TYPE_MULTICAST;
729 data->remoteEndpoint = remoteEndpoint;
730 data->requestInfo = ReqInfo;
732 data->responseInfo = NULL;
733 data->options = NULL;
734 data->numOptions = 0;
736 if (options != NULL && numOptions > 0)
739 CAHeaderOption_t *temp = (CAHeaderOption_t *) OICCalloc(numOptions,
740 sizeof(CAHeaderOption_t));
741 CA_MEMORY_ALLOC_CHECK(temp);
743 memcpy(temp, options, sizeof(CAHeaderOption_t) * numOptions);
745 data->options = temp;
746 data->numOptions = numOptions;
750 CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
754 // memory error label.
757 CADestroyRemoteEndpointInternal(remoteEndpoint);
759 if (tempToken != NULL)
774 return CA_MEMORY_ALLOC_FAILED;
777 void CASetRequestResponseCallbacks(CARequestCallback ReqHandler,
778 CAResponseCallback RespHandler)
780 OIC_LOG_V(DEBUG, TAG, "set request, response handler callback.");
782 g_requestHandler = ReqHandler;
783 g_responseHandler = RespHandler;
786 CAResult_t CAInitializeMessageHandler()
788 OIC_LOG(DEBUG, TAG, "CAInitializeMessageHandler - Entry");
789 CASetPacketReceivedCallback(CAReceivedPacketCallback);
791 CASetNetworkChangeCallback(CANetworkChangedCallback);
793 // create thread pool
795 res = u_thread_pool_init(MAX_THREAD_POOL_SIZE, &g_threadPoolHandle);
797 if (res != CA_STATUS_OK)
799 OIC_LOG_V(ERROR, TAG, "thread pool initialize error.");
803 // send thread initialize
804 CAQueueingThreadInitialize(&g_sendThread, g_threadPoolHandle, CASendThreadProcess,
808 res = CAQueueingThreadStart(&g_sendThread);
810 if (res != CA_STATUS_OK)
812 OIC_LOG_V(ERROR, TAG, "thread start error(send thread).");
813 u_thread_pool_free(g_threadPoolHandle);
814 g_threadPoolHandle = NULL;
818 // receive thread initialize
819 CAQueueingThreadInitialize(&g_receiveThread, g_threadPoolHandle, CAReceiveThreadProcess,
822 #ifndef SINGLE_HANDLE // This will be enabled when RI supports multi threading
823 // start receive thread
824 res = CAQueueingThreadStart(&gReceiveThread);
826 if (res != CA_STATUS_OK)
828 OIC_LOG_V(DEBUG, TAG, "thread start error(receive thread).");
833 // retransmission initialize
834 CARetransmissionInitialize(&g_retransmissionContext, g_threadPoolHandle, CASendUnicastData,
835 CATimeoutCallback, NULL);
837 // start retransmission
838 res = CARetransmissionStart(&g_retransmissionContext);
840 if (res != CA_STATUS_OK)
842 OIC_LOG_V(ERROR, TAG, "thread start error(retransmission thread).");
846 // initialize interface adapters by controller
847 CAInitializeAdapters(g_threadPoolHandle);
852 void CATerminateMessageHandler()
855 CAConnectivityType_t connType;
856 u_arraylist_t *list = CAGetSelectedNetworkList();
857 uint32_t length = u_arraylist_length(list);
859 for (i = 0; i < length; i++)
861 void* ptrType = u_arraylist_get(list, i);
868 connType = *(CAConnectivityType_t *) ptrType;
869 CAStopAdapter(connType);
872 // stop retransmission
873 if (g_retransmissionContext.threadMutex != NULL)
875 CARetransmissionStop(&g_retransmissionContext);
879 // delete thread data
880 if (g_sendThread.threadMutex != NULL)
882 CAQueueingThreadStop(&g_sendThread);
886 // delete thread data
887 if (g_receiveThread.threadMutex != NULL)
889 #ifndef SINGLE_HANDLE // This will be enabled when RI supports multi threading
890 CAQueueingThreadStop(&gReceiveThread);
894 // destroy thread pool
895 if (g_threadPoolHandle != NULL)
897 u_thread_pool_free(g_threadPoolHandle);
898 g_threadPoolHandle = NULL;
901 CARetransmissionDestroy(&g_retransmissionContext);
902 CAQueueingThreadDestroy(&g_sendThread);
903 CAQueueingThreadDestroy(&g_receiveThread);
905 // terminate interface adapters by controller
906 CATerminateAdapters();
908 OIC_LOG_V(DEBUG, TAG, "message handler termination is complete!");