From: David Antler Date: Wed, 4 May 2016 16:57:46 +0000 (-0700) Subject: Merge branch 'master' into windows-port X-Git-Tag: 1.2.0+RC1~258^2~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3390476c32dd0d881b5a775907d6ee95d044938e;hp=eab619b36419b67568833e23e78a4c7749003183;p=platform%2Fupstream%2Fiotivity.git Merge branch 'master' into windows-port Change-Id: Iefbd0b074e8e654ee143617137c165d05ab56aed Signed-off-by: David Antler --- diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java b/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java index 3817c5c..bcabc663 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java @@ -30,19 +30,30 @@ import java.security.InvalidParameterException; * After creating instances of OcHeaderOptions, use setHeaderOptions API * (in OcResource) to set header Options. * NOTE: optionId is an integer value which MUST be within - * range of 2048 to 3000 inclusive of lower and upper bound. + * range of 2048 to 3000 inclusive of lower and upper bound + * except for a few options including If-Match with empty(num : 1), + * If-None-Match(num : 5), Location-Path(num : 8), + * Location-Query(num : 20) CoAP option. * HeaderOption instance creation fails if above condition is not satisfied. */ public class OcHeaderOption { public static final int MIN_HEADER_OPTION_ID = 2048; public static final int MAX_HEADER_OPTION_ID = 3000; + public static final int IF_MATCH_OPTION_ID = 1; + public static final int IF_NONE_MATCH_OPTION_ID = 5; + public static final int LOCATION_PATH_OPTION_ID = 8; + public static final int LOCATION_QUERY_OPTION_ID = 20; private int mOptionId; private String mOptionData; public OcHeaderOption(int optionId, String optionData) { - if (!(optionId >= MIN_HEADER_OPTION_ID && optionId <= MAX_HEADER_OPTION_ID)) { + if (!(optionId >= MIN_HEADER_OPTION_ID && optionId <= MAX_HEADER_OPTION_ID) + && optionId != IF_MATCH_OPTION_ID + && optionId != IF_NONE_MATCH_OPTION_ID + && optionId != LOCATION_PATH_OPTION_ID + && optionId != LOCATION_QUERY_OPTION_ID) { throw new InvalidParameterException("Option ID range is invalid"); } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java index 81ab7d5..2314df9 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java @@ -73,16 +73,16 @@ public class CaIpInterface { private static BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, - WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) { - caIpStateDisabled(); - } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { + if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); - if(nwInfo.isConnected()) { + if (mobileInfo != null && mobileInfo.isConnected() || wifiInfo.isConnected()) { caIpStateEnabled(); + } else { + caIpStateDisabled(); } } diff --git a/plugins/SConscript b/plugins/SConscript index cb4050f..86c1635 100644 --- a/plugins/SConscript +++ b/plugins/SConscript @@ -29,7 +29,7 @@ target_os = env.get('TARGET_OS') build_sample = env.get('BUILD_SAMPLE') src_dir = env.get('SRC_DIR') -if target_os not in ['android', 'arduino', 'darwin', 'ios']: +if target_os not in ['android', 'arduino', 'darwin', 'ios', 'tizen']: SConscript(os.path.join('zigbee_wrapper', 'SConscript')) diff --git a/resource/c_common/platform_features.h b/resource/c_common/platform_features.h index 8f39e19..3f712a3 100644 --- a/resource/c_common/platform_features.h +++ b/resource/c_common/platform_features.h @@ -35,7 +35,7 @@ #endif #if (__STDC_VERSION__ >= 201112L) - #include + #include #define OC_STATIC_ASSERT(condition, msg) static_assert(condition, msg) #else #define OC_STATIC_ASSERT(condition, msg) ((void)sizeof(char[2*!!(condition) - 1])) diff --git a/resource/csdk/connectivity/api/cainterface.h b/resource/csdk/connectivity/api/cainterface.h index a253846..5d50d8d 100644 --- a/resource/csdk/connectivity/api/cainterface.h +++ b/resource/csdk/connectivity/api/cainterface.h @@ -69,22 +69,14 @@ typedef struct * Callback function to pass the connection information from CA to RI. * @param[out] object remote device information. */ -typedef void (*CAKeepAliveConnectedCallback)(const CAEndpoint_t *object); +typedef void (*CAKeepAliveConnectionCallback)(const CAEndpoint_t *object, bool isConnected); /** - * Callback function to pass the disconnection information from CA to RI. - * @param[out] object remote device information. - */ -typedef void (*CAKeepAliveDisconnectedCallback)(const CAEndpoint_t *object); - -/** - * Register connected callback and disconnected callback to process KeepAlive. + * Register connection status changes callback to process KeepAlive. * connection informations are delivered these callbacks. - * @param[in] ConnHandler Connected callback. - * @param[in] DisconnHandler Disconnected Callback. + * @param[in] ConnHandler Connection status changes callback. */ -void CARegisterKeepAliveHandler(CAKeepAliveConnectedCallback ConnHandler, - CAKeepAliveDisconnectedCallback DisconnHandler); +void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler); #endif /** * Initialize the connectivity abstraction module. diff --git a/resource/csdk/connectivity/inc/caadapterinterface.h b/resource/csdk/connectivity/inc/caadapterinterface.h index 8e029ad..144f383 100644 --- a/resource/csdk/connectivity/inc/caadapterinterface.h +++ b/resource/csdk/connectivity/inc/caadapterinterface.h @@ -188,9 +188,13 @@ typedef void (*CANetworkPacketReceivedCallback)(const CASecureEndpoint_t *sep, /** * This will be used to notify network changes to the connectivity common logic layer. - * @see SendUnicastData(), SendMulticastData() */ -typedef void (*CANetworkChangeCallback)(const CAEndpoint_t *info, CANetworkStatus_t status); +typedef void (*CAAdapterChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status); + +/** + * This will be used to notify connection changes to the connectivity common logic layer. + */ +typedef void (*CAConnectionChangeCallback)(const CAEndpoint_t *info, bool isConnected); /** * This will be used to notify error result to the connectivity common logic layer. diff --git a/resource/csdk/connectivity/inc/caedradapter.h b/resource/csdk/connectivity/inc/caedradapter.h index 88794e3..bec17b7 100644 --- a/resource/csdk/connectivity/inc/caedradapter.h +++ b/resource/csdk/connectivity/inc/caedradapter.h @@ -44,7 +44,9 @@ extern "C" * Abstraction Layer. * @param[in] reqRespCallback Callback to notify request and response messages from * server(s) started at Connectivity Abstraction Layer. - * @param[in] netCallback Callback to notify the network additions to Connectivity + * @param[in] netCallback Callback to notify the adapter changes to Connectivity + * Abstraction Layer. + * @param[in] connCallback Callback to notify the connection changes to Connectivity * Abstraction Layer. * @param[in] errorCallback errorCallback to notify error to connectivity common logic * layer from adapter. @@ -52,8 +54,9 @@ extern "C" * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback, - CANetworkPacketReceivedCallback reqRespCallback, - CANetworkChangeCallback netCallback, + CANetworkPacketReceivedCallback packetReceivedCallback, + CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle); /** diff --git a/resource/csdk/connectivity/inc/caedradapter_singlethread.h b/resource/csdk/connectivity/inc/caedradapter_singlethread.h index f2422ae..f1cba26 100644 --- a/resource/csdk/connectivity/inc/caedradapter_singlethread.h +++ b/resource/csdk/connectivity/inc/caedradapter_singlethread.h @@ -55,7 +55,7 @@ extern "C" */ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback reqRespCallback, - CANetworkChangeCallback netCallback); + CAAdapterChangeCallback netCallback); /** * @brief Starting EDR connectivity adapters. As its peer to peer it doesnot require to start diff --git a/resource/csdk/connectivity/inc/cainterfacecontroller.h b/resource/csdk/connectivity/inc/cainterfacecontroller.h index 477674f..edf060f 100644 --- a/resource/csdk/connectivity/inc/cainterfacecontroller.h +++ b/resource/csdk/connectivity/inc/cainterfacecontroller.h @@ -67,11 +67,12 @@ void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback); void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback); /** - * Set the network status changed callback for message handler. - * @param[in] callback message handler network status callback - * to receive network changes. + * Set the network status changed callback for CAUtil. + * @param[in] adapterCB CAUtil callback to receive adapter status changes. + * @param[in] connCB CAUtil callback to receive connection status changes. */ -void CASetNetworkChangeCallback(CANetworkChangeCallback callback); +void CASetNetworkMonitorCallbacks(CAAdapterChangeCallback adapterCB, + CAConnectionChangeCallback connCB); /** * Starting different connectivity adapters based on the network selection. diff --git a/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h b/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h index b8234f9..6ab085e 100644 --- a/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h +++ b/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h @@ -51,12 +51,12 @@ void CAInitializeAdapters(); void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback); /** - * @brief Set the network status changed callback for message handler + * @brief Set the adapter status changed callback for message handler * @param callback [IN] message handler network status callback to receive network * changes. * @return none */ -void CASetNetworkChangeCallback(CANetworkChangeCallback callback); +void CASetNetworkChangeCallback(CAAdapterChangeCallback callback); /** * @brief Set the error handler callback for message handler diff --git a/resource/csdk/connectivity/inc/caipadapter.h b/resource/csdk/connectivity/inc/caipadapter.h index e7fa8c0..d4ec30a 100644 --- a/resource/csdk/connectivity/inc/caipadapter.h +++ b/resource/csdk/connectivity/inc/caipadapter.h @@ -50,7 +50,7 @@ extern "C" */ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle); /** diff --git a/resource/csdk/connectivity/inc/caipinterface.h b/resource/csdk/connectivity/inc/caipinterface.h index 2caf5b1..1dc028f 100644 --- a/resource/csdk/connectivity/inc/caipinterface.h +++ b/resource/csdk/connectivity/inc/caipinterface.h @@ -187,6 +187,30 @@ typedef struct uint32_t ipv4addr; /**< used for IPv4 only. */ } CAInterface_t; + +/** + * Callback to be notified when IP adapter connection state changes. + * + * @param[in] adapter Transport adapter. + * @param[in] status Connection status either ::CA_INTERFACE_UP or ::CA_INTERFACE_DOWN. + * @see CAIPSetConnectionStateChangeCallback() for registration. + */ +typedef void (*CAIPConnectionStateChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status); + +/** + * Set callback for receiving local IP adapter connection status. + * + * @param[in] adapter Callback to be notified when IP adapter connection state changes. + */ +void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback); + +/** + * Set callback for receiving local IP adapter connection status. + * + * @param[in] callback Callback to be notified when IP adapter connection state changes. + */ +void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback); + /** * Get a list of CAInterface_t items. * @@ -195,14 +219,14 @@ typedef struct u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex); /** - * @brief Find a new network interface. + * Find a new network interface. * * @return Description of interface (or NULL if no change) */ CAInterface_t *CAFindInterfaceChange(); /** - * @brief Let the network monitor update the polling interval. + * Let the network monitor update the polling interval. * @param [in] current polling interval * * @return desired polling interval @@ -210,7 +234,7 @@ CAInterface_t *CAFindInterfaceChange(); int CAGetPollingInterval(int interval); /** - * @brief Tell the IP server an interface has been added. + * Tell the IP server an interface has been added. */ void CAWakeUpForChange(); @@ -229,7 +253,7 @@ CAResult_t CAIPStartNetworkMonitor(); CAResult_t CAIPStopNetworkMonitor(); /** - * @brief Set callback for error handling. + * Set callback for error handling. * * @param[in] ipErrorCallback callback to notify error to the ipadapter. */ diff --git a/resource/csdk/connectivity/inc/caleadapter.h b/resource/csdk/connectivity/inc/caleadapter.h index bf85d27..11a0b79 100644 --- a/resource/csdk/connectivity/inc/caleadapter.h +++ b/resource/csdk/connectivity/inc/caleadapter.h @@ -40,7 +40,9 @@ extern "C" * @param[in] reqRespCallback Callback to notify request and response * messages from server(s) started at * Connectivity Abstraction Layer. - * @param[in] netCallback Callback to notify the network additions + * @param[in] netCallback Callback to notify the adapter changes + * to Connectivity Abstraction Layer. + * @param[in] connCallback Callback to notify the connection changes * to Connectivity Abstraction Layer. * @param[in] errorCallback errorCallback to notify error to * connectivity common logic layer from adapter. @@ -50,7 +52,8 @@ extern "C" */ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback reqRespCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle); diff --git a/resource/csdk/connectivity/inc/canfcadapter.h b/resource/csdk/connectivity/inc/canfcadapter.h index 3e8fb48..3083ab3 100644 --- a/resource/csdk/connectivity/inc/canfcadapter.h +++ b/resource/csdk/connectivity/inc/canfcadapter.h @@ -49,7 +49,7 @@ extern "C" */ CAResult_t CAInitializeNFC(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle); /** diff --git a/resource/csdk/connectivity/inc/caraadapter.h b/resource/csdk/connectivity/inc/caraadapter.h index 7dd0940..ed730f0 100644 --- a/resource/csdk/connectivity/inc/caraadapter.h +++ b/resource/csdk/connectivity/inc/caraadapter.h @@ -51,7 +51,7 @@ extern "C" */ CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, ca_thread_pool_t handle); diff --git a/resource/csdk/connectivity/inc/catcpadapter.h b/resource/csdk/connectivity/inc/catcpadapter.h index 2528df1..e3da369 100644 --- a/resource/csdk/connectivity/inc/catcpadapter.h +++ b/resource/csdk/connectivity/inc/catcpadapter.h @@ -54,7 +54,9 @@ typedef struct * @param[in] networkPacketCallback Callback to notify request and * response messages from server(s) * started at Connectivity Abstraction Layer. - * @param[in] netCallback Callback to notify the network additions + * @param[in] netCallback Callback to notify the adapter changes + * to Connectivity Abstraction Layer. + * @param[in] connCallback Callback to notify the connection changes * to Connectivity Abstraction Layer. * @param[in] errorCallback Callback to notify the network errors to * Connectivity Abstraction Layer. @@ -63,7 +65,8 @@ typedef struct */ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle); /** @@ -152,13 +155,11 @@ CAResult_t CAStopTCP(); void CATerminateTCP(); /** - * Set connected callback and disconnected callback to process KeepAlive. + * Set connection status changes callback to process KeepAlive. * connection informations are delivered these callbacks. - * @param[in] ConnHandler Connected callback. - * @param[in] DisconnHandler Disconnected Callback. + * @param[in] ConnHandler Connection status changes callback. */ -void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectedCallback ConnHandler, - CAKeepAliveDisconnectedCallback DisconnHandler); +void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler); #ifdef __cplusplus } /* extern "C" */ diff --git a/resource/csdk/connectivity/inc/catcpinterface.h b/resource/csdk/connectivity/inc/catcpinterface.h index 38efb00..10dd685 100644 --- a/resource/csdk/connectivity/inc/catcpinterface.h +++ b/resource/csdk/connectivity/inc/catcpinterface.h @@ -70,7 +70,7 @@ typedef void (*CATCPErrorHandleCallback)(const CAEndpoint_t *endpoint, const voi * @param[in] isConnected Whether keepalive message needs to be sent. * @see Callback must be registered using CATCPSetKeepAliveCallback(). */ -typedef void (*CATCPKeepAliveHandleCallback)(const char *addr, uint16_t port, bool isConnected); +typedef void (*CATCPConnectionHandleCallback)(const char *addr, uint16_t port, bool isConnected); /** * set error callback to notify error in TCP adapter. @@ -86,7 +86,7 @@ void CATCPSetErrorHandler(CATCPErrorHandleCallback errorHandleCallback); * @param[in] keepaliveHandler Callback function to notify the connection information. * in the TCP adapter. */ -void CATCPSetKeepAliveCallback(CATCPKeepAliveHandleCallback keepaliveHandler); +void CATCPSetKeepAliveCallback(CAKeepAliveConnectionCallback keepaliveHandler); /** * Start TCP server. diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c b/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c index 1979eee..3d4dcb6 100644 --- a/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c +++ b/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c @@ -555,7 +555,7 @@ CAResult_t CAEDRStopReceiveThread() return CA_STATUS_OK; } -CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) +CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t idx) { if ((*env)->ExceptionCheck(env)) { @@ -565,7 +565,7 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) return CA_STATUS_FAILED; } - jobject jni_obj_inputStream = CAEDRNativeGetInputStream(id); + jobject jni_obj_inputStream = CAEDRNativeGetInputStream(idx); if (!jni_obj_inputStream) { OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null"); @@ -583,12 +583,13 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) if (0 < available) { - jobject jni_obj_socket = CAEDRNativeGetDeviceSocket(id); + jobject jni_obj_socket = CAEDRNativeGetDeviceSocket(idx); if (!jni_obj_socket) { OIC_LOG(ERROR, TAG, "jni_obj_socket is null"); return CA_STATUS_FAILED; } + jstring jni_str_address = CAEDRNativeGetAddressFromDeviceSocket(env, jni_obj_socket); if (!jni_str_address) { @@ -604,35 +605,26 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) return CA_STATUS_FAILED; } - OIC_LOG_V(DEBUG, TAG, "get InputStream..%d, %s", id, address); - jmethodID jni_mid_read = CAGetJNIMethodID(env, "java/io/InputStream", "read", "([BII)I"); - if (!jni_mid_read) - { - OIC_LOG(ERROR, TAG, "jni_mid_read is null"); - (*env)->ReleaseStringUTFChars(env, jni_str_address, address); - (*env)->DeleteLocalRef(env, jni_str_address); - return CA_STATUS_FAILED; - } - CAConnectedDeviceInfo_t *deviceInfo = (CAConnectedDeviceInfo_t *) CAEDRGetDeviceInfoFromAddress(address); - - (*env)->ReleaseStringUTFChars(env, jni_str_address, address); - (*env)->DeleteLocalRef(env, jni_str_address); if (!deviceInfo) { OIC_LOG(ERROR, TAG, "failed to get device info from list"); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } - jint bufSize = (deviceInfo->totalDataLen == 0) ? - EDR_MAX_HEADER_LEN : deviceInfo->totalDataLen; + jint bufSize = (deviceInfo->totalDataLen == 0) ? EDR_MAX_HEADER_LEN + : deviceInfo->totalDataLen; if (!deviceInfo->recvData) { deviceInfo->recvData = OICCalloc(1, bufSize); if (!deviceInfo->recvData) { OIC_LOG(ERROR, TAG, "out of memory"); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } } @@ -641,29 +633,50 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) if (0 >= remainSize) { OIC_LOG(ERROR, TAG, "remainSize value is invalid."); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } + jbyteArray jbuf = (*env)->NewByteArray(env, remainSize); if (!jbuf) { OIC_LOG(ERROR, TAG, "jbuf is null"); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); + return CA_STATUS_FAILED; + } + + jmethodID jni_mid_read = CAGetJNIMethodID(env, "java/io/InputStream", "read", "([BII)I"); + if (!jni_mid_read) + { + OIC_LOG(ERROR, TAG, "jni_mid_read is null"); + (*env)->DeleteLocalRef(env, jbuf); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } + OIC_LOG_V(DEBUG, TAG, "read InputStream (idx:%d, addr:%s)", idx, address); jint recvLen = (*env)->CallIntMethod(env, jni_obj_inputStream, jni_mid_read, jbuf, (jint) 0, remainSize); if (-1 == recvLen) { OIC_LOG(ERROR, TAG, "recvLen is -1"); (*env)->DeleteLocalRef(env, jbuf); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } + OIC_LOG_V(DEBUG, TAG, "read success (length: %d bytes)", recvLen); jbyte* buf = (*env)->GetByteArrayElements(env, jbuf, NULL); if (!buf) { OIC_LOG(ERROR, TAG, "buf is null"); (*env)->DeleteLocalRef(env, jbuf); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } memcpy(deviceInfo->recvData + deviceInfo->recvDataLen, (const char*) buf, recvLen); @@ -672,8 +685,6 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) (*env)->ReleaseByteArrayElements(env, jbuf, buf, 0); (*env)->DeleteLocalRef(env, jbuf); - OIC_LOG(DEBUG, TAG, "read something from InputStream"); - if (!deviceInfo->totalDataLen) { coap_transport_type transport = coap_get_tcp_header_type_from_initbyte( @@ -689,6 +700,8 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) if (!newBuf) { OIC_LOG(ERROR, TAG, "out of memory"); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } deviceInfo->recvData = newBuf; @@ -709,13 +722,15 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) CAEDRUpdateDeviceState(STATE_DISCONNECTED, address); ca_mutex_unlock(g_mutexStateList); + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); return CA_STATUS_FAILED; } if (g_edrPacketReceivedCallback) { - OIC_LOG_V(DEBUG, TAG,"data will be sent to callback routine: \ - %s, %d", deviceInfo->recvData, deviceInfo->recvDataLen); + OIC_LOG_V(DEBUG, TAG, "data will be sent to callback routine: %s, %d", + deviceInfo->recvData, deviceInfo->recvDataLen); uint32_t sentLength = 0; g_edrPacketReceivedCallback(address, (void*) deviceInfo->recvData, @@ -727,6 +742,9 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id) deviceInfo->totalDataLen = 0; } } + + (*env)->ReleaseStringUTFChars(env, jni_str_address, address); + (*env)->DeleteLocalRef(env, jni_str_address); } return CA_STATUS_OK; @@ -882,7 +900,16 @@ void CAEDRNativeAccept(JNIEnv *env, jobject serverSocketObject) } const char* address = (*env)->GetStringUTFChars(env, j_str_address, NULL); - OIC_LOG_V(DEBUG, TAG, "received the connection request from [%s]", address); + + OIC_LOG_V(INFO, TAG, "accept a new connection from [%s]", address); + + // update state + ca_mutex_lock(g_mutexStateList); + CAEDRUpdateDeviceState(STATE_CONNECTED, address); + ca_mutex_unlock(g_mutexStateList); + + (*env)->ReleaseStringUTFChars(env, j_str_address, address); + (*env)->DeleteLocalRef(env, j_str_address); // set socket to list jobject jni_socket = (*env)->NewGlobalRef(env, jni_obj_BTSocket); @@ -892,21 +919,13 @@ void CAEDRNativeAccept(JNIEnv *env, jobject serverSocketObject) (*env)->DeleteLocalRef(env, jni_obj_BTSocket); return; } + ca_mutex_lock(g_mutexObjectList); CAEDRNativeAddDeviceSocketToList(env, jni_socket); - (*env)->DeleteGlobalRef(env, jni_socket); - (*env)->DeleteLocalRef(env, jni_obj_BTSocket); ca_mutex_unlock(g_mutexObjectList); - // update state - ca_mutex_lock(g_mutexStateList); - CAEDRUpdateDeviceState(STATE_CONNECTED, address); - ca_mutex_unlock(g_mutexStateList); - - (*env)->ReleaseStringUTFChars(env, j_str_address, address); - (*env)->DeleteLocalRef(env, j_str_address); - - OIC_LOG_V(DEBUG, TAG, "connected with [%s]", address); + (*env)->DeleteGlobalRef(env, jni_socket); + (*env)->DeleteLocalRef(env, jni_obj_BTSocket); } else { diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrutils.c b/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrutils.c index a70ddc0..6dc604d 100644 --- a/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrutils.c +++ b/resource/csdk/connectivity/src/bt_edr_adapter/android/caedrutils.c @@ -44,11 +44,7 @@ static u_arraylist_t *g_deviceObjectList = NULL; // get address from bluetooth socket jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj) { - if (!bluetoothSocketObj) - { - OIC_LOG(ERROR, TAG, "bluetoothSocketObj is null"); - return NULL; - } + VERIFY_NON_NULL_RET(bluetoothSocketObj, TAG, "bluetoothSocketObj", NULL); jmethodID jni_mid_getRemoteDevice = CAGetJNIMethodID( env, CLASSPATH_BT_SOCKET, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;"); @@ -298,11 +294,7 @@ jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env) jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice) { - if (!bluetoothDevice) - { - OIC_LOG(ERROR, TAG, "bluetoothDevice is null"); - return NULL; - } + VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice", NULL); jmethodID jni_mid_getAddress = CAGetJNIMethodID(env, CLASSPATH_BT_DEVICE, @@ -342,11 +334,8 @@ void CAEDRNativeCreateDeviceStateList() void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address) { - if (!address) - { - OIC_LOG(ERROR, TAG, "address is null"); - return; - } + VERIFY_NON_NULL_VOID(address, TAG, "address"); + CAConnectedDeviceInfo_t *deviceInfo = (CAConnectedDeviceInfo_t *) OICCalloc(1, sizeof(CAConnectedDeviceInfo_t)); if (!deviceInfo) @@ -362,11 +351,7 @@ void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address) void CAEDRNativeAddDeviceStateToList(CAConnectedDeviceInfo_t *deviceInfo) { - if (!deviceInfo) - { - OIC_LOG(ERROR, TAG, "device is null"); - return; - } + VERIFY_NON_NULL_VOID(deviceInfo, TAG, "deviceInfo"); if (!g_deviceStateList) { @@ -385,11 +370,7 @@ void CAEDRNativeAddDeviceStateToList(CAConnectedDeviceInfo_t *deviceInfo) bool CAEDRNativeIsDeviceInList(const char* remoteAddress) { - if (!remoteAddress) - { - OIC_LOG(ERROR, TAG, "remoteAddress is null"); - return false; - } + VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress", false); jint length = u_arraylist_length(g_deviceStateList); for (jint index = 0; index < length; index++) @@ -445,17 +426,13 @@ void CAEDRNativeRemoveAllDeviceState() void CAEDRNativeRemoveDevice(const char *remoteAddress) { OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList"); + VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remoteAddress"); if (!g_deviceStateList) { OIC_LOG(ERROR, TAG, "gdeviceStateList is null"); return; } - if (!remoteAddress) - { - OIC_LOG(ERROR, TAG, "remoteAddress is null"); - return; - } jint length = u_arraylist_length(g_deviceStateList); for (jint index = 0; index < length; index++) @@ -483,12 +460,7 @@ void CAEDRNativeRemoveDevice(const char *remoteAddress) CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress) { OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice"); - - if (!remoteAddress) - { - OIC_LOG(ERROR, TAG, "remoteAddress is null"); - return STATE_DISCONNECTED; - } + VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress", STATE_DISCONNECTED); if (!g_deviceStateList) { @@ -534,12 +506,7 @@ void CAEDRNativeCreateDeviceSocketList() void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket) { OIC_LOG(DEBUG, TAG, "CANativeAddDeviceobjToList"); - - if (!deviceSocket) - { - OIC_LOG(ERROR, TAG, "Device is null"); - return; - } + VERIFY_NON_NULL_VOID(deviceSocket, TAG, "deviceSocket"); if (!g_deviceObjectList) { @@ -556,62 +523,60 @@ void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket) const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL); - if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress)) + if (CAEDRNativeIsDeviceSocketInList(env, remoteAddress)) { - CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) OICCalloc(1, sizeof(*socketInfo)); - if (!socketInfo) - { - OIC_LOG(ERROR, TAG, "Out of memory"); - return; - } + OIC_LOG(DEBUG, TAG, "the address exists in deviceObjectList. remove it to add new"); + CAEDRNativeRemoveDeviceSocketBaseAddr(env, jni_remoteAddress); + } - jmethodID jni_mid_getInputStream = CAGetJNIMethodID(env, - "android/bluetooth/BluetoothSocket", - "getInputStream", - "()Ljava/io/InputStream;"); - if (!jni_mid_getInputStream) - { - OIC_LOG(ERROR, TAG, "jni_mid_getInputStream is null"); - return; - } + (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); + (*env)->DeleteLocalRef(env, jni_remoteAddress); - jobject jni_obj_inputStream = (*env)->CallObjectMethod(env, deviceSocket, - jni_mid_getInputStream); - if (!jni_obj_inputStream) - { - OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null"); - return; - } + CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) OICCalloc(1, sizeof(*socketInfo)); + if (!socketInfo) + { + OIC_LOG(ERROR, TAG, "Out of memory"); + return; + } - socketInfo->deviceSocket = (*env)->NewGlobalRef(env, deviceSocket); - socketInfo->inputStream = (*env)->NewGlobalRef(env, jni_obj_inputStream); - (*env)->DeleteLocalRef(env, jni_obj_inputStream); + jmethodID jni_mid_getInputStream = CAGetJNIMethodID(env, "android/bluetooth/BluetoothSocket", + "getInputStream", + "()Ljava/io/InputStream;"); + if (!jni_mid_getInputStream) + { + OIC_LOG(ERROR, TAG, "jni_mid_getInputStream is null"); + return; + } - bool result = u_arraylist_add(g_deviceObjectList, (void *) socketInfo); - if (!result) - { - OIC_LOG(ERROR, TAG, "u_arraylist_add failed."); - OICFree(socketInfo); - return; - } + jobject jni_obj_inputStream = (*env)->CallObjectMethod(env, deviceSocket, + jni_mid_getInputStream); + if (!jni_obj_inputStream) + { + OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null"); + return; + } - OIC_LOG(DEBUG, TAG, "add new device socket object to list"); + socketInfo->deviceSocket = (*env)->NewGlobalRef(env, deviceSocket); + socketInfo->inputStream = (*env)->NewGlobalRef(env, jni_obj_inputStream); + (*env)->DeleteLocalRef(env, jni_obj_inputStream); + + bool result = u_arraylist_add(g_deviceObjectList, (void *) socketInfo); + if (!result) + { + OIC_LOG(ERROR, TAG, "u_arraylist_add failed."); + OICFree(socketInfo); + return; } - (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); - (*env)->DeleteLocalRef(env, jni_remoteAddress); + + OIC_LOG(DEBUG, TAG, "add new device socket object to list"); } bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress) { OIC_LOG(DEBUG, TAG, "CANativeIsDeviceObjInList"); + VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress", false); - if (!remoteAddress) - { - OIC_LOG(ERROR, TAG, "remoteAddress is null"); - return false; - } - - jint length = u_arraylist_length(g_deviceStateList); + jint length = u_arraylist_length(g_deviceObjectList); for (jint index = 0; index < length; index++) { CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList, @@ -678,7 +643,7 @@ void CAEDRNativeSocketCloseToAll(JNIEnv *env) return; } - jint length = u_arraylist_length(g_deviceStateList); + jint length = u_arraylist_length(g_deviceObjectList); for (jint index = 0; index < length; index++) { jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index); @@ -710,10 +675,9 @@ void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env) return; } - jint length = u_arraylist_length(g_deviceStateList); + jint length = u_arraylist_length(g_deviceObjectList); for (jint index = 0; index < length; index++) { - CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList, index); if (!socketInfo) @@ -743,74 +707,24 @@ void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env) void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket) { OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket"); + VERIFY_NON_NULL_VOID(deviceSocket, TAG, "deviceSocket"); - if (!g_deviceObjectList) + jstring jni_address = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket); + if (!jni_address) { - OIC_LOG(ERROR, TAG, "gdeviceObjectList is null"); + OIC_LOG(ERROR, TAG, "jni_address is null"); return; } - jint length = u_arraylist_length(g_deviceStateList); - for (jint index = 0; index < length; index++) - { - CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList, - index); - if (!socketInfo) - { - OIC_LOG(ERROR, TAG, "socketInfo is null"); - continue; - } - - jobject jarrayObj = socketInfo->deviceSocket; - if (!jarrayObj) - { - OIC_LOG(DEBUG, TAG, "jarrayObj is null"); - continue; - } - - jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj); - if (!jni_setAddress) - { - OIC_LOG(DEBUG, TAG, "jni_setAddress is null"); - continue; - } - - jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket); - if (!jni_remoteAddress) - { - OIC_LOG(DEBUG, TAG, "jni_remoteAddress is null"); - continue; - } + CAEDRNativeRemoveDeviceSocketBaseAddr(env, jni_address); - const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL); - const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL); - - if (!strcmp(setAddress, remoteAddress)) - { - OIC_LOG_V(DEBUG, TAG, "remove object : %s", remoteAddress); - (*env)->DeleteGlobalRef(env, jarrayObj); - jobject jinputStream = socketInfo->inputStream; - if (jinputStream) - { - (*env)->DeleteGlobalRef(env, jinputStream); - } - (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); - (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); - - u_arraylist_remove(g_deviceObjectList, index); - break; - } - (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); - (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); - } - - OIC_LOG(DEBUG, TAG, "there are no target object"); return; } void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address) { - OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket"); + OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocketBaseAddr"); + VERIFY_NON_NULL_VOID(address, TAG, "address"); if (!g_deviceObjectList) { @@ -818,7 +732,9 @@ void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address) return; } - jint length = u_arraylist_length(g_deviceStateList); + const char* targetAddress = (*env)->GetStringUTFChars(env, address, NULL); + + jint length = u_arraylist_length(g_deviceObjectList); for (jint index = 0; index < length; index++) { CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList, @@ -842,29 +758,33 @@ void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address) OIC_LOG(ERROR, TAG, "jni_setAddress is null"); continue; } + const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL); - const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL); - if (!strcmp(setAddress, remoteAddress)) + if (!strcmp(setAddress, targetAddress)) { - OIC_LOG_V(DEBUG, TAG, "remove object : %s", remoteAddress); + OIC_LOG_V(DEBUG, TAG, "remove object : %s", targetAddress); (*env)->DeleteGlobalRef(env, jarrayObj); jobject jinputStream = socketInfo->inputStream; if (jinputStream) { (*env)->DeleteGlobalRef(env, jinputStream); } + (*env)->ReleaseStringUTFChars(env, address, targetAddress); (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); - (*env)->ReleaseStringUTFChars(env, address, remoteAddress); + (*env)->DeleteLocalRef(env, jni_setAddress); u_arraylist_remove(g_deviceObjectList, index); - break; + return; } (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); - (*env)->ReleaseStringUTFChars(env, address, remoteAddress); + (*env)->DeleteLocalRef(env, jni_setAddress); } - OIC_LOG(DEBUG, TAG, "there are no target object"); + OIC_LOG_V(DEBUG, TAG, "the target object doesn't exist in deviceObjectList (addr: %s)", + targetAddress); + (*env)->ReleaseStringUTFChars(env, address, targetAddress); + return; } @@ -895,7 +815,8 @@ jobject CAEDRNativeGetDeviceSocket(uint32_t index) jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress) { - OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket"); + OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocketBaseAddr"); + VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress", NULL); if (!g_deviceObjectList) { @@ -903,7 +824,7 @@ jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddres return NULL; } - jint length = u_arraylist_length(g_deviceStateList); + jint length = u_arraylist_length(g_deviceObjectList); for (jint index = 0; index < length; index++) { CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList, @@ -982,17 +903,13 @@ uint32_t CAEDRGetSocketListLength() CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress) { OIC_LOG(DEBUG, TAG, "CAEDRGetDeviceInfoFromAddress"); + VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress", NULL); if (!g_deviceStateList) { OIC_LOG(ERROR, TAG, "gdeviceStateList is null"); return NULL; } - if (!remoteAddress) - { - OIC_LOG(ERROR, TAG, "remoteAddress is null"); - return NULL; - } jint length = u_arraylist_length(g_deviceStateList); for (jint index = 0; index < length; index++) diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c b/resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c index 9a1c018..f0b3fdf 100644 --- a/resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c +++ b/resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c @@ -35,63 +35,53 @@ #include "pdu.h" /** - * @var EDR_ADAPTER_TAG - * @brief Logging tag for module name. + * Logging tag for module name. */ -#define EDR_ADAPTER_TAG "OIC_CA_EDR_ADAP" +#define TAG "OIC_CA_EDR_ADAP" /** - * @var g_edrThreadPool - * @brief Reference to threadpool. + * Reference to threadpool. */ static ca_thread_pool_t g_edrThreadPool = NULL; /** - * @var g_sendQueueHandle - * @brief Queue handle for Send Data + * Queue handle for Send Data */ static CAQueueingThread_t *g_sendQueueHandle = NULL; /** - * @var g_recvQueueHandle - * @brief Queue handle for Receive Data + * Queue handle for Receive Data */ static CAQueueingThread_t *g_recvQueueHandle = NULL; /** - * @var g_adapterState - * @brief Storing Adapter state information + * Storing Adapter state information */ static bool g_adapterState = true; /** - * @var g_networkPacketReceivedCallback - * @brief Maintains the callback to be notified on receival of network packets from other - * Bluetooth devices. + * Maintains the callback to be notified on receival of network packets from other + * Bluetooth devices. */ static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL; /** - * @var g_networkChangeCallback - * @brief Maintains the callback to be notified on local bluetooth adapter status change. + * Maintains the callback to be notified on local bluetooth adapter status change. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_adapterChangeCallback = NULL; /** - * @var g_errorCallback - * @brief error Callback to CA adapter + * error Callback to CA adapter */ static CAErrorHandleCallback g_errorCallback = NULL; /** - * @var g_localConnectivity - * @brief Information of local Bluetooth adapter. + * Information of local Bluetooth adapter. */ static CAEndpoint_t *g_localConnectivity = NULL; /** - * @var g_serverState - * @brief Storing Rfcommserver state information + * Storing Rfcommserver state information */ static bool g_serverState = false; @@ -139,29 +129,28 @@ static void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data, CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback packetReceivedCallback, - CANetworkChangeCallback networkStateChangeCallback, + CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle) { // Input validation - VERIFY_NON_NULL(registerCallback, EDR_ADAPTER_TAG, "register callback is NULL"); - VERIFY_NON_NULL(packetReceivedCallback, EDR_ADAPTER_TAG, "data receive callback is NULL"); - VERIFY_NON_NULL(networkStateChangeCallback, EDR_ADAPTER_TAG, - "network state change callback is NULL"); - VERIFY_NON_NULL(handle, EDR_ADAPTER_TAG, "Thread pool handle is NULL"); + VERIFY_NON_NULL(registerCallback, TAG, "register callback is NULL"); + VERIFY_NON_NULL(packetReceivedCallback, TAG, "data receive callback is NULL"); + VERIFY_NON_NULL(netCallback, TAG, "adapter state change callback is NULL"); + VERIFY_NON_NULL(connCallback, TAG, "connection state change callback is NULL"); + VERIFY_NON_NULL(handle, TAG, "Thread pool handle is NULL"); // Register the callbacks - g_edrThreadPool = handle; g_networkPacketReceivedCallback = packetReceivedCallback; - g_networkChangeCallback = networkStateChangeCallback; + g_adapterChangeCallback = netCallback; g_errorCallback = errorCallback; // Initialize EDR Network Monitor CAResult_t res = CAEDRInitializeNetworkMonitor(handle); if (CA_STATUS_OK != res) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR N/w Monitor Initialize failed!, error number [%d]", - res); + OIC_LOG_V(ERROR, TAG, "EDR N/w Monitor Initialize failed!, error number [%d]", res); return res; } @@ -171,14 +160,14 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback, res = CAEDRClientInitialize(); if (CA_STATUS_OK != res) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR Client Initialize failed, error number [%d]", res); + OIC_LOG_V(ERROR, TAG, "EDR Client Initialize failed, error number [%d]", res); return res; } res = CAEDRServerInitialize(handle); if (CA_STATUS_OK != res) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR Server Initialize failed, error number [%d]", res); + OIC_LOG_V(ERROR, TAG, "EDR Server Initialize failed, error number [%d]", res); return res; } @@ -198,7 +187,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback, }; registerCallback(handler); - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT"); + OIC_LOG(DEBUG, TAG, "OUT"); return CA_STATUS_OK; } @@ -208,34 +197,34 @@ CAResult_t CAStartEDR() CAResult_t ret = CAEDRStartNetworkMonitor(); if (CA_STATUS_OK != ret) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Start n/w monitor"); + OIC_LOG(ERROR, TAG, "Failed to Start n/w monitor"); } // Get Bluetooth adapter state bool adapterState = false; if (CA_STATUS_OK != CAEDRGetAdapterEnableState(&adapterState)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to get adapter enable state"); + OIC_LOG(ERROR, TAG, "Failed to get adapter enable state"); return CA_STATUS_FAILED; } if (false == adapterState) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!"); + OIC_LOG(ERROR, TAG, "Bluetooth adapter is disabled!"); g_adapterState = false; return CA_ADAPTER_NOT_ENABLED; } if (CA_STATUS_OK != (ret = CAEDRClientSetCallbacks())) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Start Network Monitor failed!, error number [%d] ", + OIC_LOG_V(ERROR, TAG, "Start Network Monitor failed!, error number [%d] ", ret); } // Initialize Send/Receive data message queues if (CA_STATUS_OK != (ret = CAEDRInitializeQueueHandlers())) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, + OIC_LOG_V(ERROR, TAG, "CAAdapterInitializeQueues failed!, error number [%d] ", ret); CATerminateEDR(); return CA_STATUS_FAILED; @@ -244,7 +233,7 @@ CAResult_t CAStartEDR() // Start Send/Receive data message queues if (CA_STATUS_OK != (ret = CAAdapterStartQueue())) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "CAAdapterStartQueue failed!, error number [%d] ", ret); + OIC_LOG_V(ERROR, TAG, "CAAdapterStartQueue failed!, error number [%d] ", ret); } return ret; @@ -267,7 +256,7 @@ CAResult_t CAStartEDRDiscoveryServer() CAResult_t result = CAEDRStartDeviceDiscovery(); if(CA_STATUS_OK != result) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Failed to Start Device discovery"); + OIC_LOG(DEBUG, TAG, "Failed to Start Device discovery"); } #endif @@ -278,18 +267,18 @@ int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *dat uint32_t dataLength) { // Input validation - VERIFY_NON_NULL_RET(remoteEndpoint, EDR_ADAPTER_TAG, "Remote endpoint is null", -1); - VERIFY_NON_NULL_RET(data, EDR_ADAPTER_TAG, "Data is null", -1); + VERIFY_NON_NULL_RET(remoteEndpoint, TAG, "Remote endpoint is null", -1); + VERIFY_NON_NULL_RET(data, TAG, "Data is null", -1); if (0 == dataLength) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: data length is zero!"); + OIC_LOG(ERROR, TAG, "Invalid input: data length is zero!"); return -1; } if (0 == strlen(remoteEndpoint->addr)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: EDR Address is empty!"); + OIC_LOG(ERROR, TAG, "Invalid input: EDR Address is empty!"); return -1; } @@ -299,7 +288,7 @@ int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *dat CAResult_t err = CAAdapterSendData(address, serviceUUID, data, dataLength, &sentLength); if (CA_STATUS_OK != err) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Send unicast data failed!, error num [%d]", err); + OIC_LOG_V(ERROR, TAG, "Send unicast data failed!, error num [%d]", err); g_errorCallback(remoteEndpoint, data, dataLength, err); return -1; } @@ -309,14 +298,14 @@ int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *dat int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CASendEDRMulticastData"); + OIC_LOG(DEBUG, TAG, "IN - CASendEDRMulticastData"); // Input validation - VERIFY_NON_NULL_RET(data, EDR_ADAPTER_TAG, "Data is null", -1); + VERIFY_NON_NULL_RET(data, TAG, "Data is null", -1); if (0 == dataLength) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: data length is zero!"); + OIC_LOG(ERROR, TAG, "Invalid input: data length is zero!"); return -1; } @@ -325,25 +314,24 @@ int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, u CAResult_t err = CAAdapterSendData(NULL, serviceUUID, data, dataLength, &sentLen); if (CA_STATUS_OK != err) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Send multicast data failed!, error num [%d]", err); + OIC_LOG_V(ERROR, TAG, "Send multicast data failed!, error num [%d]", err); g_errorCallback(endpoint, data, dataLength, err); return -1; } - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT - CASendEDRMulticastData"); + OIC_LOG(DEBUG, TAG, "OUT - CASendEDRMulticastData"); return sentLen; } CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size) { - VERIFY_NON_NULL(info, EDR_ADAPTER_TAG, "LocalConnectivity info is null"); + VERIFY_NON_NULL(info, TAG, "LocalConnectivity info is null"); CAResult_t err = CA_STATUS_OK; *size = 0; if (CA_STATUS_OK != (err = CAEDRGetInterfaceInformation(info))) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, - "Failed to get local interface information!, error num [%d]", err); + OIC_LOG_V(ERROR, TAG, "Failed to get local interface information!, error num [%d]", err); return err; } @@ -385,7 +373,7 @@ void CATerminateEDR() CAAdapterTerminateQueues(); g_networkPacketReceivedCallback = NULL; - g_networkChangeCallback = NULL; + g_adapterChangeCallback = NULL; // Terminate thread pool g_edrThreadPool = NULL; @@ -405,7 +393,7 @@ CAResult_t CAStartServer() { if (false == g_adapterState) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!"); + OIC_LOG(DEBUG, TAG, "Bluetooth adapter is disabled!"); // Setting g_serverState for starting Rfcommserver when adapter starts g_serverState = true; return CA_STATUS_OK; @@ -414,7 +402,7 @@ CAResult_t CAStartServer() CAResult_t err = CA_STATUS_OK; if (CA_STATUS_OK != (err = CAEDRServerStart())) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to start RFCOMM server!, error num [%d]", + OIC_LOG_V(ERROR, TAG, "Failed to start RFCOMM server!, error num [%d]", err); return err; } @@ -427,7 +415,7 @@ CAResult_t CAEDRInitializeQueueHandlers() if (CA_STATUS_OK == CAEDRInitializeSendHandler() && CA_STATUS_OK == CAEDRInitializeReceiveHandler()) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Queue is initialized!"); + OIC_LOG(DEBUG, TAG, "Queue is initialized!"); return CA_STATUS_OK; } @@ -439,21 +427,21 @@ CAResult_t CAEDRInitializeSendHandler() // Check if the message queue is already initialized if (g_sendQueueHandle) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Already queue is initialized!"); + OIC_LOG(DEBUG, TAG, "Already queue is initialized!"); return CA_STATUS_OK; } g_sendQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t)); if (!g_sendQueueHandle) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Memory allocation failed!"); + OIC_LOG(ERROR, TAG, "Memory allocation failed!"); return CA_MEMORY_ALLOC_FAILED; } if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_edrThreadPool, CAAdapterDataSendHandler, CAEDRDataDestroyer)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Initialize send queue thread"); + OIC_LOG(ERROR, TAG, "Failed to Initialize send queue thread"); return CA_STATUS_FAILED; } return CA_STATUS_OK; @@ -464,14 +452,14 @@ CAResult_t CAEDRInitializeReceiveHandler() // Check if the message queue is already initialized if (g_recvQueueHandle) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Already queue is initialized!"); + OIC_LOG(DEBUG, TAG, "Already queue is initialized!"); return CA_STATUS_OK; } g_recvQueueHandle = (CAQueueingThread_t *) OICMalloc(sizeof(CAQueueingThread_t)); if (!g_recvQueueHandle) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Memory allocation failed!"); + OIC_LOG(ERROR, TAG, "Memory allocation failed!"); return CA_MEMORY_ALLOC_FAILED; } @@ -480,7 +468,7 @@ CAResult_t CAEDRInitializeReceiveHandler() CAAdapterDataReceiverHandler, CAEDRDataDestroyer)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Initialize send queue thread"); + OIC_LOG(ERROR, TAG, "Failed to Initialize send queue thread"); OICFree(g_recvQueueHandle); g_recvQueueHandle = NULL; return CA_STATUS_FAILED; @@ -505,25 +493,25 @@ void CAAdapterTerminateQueues() void CAAdapterDataSendHandler(void *context) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CAAdapterDataSendHandler"); + OIC_LOG(DEBUG, TAG, "IN - CAAdapterDataSendHandler"); CAEDRData *message = (CAEDRData *) context; if (!message) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to get message!"); + OIC_LOG(ERROR, TAG, "Failed to get message!"); return; } if (!message->remoteEndpoint) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "remoteEndpoint is not available"); + OIC_LOG(DEBUG, TAG, "remoteEndpoint is not available"); return; } const char *remoteAddress = message->remoteEndpoint->addr; if(!remoteAddress) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "EDR Send Message error"); + OIC_LOG(ERROR, TAG, "EDR Send Message error"); //Error cannot be sent if remote address is NULL return; } @@ -531,12 +519,12 @@ void CAAdapterDataSendHandler(void *context) CAResult_t result = CAEDRClientSendData(remoteAddress, message->data, message->dataLen); if(CA_STATUS_OK != result) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "CAEDRClientSendData API failed"); + OIC_LOG(ERROR, TAG, "CAEDRClientSendData API failed"); CAEDRErrorHandler(remoteAddress, message->data, message->dataLen, result); return; } - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT"); + OIC_LOG(DEBUG, TAG, "OUT"); } CAResult_t CAEDRClientSendData(const char *remoteAddress, const uint8_t *data, @@ -550,18 +538,18 @@ CAResult_t CAEDRClientSendData(const char *remoteAddress, const uint8_t *data, result = CAEDRClientSendUnicastData(remoteAddress, data, dataLength); if (CA_STATUS_OK != result) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to send unicast data !"); + OIC_LOG(ERROR, TAG, "Failed to send unicast data !"); return result; } } else { - OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "sending multicast data : %s", data); + OIC_LOG_V(DEBUG, TAG, "sending multicast data : %s", data); result = CAEDRClientSendMulticastData(data, dataLength); if (CA_STATUS_OK != result) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to send multicast data !"); + OIC_LOG(ERROR, TAG, "Failed to send multicast data !"); return result; } } @@ -570,18 +558,18 @@ CAResult_t CAEDRClientSendData(const char *remoteAddress, const uint8_t *data, void CAAdapterDataReceiverHandler(void *context) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN_CAAdapterDataReceiverHandler"); + OIC_LOG(DEBUG, TAG, "IN_CAAdapterDataReceiverHandler"); if (NULL == g_networkPacketReceivedCallback) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "g_networkPacketReceivedCallback is NULL"); + OIC_LOG(ERROR, TAG, "g_networkPacketReceivedCallback is NULL"); return; } CAEDRData *message = (CAEDRData *) context; if (NULL == message || NULL == message->remoteEndpoint) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to get message!"); + OIC_LOG(ERROR, TAG, "Failed to get message!"); return; } @@ -592,11 +580,11 @@ void CAAdapterDataReceiverHandler(void *context) if (!remoteEndpoint) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "remoteEndpoint is NULL"); + OIC_LOG(ERROR, TAG, "remoteEndpoint is NULL"); return; } - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Sending data up !"); + OIC_LOG(DEBUG, TAG, "Sending data up !"); const CASecureEndpoint_t sep = { .endpoint = *remoteEndpoint }; @@ -604,7 +592,7 @@ void CAAdapterDataReceiverHandler(void *context) CAFreeEndpoint(remoteEndpoint); - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT_CAAdapterDataReceiverHandler"); + OIC_LOG(DEBUG, TAG, "OUT_CAAdapterDataReceiverHandler"); } CAResult_t CAAdapterStartQueue() @@ -612,7 +600,7 @@ CAResult_t CAAdapterStartQueue() // Start send queue thread if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Start Send Data Thread"); + OIC_LOG(ERROR, TAG, "Failed to Start Send Data Thread"); CAEDRClientUnsetCallbacks(); //Disconnect all the client connections CAEDRClientDisconnectAll(); @@ -622,7 +610,7 @@ CAResult_t CAAdapterStartQueue() // Start receive queue thread if (CA_STATUS_OK != CAQueueingThreadStart(g_recvQueueHandle)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Start Receive Data Thread"); + OIC_LOG(ERROR, TAG, "Failed to Start Receive Data Thread"); CAEDRClientUnsetCallbacks(); //Disconnect all the client connections CAEDRClientDisconnectAll(); @@ -648,14 +636,14 @@ void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t { if (false == g_adapterState) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!"); + OIC_LOG_V(ERROR, TAG, "Bluetooth adapter is disabled!"); *sentLength = 0; return; } // Input validation - VERIFY_NON_NULL_VOID(data, EDR_ADAPTER_TAG, "Data is null"); - VERIFY_NON_NULL_VOID(sentLength, EDR_ADAPTER_TAG, "Sent data length holder is null"); + VERIFY_NON_NULL_VOID(data, TAG, "Data is null"); + VERIFY_NON_NULL_VOID(sentLength, TAG, "Sent data length holder is null"); // Create remote endpoint CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, @@ -663,7 +651,7 @@ void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t remoteAddress, 0); if (NULL == remoteEndpoint) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !"); + OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !"); return; } @@ -680,14 +668,14 @@ void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data, uint32_t dataLength, CAResult_t result) { // Input validation - VERIFY_NON_NULL_VOID(data, EDR_ADAPTER_TAG, "Data is null"); + VERIFY_NON_NULL_VOID(data, TAG, "Data is null"); // Create remote endpoint CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(0, CA_ADAPTER_RFCOMM_BTEDR, remoteAddress, 0); if (!remoteEndpoint) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !"); + OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !"); return; } @@ -700,18 +688,18 @@ void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data, CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const uint8_t *data, uint32_t dataLength, uint32_t *sentLength) { - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CAAdapterSendData"); + OIC_LOG(DEBUG, TAG, "IN - CAAdapterSendData"); if (false == g_adapterState) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!"); + OIC_LOG(ERROR, TAG, "Bluetooth adapter is disabled!"); *sentLength = 0; return CA_ADAPTER_NOT_ENABLED; } // Input validation - VERIFY_NON_NULL(serviceUUID, EDR_ADAPTER_TAG, "service UUID is null"); - VERIFY_NON_NULL(data, EDR_ADAPTER_TAG, "Data is null"); - VERIFY_NON_NULL(sentLength, EDR_ADAPTER_TAG, "Sent data length holder is null"); + VERIFY_NON_NULL(serviceUUID, TAG, "service UUID is null"); + VERIFY_NON_NULL(data, TAG, "Data is null"); + VERIFY_NON_NULL(sentLength, TAG, "Sent data length holder is null"); // Create remote endpoint CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, @@ -719,7 +707,7 @@ CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, remoteAddress, 0); if (NULL == remoteEndpoint) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !"); + OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !"); return CA_MEMORY_ALLOC_FAILED; } @@ -731,7 +719,7 @@ CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, // Free remote endpoint CAFreeEndpoint(remoteEndpoint); - OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT - CAAdapterSendData"); + OIC_LOG(DEBUG, TAG, "OUT - CAAdapterSendData"); return CA_STATUS_OK; } @@ -751,13 +739,13 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status) bool adapterState = false; if (CA_STATUS_OK != CAEDRGetAdapterEnableState(&adapterState)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to get adapter enable state"); + OIC_LOG(ERROR, TAG, "Failed to get adapter enable state"); return; } if (false == adapterState) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!"); + OIC_LOG(ERROR, TAG, "Bluetooth adapter is disabled!"); g_adapterState = false; return; } @@ -778,7 +766,7 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status) } // Notify to upper layer - if (g_networkChangeCallback && g_localConnectivity && g_edrThreadPool) + if (g_adapterChangeCallback && g_localConnectivity && g_edrThreadPool) { // Add notification task to thread pool CAEDRNetworkEvent *event = CAEDRCreateNetworkEvent(g_localConnectivity, status); @@ -787,7 +775,7 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status) if (CA_STATUS_OK != ca_thread_pool_add_task(g_edrThreadPool, CAEDROnNetworkStatusChanged,event)) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create threadpool!"); + OIC_LOG(ERROR, TAG, "Failed to create threadpool!"); return; } } @@ -798,16 +786,16 @@ void CAEDROnNetworkStatusChanged(void *context) { if (NULL == context) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "context is NULL!"); + OIC_LOG(ERROR, TAG, "context is NULL!"); return; } CAEDRNetworkEvent *networkEvent = (CAEDRNetworkEvent *) context; // Notify to upper layer - if (g_networkChangeCallback) + if (g_adapterChangeCallback) { - g_networkChangeCallback(networkEvent->info, networkEvent->status); + g_adapterChangeCallback(networkEvent->info->adapter, networkEvent->status); } // Free the created Network event @@ -817,13 +805,13 @@ void CAEDROnNetworkStatusChanged(void *context) CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CAEndpoint_t *connectivity, CANetworkStatus_t status) { - VERIFY_NON_NULL_RET(connectivity, EDR_ADAPTER_TAG, "connectivity is NULL", NULL); + VERIFY_NON_NULL_RET(connectivity, TAG, "connectivity is NULL", NULL); // Create CAEDRNetworkEvent CAEDRNetworkEvent *event = (CAEDRNetworkEvent *) OICMalloc(sizeof(CAEDRNetworkEvent)); if (NULL == event) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to allocate memory to network event!"); + OIC_LOG(ERROR, TAG, "Failed to allocate memory to network event!"); return NULL; } @@ -848,7 +836,7 @@ CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, CAEDRData *edrData = (CAEDRData *) OICCalloc(1, sizeof(*edrData)); if (!edrData) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Memory allocation failed!"); + OIC_LOG(ERROR, TAG, "Memory allocation failed!"); return NULL; } @@ -857,7 +845,7 @@ CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, edrData->data = OICMalloc(dataLength); if (NULL == edrData->data) { - OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Memory allocation failed!"); + OIC_LOG(ERROR, TAG, "Memory allocation failed!"); CAFreeEDRData(edrData); return NULL; } @@ -869,7 +857,7 @@ CAEDRData *CACreateEDRData(const CAEndpoint_t *remoteEndpoint, void CAFreeEDRData(CAEDRData *edrData) { - VERIFY_NON_NULL_VOID(edrData, EDR_ADAPTER_TAG, "edrData is NULL"); + VERIFY_NON_NULL_VOID(edrData, TAG, "edrData is NULL"); CAFreeEndpoint(edrData->remoteEndpoint); OICFree(edrData->data); @@ -880,7 +868,7 @@ void CAEDRDataDestroyer(void *data, uint32_t size) { if ((size_t)size < sizeof(CAEDRData)) { - OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Destroy data too small %p %d", data, size); + OIC_LOG_V(ERROR, TAG, "Destroy data too small %p %d", data, size); } CAEDRData *edrdata = (CAEDRData *) data; diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/linux/SConscript b/resource/csdk/connectivity/src/bt_edr_adapter/linux/SConscript deleted file mode 100644 index 0e09967..0000000 --- a/resource/csdk/connectivity/src/bt_edr_adapter/linux/SConscript +++ /dev/null @@ -1,9 +0,0 @@ -########################################## -# Build BT EDR adapter for Linux -########################################## - -Import('env') - -src_files = [ 'caedradapter.c'] - -Return('src_files') diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c b/resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c deleted file mode 100644 index 4863861..0000000 --- a/resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c +++ /dev/null @@ -1,141 +0,0 @@ -/****************************************************************** - * - * 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 -#include -#include - -#include "caedradapter.h" -#include "logger.h" - -#define TAG PCF("OIC_CA") - -static CANetworkPacketReceivedCallback g_edrReceivedCallback = NULL; -static ca_thread_pool_t g_threadPoolHandle = NULL; - -CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback, - CANetworkPacketReceivedCallback reqRespCallback, - CANetworkChangeCallback networkStateChangeCallback, - CAErrorHandleCallback errorCallback, ca_thread_pool_t handle) -{ - (void)networkStateChangeCallback; - (void)errorCallback; - OIC_LOG(DEBUG, TAG, "CAInitializeEDR"); - - g_edrReceivedCallback = reqRespCallback; - g_threadPoolHandle = handle; - - // register handlers - CAConnectivityHandler_t handler = { - .startAdapter = CAStartEDR, - .startListenServer = CAStartEDRListeningServer, - .stopListenServer = CAStopEDRListeningServer, - .startDiscoveryServer = CAStartEDRDiscoveryServer, - .sendData = CASendEDRUnicastData, - .sendDataToAll = CASendEDRMulticastData, - .GetnetInfo = CAGetEDRInterfaceInformation, - .readData = CAReadEDRData, - .stopAdapter = CAStopEDR, - .terminate = CATerminateEDR, - .cType = CA_ADAPTER_RFCOMM_BTEDR - }; - - registerCallback(handler); - - return CA_STATUS_OK; -} - -CAResult_t CAStartEDR() -{ - OIC_LOG(DEBUG, TAG, "CAStartEDR"); - - return CA_STATUS_OK; -} - -CAResult_t CAStartEDRListeningServer() -{ - OIC_LOG(DEBUG, TAG, "CAStartEDRListeningServer"); - - return CA_STATUS_OK; -} - -CAResult_t CAStopEDRListeningServer() -{ - OIC_LOG(DEBUG, TAG, "CAStopEDRListeningServer"); - - return CA_STATUS_OK; -} - -CAResult_t CAStartEDRDiscoveryServer() -{ - OIC_LOG(DEBUG, TAG, "CAStartEDRDiscoveryServer"); - - return CA_STATUS_OK; -} - -int32_t CASendEDRUnicastData(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLen) -{ - (void)endpoint; - (void)data; - (void)dataLen; - OIC_LOG(DEBUG, TAG, "CASendEDRUnicastData"); - - return -1; -} - -int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen) -{ - (void)endpoint; - (void)data; - (void)dataLen; - OIC_LOG(DEBUG, TAG, "CASendEDRMulticastData"); - - return -1; -} - -CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size) -{ - (void)info; - (void)size; - OIC_LOG(DEBUG, TAG, "CAGetEDRInterfaceInformation"); - - return CA_STATUS_OK; -} - -CAResult_t CAReadEDRData() -{ - OIC_LOG(DEBUG, TAG, "Read EDR Data"); - - return CA_STATUS_OK; -} - -CAResult_t CAStopEDR() -{ - OIC_LOG(DEBUG, TAG, "CAStopEDR"); - - return CA_STATUS_OK; -} - -void CATerminateEDR() -{ - OIC_LOG(DEBUG, TAG, "CATerminateEDR"); -} - diff --git a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c index f181dd9..ca42cb4 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c @@ -69,7 +69,12 @@ typedef enum /** * Callback to provide the status of the network change to CA layer. */ -static CANetworkChangeCallback g_networkCallback = NULL; +static CAAdapterChangeCallback g_networkCallback = NULL; + +/** + * Callback to provide the status of the connection change to CA layer. + */ +static CAConnectionChangeCallback g_connectionCallback = NULL; /** * bleAddress of the local adapter. Value will be initialized to zero, @@ -145,8 +150,10 @@ static CAErrorHandleCallback g_errorHandler = NULL; /** * Register network change notification callback. * - * @param[in] netCallback CANetworkChangeCallback callback which will - * be set for the change in network. + * @param[in] netCallback CAAdapterChangeCallback callback which will + * be set for the change in adapter. + * @param[in] connCallback CAConnectionChangeCallback callback which will + * be set for the change in connection. * * @return 0 on success otherwise a positive error value. * @retval ::CA_STATUS_OK Successful. @@ -154,7 +161,8 @@ static CAErrorHandleCallback g_errorHandler = NULL; * @retval ::CA_STATUS_FAILED Operation failed. * */ -static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback); +static CAResult_t CALERegisterNetworkNotifications(CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback); /** * Set the thread pool handle which is required for spawning new @@ -1717,7 +1725,8 @@ static CAResult_t CALEAdapterGattClientStop() CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback reqRespCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle) { @@ -1727,6 +1736,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback, VERIFY_NON_NULL(registerCallback, CALEADAPTER_TAG, "RegisterConnectivity callback is null"); VERIFY_NON_NULL(reqRespCallback, CALEADAPTER_TAG, "PacketReceived Callback is null"); VERIFY_NON_NULL(netCallback, CALEADAPTER_TAG, "NetworkChange Callback is null"); + VERIFY_NON_NULL(connCallback, CALEADAPTER_TAG, "ConnectionChange Callback is null"); CAResult_t result = CA_STATUS_OK; result = CAInitLEAdapterMutex(); @@ -1768,7 +1778,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback, CASetBLEClientErrorHandleCallback(CALEErrorHandler); CASetBLEServerErrorHandleCallback(CALEErrorHandler); - CALERegisterNetworkNotifications(netCallback); + CALERegisterNetworkNotifications(netCallback, connCallback); g_errorHandler = errorCallback; @@ -1837,7 +1847,7 @@ static void CATerminateLE() CASetLEReqRespServerCallback(NULL); CASetLEReqRespClientCallback(NULL); - CALERegisterNetworkNotifications(NULL); + CALERegisterNetworkNotifications(NULL, NULL); CASetLEReqRespAdapterCallback(NULL); CATerminateLENetworkMonitor(); @@ -2153,12 +2163,14 @@ static CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *siz return CA_STATUS_OK; } -static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback) +static CAResult_t CALERegisterNetworkNotifications(CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback) { OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN"); ca_mutex_lock(g_bleNetworkCbMutex); g_networkCallback = netCallback; + g_connectionCallback = connCallback; ca_mutex_unlock(g_bleNetworkCbMutex); CAResult_t res = CA_STATUS_OK; if (netCallback) @@ -2168,12 +2180,6 @@ static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCa { OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!"); } - - res = CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCb); - if (CA_STATUS_OK != res) - { - OIC_LOG(ERROR, CALEADAPTER_TAG, "CALEConnectionStateChangedCb failed!"); - } } else { @@ -2184,6 +2190,15 @@ static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCa } } + if (g_connectionCallback) + { + res = CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCb); + if (CA_STATUS_OK != res) + { + OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLENWConnectionStateChangedCb failed!"); + } + } + OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT"); return res; } @@ -2246,6 +2261,16 @@ static void CALEConnectionStateChangedCb(CATransportAdapter_t adapter, const cha #endif } + CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE }; + OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), address); + + ca_mutex_lock(g_bleNetworkCbMutex); + if (g_connectionCallback) + { + g_connectionCallback(&localEndpoint, isConnected); + } + ca_mutex_unlock(g_bleNetworkCbMutex); + OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT"); } @@ -2253,15 +2278,6 @@ static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state) { OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN - CALEDeviceStateChangedCb"); - VERIFY_NON_NULL_VOID(g_localBLEAddress, CALEADAPTER_TAG, "g_localBLEAddress is null"); - CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE }; - - ca_mutex_lock(g_bleLocalAddressMutex); - OICStrcpy(localEndpoint.addr, - sizeof(localEndpoint.addr), - g_localBLEAddress); - ca_mutex_unlock(g_bleLocalAddressMutex); - if (CA_ADAPTER_ENABLED == adapter_state) { ca_mutex_lock(g_bleIsServerMutex); @@ -2306,7 +2322,7 @@ static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state) ca_mutex_lock(g_bleNetworkCbMutex); if (NULL != g_networkCallback) { - g_networkCallback(&localEndpoint, adapter_state); + g_networkCallback(CA_ADAPTER_GATT_BTLE, adapter_state); } else { diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c index f21b637..0b234d7 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c @@ -114,13 +114,6 @@ static ca_thread_pool_t g_leServerThreadPool = NULL; */ static GMainLoop *g_eventLoop = NULL; -static CALEConnectionStateChangedCallback g_connStateCb = NULL; - -void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb) -{ - g_connStateCb = connStateCb; -} - void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress) { VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address"); @@ -128,18 +121,10 @@ void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddr if (connected) { OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress); - if (g_connStateCb) - { - g_connStateCb(CA_ADAPTER_GATT_BTLE, remoteAddress, true); - } } else { OIC_LOG_V(DEBUG, TAG, "Disconnected from [%s]", remoteAddress); - if (g_connStateCb) - { - g_connStateCb(CA_ADAPTER_GATT_BTLE, remoteAddress, false); - } } } diff --git a/resource/csdk/connectivity/src/caconnectivitymanager.c b/resource/csdk/connectivity/src/caconnectivitymanager.c index 691e2bc..82919b7 100644 --- a/resource/csdk/connectivity/src/caconnectivitymanager.c +++ b/resource/csdk/connectivity/src/caconnectivitymanager.c @@ -553,9 +553,8 @@ CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint) #endif /* __WITH_DTLS__ */ #ifdef TCP_ADAPTER -void CARegisterKeepAliveHandler(CAKeepAliveConnectedCallback ConnHandler, - CAKeepAliveDisconnectedCallback DisconnHandler) +void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler) { - CATCPSetKeepAliveCallbacks(ConnHandler, DisconnHandler); + CATCPSetKeepAliveCallbacks(ConnHandler); } #endif diff --git a/resource/csdk/connectivity/src/cainterfacecontroller.c b/resource/csdk/connectivity/src/cainterfacecontroller.c index 562a7b5..64b3f68 100644 --- a/resource/csdk/connectivity/src/cainterfacecontroller.c +++ b/resource/csdk/connectivity/src/cainterfacecontroller.c @@ -49,15 +49,15 @@ #define CA_MEMORY_ALLOC_CHECK(arg) {if (arg == NULL) \ {OIC_LOG(ERROR, TAG, "memory error");goto memory_error_exit;} } - - static CAConnectivityHandler_t *g_adapterHandler = NULL; static uint32_t g_numberOfAdapters = 0; static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL; -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_adapterChangeCallback = NULL; + +static CAConnectionChangeCallback g_connChangeCallback = NULL; static CAErrorHandleCallback g_errorHandleCallback = NULL; @@ -124,13 +124,24 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, } } -static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status) +static void CAAdapterChangedCallback(CATransportAdapter_t adapter, CANetworkStatus_t status) +{ + // Call the callback. + if (g_adapterChangeCallback != NULL) + { + g_adapterChangeCallback(adapter, status); + } + OIC_LOG_V(DEBUG, TAG, "[%d]adapter status is changed to [%d]", adapter, status); +} + +static void CAConnectionChangedCallback(const CAEndpoint_t *info, bool isConnected) { // Call the callback. - if (g_networkChangeCallback != NULL) + if (g_connChangeCallback != NULL) { - g_networkChangeCallback(info, status); + g_connChangeCallback(info, isConnected); } + OIC_LOG_V(DEBUG, TAG, "[%s] connection status is changed to [%d]", info->addr, isConnected); } static void CAAdapterErrorHandleCallback(const CAEndpoint_t *endpoint, @@ -152,32 +163,32 @@ void CAInitializeAdapters(ca_thread_pool_t handle) // Initialize adapters and register callback. #ifdef IP_ADAPTER - CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, + CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback, CAAdapterErrorHandleCallback, handle); #endif /* IP_ADAPTER */ #ifdef EDR_ADAPTER - CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, - CAAdapterErrorHandleCallback, handle); + CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback, + CAConnectionChangedCallback, CAAdapterErrorHandleCallback, handle); #endif /* EDR_ADAPTER */ #ifdef LE_ADAPTER - CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, - CAAdapterErrorHandleCallback, handle); + CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback, + CAConnectionChangedCallback, CAAdapterErrorHandleCallback, handle); #endif /* LE_ADAPTER */ #ifdef RA_ADAPTER - CAInitializeRA(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, + CAInitializeRA(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback, handle); #endif /* RA_ADAPTER */ #ifdef TCP_ADAPTER - CAInitializeTCP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, - CAAdapterErrorHandleCallback, handle); + CAInitializeTCP(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback, + CAConnectionChangedCallback, CAAdapterErrorHandleCallback, handle); #endif /* TCP_ADAPTER */ #ifdef NFC_ADAPTER - CAInitializeNFC(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback, + CAInitializeNFC(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback, CAAdapterErrorHandleCallback, handle); #endif /* NFC_ADAPTER */ } @@ -189,11 +200,13 @@ void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback) g_networkPacketReceivedCallback = callback; } -void CASetNetworkChangeCallback(CANetworkChangeCallback callback) +void CASetNetworkMonitorCallbacks(CAAdapterChangeCallback adapterCB, + CAConnectionChangeCallback connCB) { - OIC_LOG(DEBUG, TAG, "Set network handle callback"); + OIC_LOG(DEBUG, TAG, "Set network monitoring callback"); - g_networkChangeCallback = callback; + g_adapterChangeCallback = adapterCB; + g_connChangeCallback = connCB; } void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback) diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index e637642..5d5ed73 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -842,17 +842,6 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, coap_delete_pdu(pdu); } -static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status) -{ - (void)info; - (void)status; - - if (g_nwMonitorHandler) - { - g_nwMonitorHandler(info, status); - } -} - void CAHandleRequestResponseCallbacks() { #ifdef SINGLE_THREAD @@ -1045,8 +1034,6 @@ void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler) CAResult_t CAInitializeMessageHandler() { CASetPacketReceivedCallback(CAReceivedPacketCallback); - - CASetNetworkChangeCallback(CANetworkChangedCallback); CASetErrorHandleCallback(CAErrorHandler); #ifndef SINGLE_THREAD diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index 631e05e..7d84c1c 100644 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -670,7 +670,10 @@ uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter) && COAP_OPTION_BLOCK1 != opt_iter.type && COAP_OPTION_BLOCK2 != opt_iter.type && COAP_OPTION_SIZE1 != opt_iter.type && COAP_OPTION_SIZE2 != opt_iter.type && COAP_OPTION_CONTENT_FORMAT != opt_iter.type - && COAP_OPTION_ACCEPT != opt_iter.type && COAP_OPTION_URI_PORT != opt_iter.type) + && COAP_OPTION_ACCEPT != opt_iter.type + && COAP_OPTION_URI_HOST != opt_iter.type && COAP_OPTION_URI_PORT != opt_iter.type + && COAP_OPTION_ETAG != opt_iter.type && COAP_OPTION_MAXAGE != opt_iter.type + && COAP_OPTION_PROXY_URI != opt_iter.type && COAP_OPTION_PROXY_SCHEME != opt_iter.type) { count++; } @@ -866,7 +869,12 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint, OIC_LOG_V(DEBUG, TAG, "option[%d] has an unsupported format [%d]", opt_iter.type, (uint8_t)buf[0]); } - else if (COAP_OPTION_URI_PORT == opt_iter.type) + else if (COAP_OPTION_URI_PORT == opt_iter.type || + COAP_OPTION_URI_HOST == opt_iter.type || + COAP_OPTION_ETAG == opt_iter.type || + COAP_OPTION_MAXAGE == opt_iter.type || + COAP_OPTION_PROXY_URI == opt_iter.type || + COAP_OPTION_PROXY_SCHEME== opt_iter.type) { OIC_LOG_V(INFO, TAG, "option[%d] has an unsupported format [%d]", opt_iter.type, (uint8_t)buf[0]); diff --git a/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c index 2685880..ff70009 100644 --- a/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c @@ -38,6 +38,8 @@ #define TAG "OIC_CA_IP_MONITOR" +static CAIPConnectionStateChangeCallback g_networkChangeCallback; + static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family, uint32_t addr, int flags); @@ -69,6 +71,11 @@ int CAGetPollingInterval(int interval) return interval; } +void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback) +{ + g_networkChangeCallback = callback; +} + CAInterface_t *CAFindInterfaceChange() { char buf[MAX_INTERFACE_INFO_LENGTH] = { 0 }; @@ -438,9 +445,9 @@ Java_org_iotivity_ca_CaIpInterface_caIpStateEnabled(JNIEnv *env, jclass class) { (void)env; (void)class; - OIC_LOG(DEBUG, TAG, "caIpStateEnabled"); - CAWakeUpForChange(); + OIC_LOG(DEBUG, TAG, "Wifi is in Activated State"); + g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_UP); } JNIEXPORT void JNICALL @@ -448,13 +455,7 @@ Java_org_iotivity_ca_CaIpInterface_caIpStateDisabled(JNIEnv *env, jclass class) { (void)env; (void)class; - OIC_LOG(DEBUG, TAG, "caIpStateDisabled"); - u_arraylist_t *iflist = CAIPGetInterfaceInformation(0); - if (!iflist) - { - OIC_LOG_V(ERROR, TAG, "get interface info failed"); - return; - } - u_arraylist_destroy(iflist); + OIC_LOG(DEBUG, TAG, "Wifi is in Deactivated State"); + g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_DOWN); } diff --git a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c index 308ec6d..4c4c9fb 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c @@ -68,7 +68,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; /** * Network Changed Callback to CA. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_networkChangeCallback = NULL; /** * error Callback to CA adapter. @@ -137,10 +137,16 @@ void CAIPDeinitializeQueueHandles() #endif // SINGLE_THREAD -void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status) +void CAIPConnectionStateCB(CATransportAdapter_t adapter, CANetworkStatus_t status) { - (void)ipAddress; - (void)status; + if (g_networkChangeCallback) + { + g_networkChangeCallback(adapter, status); + } + else + { + OIC_LOG(ERROR, TAG, "g_networkChangeCallback is NULL"); + } } #ifdef __WITH_DTLS__ @@ -215,7 +221,7 @@ static void CAInitializeIPGlobals() CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, TAG, "IN"); @@ -234,6 +240,9 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback, caglobals.ip.threadpool = handle; CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB); +#ifndef SINGLE_THREAD + CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB); +#endif #ifdef __WITH_DTLS__ CAAdapterNetDtlsInit(); diff --git a/resource/csdk/connectivity/src/ip_adapter/caipserver.c b/resource/csdk/connectivity/src/ip_adapter/caipserver.c index 83433d8..da0375f 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipserver.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipserver.c @@ -250,7 +250,12 @@ static void CASelectReturned(fd_set *readFds, int ret) else ISSET(m4s, readFds, CA_MULTICAST | CA_IPV4 | CA_SECURE) else if (FD_ISSET(caglobals.ip.netlinkFd, readFds)) { - CAHandleNetlink(); + CAInterface_t *ifchanged = CAFindInterfaceChange(); + if (ifchanged) + { + CAProcessNewInterface(ifchanged); + OICFree(ifchanged); + } break; } else if (FD_ISSET(caglobals.ip.shutdownFds[0], readFds)) @@ -261,13 +266,6 @@ static void CASelectReturned(fd_set *readFds, int ret) { continue; } - - CAInterface_t *ifchanged = CAFindInterfaceChange(); - if (ifchanged) - { - CAProcessNewInterface(ifchanged); - OICFree(ifchanged); - } break; } else @@ -836,64 +834,18 @@ static void CAProcessNewInterface(CAInterface_t *ifitem) OIC_LOG(DEBUG, TAG, "ifitem is null"); return; } - - applyMulticastToInterface6(ifitem->index); - struct in_addr inaddr = { .s_addr = ifitem->ipv4addr }; - applyMulticastToInterface4(inaddr); + if (ifitem->family == AF_INET6) + { + applyMulticastToInterface6(ifitem->index); + } + if (ifitem->family == AF_INET) + { + struct in_addr inaddr = { .s_addr = ifitem->ipv4addr }; + applyMulticastToInterface4(inaddr); + } } static void CAHandleNetlink() { -#ifdef __linux__ - char buf[4096]; - struct nlmsghdr *nh; - struct sockaddr_nl sa; - struct iovec iov = { buf, sizeof (buf) }; - struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 }; - - size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0); - - for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) - { - if (nh != NULL && nh->nlmsg_type != RTM_NEWLINK) - { - continue; - } - - struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh); - if (!ifi || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING)) - { - continue; - } - - int newIndex = ifi->ifi_index; - - u_arraylist_t *iflist = CAIPGetInterfaceInformation(newIndex); - if (!iflist) - { - OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno)); - return; - } - - uint32_t listLength = u_arraylist_length(iflist); - for (uint32_t i = 0; i < listLength; i++) - { - CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); - if (!ifitem) - { - continue; - } - - if ((int)ifitem->index != newIndex) - { - continue; - } - - CAProcessNewInterface(ifitem); - break; // we found the one we were looking for - } - u_arraylist_destroy(iflist); - } -#endif // __linux__ } void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback) @@ -906,6 +858,11 @@ void CAIPSetExceptionCallback(CAIPExceptionCallback callback) g_exceptionCallback = callback; } +void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback) +{ + CAIPSetNetworkMonitorCallback(callback); +} + static void sendData(int fd, const CAEndpoint_t *endpoint, const void *data, uint32_t dlen, const char *cast, const char *fam) diff --git a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c index f1d5211..a2f2e4f 100644 --- a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c @@ -20,15 +20,29 @@ #include "caipinterface.h" +#include +#include +#include +#include #include +#include #include +#include +#include +#include +#include #include -#include #include -#include #include -#include +#ifdef __linux__ +#include +#include +#include +#include +#endif + +#include "camutex.h" #include "caadapterutils.h" #include "logger.h" #include "oic_malloc.h" @@ -36,13 +50,137 @@ #define TAG "OIC_CA_IP_MONITOR" -CAResult_t CAIPStartNetworkMonitor() +/** + * Mutex for synchronizing access to cached interface and IP address information. + */ +static ca_mutex g_networkMonitorContextMutex = NULL; + +/** + * Used to storing network interface. + */ +static u_arraylist_t *g_netInterfaceList = NULL; + +static CAIPConnectionStateChangeCallback g_networkChangeCallback = NULL; + +static CAResult_t CAIPInitializeNetworkMonitorList(); +static void CAIPDestroyNetworkMonitorList(); +static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family, + uint32_t addr, int flags); + +static CAResult_t CAIPInitializeNetworkMonitorList() +{ + if (!g_networkMonitorContextMutex) + { + g_networkMonitorContextMutex = ca_mutex_new(); + if (!g_networkMonitorContextMutex) + { + OIC_LOG(ERROR, TAG, "ca_mutex_new has failed"); + return CA_STATUS_FAILED; + } + } + + if (!g_netInterfaceList) + { + g_netInterfaceList = u_arraylist_create(); + if (!g_netInterfaceList) + { + OIC_LOG(ERROR, TAG, "u_arraylist_create has failed"); + CAIPDestroyNetworkMonitorList(); + return CA_STATUS_FAILED; + } + } +} + +static void CAIPDestroyNetworkMonitorList() +{ + if (g_netInterfaceList) + { + u_arraylist_destroy(g_netInterfaceList); + g_netInterfaceList = NULL; + } + + if (g_networkMonitorContextMutex) + { + ca_mutex_free(g_networkMonitorContextMutex); + g_networkMonitorContextMutex = NULL; + } +} + +static bool CACmpNetworkList(uint32_t ifiindex) +{ + if (!g_netInterfaceList) + { + OIC_LOG(ERROR, TAG, "g_netInterfaceList is NULL"); + return false; + } + + ca_mutex_lock(g_networkMonitorContextMutex); + + uint32_t list_length = u_arraylist_length(g_netInterfaceList); + for (uint32_t list_index = 0; list_index < list_length; list_index++) + { + CAInterface_t *currItem = (CAInterface_t *) u_arraylist_get(g_netInterfaceList, list_index); + if (currItem->index == ifiindex) + { + ca_mutex_unlock(g_networkMonitorContextMutex); + return true; + } + } + ca_mutex_unlock(g_networkMonitorContextMutex); + return false; +} + +static CAResult_t CAAddNetworkMonitorList(CAInterface_t *ifitem) { + VERIFY_NON_NULL(g_netInterfaceList, TAG, "g_netInterfaceList is NULL"); + VERIFY_NON_NULL(ifitem, TAG, "ifitem is NULL"); + + ca_mutex_lock(g_networkMonitorContextMutex); + bool result = u_arraylist_add(g_netInterfaceList, (void *) ifitem); + if (!result) + { + OIC_LOG(ERROR, TAG, "u_arraylist_add failed."); + ca_mutex_unlock(g_networkMonitorContextMutex); + return CA_STATUS_FAILED; + } + ca_mutex_unlock(g_networkMonitorContextMutex); return CA_STATUS_OK; } +static void CARemoveNetworkMonitorList(int ifiindex) +{ + VERIFY_NON_NULL_VOID(g_netInterfaceList, TAG, "g_netInterfaceList is NULL"); + + ca_mutex_lock(g_networkMonitorContextMutex); + + uint32_t list_length = u_arraylist_length(g_netInterfaceList); + for (uint32_t list_index = 0; list_index < list_length; list_index++) + { + CAInterface_t *removedifitem = (CAInterface_t *) u_arraylist_get( + g_netInterfaceList, list_index); + if (removedifitem && removedifitem->index == ifiindex) + { + if (u_arraylist_remove(g_netInterfaceList, list_index)) + { + OICFree(removedifitem); + ca_mutex_unlock(g_networkMonitorContextMutex); + return; + } + continue; + } + } + ca_mutex_unlock(g_networkMonitorContextMutex); + return; +} + +CAResult_t CAIPStartNetworkMonitor() +{ + return CAIPInitializeNetworkMonitorList(); +} + CAResult_t CAIPStopNetworkMonitor() { + CAIPDestroyNetworkMonitorList(); return CA_STATUS_OK; } @@ -51,9 +189,96 @@ int CAGetPollingInterval(int interval) return interval; } +void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback) +{ + g_networkChangeCallback = callback; +} + +static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family, + uint32_t addr, int flags) +{ + CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof (CAInterface_t)); + if (!ifitem) + { + OIC_LOG(ERROR, TAG, "Malloc failed"); + return NULL; + } + + OICStrcpy(ifitem->name, sizeof (ifitem->name), name); + ifitem->index = index; + ifitem->family = family; + ifitem->ipv4addr = addr; + ifitem->flags = flags; + + return ifitem; +} + CAInterface_t *CAFindInterfaceChange() { - return NULL; + CAInterface_t *foundNewInterface = NULL; +#ifdef __linux__ + char buf[4096]; + struct nlmsghdr *nh; + struct sockaddr_nl sa; + struct iovec iov = { buf, sizeof (buf) }; + struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 }; + + size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0); + + for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) + { + if (nh != NULL && nh->nlmsg_type != RTM_NEWLINK) + { + continue; + } + + struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh); + + int ifiIndex = ifi->ifi_index; + u_arraylist_t *iflist = CAIPGetInterfaceInformation(ifiIndex); + + if ((!ifi || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING))) + { + bool isFound = CACmpNetworkList(ifiIndex); + if (isFound) + { + CARemoveNetworkMonitorList(ifiIndex); + if (g_networkChangeCallback) + { + g_networkChangeCallback(CA_ADAPTER_IP ,CA_INTERFACE_DOWN); + } + } + continue; + } + + if (!iflist) + { + OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno)); + return NULL; + } + + uint32_t listLength = u_arraylist_length(iflist); + for (uint32_t i = 0; i < listLength; i++) + { + CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); + if (!ifitem) + { + continue; + } + + if ((int)ifitem->index != ifiIndex) + { + continue; + } + + foundNewInterface = CANewInterfaceItem(ifitem->index, ifitem->name, ifitem->family, + ifitem->ipv4addr, ifitem->flags); + break; // we found the one we were looking for + } + u_arraylist_destroy(iflist); + } +#endif + return foundNewInterface; } u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) @@ -138,9 +363,24 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) goto exit; } - OIC_LOG_V(DEBUG, TAG, "Added interface: %s (%d)", ifitem->name, family); + bool isFound = CACmpNetworkList(ifitem->index); + if (!isFound) + { + CAInterface_t *newifitem = CANewInterfaceItem(ifitem->index, ifitem->name, ifitem->family, + ifitem->ipv4addr, ifitem->flags); + CAResult_t ret = CAAddNetworkMonitorList(newifitem); + if (CA_STATUS_OK != ret) + { + OICFree(newifitem); + goto exit; + } + if (g_networkChangeCallback) + { + g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_UP); + } + OIC_LOG_V(DEBUG, TAG, "Added interface: %s (%d)", ifitem->name, ifitem->family); + } } - freeifaddrs(ifp); return iflist; diff --git a/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c index 437e535..aaa39d4 100644 --- a/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c @@ -39,6 +39,8 @@ #define TAG "IP_MONITOR" #define MAX_INTERFACE_INFO_LENGTH (1024) +static CAIPConnectionStateChangeCallback g_networkChangeCallback; + static CAInterface_t *CANewInterfaceItem(int index, char *name, int family, uint32_t addr, int flags); @@ -56,6 +58,11 @@ int CAGetPollingInterval(int interval) return interval; } +void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback) +{ + g_networkChangeCallback = callback; +} + CAInterface_t *CAFindInterfaceChange() { char buf[MAX_INTERFACE_INFO_LENGTH] = { 0 }; @@ -357,17 +364,11 @@ void CAWIFIConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, if (WIFI_CONNECTION_STATE_CONNECTED == state) { - CAWakeUpForChange(); + g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_UP); } else { - u_arraylist_t *iflist = CAIPGetInterfaceInformation(0); - if (!iflist) - { - OIC_LOG_V(ERROR, TAG, "get interface info failed"); - return; - } - u_arraylist_destroy(iflist); + g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_DOWN); } OIC_LOG(DEBUG, TAG, "OUT"); diff --git a/resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c b/resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c index cc34caa..eddee4d 100644 --- a/resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c +++ b/resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c @@ -58,9 +58,9 @@ static CAQueueingThread_t *g_sendQueueHandle = NULL; static CANetworkPacketReceivedCallback g_packetReceivedCallback = NULL; /** - * Network Changed Callback to CA + * Adapter Changed Callback to CA */ -static CANetworkChangeCallback g_connectionStateCallback = NULL; +static CAAdapterChangeCallback g_adapterStateCallback = NULL; /** * error Callback to CA adapter @@ -177,16 +177,16 @@ void CANFCErrorHandler(const CAEndpoint_t *endpoint, const void *data, uint32_t CAResult_t CAInitializeNFC(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback packetReceivedCallback, - CANetworkChangeCallback connectionStateCallback, + CAAdapterChangeCallback netCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, TAG, "IN"); VERIFY_NON_NULL(registerCallback, TAG, "registerCallback"); VERIFY_NON_NULL(packetReceivedCallback, TAG, "packetReceivedCallback"); - VERIFY_NON_NULL(connectionStateCallback, TAG, "connectionStateCallback"); + VERIFY_NON_NULL(netCallback, TAG, "netCallback"); VERIFY_NON_NULL(handle, TAG, "thread pool handle"); - g_connectionStateCallback = connectionStateCallback; + g_adapterStateCallback = netCallback; g_packetReceivedCallback = packetReceivedCallback; g_errorCallback = errorCallback; diff --git a/resource/csdk/connectivity/src/ra_adapter/caraadapter.c b/resource/csdk/connectivity/src/ra_adapter/caraadapter.c index b34cb83..fba4ca8 100644 --- a/resource/csdk/connectivity/src/ra_adapter/caraadapter.c +++ b/resource/csdk/connectivity/src/ra_adapter/caraadapter.c @@ -59,7 +59,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; /** * Network Changed Callback to CA. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_networkChangeCallback = NULL; /** * Holds XMPP data information. @@ -91,26 +91,16 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status) g_xmppData.connectionStatus = status; - CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, - CA_ADAPTER_REMOTE_ACCESS, - address, 0); - if (!localEndpoint) - { - OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!"); - return; - } - CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback; + CAAdapterChangeCallback networkChangeCallback = g_networkChangeCallback; if (networkChangeCallback) { - networkChangeCallback(localEndpoint, status); + networkChangeCallback(CA_ADAPTER_REMOTE_ACCESS, status); } else { OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL"); } - CAFreeEndpoint(localEndpoint); - OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT"); } @@ -359,8 +349,8 @@ static int CARAConnHandler(xmpp_t *xmpp, xmppconn_info_t *conninfo, void *udata) } CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, - CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, ca_thread_pool_t handle) + CANetworkPacketReceivedCallback networkPacketCallback, + CAAdapterChangeCallback netCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN"); if (!registerCallback || !networkPacketCallback || !netCallback || !handle) @@ -615,7 +605,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; /** * Network Changed Callback to CA. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_networkChangeCallback = NULL; /** * Holds XMPP data information. @@ -657,26 +647,16 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status) { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange IN"); - CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, - CA_ADAPTER_REMOTE_ACCESS, - address, 0); - if (!localEndpoint) - { - OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!"); - return; - } - CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback; + CAAdapterChangeCallback networkChangeCallback = g_networkChangeCallback; if (networkChangeCallback) { - networkChangeCallback(localEndpoint, status); + networkChangeCallback(CA_ADAPTER_REMOTE_ACCESS, status); } else { OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL"); } - CAFreeEndpoint(localEndpoint); - OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT"); } @@ -783,8 +763,8 @@ void CARAXmppMessageReceivedCB(void * const param, xmpp_error_code_t result, } CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, - CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, ca_thread_pool_t handle) + CANetworkPacketReceivedCallback networkPacketCallback, + CAAdapterChangeCallback netCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN"); if (!registerCallback || !networkPacketCallback || !netCallback || !handle) diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c index 64aa5d7..6ea9c36 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c @@ -71,9 +71,14 @@ static CAQueueingThread_t *g_sendQueueHandle = NULL; static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; /** - * Network Changed Callback to CA. + * Adapter Changed Callback to CA. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_networkChangeCallback = NULL; + +/** + * Connection Changed Callback to CA. + */ +static CAConnectionChangeCallback g_connectionChangeCallback = NULL; /** * error Callback to CA adapter. @@ -84,14 +89,9 @@ static void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data, uint32_t dataLength); /** - * KeepAlive Connected Callback to CA adapter. + * KeepAlive Connected or Disconnected Callback to CA adapter. */ -static CAKeepAliveConnectedCallback g_connCallback = NULL; - -/** - * KeepAlive Disconnected Callback to CA adapter. - */ -static CAKeepAliveDisconnectedCallback g_disconnCallback = NULL; +static CAKeepAliveConnectionCallback g_connKeepAliveCallback = NULL; static CAResult_t CATCPInitializeQueueHandles(); @@ -175,29 +175,28 @@ void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data, } } -static void CATCPKeepAliveHandler(const char *addr, uint16_t port, bool isConnected) +static void CATCPConnectionHandler(const char *addr, uint16_t port, bool isConnected) { CAEndpoint_t endpoint = { .adapter = CA_ADAPTER_TCP, .port = port }; OICStrcpy(endpoint.addr, sizeof(endpoint.addr), addr); - if (isConnected) + // Pass the changed connection status to RI Layer for keepalive. + if (g_connKeepAliveCallback) { - g_connCallback(&endpoint); + g_connKeepAliveCallback(&endpoint, isConnected); } - else + + // Pass the changed connection status to CAUtil. + if (g_connectionChangeCallback) { - g_disconnCallback(&endpoint); + g_connectionChangeCallback(&endpoint, isConnected); } } -void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectedCallback ConnHandler, - CAKeepAliveDisconnectedCallback DisconnHandler) +void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler) { - g_connCallback = ConnHandler; - g_disconnCallback = DisconnHandler; - - CATCPSetKeepAliveCallback(CATCPKeepAliveHandler); + g_connKeepAliveCallback = ConnHandler; } static void CAInitializeTCPGlobals() @@ -226,7 +225,8 @@ static void CAInitializeTCPGlobals() CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback, CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, + CAAdapterChangeCallback netCallback, + CAConnectionChangeCallback connCallback, CAErrorHandleCallback errorCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, TAG, "IN"); @@ -236,12 +236,14 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback, VERIFY_NON_NULL(handle, TAG, "thread pool handle"); g_networkChangeCallback = netCallback; + g_connectionChangeCallback = connCallback; g_networkPacketCallback = networkPacketCallback; g_errorCallback = errorCallback; CAInitializeTCPGlobals(); caglobals.tcp.threadpool = handle; + CATCPSetConnectionChangedCallback(CATCPConnectionHandler); CATCPSetPacketReceiveCallback(CATCPPacketReceivedCB); CATCPSetErrorHandler(CATCPErrorHandler); diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index b266815..3d9ef2f 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -83,7 +83,7 @@ static CATCPErrorHandleCallback g_TCPErrorHandler = NULL; /** * Connected Callback to pass the connection information to RI. */ -static CATCPKeepAliveHandleCallback g_keepaliveCallback = NULL; +static CATCPConnectionHandleCallback g_connectionCallback = NULL; static CAResult_t CATCPCreateMutex(); static void CATCPDestroyMutex(); @@ -720,9 +720,9 @@ void CATCPSetPacketReceiveCallback(CATCPPacketReceivedCallback callback) g_packetReceivedCallback = callback; } -void CATCPSetKeepAliveCallback(CATCPKeepAliveHandleCallback keepaliveHandler) +void CATCPSetConnectionChangedCallback(CATCPConnectionHandleCallback connHandler) { - g_keepaliveCallback = keepaliveHandler; + g_connectionCallback = connHandler; } static size_t CACheckPayloadLength(const void *data, size_t dlen) @@ -892,10 +892,10 @@ CATCPSessionInfo_t *CAConnectTCPSession(const CAEndpoint_t *endpoint) CHECKFD(fd); - // pass the connection information to RI for keepalive. - if (g_keepaliveCallback) + // pass the connection information to CA Common Layer. + if (g_connectionCallback) { - g_keepaliveCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, true); + g_connectionCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, true); } return svritem; @@ -915,10 +915,10 @@ CAResult_t CADisconnectTCPSession(CATCPSessionInfo_t *svritem, size_t index) u_arraylist_remove(caglobals.tcp.svrlist, index); OICFree(svritem->recvData); - // pass the connection information to RI for keepalive. - if (g_keepaliveCallback) + // pass the connection information to CA Common Layer. + if (g_connectionCallback) { - g_keepaliveCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, false); + g_connectionCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, false); } OICFree(svritem); diff --git a/resource/csdk/connectivity/test/SConscript b/resource/csdk/connectivity/test/SConscript index efa854c..688a04f 100644 --- a/resource/csdk/connectivity/test/SConscript +++ b/resource/csdk/connectivity/test/SConscript @@ -67,19 +67,31 @@ if env.get('LOGGING'): ###################################################################### # Source files and Targets ###################################################################### -catests = catest_env.Program('catests', ['catests.cpp', - 'caprotocolmessagetest.cpp', - 'cablocktransfertest.cpp', - 'ca_api_unittest.cpp', - 'camutex_tests.cpp', - 'uarraylist_test.cpp' - ]) + +target_os = env.get('TARGET_OS') +target_transport = env.get('TARGET_TRANSPORT') + +if (('IP' in target_transport) or ('ALL' in target_transport)): + if target_os != 'arduino': + catests = catest_env.Program('catests', ['catests.cpp', + 'caprotocolmessagetest.cpp', + 'cablocktransfertest.cpp', + 'ca_api_unittest.cpp', + 'camutex_tests.cpp', + 'uarraylist_test.cpp' + ]) +else: + catests = catest_env.Program('catests', ['catests.cpp', + 'caprotocolmessagetest.cpp', + 'ca_api_unittest.cpp', + 'camutex_tests.cpp', + 'uarraylist_test.cpp' + ]) Alias("test", [catests]) env.AppendTarget('test') if env.get('TEST') == '1': - target_os = env.get('TARGET_OS') if target_os == 'linux': from tools.scons.RunTest import * run_test(catest_env, diff --git a/resource/csdk/connectivity/util/SConscript b/resource/csdk/connectivity/util/SConscript index 6305edb..c89cb4c 100644 --- a/resource/csdk/connectivity/util/SConscript +++ b/resource/csdk/connectivity/util/SConscript @@ -9,36 +9,25 @@ print "Reading util folder script" ca_os = env.get('TARGET_OS') ca_transport = env.get('TARGET_TRANSPORT') +target_os = env.get('TARGET_OS') project_root = env.get('SRC_DIR') root_dir = os.path.join(project_root, 'resource', 'csdk', 'connectivity') src_dir = os.path.join(root_dir, 'util', 'src') -env.PrependUnique(CPPPATH = [ os.path.join(root_dir, 'api') ]) -env.AppendUnique(CPPPATH = [ os.path.join(root_dir, 'inc'), - os.path.join(project_root, 'resource', 'csdk', 'logger', 'include'), - os.path.join(root_dir, 'lib', 'libcoap-4.1.1'), - os.path.join(root_dir, 'common', 'inc'), - os.path.join(root_dir, 'util', 'inc') ]) - ###################################################################### # Source files to build common for platforms ###################################################################### -env.AppendUnique(CA_SRC = [os.path.join('./../util/src','cautilinterface.c')]) - -if (('BLE' in ca_transport) or ('ALL' in ca_transport)): - if ca_os in ['linux', 'tizen', 'arduino']: - env.AppendUnique(CA_SRC = [ - os.path.join(src_dir, 'camanager', ca_os, 'caleconnectionmanager.c')]) +env.AppendUnique(CA_SRC = [os.path.join('./../util/src/cautilinterface.c')]) - if ca_os == 'android': - env.AppendUnique(CA_SRC = [ - os.path.join(src_dir, 'camanager', 'android', 'caleconnectionmanager.c'), - os.path.join(src_dir, 'camanager', 'android', 'caleautoconnector.c'), - os.path.join(src_dir, 'camanager', 'android', 'camanagerleutil.c'), - os.path.join(src_dir, 'camanager', 'android', 'camanagerdevice.c')]) +if target_os == 'android': + if (('BLE' in ca_transport) or ('ALL' in ca_transport)): + env.AppendUnique(CA_SRC = [ + os.path.join(src_dir, 'camanager', 'android', 'caleconnectionmanager.c'), + os.path.join(src_dir, 'camanager', 'android', 'caleautoconnector.c'), + os.path.join(src_dir, 'camanager', 'android', 'camanagerleutil.c'), + os.path.join(src_dir, 'camanager', 'android', 'camanagerdevice.c')]) -if (('BT' in ca_transport) or ('ALL' in ca_transport)): - if ca_os == 'android': - env.AppendUnique(CA_SRC = [ - os.path.join(src_dir, 'btpairing' ,'android', 'cabtpairing.c')]) + if (('BT' in ca_transport) or ('ALL' in ca_transport)): + env.AppendUnique(CA_SRC = [ + os.path.join(src_dir, 'btpairing' ,'android', 'cabtpairing.c')]) \ No newline at end of file diff --git a/resource/csdk/connectivity/util/inc/camanagerleinterface.h b/resource/csdk/connectivity/util/inc/camanagerleinterface.h index 9a175bf..fa3cb81 100644 --- a/resource/csdk/connectivity/util/inc/camanagerleinterface.h +++ b/resource/csdk/connectivity/util/inc/camanagerleinterface.h @@ -48,18 +48,7 @@ CAResult_t CASetLEClientAutoConnectionDeviceInfo(); */ CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(); -/** - * Start advertise to receive request for scanning or connecting. - */ -void CAStartServerLEAdvertising(); - -/** - * Stop advertise to destroy advertiser. - */ -void CAStopServerLEAdvertising(); - -#ifdef __ANDROID__ -#ifdef LE_ADAPTER +#if defined(__ANDROID__) && defined(LE_ADAPTER) /** * initialize client connection manager * @param[in] env JNI interface pointer. @@ -78,7 +67,6 @@ CAResult_t CAManagerLEClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context */ CAResult_t CAManagerLEClientTerminate(JNIEnv *env); #endif -#endif #ifdef __cplusplus } /* extern "C" */ diff --git a/resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c index 18ba248..fb5742b 100644 --- a/resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c +++ b/resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c @@ -32,9 +32,6 @@ #define TAG "OIC_CA_MANAGER_LE" -static CAAdapterStateChangedCB g_adapterStateCB = NULL; -static CAConnectionStateChangedCB g_connStateCB = NULL; - static const jint SUPPORT_ADNROID_API_LEVEL = 18; static const jint AUTH_FAIL = 5; static const jint LINK_LOSS = 8; @@ -46,14 +43,6 @@ static JavaVM *g_jvm = NULL; static jobject g_context = NULL; static jobject g_connectedDeviceSet = NULL; -void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB, - CAConnectionStateChangedCB connStateCB) -{ - OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks"); - - g_adapterStateCB = adapterStateCB; - g_connStateCB = connStateCB; -} CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char* address) { @@ -306,10 +295,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback( if (state_on == state) { OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_on"); - if (g_adapterStateCB) - { - g_adapterStateCB(CA_ADAPTER_GATT_BTLE, true); - } // when BT state is on. recovery flag has to be reset. CAManagerSetBTRecovery(false); @@ -334,10 +319,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback( else if (state_off == state) { OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_off"); - if (g_adapterStateCB) - { - g_adapterStateCB(CA_ADAPTER_GATT_BTLE, false); - } // reset isAutoConnecting flag for all target devices size_t length = CAManagerGetACDataLength(); @@ -458,13 +439,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeGattConnectionStateChangeCB( { OIC_LOG(DEBUG, TAG, "LE is disconnected"); - if (g_connStateCB) - { - OIC_LOG_V(DEBUG, TAG, "LE Disconnected state is %d, %s", newState, address); - g_connStateCB(CA_ADAPTER_GATT_BTLE, address, false); - OIC_LOG(DEBUG, TAG, "LE Disconnected state callback is called"); - } - if (LINK_LOSS == status || REMOTE_DISCONNECT == status) { if (!CAManagerIsInACDataList(env, jni_address)) @@ -550,12 +524,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J OIC_LOG(DEBUG, TAG, "AC list - the address is not set to AutoConnect"); } - if (g_connStateCB) - { - g_connStateCB(CA_ADAPTER_GATT_BTLE, address, true); - OIC_LOG(DEBUG, TAG, "LE Connected callback is called"); - } - (*env)->ReleaseStringUTFChars(env, jni_address, address); (*env)->DeleteLocalRef(env, jni_address); diff --git a/resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c deleted file mode 100644 index 33f7648..0000000 --- a/resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c +++ /dev/null @@ -1,61 +0,0 @@ -/* **************************************************************** - * - * Copyright 2016 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 "camanagerleinterface.h" -#include "cacommon.h" -#include "logger.h" - -#define TAG "OIC_CA_MANAGER_AR_LE" - -static CAAdapterStateChangedCB g_adapterStateCB = NULL; -static CAConnectionStateChangedCB g_connStateCB = NULL; - -void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB, - CAConnectionStateChangedCB connStateCB) -{ - OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks"); - - g_adapterStateCB = adapterStateCB; - g_connStateCB = connStateCB; -} - -CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address) -{ - OIC_LOG(DEBUG, TAG, "CASetClientAutoConnectionDeviceInfo"); - (void)address; - return CA_NOT_SUPPORTED; -} - -CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address) -{ - OIC_LOG(DEBUG, TAG, "CAUnsetClientAutoConnectionDeviceInfo"); - (void)address; - return CA_NOT_SUPPORTED; -} - -void CAStartServerLEAdvertising() -{ - OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising"); -} - -void CAStopServerLEAdvertising() -{ - OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising"); -} diff --git a/resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c deleted file mode 100644 index 98f336e..0000000 --- a/resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c +++ /dev/null @@ -1,61 +0,0 @@ -/* **************************************************************** - * - * Copyright 2016 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 "camanagerleinterface.h" -#include "cacommon.h" -#include "logger.h" - -#define TAG "OIC_CA_MANAGER_LI_LE" - -static CAAdapterStateChangedCB g_adapterStateCB = NULL; -static CAConnectionStateChangedCB g_connStateCB = NULL; - -void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB, - CAConnectionStateChangedCB connStateCB) -{ - OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks"); - - g_adapterStateCB = adapterStateCB; - g_connStateCB = connStateCB; -} - -CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address) -{ - OIC_LOG(DEBUG, TAG, "CASetLEClientAutoConnectionDeviceInfo"); - (void)address; - return CA_NOT_SUPPORTED; -} - -CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address) -{ - OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo"); - (void)address; - return CA_NOT_SUPPORTED; -} - -void CAStartServerLEAdvertising() -{ - OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising"); -} - -void CAStopServerLEAdvertising() -{ - OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising"); -} diff --git a/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c deleted file mode 100644 index cc196f2..0000000 --- a/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c +++ /dev/null @@ -1,144 +0,0 @@ -/* **************************************************************** - * - * Copyright 2016 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 -#include -#include - -#include "camanagerleinterface.h" -#include "cacommon.h" -#include "camessagehandler.h" -#include "caleserver.h" -#include "cagattservice.h" -#include "logger.h" - -#define TAG "OIC_CA_MANAGER_TZ_LE" - -static CAAdapterStateChangedCB g_adapterStateCB = NULL; -static CAConnectionStateChangedCB g_connStateCB = NULL; - -static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status); -static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter, - const char *remoteAddress, bool connected); - -void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB, - CAConnectionStateChangedCB connStateCB) -{ - OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks"); - - g_adapterStateCB = adapterStateCB; - CASetNetworkMonitorCallback(CAManagerAdapterMonitorHandler); - - g_connStateCB = connStateCB; - CASetLEConnectionStateChangedCallback(CAManagerConnectionMonitorHandler); -} - -void CAStartServerLEAdvertising() -{ - OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising"); - - CAResult_t res = CALEStartAdvertise(CA_GATT_SERVICE_UUID); - if (CA_STATUS_OK != res) - { - OIC_LOG_V(ERROR, TAG, "Failed to start le advertising [%d]", res); - return; - } -} - -void CAStopServerLEAdvertising() -{ - OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising"); - - CAResult_t res = CALEStopAdvertise(); - if (CA_STATUS_OK != res) - { - OIC_LOG_V(ERROR, TAG, "Failed to stop le advertising [%d]", res); - return; - } -} - -CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address) -{ - OIC_LOG(DEBUG, TAG, "CASetLEClientAutoConnectionDeviceInfo"); - (void)address; - return CA_NOT_SUPPORTED; -} - -CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address) -{ - OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo"); - (void)address; - return CA_NOT_SUPPORTED; -} - -static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status) -{ - if (CA_INTERFACE_DOWN == status) - { - if (info && g_adapterStateCB) - { - g_adapterStateCB(info->adapter, false); - OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer"); - } - } - else if (CA_INTERFACE_UP == status) - { - if (info && g_adapterStateCB) - { - g_adapterStateCB(info->adapter, true); - OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer"); - } - } -} - -static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter, - const char *remoteAddress, bool connected) -{ - (void)adapter; - - if (!remoteAddress) - { - OIC_LOG(ERROR, TAG, "remoteAddress is NULL"); - return; - } - - if (connected) - { - if (g_connStateCB) - { - g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, true); - OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer"); - - // stop le advertising - CAStopServerLEAdvertising(); - } - } - else - { - if (g_connStateCB) - { - g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, false); - OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer"); - - // start le advertising to receive new connection request. - CAStartServerLEAdvertising(); - } - } -} diff --git a/resource/csdk/connectivity/util/src/cautilinterface.c b/resource/csdk/connectivity/util/src/cautilinterface.c index 83513f7..046ace4 100644 --- a/resource/csdk/connectivity/util/src/cautilinterface.c +++ b/resource/csdk/connectivity/util/src/cautilinterface.c @@ -21,33 +21,80 @@ #include "camanagerleinterface.h" #include "cabtpairinginterface.h" #include "cautilinterface.h" - +#include "cainterfacecontroller.h" #include "cacommon.h" #include "logger.h" #define TAG "OIC_CA_COMMON_UTILS" +static CAAdapterStateChangedCB g_adapterStateCB = NULL; +static CAConnectionStateChangedCB g_connStateCB = NULL; + +static void CAManagerAdapterMonitorHandler(CATransportAdapter_t adapter, + CANetworkStatus_t status) +{ + if (CA_INTERFACE_DOWN == status) + { + if (g_adapterStateCB) + { + g_adapterStateCB(adapter, false); + OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer"); + } + } + else if (CA_INTERFACE_UP == status) + { + if (g_adapterStateCB) + { + g_adapterStateCB(adapter, true); + OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer"); + } + } +} + +static void CAManagerConnectionMonitorHandler(const CAEndpoint_t *info, bool isConnected) +{ + if (!info || !info->addr) + { + OIC_LOG(ERROR, TAG, "remoteAddress is NULL"); + return; + } + + if (isConnected) + { + if (g_connStateCB) + { + g_connStateCB(info->adapter, info->addr, isConnected); + OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer"); + } + } + else + { + if (g_connStateCB) + { + g_connStateCB(info->adapter, info->addr, isConnected); + OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer"); + } + } +} + CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB, CAConnectionStateChangedCB connStateCB) { OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler"); -#ifdef LE_ADAPTER - CASetLENetworkMonitorCallbacks(adapterStateCB, connStateCB); - return CA_STATUS_OK; -#else - (void)adapterStateCB; - (void)connStateCB; - return CA_NOT_SUPPORTED; -#endif + g_adapterStateCB = adapterStateCB; + g_connStateCB = connStateCB; + CASetNetworkMonitorCallbacks(CAManagerAdapterMonitorHandler, + CAManagerConnectionMonitorHandler); + return CA_STATUS_OK; } CAResult_t CASetAutoConnectionDeviceInfo(const char *address) { OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo"); -#ifdef LE_ADAPTER +#if defined(__ANDROID__) && defined(LE_ADAPTER) return CASetLEClientAutoConnectionDeviceInfo(address); #else (void)address; @@ -59,7 +106,7 @@ CAResult_t CAUnsetAutoConnectionDeviceInfo(const char *address) { OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo"); -#ifdef LE_ADAPTER +#if defined(__ANDROID__) && defined(LE_ADAPTER) return CAUnsetLEClientAutoConnectionDeviceInfo(address); #else (void)address; diff --git a/resource/csdk/stack/include/internal/oickeepalive.h b/resource/csdk/stack/include/internal/oickeepalive.h index c6a4d02..95f3cd0 100644 --- a/resource/csdk/stack/include/internal/oickeepalive.h +++ b/resource/csdk/stack/include/internal/oickeepalive.h @@ -85,13 +85,7 @@ OCStackResult HandleKeepAliveRequest(const CAEndpoint_t* endPoint, * API to handle the connected device for KeepAlive. * @return Current Time. */ -void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint); - -/** - * API to handle the disconnected device for KeepAlive. - * @return Current Time. - */ -void HandleKeepAliveDisconnCB(const CAEndpoint_t *endpoint); +void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected); #ifdef __cplusplus } // extern "C" diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index e8ce987..4061893 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -2041,7 +2041,7 @@ OCStackResult OCInit1(OCMode mode, OCTransportFlags serverFlags, OCTransportFlag VERIFY_SUCCESS(result, OC_STACK_OK); #ifdef TCP_ADAPTER - CARegisterKeepAliveHandler(HandleKeepAliveConnCB, HandleKeepAliveDisconnCB); + CARegisterKeepAliveHandler(HandleKeepAliveConnCB); #endif #ifdef WITH_PRESENCE diff --git a/resource/csdk/stack/src/oickeepalive.c b/resource/csdk/stack/src/oickeepalive.c index 8063f2b..c94bb85 100644 --- a/resource/csdk/stack/src/oickeepalive.c +++ b/resource/csdk/stack/src/oickeepalive.c @@ -716,31 +716,31 @@ OCStackResult RemoveKeepAliveEntry(const CAEndpoint_t *endpoint) return OC_STACK_OK; } -void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint) +void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected) { VERIFY_NON_NULL_NR(endpoint, FATAL); - OIC_LOG(DEBUG, TAG, "Received the connected device information from CA"); - - // Send discover message to find ping resource - OCCallbackData pingData = { .cb = PingRequestCallback }; - OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP }; - CopyEndpointToDevAddr(endpoint, &devAddr); - - OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI, &devAddr, NULL, - OC_ADAPTER_TCP, OC_HIGH_QOS, &pingData, NULL, 0); -} - -void HandleKeepAliveDisconnCB(const CAEndpoint_t *endpoint) -{ - VERIFY_NON_NULL_NR(endpoint, FATAL); + if (isConnected) + { + OIC_LOG(DEBUG, TAG, "Received the connected device information from CA"); - OIC_LOG(DEBUG, TAG, "Received the disconnected device information from CA"); + // Send discover message to find ping resource + OCCallbackData pingData = { .cb = PingRequestCallback }; + OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP }; + CopyEndpointToDevAddr(endpoint, &devAddr); - OCStackResult result = RemoveKeepAliveEntry(endpoint); - if(result != OC_STACK_OK) + OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI, &devAddr, NULL, + OC_ADAPTER_TCP, OC_HIGH_QOS, &pingData, NULL, 0); + } + else { - OIC_LOG(ERROR, TAG, "Failed to remove entry"); - return; + OIC_LOG(DEBUG, TAG, "Received the disconnected device information from CA"); + + OCStackResult result = RemoveKeepAliveEntry(endpoint); + if(result != OC_STACK_OK) + { + OIC_LOG(ERROR, TAG, "Failed to remove entry"); + return; + } } } diff --git a/resource/include/OCHeaderOption.h b/resource/include/OCHeaderOption.h index 65ec176..519da78 100644 --- a/resource/include/OCHeaderOption.h +++ b/resource/include/OCHeaderOption.h @@ -40,11 +40,17 @@ namespace OC * After creating instances of OCHeaderOptions, use setHeaderOptions API * (in OCResource.h) to set header Options. * NOTE: HeaderOptionID is an unsigned integer value which MUST be within - * range of 2048 to 3000 inclusive of lower and upper bound. + * range of 2048 to 3000 inclusive of lower and upper bound + * except for If-Match with empty(num : 1), If-None-Match(num : 5), + * Location-Path(num : 8), Location-Query(num : 20) option. * HeaderOptions instance creation fails if above condition is not satisfied. */ const uint16_t MIN_HEADER_OPTIONID = 2048; const uint16_t MAX_HEADER_OPTIONID = 3000; + const uint16_t IF_MATCH_OPTION_ID = 1; + const uint16_t IF_NONE_MATCH_OPTION_ID = 5; + const uint16_t LOCATION_PATH_OPTION_ID = 8; + const uint16_t LOCATION_QUERY_OPTION_ID = 20; class OCHeaderOption { @@ -60,7 +66,11 @@ namespace OC m_optionID(optionID), m_optionData(optionData) { - if(!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID)) + if (!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID) + && optionID != IF_MATCH_OPTION_ID + && optionID != IF_NONE_MATCH_OPTION_ID + && optionID != LOCATION_PATH_OPTION_ID + && optionID != LOCATION_QUERY_OPTION_ID) { throw OCException(OC::Exception::OPTION_ID_RANGE_INVALID); } diff --git a/resource/include/OCUtilities.h b/resource/include/OCUtilities.h index ac9d6ad..1c17c10 100644 --- a/resource/include/OCUtilities.h +++ b/resource/include/OCUtilities.h @@ -106,7 +106,7 @@ namespace OC template struct is_vector>::value + std::is_same >::value >::type > { @@ -130,17 +130,17 @@ namespace OC // specialization to handle the single-item case template class Base, typename T> - struct is_component> + struct is_component > { static constexpr bool value = std::is_same::value; }; // Recursive specialization to handle cases with multiple values template class Base, typename T, typename ...Rest> - struct is_component> + struct is_component > { static constexpr bool value = std::is_same::value - || is_component>::value; + || is_component >::value; }; } // namespace OC diff --git a/resource/include/StringConstants.h b/resource/include/StringConstants.h index 526a0b9..4b97938 100644 --- a/resource/include/StringConstants.h +++ b/resource/include/StringConstants.h @@ -60,7 +60,9 @@ namespace OC static const char GENERAL_JSON_PARSE_FAILED[] = "JSON Parser Error"; static const char RESOURCE_UNREG_FAILED[] = "Unregistering resource failed"; static const char OPTION_ID_RANGE_INVALID[] = - "Error: OptionID valid only from 2048 to 3000 inclusive."; + "Error: OptionID valid only If-Match(1), If-None-Match(5)," + "Location-Path(8), Location-Query(20)," + "and from 2048 to 3000 inclusive."; static const char NO_ERROR[] = "No Error"; static const char RESOURCE_CREATED[] = "Resource Created"; static const char RESOURCE_DELETED[] = "Resource Deleted"; diff --git a/resource/src/SConscript b/resource/src/SConscript index 06b1369..f1106a1 100644 --- a/resource/src/SConscript +++ b/resource/src/SConscript @@ -112,6 +112,7 @@ oclib_env.UserInstallTargetHeader(header_dir + 'AttributeValue.h', 'resource', ' oclib_env.UserInstallTargetHeader(header_dir + 'OCResource.h', 'resource', 'OCResource.h') oclib_env.UserInstallTargetHeader(header_dir + 'OCResourceRequest.h', 'resource', 'OCResourceRequest.h') oclib_env.UserInstallTargetHeader(header_dir + 'OCResourceResponse.h', 'resource', 'OCResourceResponse.h') +oclib_env.UserInstallTargetHeader(header_dir + 'OCUtilities.h', 'resource', 'OCUtilities.h') oclib_env.UserInstallTargetHeader(header_dir + 'CAManager.h', 'resource', 'CAManager.h') diff --git a/resource/unittests/OCHeaderOptionTest.cpp b/resource/unittests/OCHeaderOptionTest.cpp index df1a5e3..fbe63b1 100644 --- a/resource/unittests/OCHeaderOptionTest.cpp +++ b/resource/unittests/OCHeaderOptionTest.cpp @@ -48,9 +48,15 @@ namespace OC { for(uint16_t i = 0; i < HeaderOption::MIN_HEADER_OPTIONID; ++i) { - ASSERT_THROW( - HeaderOption::OCHeaderOption(i,""), - OCException); + if (HeaderOption::IF_MATCH_OPTION_ID != i + && HeaderOption::IF_NONE_MATCH_OPTION_ID != i + && HeaderOption::LOCATION_PATH_OPTION_ID != i + && HeaderOption::LOCATION_QUERY_OPTION_ID != i) + { + ASSERT_THROW( + HeaderOption::OCHeaderOption(i,""), + OCException); + } } } diff --git a/service/easy-setup/mediator/richsdk/unittests/SConscript b/service/easy-setup/mediator/richsdk/unittests/SConscript index 480df19..0b27415 100644 --- a/service/easy-setup/mediator/richsdk/unittests/SConscript +++ b/service/easy-setup/mediator/richsdk/unittests/SConscript @@ -80,12 +80,12 @@ if env.get('SECURED') == '1': mediator_rich_test_env.PrependUnique(LIBS = ['tinydtls','ocprovision', 'ocpmapi']) mediator_rich_test_env.PrependUnique(LIBS = [ - 'oc', - 'octbstack', + 'coap', + 'connectivity_abstraction', 'oc_logger', 'oc_logger_core', - 'connectivity_abstraction', - 'coap', + 'octbstack', + 'oc', 'ESMediatorRich', gtest, gtest_main]) @@ -105,4 +105,4 @@ if env.get('TEST') == '1': target_os = env.get('TARGET_OS') if target_os == 'linux': from tools.scons.RunTest import * - run_test(mediator_rich_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/mediator_richsdk_test') \ No newline at end of file + run_test(mediator_rich_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/mediator_richsdk_test') diff --git a/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/SConscript b/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/SConscript index 22bd821..20516e4 100644 --- a/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/SConscript +++ b/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/SConscript @@ -16,11 +16,11 @@ linux_sample_env.AppendUnique(CPPPATH = ['include']) linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread']) linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX']) linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) -linux_sample_env.AppendUnique(LIBS = ['oc']) -linux_sample_env.AppendUnique(LIBS = ['octbstack']) -linux_sample_env.AppendUnique(LIBS = ['libconnectivity_abstraction']) linux_sample_env.AppendUnique(LIBS = ['libcoap']) +linux_sample_env.AppendUnique(LIBS = ['libconnectivity_abstraction']) linux_sample_env.AppendUnique(LIBS = ['liboc_logger']) +linux_sample_env.AppendUnique(LIBS = ['octbstack']) +linux_sample_env.AppendUnique(LIBS = ['oc']) linux_sample_env.AppendUnique(LIBS = ['pthread']) if env.get('SECURED') == '1': @@ -36,4 +36,4 @@ if 'rt' in linux_sample_env.get('LIBS'): ###################################################################### heightsensorapp = linux_sample_env.Program('HeightSensorApp', 'src/HeightSensorApp.cpp') Alias("heightsensorapp_sample", heightsensorapp) -env.AppendTarget('heightsensorapp') \ No newline at end of file +env.AppendTarget('heightsensorapp') diff --git a/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp b/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp index 90ae1a1..ba77414 100644 --- a/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp +++ b/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp @@ -44,9 +44,9 @@ HueLight::~HueLight() void HueLight::initAttributes() { - BundleResource::setAttribute("on-off", false); - BundleResource::setAttribute("dim", 0); - BundleResource::setAttribute("color", 0); + BundleResource::setAttribute("on-off", false, false); + BundleResource::setAttribute("dim", 0, false); + BundleResource::setAttribute("color", 0, false); } RCSResourceAttributes HueLight::handleGetAttributesRequest() diff --git a/service/resource-container/examples/tizen/ContainerServerApp/lib/ResourceContainerConfig.xml b/service/resource-container/examples/tizen/ContainerServerApp/lib/ResourceContainerConfig.xml index 3dfc9a9..9938053 100644 --- a/service/resource-container/examples/tizen/ContainerServerApp/lib/ResourceContainerConfig.xml +++ b/service/resource-container/examples/tizen/ContainerServerApp/lib/ResourceContainerConfig.xml @@ -6,11 +6,11 @@ huesample 1.0.0 - - light - oic.r.control -
http://192.168.0.2/api/newdeveloper/lights/1
-
+
- + + + + + diff --git a/service/resource-container/examples/tizen/ContainerServerApp/src/container.cpp b/service/resource-container/examples/tizen/ContainerServerApp/src/container.cpp index eb5572b..64652d5 100644 --- a/service/resource-container/examples/tizen/ContainerServerApp/src/container.cpp +++ b/service/resource-container/examples/tizen/ContainerServerApp/src/container.cpp @@ -528,18 +528,6 @@ void *showContainerAPIs(void *data) elm_list_item_append(listnew, "4. Remove HUE Bundle Resource", NULL, NULL, removeHueResourceConfig, NULL); - elm_list_item_append(listnew, "5. Add BMI Bundle", NULL, NULL, - addBMIBundle, NULL); - - elm_list_item_append(listnew, "6. Start BMI Bundle", NULL, NULL, - startBMIBundle, NULL); - - elm_list_item_append(listnew, "7. Remove BMI Bundle", NULL, NULL, - removeBMIBundle, NULL); - - elm_list_item_append(listnew, "8. Stop BMI Bundle", NULL, NULL, - stopBMIBundle, NULL); - elm_list_go(listnew); } return NULL; @@ -593,8 +581,8 @@ static void stopContainer(void *data, Evas_Object *obj, void *event_info) if (checkContainer) { s_containerFlag = false; - removeHueBundle(NULL, NULL, NULL); stopHueBundle(NULL, NULL, NULL); + removeHueBundle(NULL, NULL, NULL); container->stopContainer(); logMessage += "CONTAINER STOPPED
"; diff --git a/service/resource-container/src/BundleResource.cpp b/service/resource-container/src/BundleResource.cpp index 5b38edc..f39e77c 100644 --- a/service/resource-container/src/BundleResource.cpp +++ b/service/resource-container/src/BundleResource.cpp @@ -32,7 +32,7 @@ namespace OIC { namespace Service { - BundleResource::BundleResource() : m_pNotiReceiver(nullptr) + BundleResource::BundleResource() : m_pNotiReceiver(nullptr), m_resourceAttributes_mutex() { } diff --git a/service/resource-container/src/ResourceContainerImpl.cpp b/service/resource-container/src/ResourceContainerImpl.cpp index 328fe50..1cbbd62 100644 --- a/service/resource-container/src/ResourceContainerImpl.cpp +++ b/service/resource-container/src/ResourceContainerImpl.cpp @@ -68,58 +68,53 @@ namespace OIC activationLock.lock(); - if (!configFile.empty()) - { - m_config = new Configuration(configFile); - - if (m_config->isLoaded()) + try{ + if (!configFile.empty()) { - configInfo bundles; - m_config->getConfiguredBundles(&bundles); + m_config = new Configuration(configFile); - for (unsigned int i = 0; i < bundles.size(); i++) + if (m_config->isLoaded()) { - shared_ptr bundleInfo(new BundleInfoInternal); - bundleInfo->setPath(bundles[i][BUNDLE_PATH]); - bundleInfo->setVersion(bundles[i][BUNDLE_VERSION]); - bundleInfo->setID(bundles[i][BUNDLE_ID]); - if (!bundles[i][BUNDLE_ACTIVATOR].empty()) + configInfo bundles; + m_config->getConfiguredBundles(&bundles); + + for (unsigned int i = 0; i < bundles.size(); i++) { - string activatorName = bundles[i][BUNDLE_ACTIVATOR]; - std::replace(activatorName.begin(), activatorName.end(), '.', '/'); - bundleInfo->setActivatorName(activatorName); - bundleInfo->setLibraryPath(bundles[i][BUNDLE_LIBRARY_PATH]); - } + shared_ptr bundleInfo(new BundleInfoInternal); + bundleInfo->setPath(bundles[i][BUNDLE_PATH]); + bundleInfo->setVersion(bundles[i][BUNDLE_VERSION]); + bundleInfo->setID(bundles[i][BUNDLE_ID]); + if (!bundles[i][BUNDLE_ACTIVATOR].empty()) + { + string activatorName = bundles[i][BUNDLE_ACTIVATOR]; + std::replace(activatorName.begin(), activatorName.end(), '.', '/'); + bundleInfo->setActivatorName(activatorName); + bundleInfo->setLibraryPath(bundles[i][BUNDLE_LIBRARY_PATH]); + } - OIC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)", - std::string(bundles[i][BUNDLE_ID] + ";" + - bundles[i][BUNDLE_PATH]).c_str()); + OIC_LOG_V(INFO, CONTAINER_TAG, "Init Bundle:(%s)", + std::string(bundles[i][BUNDLE_ID] + ";" + + bundles[i][BUNDLE_PATH]).c_str()); - registerBundle(bundleInfo); - activateBundle(bundleInfo); + registerBundle(bundleInfo); + activateBundle(bundleInfo); + } + } + else + { + OIC_LOG_V(ERROR, CONTAINER_TAG, "Container started with invalid configfile path."); } } else { - OIC_LOG_V(ERROR, CONTAINER_TAG, "Container started with invalid configfile path."); + OIC_LOG_V(INFO, CONTAINER_TAG, "No configuration file for the container provided."); } - } - else - { - OIC_LOG_V(INFO, CONTAINER_TAG, "No configuration file for the container provided."); - } - - map::iterator activatorIterator; - for (activatorIterator = m_activators.begin(); activatorIterator != m_activators.end(); - activatorIterator++) - { - activatorIterator->second.timed_join( - boost::posix_time::seconds(BUNDLE_ACTIVATION_WAIT_SEC)); - // wait for bundles to be activated + OIC_LOG(INFO, CONTAINER_TAG, "Resource container started."); + }catch(...){ + OIC_LOG(INFO, CONTAINER_TAG, "Resource container failed starting."); } activationLock.unlock(); - OIC_LOG(INFO, CONTAINER_TAG, "Resource container started."); } void ResourceContainerImpl::stopContainer() @@ -178,11 +173,15 @@ namespace OIC { OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s)", std::string(m_bundles[id]->getID()).c_str()); + activationLock.lock(); - auto f = std::bind(&ResourceContainerImpl::activateBundleThread, this, - id); - boost::thread activator(f); - activator.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC)); + try{ + activateBundleThread(id); + } + catch(...){ + OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s) failed", + std::string(m_bundles[id]->getID()).c_str()); + } activationLock.unlock(); OIC_LOG_V(INFO, CONTAINER_TAG, "Bundle activated: (%s)", std::string(m_bundles[id]->getID()).c_str()); diff --git a/service/resource-container/src/ResourceContainerImpl.h b/service/resource-container/src/ResourceContainerImpl.h index b7cb614..5d5f81b 100644 --- a/service/resource-container/src/ResourceContainerImpl.h +++ b/service/resource-container/src/ResourceContainerImpl.h @@ -107,8 +107,6 @@ namespace OIC // string m_configFile; Configuration *m_config; - // holds for a bundle the threads for bundle activation - map< std::string, boost::thread > m_activators; // used for synchronize the resource registration of multiple bundles std::mutex registrationLock; // used to synchronize the startup of the container with other operation diff --git a/service/things-manager/unittests/SConscript b/service/things-manager/unittests/SConscript index e1bd784..461103a 100644 --- a/service/things-manager/unittests/SConscript +++ b/service/things-manager/unittests/SConscript @@ -77,11 +77,12 @@ if target_os not in ['windows', 'winrt']: ThingsManager_gtest_env.PrependUnique(LIBS = [ 'libTGMSDKLibrary', - 'oc', - 'octbstack', + 'coap', + 'connectivity_abstraction', 'oc_logger', 'oc_logger_core', - 'connectivity_abstraction', + 'oc', + 'octbstack', gtest, gtest_main]) @@ -101,4 +102,4 @@ if env.get('TEST') == '1': if target_os == 'linux': from tools.scons.RunTest import * run_test(ThingsManager_gtest_env, '', - 'service/things-manager/unittests/ThingsManagerTest') \ No newline at end of file + 'service/things-manager/unittests/ThingsManagerTest') diff --git a/tools/tizen/iotivity.spec b/tools/tizen/iotivity.spec index 9b72899..58b94b7 100644 --- a/tools/tizen/iotivity.spec +++ b/tools/tizen/iotivity.spec @@ -1,5 +1,5 @@ Name: iotivity -Version: 1.0.1 +Version: 1.1.0 Release: 0 Summary: IoT Connectivity sponsored by the OIC Group: Network & Connectivity/Other