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 OIC_LOG(DEBUG, TAG, "CADataDestroyer is ran!");
124 CAData_t *cadata = (CAData_t *) data;
131 if (cadata->remoteEndpoint != NULL)
133 CADestroyRemoteEndpointInternal((CARemoteEndpoint_t *)cadata->remoteEndpoint);
136 if (cadata->requestInfo != NULL)
138 CADestroyRequestInfoInternal((CARequestInfo_t *)cadata->requestInfo);
141 if (cadata->responseInfo != NULL)
143 CADestroyResponseInfoInternal((CAResponseInfo_t *)cadata->responseInfo);
146 if (cadata->options != NULL)
148 OICFree(cadata->options);
154 static void CAReceiveThreadProcess(void *threadData)
156 // Currently not supported
157 // This will be enabled when RI supports multi threading
158 #ifndef SINGLE_HANDLE
159 CAData_t *data = (CAData_t *) threadData;
163 OIC_LOG(DEBUG, TAG, "thread data error!!");
167 // parse the data and call the callbacks.
170 CARemoteEndpoint_t *rep = (CARemoteEndpoint_t *)(data->remoteEndpoint);
175 if (data->requestInfo != NULL)
179 gRequestHandler(rep, data->requestInfo);
183 if (data->responseInfo != NULL)
185 if (gResponseHandler)
187 gResponseHandler(rep, data->responseInfo);
193 static void CASendThreadProcess(void *threadData)
195 CAData_t *data = (CAData_t *) threadData;
199 OIC_LOG(DEBUG, TAG, "thread data error!!");
203 if (NULL == data->remoteEndpoint)
205 OIC_LOG(DEBUG, TAG, "remoteEndpoint is null");
209 CAResult_t res = CA_STATUS_FAILED;
211 CASendDataType_t type = data->type;
213 if (type == SEND_TYPE_UNICAST)
215 coap_pdu_t *pdu = NULL;
217 if (data->requestInfo != NULL)
219 OIC_LOG_V(DEBUG, TAG, "requestInfo is available..");
221 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
222 data->requestInfo->method,
223 data->requestInfo->info);
225 else if (data->responseInfo != NULL)
227 OIC_LOG_V(DEBUG, TAG, "responseInfo is available..");
229 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri,
230 data->responseInfo->result,
231 data->responseInfo->info);
235 OIC_LOG(DEBUG, TAG, "request info, response info is empty");
238 // interface controller function call.
241 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
243 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
245 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
247 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
249 OIC_LOG_V(DEBUG, TAG, "PDU Maker - token : %s", pdu->hdr->token);
251 OIC_LOG_V(DEBUG, TAG, "PDU Maker - buffer data : %s", pdu->hdr);
253 res = CASendUnicastData(data->remoteEndpoint, pdu->hdr, pdu->length);
255 // for retransmission
256 CARetransmissionSentData(&gRetransmissionContext, data->remoteEndpoint, pdu->hdr,
259 coap_delete_pdu(pdu);
262 else if (type == SEND_TYPE_MULTICAST)
264 OIC_LOG(DEBUG, TAG, "both requestInfo & responseInfo is not available");
266 coap_pdu_t *pdu = NULL;
268 memset(&info, 0, sizeof(CAInfo_t));
270 info.options = data->options;
271 info.numOptions = data->numOptions;
272 info.token = data->requestInfo->info.token;
273 info.type = data->requestInfo->info.type;
275 pdu = (coap_pdu_t *) CAGeneratePdu(data->remoteEndpoint->resourceUri, CA_GET, info);
279 OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
281 OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->hdr->type);
283 OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->hdr->code);
285 OIC_LOG_V(DEBUG, TAG, "PDU Maker - id : %d", ntohs(pdu->hdr->id));
287 OIC_LOG_V(DEBUG, TAG, "PDU Maker - token : %s", pdu->hdr->token);
289 OIC_LOG_V(DEBUG, TAG, "PDU Maker - buffer data : %s", pdu->hdr);
291 res = CASendMulticastData(pdu->hdr, pdu->length);
292 coap_delete_pdu(pdu);
296 OIC_LOG_V(DEBUG, TAG, " Result :%d", res);
299 static void CAReceivedPacketCallback(CARemoteEndpoint_t *endpoint, void *data,
302 OIC_LOG(DEBUG, TAG, "receivedPacketCallback in message handler!!");
306 OIC_LOG(DEBUG, TAG, "received data is null");
311 uint32_t code = CA_NOT_FOUND;
313 OIC_LOG_V(DEBUG, TAG, "data : %s", data);
314 pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
319 OIC_LOG(DEBUG, TAG, "pdu is null");
323 char uri[CA_MAX_URI_LENGTH] =
326 if (code == CA_GET || code == CA_POST || code == CA_PUT || code == CA_DELETE)
328 CARequestInfo_t *ReqInfo;
329 ReqInfo = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
332 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
333 coap_delete_pdu(pdu);
336 memset(ReqInfo, 0, sizeof(CARequestInfo_t));
337 CAGetRequestInfoFromPdu(pdu, ReqInfo, uri);
339 if (NULL != ReqInfo->info.options)
342 for (i = 0; i < ReqInfo->info.numOptions; i++)
344 OIC_LOG_V(DEBUG, TAG, "Request- optionID: %d", ReqInfo->info.options[i].optionID);
346 OIC_LOG_V(DEBUG, TAG, "Request- list: %s", ReqInfo->info.options[i].optionData);
350 if (NULL != ReqInfo->info.payload)
352 OIC_LOG_V(DEBUG, TAG, "Request- payload: %s", ReqInfo->info.payload);
354 OIC_LOG_V(DEBUG, TAG, "Request- code: %d", ReqInfo->method);
355 OIC_LOG_V(DEBUG, TAG, "Request- token : %s", ReqInfo->info.token);
356 OIC_LOG_V(DEBUG, TAG, "Request- msgID: %d", ReqInfo->info.messageId);
358 if (NULL != endpoint)
360 endpoint->resourceUri = (char *) OICMalloc(strlen(uri) + 1);
361 if (endpoint->resourceUri == NULL)
363 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
365 coap_delete_pdu(pdu);
368 memset(endpoint->resourceUri, 0, strlen(uri) + 1);
369 memcpy(endpoint->resourceUri, uri, strlen(uri));
370 OIC_LOG_V(DEBUG, TAG, "resource URI : %s", endpoint->resourceUri);
372 // store the data at queue.
373 CAData_t *cadata = NULL;
374 cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
377 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
378 if (endpoint != NULL && endpoint->resourceUri != NULL)
379 OICFree(endpoint->resourceUri);
381 coap_delete_pdu(pdu);
384 memset(cadata, 0, sizeof(CAData_t));
386 cadata->type = SEND_TYPE_UNICAST;
387 cadata->remoteEndpoint = endpoint;
388 cadata->requestInfo = ReqInfo;
389 cadata->responseInfo = NULL;
390 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
394 CAResponseInfo_t *ResInfo;
395 ResInfo = (CAResponseInfo_t *) OICMalloc(sizeof(CAResponseInfo_t));
398 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
399 coap_delete_pdu(pdu);
402 memset(ResInfo, 0, sizeof(CAResponseInfo_t));
403 CAGetResponseInfoFromPdu(pdu, ResInfo, uri);
405 if (NULL != ResInfo->info.options)
408 for (i = 0; i < ResInfo->info.numOptions; i++)
410 OIC_LOG_V(DEBUG, TAG, "Response- optionID: %d", ResInfo->info.options[i].optionID);
412 OIC_LOG_V(DEBUG, TAG, "Response- list: %s", ResInfo->info.options[i].optionData);
416 if (NULL != ResInfo->info.payload)
418 OIC_LOG_V(DEBUG, TAG, "Response- payload: %s", ResInfo->info.payload);
421 OIC_LOG_V(DEBUG, TAG, "Response- response code: %d", ResInfo->result);
422 OIC_LOG_V(DEBUG, TAG, "Response- token : %s", ResInfo->info.token);
423 OIC_LOG_V(DEBUG, TAG, "Response- msgID: %d", ResInfo->info.messageId);
425 if (NULL != endpoint)
427 endpoint->resourceUri = (char *) OICMalloc(strlen(uri) + 1);
428 if (endpoint->resourceUri == NULL)
430 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
432 coap_delete_pdu(pdu);
435 memset(endpoint->resourceUri, 0, strlen(uri) + 1);
436 memcpy(endpoint->resourceUri, uri, strlen(uri));
437 OIC_LOG_V(DEBUG, TAG, "resource URI : %s", endpoint->resourceUri);
440 // store the data at queue.
441 CAData_t *cadata = NULL;
442 cadata = (CAData_t *) OICMalloc(sizeof(CAData_t));
445 OIC_LOG(DEBUG, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
446 if (endpoint != NULL && endpoint->resourceUri != NULL)
447 OICFree(endpoint->resourceUri);
449 coap_delete_pdu(pdu);
452 memset(cadata, 0, sizeof(CAData_t));
454 cadata->type = SEND_TYPE_UNICAST;
455 cadata->remoteEndpoint = endpoint;
456 cadata->requestInfo = NULL;
458 // for retransmission
459 void *retransmissionPdu = NULL;
460 CARetransmissionReceivedData(&gRetransmissionContext, endpoint, pdu->hdr, pdu->length, &retransmissionPdu);
462 // get token from saved data in retransmission list
463 if(retransmissionPdu && CA_EMPTY == code)
465 CAGetTokenFromPDU((const coap_hdr_t *)retransmissionPdu, &(ResInfo->info));
466 OICFree(retransmissionPdu);
468 cadata->responseInfo = ResInfo;
470 CAQueueingThreadAddData(&gReceiveThread, cadata, sizeof(CAData_t));
475 coap_delete_pdu(pdu);
479 static void CANetworkChangedCallback(CALocalConnectivity_t *info, CANetworkStatus_t status)
481 OIC_LOG(DEBUG, TAG, "networkChangeCallback in message handler!!");
483 OIC_LOG_V(DEBUG, TAG, "Changed Network Status: %d", status);
486 void CAHandleRequestResponseCallbacks()
488 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks IN");
491 // parse the data and call the callbacks.
495 u_mutex_lock(gReceiveThread.threadMutex);
497 u_queue_message_t *item = u_queue_get_element(gReceiveThread.dataQueue);
499 u_mutex_unlock(gReceiveThread.threadMutex);
505 void *msg = item->msg;
511 CAData_t *td = (CAData_t *) msg;
512 CARemoteEndpoint_t *rep = td->remoteEndpoint;
517 if (td->requestInfo != NULL)
521 OIC_LOG_V(DEBUG, TAG, "callback will be sent : %d", td->requestInfo->info.numOptions);
522 gRequestHandler(rep, td->requestInfo);
525 if (NULL != td->requestInfo->info.options)
527 OICFree(td->requestInfo->info.options);
530 if (NULL != td->requestInfo->info.payload)
532 OICFree(td->requestInfo->info.payload);
535 if (NULL != td->requestInfo->info.token)
537 OICFree(td->requestInfo->info.token);
539 OICFree(td->requestInfo);
542 if (td->responseInfo != NULL)
544 if (gResponseHandler)
546 gResponseHandler(rep, td->responseInfo);
549 if (NULL != td->responseInfo->info.options)
551 OICFree(td->responseInfo->info.options);
554 if (NULL != td->responseInfo->info.payload)
556 OICFree(td->responseInfo->info.payload);
559 if (NULL != td->responseInfo->info.token)
561 OICFree(td->responseInfo->info.token);
563 OICFree(td->responseInfo);
566 if (NULL != rep->resourceUri)
568 OICFree(rep->resourceUri);
575 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponseCallbacks OUT");
578 CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object,
579 const CARequestInfo_t *request)
581 OIC_LOG_V(DEBUG, TAG, "CADetachRequestMessage");
583 if (object == NULL || request == NULL)
585 return CA_STATUS_FAILED;
588 CARemoteEndpoint_t *remoteEndpoint = NULL;
589 CARequestInfo_t *requestInfo = NULL;
591 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
592 MEMORY_ALLOC_CHECK(data);
595 memset(data, 0, sizeof(CAData_t));
597 // clone remote endpoint
599 remoteEndpoint = CACloneRemoteEndpoint(object);
600 MEMORY_ALLOC_CHECK(remoteEndpoint);
602 // clone request info
603 requestInfo = CACloneRequestInfo(request);
604 MEMORY_ALLOC_CHECK(requestInfo);
607 data->type = SEND_TYPE_UNICAST;
608 data->remoteEndpoint = remoteEndpoint;
609 data->requestInfo = requestInfo;
610 data->responseInfo = NULL;
613 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
617 // memory error label.
620 CADestroyRemoteEndpointInternal(remoteEndpoint);
622 CADestroyRequestInfoInternal(requestInfo);
629 return CA_MEMORY_ALLOC_FAILED;
632 CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object,
633 const CARequestInfo_t *request)
636 OIC_LOG_V(DEBUG, TAG, "CADetachRequestToAllMessage");
639 if (object == NULL || request == NULL)
641 return CA_STATUS_FAILED;
644 CARemoteEndpoint_t *remoteEndpoint = NULL;
645 CARequestInfo_t *requestInfo = NULL;
647 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
648 MEMORY_ALLOC_CHECK(data);
651 memset(data, 0, sizeof(CAData_t));
654 memset(&addr, 0, sizeof(CAAddress_t));
655 remoteEndpoint = CACreateRemoteEndpointInternal(object->resourceUri, addr,
656 object->connectivityType);
658 // clone request info
659 requestInfo = CACloneRequestInfo(request);
660 MEMORY_ALLOC_CHECK(requestInfo);
663 data->type = SEND_TYPE_MULTICAST;
664 data->remoteEndpoint = remoteEndpoint;
665 data->requestInfo = requestInfo;
666 data->responseInfo = NULL;
669 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
673 // memory error label.
676 CADestroyRemoteEndpointInternal(remoteEndpoint);
678 CADestroyRequestInfoInternal(requestInfo);
685 return CA_MEMORY_ALLOC_FAILED;
688 CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object,
689 const CAResponseInfo_t *response)
691 OIC_LOG_V(DEBUG, TAG, "CADetachResponseMessage");
693 if (object == NULL || response == NULL)
695 return CA_STATUS_FAILED;
698 CARemoteEndpoint_t *remoteEndpoint = NULL;
699 CAResponseInfo_t *responseInfo = NULL;
701 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
702 MEMORY_ALLOC_CHECK(data);
705 memset(data, 0, sizeof(CAData_t));
707 // clone remote endpoint
708 remoteEndpoint = CACloneRemoteEndpoint(object);
709 MEMORY_ALLOC_CHECK(remoteEndpoint);
711 // clone response info
712 responseInfo = CACloneResponseInfo(response);
713 MEMORY_ALLOC_CHECK(responseInfo);
716 data->type = SEND_TYPE_UNICAST;
717 data->remoteEndpoint = remoteEndpoint;
718 data->requestInfo = NULL;
719 data->responseInfo = responseInfo;
722 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
726 // memory error label.
729 CADestroyRemoteEndpointInternal(remoteEndpoint);
731 CADestroyResponseInfoInternal(responseInfo);
738 return CA_MEMORY_ALLOC_FAILED;
741 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
742 const CAHeaderOption_t *options, uint8_t numOptions)
744 if (resourceUri == NULL)
746 return CA_STATUS_FAILED;
748 CARequestInfo_t *ReqInfo = NULL;
749 CAToken_t tempToken = NULL;
750 CARemoteEndpoint_t *remoteEndpoint = NULL;
752 CAData_t *data = (CAData_t *) OICMalloc(sizeof(CAData_t));
753 MEMORY_ALLOC_CHECK(data);
756 memset(data, 0, sizeof(CAData_t));
759 memset(&addr, 0, sizeof(CAAddress_t));
760 remoteEndpoint = CACreateRemoteEndpointInternal(resourceUri, addr,
761 CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE);
763 // create request info
764 ReqInfo = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
765 MEMORY_ALLOC_CHECK(ReqInfo);
766 memset(ReqInfo, 0, sizeof(CARequestInfo_t));
771 int32_t len = strlen(token);
772 tempToken = (char *) OICMalloc(sizeof(char) * (len + 1));
773 MEMORY_ALLOC_CHECK(tempToken);
774 memset(tempToken, 0, sizeof(char) * (len + 1));
775 strncpy(tempToken, token, len);
778 // save request info data
779 ReqInfo->method = CA_GET;
780 ReqInfo->info.token = tempToken;
781 ReqInfo->info.type = CA_MSG_NONCONFIRM;
783 data->type = SEND_TYPE_MULTICAST;
784 data->remoteEndpoint = remoteEndpoint;
785 data->requestInfo = ReqInfo;
787 data->responseInfo = NULL;
788 data->options = NULL;
789 data->numOptions = 0;
791 if (options != NULL && numOptions > 0)
794 CAHeaderOption_t *temp = (CAHeaderOption_t *) OICMalloc(
795 sizeof(CAHeaderOption_t) * numOptions);
797 MEMORY_ALLOC_CHECK(temp);
799 memset(temp, 0, sizeof(CAHeaderOption_t) * numOptions);
800 memcpy(temp, options, sizeof(CAHeaderOption_t) * numOptions);
802 data->options = temp;
803 data->numOptions = numOptions;
807 CAQueueingThreadAddData(&gSendThread, data, sizeof(CAData_t));
811 // memory error label.
814 CADestroyRemoteEndpointInternal(remoteEndpoint);
816 if (tempToken != NULL)
831 return CA_MEMORY_ALLOC_FAILED;
834 void CASetRequestResponseCallbacks(CARequestCallback ReqHandler,
835 CAResponseCallback RespHandler)
837 OIC_LOG_V(DEBUG, TAG, "set request, response handler callback.");
839 gRequestHandler = ReqHandler;
840 gResponseHandler = RespHandler;
843 CAResult_t CAInitializeMessageHandler()
845 OIC_LOG(DEBUG, TAG, "CAInitializeMessageHandler - Entry");
846 CASetPacketReceivedCallback(CAReceivedPacketCallback);
848 CASetNetworkChangeCallback(CANetworkChangedCallback);
850 // create thread pool
852 res = u_thread_pool_init(MAX_THREAD_POOL_SIZE, &gThreadPoolHandle);
854 if (res != CA_STATUS_OK)
856 OIC_LOG_V(DEBUG, TAG, "thread pool initialize error.");
860 // send thread initialize
861 CAQueueingThreadInitialize(&gSendThread, gThreadPoolHandle, CASendThreadProcess,
865 res = CAQueueingThreadStart(&gSendThread);
867 if (res != CA_STATUS_OK)
869 OIC_LOG_V(DEBUG, TAG, "thread start error(send thread).");
873 // receive thread initialize
874 CAQueueingThreadInitialize(&gReceiveThread, gThreadPoolHandle, CAReceiveThreadProcess,
877 #ifndef SINGLE_HANDLE// This will be enabled when RI supports multi threading
878 // start receive thread
879 res = CAQueueingThreadStart(&gReceiveThread);
881 if (res != CA_STATUS_OK)
883 OIC_LOG_V(DEBUG, TAG, "thread start error(receive thread).");
888 // retransmission initialize
889 CARetransmissionInitialize(&gRetransmissionContext, gThreadPoolHandle, CASendUnicastData,
890 CATimeoutCallback, NULL);
892 // start retransmission
893 res = CARetransmissionStart(&gRetransmissionContext);
895 if (res != CA_STATUS_OK)
897 OIC_LOG_V(DEBUG, TAG, "thread start error(retransmission thread).");
901 // initialize interface adapters by controller
902 CAInitializeAdapters(gThreadPoolHandle);
907 void CATerminateMessageHandler()
909 // terminate interface adapters by controller
910 CATerminateAdapters();
912 // stop retransmission
913 if(gRetransmissionContext.threadMutex != NULL) {
914 CARetransmissionStop(&gRetransmissionContext);
915 CARetransmissionDestroy(&gRetransmissionContext);
919 // delete thread data
920 if(gSendThread.threadMutex != NULL) {
921 CAQueueingThreadStop(&gSendThread);
922 CAQueueingThreadDestroy(&gSendThread);
926 // delete thread data
927 if(gReceiveThread.threadMutex != NULL) {
928 #ifndef SINGLE_HANDLE// This will be enabled when RI supports multi threading
929 // CAQueueingThreadStop(&gReceiveThread);
931 CAQueueingThreadDestroy(&gReceiveThread);
934 // destroy thread pool
935 if(gThreadPoolHandle != NULL) {
936 u_thread_pool_free(gThreadPoolHandle);
937 gThreadPoolHandle = NULL;
940 OIC_LOG_V(DEBUG, TAG, "message handler termination is complete!");