Merged serperated files by using #SINGLE_THREAD and #MULTI_THREAD flags.
Signed-off-by: jw1103.kim <jw1103.kim@samsung.com>
Signed-off-by: Ashok Channa <ashok.channa@samsung.com>
Change-Id: I2d7b38d86226bdfc03c7a7b12626c2c4459ad305
Signed-off-by: jw1103.kim <jw1103.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/783
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
#define CA_INTERFACE_CONTROLLER_H_
#include "caadapterinterface.h"
+
+#ifndef SINGLE_THREAD
#include "cathreadpool.h" /* for thread pool */
+#endif
#ifdef __cplusplus
extern "C"
{
#endif
+#ifdef SINGLE_THREAD
+/**
+ * @brief Initializes different adapters based on the compilation flags.
+ * @return none
+ */
+void CAInitializeAdapters();
+#else
/**
* @brief Initializes different adapters based on the compilation flags.
* @param handle [IN] thread pool handle created by message handler for different adapters.
* @return none
*/
void CAInitializeAdapters(ca_thread_pool_t handle);
+#endif
/**
* @brief Set the received packets callback for message handler
*/
void CATerminateAdapters();
+#ifdef SINGLE_THREAD
+/**
+ * @brief Checks for available data and reads it
+ * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ */
+CAResult_t CAReadData();
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif
env.AppendUnique(CPPDEFINES = ['WITH_ARDUINO'])
print "setting WITH_ARDUINO"
ca_common_src = [
- 'caconnectivitymanager_singlethread.c',
- 'cainterfacecontroller_singlethread.c',
+ 'caconnectivitymanager.c',
+ 'cainterfacecontroller.c',
'camessagehandler_singlethread.c',
'canetworkconfigurator.c',
'caprotocolmessage.c',
CAGlobals_t caglobals;
-#define TAG PCF("CA")
+#define TAG "CA"
static bool g_isInitialized = false;
void CADestroyToken(CAToken_t token)
{
OIC_LOG(DEBUG, TAG, "CADestroyToken");
+
CADestroyTokenInternal(token);
+
+ OIC_LOG(DEBUG, TAG, "OUT");
}
CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "cainterface.h"
-#include "caremotehandler.h"
-#include "caprotocolmessage.h"
-#include "canetworkconfigurator.h"
-#include "logger.h"
-
-#include "cainterfacecontroller_singlethread.h"
-#include "camessagehandler_singlethread.h"
-
-#define TAG "CM_ST"
-
-CAGlobals_t caglobals;
-
-static bool g_isInitialized = false;
-
-CAResult_t CAInitialize()
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- if (!g_isInitialized)
- {
- CAResult_t res = CAInitializeMessageHandler();
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return res;
- }
- g_isInitialized = true;
- }
-
- return CA_STATUS_OK;
-}
-
-void CATerminate()
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- if (g_isInitialized)
- {
- CASetInterfaceCallbacks(NULL, NULL, NULL);
- CATerminateMessageHandler();
- CATerminateNetworkType();
- g_isInitialized = false;
- }
-
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CAStartListeningServer()
-{
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- return CAStartListeningServerAdapters();
-}
-
-CAResult_t CAStartDiscoveryServer()
-{
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- return CAStartDiscoveryServerAdapters();
-}
-
-void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
- CAErrorCallback errorHandler)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return;
- }
-
- CASetInterfaceCallbacks(ReqHandler, RespHandler, errorHandler);
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CACreateEndpoint(CATransportFlags_t flags,
- CATransportAdapter_t adapter,
- const char *addr,
- uint16_t port,
- CAEndpoint_t **object)
-{
- if (!object)
- {
- OIC_LOG(ERROR, TAG, "Invalid Parameter");
- return CA_STATUS_INVALID_PARAM;
- }
-
- CAEndpoint_t *endpoint = CACreateEndpointObject(flags, adapter, addr, port);
- if (!endpoint)
- {
- return CA_STATUS_FAILED;
- }
- *object = endpoint;
- return CA_STATUS_OK;
-}
-
-void CADestroyEndpoint(CAEndpoint_t *rep)
-{
- CAFreeEndpoint(rep);
-}
-
-CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
-{
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- return CAGenerateTokenInternal(token, tokenLength);
-}
-
-void CADestroyToken(CAToken_t token)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- CADestroyTokenInternal(token);
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
-{
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- return CAGetNetworkInformationInternal(info, size);
-}
-
-CAResult_t CASendRequest(const CAEndpoint_t *object,const CARequestInfo_t *requestInfo)
-{
- OIC_LOG(DEBUG, TAG, "CASendGetRequest");
-
- return CADetachRequestMessage(object, requestInfo);
-}
-
-CAResult_t CASendNotification(const CAEndpoint_t *object,
- const CAResponseInfo_t *responseInfo)
-{
- OIC_LOG(DEBUG, TAG, "CASendNotification");
-
- return CADetachResponseMessage(object, responseInfo);
-}
-
-CAResult_t CASendResponse(const CAEndpoint_t *object,
- const CAResponseInfo_t *responseInfo)
-{
- OIC_LOG(DEBUG, TAG, "CASendResponse");
-
- return CADetachResponseMessage(object, responseInfo);
-}
-
-CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
-{
- OIC_LOG_V(DEBUG, TAG, "Selected n/W=%d", interestedNetwork);
-
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- if (!(interestedNetwork & 0xf))
- {
- OIC_LOG(ERROR, TAG, "not supported");
- return CA_NOT_SUPPORTED;
- }
- CAResult_t res = CA_STATUS_OK;
-
- if (interestedNetwork & CA_ADAPTER_IP)
- {
- res = CAAddNetworkType(CA_ADAPTER_IP);
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
- return res;
- }
- }
-
- if (interestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
- {
- res = CAAddNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
- return res;
- }
- }
-
- if (interestedNetwork & CA_ADAPTER_GATT_BTLE)
- {
- res = CAAddNetworkType(CA_ADAPTER_GATT_BTLE);
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
- return res;
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return res;
-}
-
-CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
-{
- OIC_LOG_V(DEBUG, TAG, "unselected n/w=%d", nonInterestedNetwork);
-
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- if (!(nonInterestedNetwork & 0xf))
- {
- OIC_LOG(ERROR, TAG, "not supported");
- return CA_NOT_SUPPORTED;
- }
-
- CAResult_t res = CA_STATUS_OK;
-
- if (nonInterestedNetwork & CA_ADAPTER_IP)
- {
- res = CARemoveNetworkType(CA_ADAPTER_IP);
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
- return res;
- }
- }
-
- if (nonInterestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
- {
- res = CARemoveNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
- return res;
- }
- }
-
- if (nonInterestedNetwork & CA_ADAPTER_GATT_BTLE)
- {
- res = CARemoveNetworkType(CA_ADAPTER_GATT_BTLE);
- if (res != CA_STATUS_OK)
- {
- OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
- return res;
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return res;
-}
-
-CAResult_t CAHandleRequestResponse()
-{
- if (!g_isInitialized)
- {
- OIC_LOG(ERROR, TAG, "not initialized");
- return CA_STATUS_NOT_INITIALIZED;
- }
-
- CAHandleRequestResponseCallbacks();
- return CA_STATUS_OK;
-}
-
#include <string.h>
#include <inttypes.h>
+#include "logger.h"
+#include "oic_malloc.h"
+#include "caadapterutils.h"
+#include "canetworkconfigurator.h"
#include "cainterfacecontroller.h"
-#include "caipadapter.h"
#include "caedradapter.h"
#include "caleadapter.h"
-#include "canetworkconfigurator.h"
#include "caremotehandler.h"
-#include "oic_malloc.h"
-#include "logger.h"
#include "cathreadpool.h"
+#include "caipadapter.h"
-#define TAG PCF("CA")
+#define TAG "CA"
#define CA_MEMORY_ALLOC_CHECK(arg) {if (arg == NULL) \
{OIC_LOG(ERROR, TAG, "memory error");goto memory_error_exit;} }
static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapter_t cType)
{
- OIC_LOG(DEBUG, TAG, "CARegisterCallback - Entry");
+ OIC_LOG(DEBUG, TAG, "IN");
if(handler.startAdapter == NULL ||
handler.startListenServer == NULL ||
g_adapterHandler[index] = handler;
OIC_LOG_V(DEBUG, TAG, "%d type adapter, register complete!", cType);
+ OIC_LOG(DEBUG, TAG, "OUT");
}
static void CAReceivedPacketCallback(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen)
{
- OIC_LOG(DEBUG, TAG, "receivedPacketCallback in interface controller");
+ OIC_LOG(DEBUG, TAG, "IN");
// Call the callback.
if (g_networkPacketReceivedCallback != NULL)
OIC_LOG(ERROR, TAG, "network packet received callback is NULL!");
}
+
+ OIC_LOG(DEBUG, TAG, "OUT");
}
static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status)
{
- OIC_LOG(DEBUG, TAG, "Network Changed callback");
+ OIC_LOG(DEBUG, TAG, "IN");
// Call the callback.
if (g_networkChangeCallback != NULL)
{
g_networkChangeCallback(info, status);
}
+
+ OIC_LOG(DEBUG, TAG, "OUT");
}
static void CAAdapterErrorHandleCallback(const CAEndpoint_t *endpoint,
void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback)
{
- OIC_LOG(DEBUG, TAG, "Set packet received callback");
+ OIC_LOG(DEBUG, TAG, "IN");
g_networkPacketReceivedCallback = callback;
+
+ OIC_LOG(DEBUG, TAG, "OUT");
}
void CASetNetworkChangeCallback(CANetworkChangeCallback callback)
{
- OIC_LOG(DEBUG, TAG, "Set network change callback");
+ OIC_LOG(DEBUG, TAG, "IN");
g_networkChangeCallback = callback;
+
+ OIC_LOG(DEBUG, TAG, "OUT");
}
void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback)
CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
{
- OIC_LOG(DEBUG, TAG, "Send unicast data to enabled interface..");
+ OIC_LOG(DEBUG, TAG, "IN");
CAResult_t res = CA_STATUS_FAILED;
{
res = CA_STATUS_OK;
}
+
+ OIC_LOG(DEBUG, TAG, "OUT");
return res;
}
CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
{
- OIC_LOG(DEBUG, TAG, "Send multicast data to enabled interface..");
+ OIC_LOG(DEBUG, TAG, "IN");
CAResult_t res = CA_SEND_FAILED;
u_arraylist_t *list = CAGetSelectedNetworkList();
}
}
+ OIC_LOG(DEBUG, TAG, "OUT");
+
return res;
}
CAResult_t CAStartListeningServerAdapters()
{
- OIC_LOG(DEBUG, TAG, "Start listening server from adapters..");
+ OIC_LOG(DEBUG, TAG, "IN");
u_arraylist_t *list = CAGetSelectedNetworkList();
if (!list)
}
}
+ OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAStartDiscoveryServerAdapters()
{
- OIC_LOG(DEBUG, TAG, "Start discovery server from adapters..");
+ OIC_LOG(DEBUG, TAG, "IN");
u_arraylist_t *list = CAGetSelectedNetworkList();
}
}
+ OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void CATerminateAdapters()
{
- OIC_LOG(DEBUG, TAG, "terminate all adapters..");
+ OIC_LOG(DEBUG, TAG, "IN");
uint32_t index;
for (index = 0; index < CA_TRANSPORT_TYPE_NUM; index++)
g_adapterHandler[index].terminate();
}
}
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+}
+
+#ifdef SINGLE_THREAD
+CAResult_t CAReadData()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ u_arraylist_t *list = CAGetSelectedNetworkList();
+
+ if (!list)
+ {
+ return CA_STATUS_FAILED;
+ }
+
+ uint8_t i = 0;
+ for (i = 0; i < u_arraylist_length(list); i++)
+ {
+ void *ptrType = u_arraylist_get(list, i);
+ if (NULL == ptrType)
+ {
+ OIC_LOG(ERROR, TAG, "get list fail");
+ return CA_STATUS_FAILED;
+ }
+
+ CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
+
+ int index = CAGetAdapterIndex(connType);
+
+ if (-1 == index)
+ {
+ OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
+ continue;
+ }
+
+ if (g_adapterHandler[index].readData != NULL)
+ {
+ g_adapterHandler[index].readData();
+ }
+ }
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
}
+#endif
+
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "cainterfacecontroller_singlethread.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-
-#include "caipadapter.h"
-#include "caedradapter_singlethread.h"
-#include "caleadapter.h"
-#include "caadapterutils.h"
-
-#include "canetworkconfigurator.h"
-#include "oic_malloc.h"
-#include "logger.h"
-
-#define TAG "CAIFCNT_ST"
-
-#define CA_MEMORY_ALLOC_CHECK(arg) { if (arg == NULL) {OIC_LOG(ERROR, TAG, "Out of memory");\
- goto memory_error_exit;} }
-
-#define CA_CONNECTIVITY_TYPE_NUM 3
-
-static CAConnectivityHandler_t g_adapterHandler[CA_CONNECTIVITY_TYPE_NUM];
-
-static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
-
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
-
-static CAErrorHandleCallback g_errorHandleCallback = NULL;
-
-static int CAGetAdapterIndex(CATransportAdapter_t cType)
-{
- switch (cType)
- {
- case CA_ADAPTER_IP:
- return 0;
- case CA_ADAPTER_GATT_BTLE:
- return 1;
- case CA_ADAPTER_RFCOMM_BTEDR:
- return 2;
- }
-
- OIC_LOG(DEBUG, TAG, "CA_CONNECTIVITY_TYPE_NUM is not 3");
-
- return -1;
-}
-
-static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapter_t cType)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- if(handler.startAdapter == NULL ||
- handler.startListenServer == NULL ||
- handler.startDiscoveryServer == NULL ||
- handler.sendData == NULL ||
- handler.sendDataToAll == NULL ||
- handler.GetnetInfo == NULL ||
- handler.readData == NULL ||
- handler.stopAdapter == NULL ||
- handler.terminate == NULL)
- {
- OIC_LOG(ERROR, TAG, "connectivity handler is not enough to be used!");
- return;
- }
-
- int index = CAGetAdapterIndex(cType);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- return;
- }
-
- g_adapterHandler[index] = handler;
-
- OIC_LOG_V(DEBUG, TAG, "%d type adapter", cType);
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-static void CAReceivedPacketCallback(CAEndpoint_t *endpoint, void *data,
- uint32_t dataLen)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- // Call the callback.
- if (g_networkPacketReceivedCallback != NULL)
- {
- g_networkPacketReceivedCallback(endpoint, data, dataLen);
- }
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback)
-{
- OIC_LOG(DEBUG, TAG, "Set error handle callback");
- g_errorHandleCallback = errorCallback;
-}
-
-static void CANetworkChangedCallback(CAEndpoint_t *info, CANetworkStatus_t status)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- // Call the callback.
- if (g_networkChangeCallback != NULL)
- {
- g_networkChangeCallback(info, status);
- }
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-void CAInitializeAdapters()
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- memset(g_adapterHandler, 0, sizeof(CAConnectivityHandler_t) * CA_CONNECTIVITY_TYPE_NUM);
-
- // Initialize adapters and register callback.
-#ifdef IP_ADAPTER
- CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
- NULL, NULL);
-#endif /* IP_ADAPTER */
-
-#ifdef EDR_ADAPTER
- CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback);
-#endif /* EDR_ADAPTER */
-
-#ifdef LE_ADAPTER
- CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
- NULL, NULL);
-#endif /* LE_ADAPTER */
-
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- g_networkPacketReceivedCallback = callback;
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-void CASetNetworkChangeCallback(CANetworkChangeCallback callback)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- g_networkChangeCallback = callback;
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CAStartAdapter(CATransportAdapter_t transportType)
-{
- OIC_LOG_V(DEBUG, TAG, "transportType[%d]", transportType);
-
- int index = CAGetAdapterIndex(transportType);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- return CA_STATUS_FAILED;
- }
-
- if (g_adapterHandler[index].startAdapter != NULL)
- {
- g_adapterHandler[index].startAdapter();
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return CA_STATUS_OK;
-}
-
-void CAStopAdapter(CATransportAdapter_t transportType)
-{
- OIC_LOG_V(DEBUG, TAG, "transportType[%d]", transportType);
-
- int index = CAGetAdapterIndex(transportType);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- return;
- }
-
- if (g_adapterHandler[index].stopAdapter != NULL)
- {
- g_adapterHandler[index].stopAdapter();
- }
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- VERIFY_NON_NULL(info, TAG, "info");
- VERIFY_NON_NULL(size, TAG, "size");
-
- CAEndpoint_t *tempInfo[CA_CONNECTIVITY_TYPE_NUM] = { 0 };
- uint32_t tempSize[CA_CONNECTIVITY_TYPE_NUM] = { 0 };
-
- CAResult_t res = CA_STATUS_FAILED;
- // #1. get information each adapter
- for (uint8_t index = 0; index < CA_CONNECTIVITY_TYPE_NUM; index++)
- {
- if (g_adapterHandler[index].GetnetInfo != NULL)
- {
- res = g_adapterHandler[index].GetnetInfo(&tempInfo[index], &tempSize[index]);
-
- OIC_LOG_V (DEBUG, TAG, "%d adapter network info size is %d", index, tempSize[index]);
- }
- }
-
- uint32_t resSize = 0;
- for (uint8_t index = 0; index < CA_CONNECTIVITY_TYPE_NUM; index++)
- {
- // check information
- if (tempInfo[index] == NULL || tempSize[index] <= 0)
- {
- continue;
- }
-
- // #2. total size
- resSize += tempSize[index];
- }
-
- OIC_LOG_V(DEBUG, TAG, "network info total size is %d!", resSize);
-
- if (resSize <= 0)
- {
- if (CA_ADAPTER_NOT_ENABLED == res || CA_NOT_SUPPORTED == res)
- {
- return res;
- }
- return CA_STATUS_FAILED;
- }
-
- // #3. add data into result
- // memory allocation
- CAEndpoint_t *resInfo = (CAEndpoint_t *)OICCalloc(resSize, sizeof(CAEndpoint_t));
- CA_MEMORY_ALLOC_CHECK(resInfo);
-
- uint8_t i = 0;
- for (uint8_t index = 0; index < CA_CONNECTIVITY_TYPE_NUM; index++)
- {
- // check information
- if (tempInfo[index] == NULL || tempSize[index] <= 0)
- {
- continue;
- }
-
- memcpy(resInfo + i, tempInfo[index], sizeof(CAEndpoint_t) * tempSize[index]);
-
- i += tempSize[index];
-
- // free adapter data
- OICFree(tempInfo[index]);
- }
-
- // #5. save data
- *info = resInfo;
- *size = resSize;
-
- OIC_LOG(DEBUG, TAG, "OUT");
-
- return res;
-
- // memory error label.
-memory_error_exit:
-
- for (uint8_t index = 0; index < CA_CONNECTIVITY_TYPE_NUM; index++)
- {
-
- OICFree(tempInfo[index]);
- }
-
- return CA_MEMORY_ALLOC_FAILED;
-}
-
-CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- CAResult_t res = CA_STATUS_FAILED;
-
- if (endpoint == NULL)
- {
- OIC_LOG(DEBUG, TAG, "Endpoint is NULL");
- return CA_STATUS_INVALID_PARAM;
- }
-
- CATransportAdapter_t type = endpoint->adapter;
-
- int index = CAGetAdapterIndex(type);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- return CA_STATUS_INVALID_PARAM;
- }
-
- uint32_t sentDataLen = 0;
- if (g_adapterHandler[index].sendData != NULL)
- {
- sentDataLen = g_adapterHandler[index].sendData(endpoint, data, length);
- }
-
- if (sentDataLen == length)
- {
- res = CA_STATUS_OK;
- }
-
- OIC_LOG(DEBUG, TAG, "OUT");
- return res;
-}
-
-CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- CAResult_t res = CA_STATUS_FAILED;
- u_arraylist_t *list = CAGetSelectedNetworkList();
-
- if (!list)
- {
- OIC_LOG(DEBUG, TAG, "No selected network");
- return res;
- }
-
- for (uint8_t i = 0; i < u_arraylist_length(list); i++)
- {
- void* ptrType = u_arraylist_get(list, i);
- if (NULL == ptrType)
- {
- continue;
- }
-
- CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
-
- int index = CAGetAdapterIndex(connType);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- continue;
- }
-
- uint32_t sentDataLen = 0;
- if (g_adapterHandler[index].sendDataToAll != NULL)
- {
- sentDataLen = g_adapterHandler[index].sendDataToAll(endpoint, data, length);
- }
-
- if (sentDataLen == length)
- {
- res = CA_STATUS_OK;
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return res;
-}
-
-CAResult_t CAStartListeningServerAdapters()
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- u_arraylist_t *list = CAGetSelectedNetworkList();
-
- if (!list)
- {
- OIC_LOG(DEBUG, TAG, "No selected network");
- return CA_STATUS_FAILED;
- }
-
- for (uint8_t i = 0; i < u_arraylist_length(list); i++)
- {
- void* ptrType = u_arraylist_get(list, i);
- if (NULL == ptrType)
- {
- OIC_LOG(ERROR, TAG, "Invalid conn type");
- continue;
- }
-
- CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
-
- int index = CAGetAdapterIndex(connType);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- continue;
- }
-
- if (g_adapterHandler[index].startListenServer != NULL)
- {
- g_adapterHandler[index].startListenServer();
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return CA_STATUS_OK;
-}
-
-CAResult_t CAStartDiscoveryServerAdapters()
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- u_arraylist_t *list = CAGetSelectedNetworkList();
-
- if (!list)
- {
- OIC_LOG(DEBUG, TAG, "No selected network");
- return CA_STATUS_FAILED;
- }
-
- for (uint8_t i = 0; i < u_arraylist_length(list); i++)
- {
- void* ptrType = u_arraylist_get(list, i);
- if (NULL == ptrType)
- {
- continue;
- }
-
- CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
-
- int index = CAGetAdapterIndex(connType);
-
- if (index == -1)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- continue;
- }
-
- if (g_adapterHandler[index].startDiscoveryServer != NULL)
- {
- g_adapterHandler[index].startDiscoveryServer();
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return CA_STATUS_OK;
-}
-
-void CATerminateAdapters()
-{
- OIC_LOG(DEBUG, TAG, "IN");
-
- uint8_t index;
-
- for (index = 0; index < CA_CONNECTIVITY_TYPE_NUM; index++)
- {
- if (g_adapterHandler[index].stopAdapter != NULL)
- {
- g_adapterHandler[index].stopAdapter();
- }
- if (g_adapterHandler[index].terminate != NULL)
- {
- g_adapterHandler[index].terminate();
- }
- }
-
- OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CAReadData()
-{
- OIC_LOG(DEBUG, TAG, "IN");
- u_arraylist_t *list = CAGetSelectedNetworkList();
-
- if (!list)
- {
- return CA_STATUS_FAILED;
- }
-
- for (uint8_t i = 0; i < u_arraylist_length(list); i++)
- {
- void *ptrType = u_arraylist_get(list, i);
- if (NULL == ptrType)
- {
- OIC_LOG(ERROR, TAG, "get list fail");
- return CA_STATUS_FAILED;
- }
-
- CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
-
- int index = CAGetAdapterIndex(connType);
-
- if (-1 == index)
- {
- OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
- continue;
- }
-
- if (g_adapterHandler[index].readData != NULL)
- {
- g_adapterHandler[index].readData();
- }
- }
-
- OIC_LOG(DEBUG, TAG, "OUT");
- return CA_STATUS_OK;
-}
-
#include "cainterface.h"
#include "camessagehandler_singlethread.h"
#include "caremotehandler.h"
-#include "cainterfacecontroller_singlethread.h"
+#include "cainterfacecontroller.h"
#include "caprotocolmessage.h"
#include "caretransmission.h"
#include "logger.h"
CARetransmissionInitialize(&g_retransmissionContext, NULL, CASendUnicastData,
CATimeoutCallback, NULL);
- CAInitializeAdapters();
+ CAInitializeAdapters(NULL);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}