\r
buildscript {\r
repositories {\r
+ mavenCentral()\r
jcenter()\r
}\r
dependencies {\r
}\r
\r
allprojects {\r
- repositories {\r
+ repositories { \r
+ mavenCentral()\r
jcenter()\r
}\r
}\r
'caleserver.c',
'calenwmonitor.c',
'caleutils.c',
- 'calestate.c' ]
+ 'calestate.c',
+ 'caleclient_jni.c' ]
Return('src_files')
#include "octhread.h"
#include "uarraylist.h"
#include "org_iotivity_ca_CaLeClientInterface.h"
+#include "caleclient_utils.h"
//#define TAG PCF("OIC_CA_LE_CLIENT")
#define TAG BLE_CLIENT_TAG
JavaVM *g_jvm;
static u_arraylist_t *g_deviceList = NULL; // device list to have same UUID
static u_arraylist_t *g_gattObjectList = NULL;
-static u_arraylist_t *g_deviceStateList = NULL;
static CAPacketReceiveCallback g_packetReceiveCallback = NULL;
-static CABLEErrorHandleCallback g_clientErrorCallback;
-static jobject g_leScanCallback = NULL;
-static jobject g_leGattCallback = NULL;
static jobject g_context = NULL;
static jobjectArray g_uuidList = NULL;
// it will be prevent to start send logic when adapter has stopped.
static bool g_isStartedLEClient = false;
-static jbyteArray g_sendBuffer = NULL;
static uint32_t g_targetCnt = 0;
static uint32_t g_currentSentCnt = 0;
static bool g_isFinishedSendData = false;
static oc_cond g_deviceDescCond = NULL;
static oc_mutex g_threadSendMutex = NULL;
-static oc_mutex g_threadWriteCharacteristicMutex = NULL;
-static oc_cond g_threadWriteCharacteristicCond = NULL;
-static bool g_isSignalSetFlag = false;
-
-static oc_mutex g_bleServerBDAddressMutex = NULL;
static oc_mutex g_deviceListMutex = NULL;
static oc_mutex g_gattObjectMutex = NULL;
-static oc_mutex g_deviceStateListMutex = NULL;
static oc_mutex g_deviceScanRetryDelayMutex = NULL;
static oc_cond g_deviceScanRetryDelayCond = NULL;
static CALEScanState_t g_curScanningStep = BLE_SCAN_NONE;
static CALEScanState_t g_nextScanningStep = BLE_SCAN_ENABLE;
-static CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback = NULL;
static int32_t g_jniIntSdk = -1;
static bool g_setHighQoS = true;
// List of Manufacture Data
static u_arraylist_t* g_manufactureDataList = NULL;
+//Variables are defined as extern in other file so using it as non-static here
+u_arraylist_t *g_deviceStateList = NULL;
+oc_mutex g_deviceStateListMutex = NULL;
+
+oc_mutex g_threadWriteCharacteristicMutex = NULL;
+oc_cond g_threadWriteCharacteristicCond = NULL;
+oc_mutex g_bleServerBDAddressMutex = NULL;
+
+CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback = NULL;
+
+jobject g_leScanCallback = NULL;
+jobject g_leGattCallback = NULL;
+
+bool g_isSignalSetFlag = false;
+
+jbyteArray g_sendBuffer = NULL;
+
+CABLEErrorHandleCallback g_clientErrorCallback = NULL;
+
/**
* check if retry logic for connection routine has to be stopped or not.
* in case of error value including this method, connection routine has to be stopped.
* @return true - waiting for background connection in BT platform.
* false - connection routine has to be stopped.
*/
-static bool CALECheckConnectionStateValue(jint state)
+bool CALECheckConnectionStateValue(jint state)
{
switch(state)
{
{
(void)object;
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return;
}
oc_mutex_lock(g_threadScanIntervalMutex);
{
OIC_LOG(DEBUG, TAG, "CALECreateJniInterfaceObject");
- if (!g_context)
- {
- OIC_LOG(ERROR, TAG, "g_context is null");
- return CA_STATUS_FAILED;
- }
-
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_context, TAG, "g_context is null", CA_STATUS_FAILED);
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
jmethodID mid_getApplicationContext = CAGetJNIMethodID(env, "android/content/Context",
CALEClientAddUuid(OIC_GATT_CUSTOM_UUID2, CA_LE_TYPE_CUSTOM_UUID);
CALEClientAddUuid(OIC_GATT_CUSTOM_UUID3, CA_LE_TYPE_CUSTOM_UUID);
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
g_jniIntSdk = CALEGetBuildVersion(env);
{
OIC_LOG(DEBUG, TAG, "CALEClientTerminate");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return;
- }
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
// stop scan
{
OIC_LOG(INFO, TAG, "IN - CALEClientHiddenConnectGatt");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return NULL;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", NULL);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return NULL;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return NULL;
}
jstring jni_address = (*env)->NewStringUTF(env, address);
{
OIC_LOG(DEBUG, TAG, "CALEClientDestroyJniInterface");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
jclass jni_LeInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeClientInterface");
OIC_LOG_V(DEBUG, TAG, "CALEClientSendMulticastMessage(%p)", data);
VERIFY_NON_NULL(data, TAG, "data is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEClientSendMulticastMessageImpl(env, data, dataLen);
data);
VERIFY_NON_NULL(address, TAG, "address is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
oc_mutex_lock(g_threadSendMutex);
return CA_STATUS_FAILED;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
+
+ JNIEnv* env = NULL;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
return CA_STATUS_FAILED;
}
{
g_setFullScanFlag = true;
}
- bool isAttached = false;
- JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
- }
OIC_LOG(DEBUG, TAG, "CALEClientStartScan");
CAResult_t CALEClientStopScan()
{
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CA_STATUS_FAILED;
static void CALEWriteCharacteristicThread(void* object)
{
VERIFY_NON_NULL_VOID(object, TAG, "object is null");
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
jobject gatt = (jobject)object;
CAResult_t CALEClientCreateUUIDList()
{
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
// create new object array
void CALEClientTerminateGattMutexVariables()
{
-
+
oc_mutex_free(g_bleServerBDAddressMutex);
g_bleServerBDAddressMutex = NULL;
{
OIC_LOG(DEBUG, TAG, "CAStopBLEGattClient");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return;
- }
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
CAResult_t ret = CALEClientDisconnectAll(env);
void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback)
{
-
+
g_CABLEClientDataReceivedCallback = callback;
-
+
}
void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
VERIFY_NON_NULL(local_address, TAG, "local_address");
return CA_NOT_SUPPORTED;
}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeRegisterLeScanCallback(JNIEnv *env, jobject obj,
- jobject callback)
-{
- OIC_LOG(DEBUG, TAG, "CaLeRegisterLeScanCallback");
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
-
- g_leScanCallback = (*env)->NewGlobalRef(env, callback);
- CACheckJNIException(env);
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeRegisterLeScanCallbackForV21(JNIEnv *env,
- jobject obj,
- jobject callback)
-{
- OIC_LOG(DEBUG, TAG, "caLeRegisterLeScanCallbackForV21");
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
-
- g_leScanCallback = (*env)->NewGlobalRef(env, callback);
- CACheckJNIException(env);
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeRegisterGattCallback(JNIEnv *env, jobject obj,
- jobject callback)
-{
- OIC_LOG(DEBUG, TAG, "CaLeRegisterGattCallback");
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
-
- g_leGattCallback = (*env)->NewGlobalRef(env, callback);
- CACheckJNIException(env);
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeScanCallback(JNIEnv *env, jobject obj,
- jobject device)
-{
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(device, TAG, "device is null");
-
- CAResult_t res = CALEClientAddScanDeviceToList(env, device);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG_V(ERROR, TAG, "CALEClientAddScanDeviceToList has failed : %d", res);
- }
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeScanFailedCallback(JNIEnv *env, jobject obj,
- jint errorCode)
-{
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
-
- switch (errorCode)
- {
- case 1:
- OIC_LOG(ERROR, TAG, "BLE scan has failed, error is SCAN_FAILED_ALREADY_STARTED");
- break;
-
- case 2:
- OIC_LOG(ERROR, TAG,
- "BLE scan has failed, error is SCAN_FAILED_APPLICATION_REGISTRATION_FAILED");
- break;
-
- case 3:
- OIC_LOG(ERROR, TAG, "BLE scan has failed, error is SCAN_FAILED_INTERNAL_ERROR");
- break;
-
- case 4:
- OIC_LOG(ERROR, TAG, "BLE scan has failed, error is SCAN_FAILED_FEATURE_UNSUPPORTED");
- break;
-
- default:
- OIC_LOG(ERROR, TAG, "BLE scan has failed with unknown error");
- break;
- }
-}
-
-/*
- * Class: org_iotivity_ca_jar_caleinterface
- * Method: CALeGattConnectionStateChangeCallback
- * Signature: (Landroid/bluetooth/BluetoothGatt;II)V
- */
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeGattConnectionStateChangeCallback(JNIEnv *env,
- jobject obj,
- jobject gatt,
- jint status,
- jint newstate)
-{
- OIC_LOG_V(INFO, TAG, "CALeGattConnectionStateChangeCallback - status %d, newstate %d", status,
- newstate);
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
-
- jint state_connected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_CONNECTED");
-
- jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
- if (!jni_address)
- {
- OIC_LOG(ERROR, TAG, "CALEClientGetAddressFromGattObj has failed");
- goto error_exit;
- }
-
- const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- OIC_LOG(ERROR, TAG, "address is null");
- CACheckJNIException(env);
- goto error_exit;
- }
- OIC_LOG_V(DEBUG, TAG, "CALeGattConnectionStateChangeCallback - address [%s]", address);
-
- if (state_connected == newstate)
- {
- OIC_LOG(DEBUG, TAG, "LE is connected");
- if (GATT_SUCCESS == status)
- {
- CAResult_t res = CALEUpdateDeviceState(address,
- CA_LE_CONNECTION_STATE,
- STATE_CONNECTED,
- g_deviceStateList,
- g_deviceStateListMutex);
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- goto error_exit;
- }
-
- res = CALEClientAddGattobjToList(env, gatt);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientAddGattobjToList has failed");
- goto error_exit;
- }
-
- res = CALEClientDiscoverServices(env, gatt);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientDiscoverServices has failed");
- goto error_exit;
- }
- }
- else
- {
- OIC_LOG(INFO, TAG, "unknown status");
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- }
- }
- else // STATE_DISCONNECTED == newstate
- {
- OIC_LOG(DEBUG, TAG, "LE is disconnected");
-
- if (CALEIsValidState(address, CA_LE_SEND_STATE, STATE_SEND_PREPARING,
- g_deviceStateList, g_deviceStateListMutex))
- {
- OIC_LOG(INFO, TAG, "current state is STATE_SEND_PREPARING");
- CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_FAIL,
- g_deviceStateList,
- g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- }
- }
-
- CAResult_t res = CALEUpdateDeviceState(address,
- CA_LE_CONNECTION_STATE,
- STATE_DISCONNECTED,
- g_deviceStateList,
- g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- }
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
-
- res = CALEClientGattClose(env, gatt);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientGattClose has failed");
- }
-
- if (CALECheckConnectionStateValue(status))
- {
- // this state is unexpected reason to disconnect
- // if the reason is suitable, connection logic of the device will be destroyed.
- OIC_LOG(INFO, TAG, "connection logic destroy");
- }
- else
- {
- // other reason except for gatt_success is expected to running
- // background connection in BT platform.
- OIC_LOG(INFO, TAG, "unknown status or manual disconnected state");
- }
- CALEClientUpdateSendCnt(env);
- }
- return;
-
- // error label.
-error_exit:
- CALEClientSendFinish(env, gatt);
- return;
-}
-
-/*
- * Class: org_iotivity_ca_jar_caleinterface
- * Method: CALeGattServicesDiscoveredCallback
- * Signature: (Landroid/bluetooth/BluetoothGatt;I)V
- */
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeGattServicesDiscoveredCallback(JNIEnv *env,
- jobject obj,
- jobject gatt,
- jint status)
-{
- OIC_LOG_V(INFO, TAG, "CALeGattServicesDiscoveredCallback - status %d", status);
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
-
- if (GATT_SUCCESS != status) // discovery error
- {
- CALEClientSendFinish(env, gatt);
- return;
- }
-
- jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
- if (!jni_address)
- {
- CALEClientSendFinish(env, gatt);
- return;
- }
-
- const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- CACheckJNIException(env);
- CALEClientSendFinish(env, gatt);
- return;
- }
-
- jstring jni_uuid = (*env)->NewStringUTF(env, OIC_GATT_CHARACTERISTIC_RESPONSE_UUID);
- if (!jni_uuid)
- {
- OIC_LOG(ERROR, TAG, "jni_uuid is null");
- goto error_exit;
- }
-
- jobject jni_obj_GattCharacteristic = CALEClientGetGattService(env, gatt, jni_uuid);
- if (!jni_obj_GattCharacteristic)
- {
- OIC_LOG(ERROR, TAG, "jni_obj_GattCharacteristic is null");
- goto error_exit;
- }
-
- CAResult_t res = CALEClientSetCharacteristicNotification(env, gatt,
- jni_obj_GattCharacteristic);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientSetCharacteristicNotification has failed");
- goto error_exit;
- }
-
- res = CALEClientSetUUIDToDescriptor(env, gatt, jni_obj_GattCharacteristic);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG_V(INFO, TAG, "Descriptor is not found : %d", res);
-
- res = CALESetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_FALSE,
- g_deviceStateList, g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALESetFlagToState has failed");
- goto error_exit;
- }
-
- res = CALEUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
- STATE_SERVICE_CONNECTED,
- g_deviceStateList,
- g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- goto error_exit;
- }
-
- res = CALEClientRequestMTU(env, gatt, CA_SUPPORTED_BLE_MTU_SIZE);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientRequestMTU has failed");
- goto error_exit;
- }
- }
- else
- {
- res = CALESetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_TRUE,
- g_deviceStateList, g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALESetFlagToState has failed");
- goto error_exit;
- }
- }
-
-#ifdef SCAN_INTERVAL
- // reset interval scan logic
- CALERestartScanWithInterval(g_scanIntervalTimePrev, 0, BLE_SCAN_ENABLE);
-#endif
-
- OIC_LOG(INFO, TAG, "ServicesDiscovery is successful");
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- return;
-
- // error label.
-error_exit:
- OIC_LOG(ERROR, TAG, "ServicesDiscovery has failed");
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- CALEClientSendFinish(env, gatt);
- return;
-}
-
-/*
- * Class: org_iotivity_ca_jar_caleinterface
- * Method: CALeGattCharacteristicWritjclasseCallback
- * Signature: (Landroid/bluetooth/BluetoothGatt;Landroid/bluetooth/BluetoothGattCharacteristic;I)V
- */
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeGattCharacteristicWriteCallback(
- JNIEnv *env, jobject obj, jobject gatt, jbyteArray data, jint status)
-{
- OIC_LOG_V(INFO, TAG, "CALeGattCharacteristicWriteCallback - status : %d", status);
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
-
- // send success & signal
- jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
- if (!jni_address)
- {
- goto error_exit;
- }
-
- const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- CACheckJNIException(env);
- goto error_exit;
- }
-
- if (GATT_SUCCESS != status) // error case
- {
- OIC_LOG(ERROR, TAG, "send failure");
-
- // retry to write
- CAResult_t res = CALEClientWriteCharacteristic(env, gatt);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "WriteCharacteristic has failed");
- oc_mutex_lock(g_threadWriteCharacteristicMutex);
- g_isSignalSetFlag = true;
- oc_cond_signal(g_threadWriteCharacteristicCond);
- oc_mutex_unlock(g_threadWriteCharacteristicMutex);
-
- CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_FAIL,
- g_deviceStateList,
- g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- }
-
- if (g_clientErrorCallback)
- {
- jint length = (*env)->GetArrayLength(env, data);
- CACheckJNIException(env);
- g_clientErrorCallback(address, data, length, CA_SEND_FAILED);
- CALogSendStateInfo(CA_ADAPTER_GATT_BTLE, address, 0, length,
- false, "writeChar failure");
- }
-
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- goto error_exit;
- }
- }
- else
- {
- OIC_LOG(DEBUG, TAG, "send success");
- CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_SUCCESS,
- g_deviceStateList,
- g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- }
-
- oc_mutex_lock(g_threadWriteCharacteristicMutex);
- OIC_LOG(DEBUG, TAG, "g_isSignalSetFlag is set true and signal");
- g_isSignalSetFlag = true;
- oc_cond_signal(g_threadWriteCharacteristicCond);
- oc_mutex_unlock(g_threadWriteCharacteristicMutex);
-
- CALogSendStateInfo(CA_ADAPTER_GATT_BTLE, address, 0,
- (*env)->GetArrayLength(env, data),
- true, "writeChar success");
- }
-
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- return;
-
- // error label.
-error_exit:
-
- CALEClientSendFinish(env, gatt);
- return;
-}
-
-/*
- * Class: org_iotivity_ca_jar_caleinterface
- * Method: CALeGattCharacteristicChangedCallback
- * Signature: (Landroid/bluetooth/BluetoothGatt;Landroid/bluetooth/BluetoothGattCharacteristic;)V
- */
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeGattCharacteristicChangedCallback(
- JNIEnv *env, jobject obj, jobject gatt, jbyteArray data)
-{
- OIC_LOG(DEBUG, TAG, "CALeGattCharacteristicChangedCallback");
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
- VERIFY_NON_NULL_VOID(data, TAG, "data is null");
-
- // get Byte Array and convert to uint8_t*
- jint length = (*env)->GetArrayLength(env, data);
-
- jboolean isCopy;
- jbyte *jni_byte_responseData = (jbyte*) (*env)->GetByteArrayElements(env, data, &isCopy);
- CACheckJNIException(env);
-
- uint8_t* receivedData = OICMalloc(length);
- if (!receivedData)
- {
- OIC_LOG(ERROR, TAG, "receivedData is null");
- return;
- }
-
- memcpy(receivedData, jni_byte_responseData, length);
- (*env)->ReleaseByteArrayElements(env, data, jni_byte_responseData, JNI_ABORT);
-
- jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
- if (!jni_address)
- {
- OIC_LOG(ERROR, TAG, "jni_address is null");
- OICFree(receivedData);
- return;
- }
-
- const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- OIC_LOG(ERROR, TAG, "address is null");
- CACheckJNIException(env);
- OICFree(receivedData);
- return;
- }
-
- OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - data. : %p, %d",
- receivedData, length);
-
- uint32_t sentLength = 0;
- oc_mutex_lock(g_bleServerBDAddressMutex);
- g_CABLEClientDataReceivedCallback(address, receivedData, length, &sentLength);
- oc_mutex_unlock(g_bleServerBDAddressMutex);
-
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
-}
-
-/*
- * Class: org_iotivity_ca_jar_caleinterface
- * Method: CALeGattDescriptorWriteCallback
- * Signature: (Landroid/bluetooth/BluetoothGatt;Landroid/bluetooth/BluetoothGattDescriptor;I)V
- */
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeGattDescriptorWriteCallback(JNIEnv *env, jobject obj,
- jobject gatt,
- jint status)
-{
- OIC_LOG_V(INFO, TAG, "CALeGattDescriptorWriteCallback - status %d", status);
- VERIFY_NON_NULL_VOID(env, TAG, "env is null");
- VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
- VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
-
- if (GATT_SUCCESS != status) // error
- {
- goto error_exit;
- }
-
- jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
- if (!jni_address)
- {
- goto error_exit;
- }
-
- const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- CACheckJNIException(env);
- goto error_exit;
- }
-
- CAResult_t res = CALEUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
- STATE_SERVICE_CONNECTED,
- g_deviceStateList,
- g_deviceStateListMutex);
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- goto error_exit;
- }
-
- res = CALEClientRequestMTU(env, gatt, CA_SUPPORTED_BLE_MTU_SIZE);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientRequestMTU has failed");
- goto error_exit;
- }
- return;
-
-// error label.
-error_exit:
-
- CALEClientSendFinish(env, gatt);
- return;
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_ca_CaLeClientInterface_caLeGattMtuChangedCallback(JNIEnv *env,
- jobject obj,
- jobject gatt,
- jint mtu,
- jint status)
-{
- OIC_LOG_V(INFO, TAG, "caLeGattMtuChangedCallback - status %d, "
- "mtu[%d-including Header size 3 byte]", status, mtu);
-
- (void)obj;
-
- if (0 == status || 133 == status)
- {
- if (g_sendBuffer)
- {
- CAResult_t res = CALEClientWriteCharacteristic(env, gatt);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientWriteCharacteristic has failed");
- }
- }
- else
- {
- OIC_LOG(INFO, TAG, "mtu nego is done");
- jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
- if (!jni_address)
- {
- CALEClientSendFinish(env, gatt);
- return;
- }
-
- const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- CACheckJNIException(env);
- (*env)->DeleteLocalRef(env, jni_address);
- CALEClientSendFinish(env, gatt);
- return;
- }
-
- // update mtu size
- CAResult_t res = CALESetMtuSize(address, mtu - CA_BLE_MTU_HEADER_SIZE,
- g_deviceStateList, g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALESetMtuSize has failed");
- }
-
- res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_MTU_NEGO_SUCCESS,
- g_deviceStateList,
- g_deviceStateListMutex);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
- }
- CALEClientUpdateSendCnt(env);
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- (*env)->DeleteLocalRef(env, jni_address);
- }
- }
-}
*/
void CALEClientStopScanWithInterval();
+/**
+ * check if retry logic for connection routine has to be stopped or not.
+ * in case of error value including this method, connection routine has to be stopped.
+ * since there is no retry logic for this error reason in this client.
+ * @param state constant value of bluetoothgatt.
+ * @return true - waiting for background connection in BT platform.
+ * false - connection routine has to be stopped.
+ */
+bool CALECheckConnectionStateValue(jint state);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2014 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <jni.h>
+#include <unistd.h>
+
+#include "calestate.h"
+#include "caleclient.h"
+#include "caleserver.h"
+#include "caleutils.h"
+#include "caleinterface.h"
+#include "caadapterutils.h"
+
+#include "uarraylist.h"
+#include "logger.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "cathreadpool.h" /* for thread pool */
+#include "octhread.h"
+#include "uarraylist.h"
+#include "org_iotivity_ca_CaLeClientInterface.h"
+#include "caleclient_utils.h"
+#include "caleclient.h"
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeRegisterLeScanCallback(JNIEnv *env, jobject obj,
+ jobject callback)
+{
+ OIC_LOG(DEBUG, TAG, "CaLeRegisterLeScanCallback");
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
+
+ g_leScanCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeRegisterLeScanCallbackForV21(JNIEnv *env,
+ jobject obj,
+ jobject callback)
+{
+ OIC_LOG(DEBUG, TAG, "caLeRegisterLeScanCallbackForV21");
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
+
+ g_leScanCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeRegisterGattCallback(JNIEnv *env, jobject obj,
+ jobject callback)
+{
+ OIC_LOG(DEBUG, TAG, "CaLeRegisterGattCallback");
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
+
+ g_leGattCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeScanCallback(JNIEnv *env, jobject obj,
+ jobject device)
+{
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(device, TAG, "device is null");
+
+ CAResult_t res = CALEClientAddScanDeviceToList(env, device);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "CALEClientAddScanDeviceToList has failed : %d", res);
+ }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeScanFailedCallback(JNIEnv *env, jobject obj,
+ jint errorCode)
+{
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+
+ switch (errorCode)
+ {
+ case 1:
+ OIC_LOG(ERROR, TAG, "BLE scan has failed, error is SCAN_FAILED_ALREADY_STARTED");
+ break;
+
+ case 2:
+ OIC_LOG(ERROR, TAG,
+ "BLE scan has failed, error is SCAN_FAILED_APPLICATION_REGISTRATION_FAILED");
+ break;
+
+ case 3:
+ OIC_LOG(ERROR, TAG, "BLE scan has failed, error is SCAN_FAILED_INTERNAL_ERROR");
+ break;
+
+ case 4:
+ OIC_LOG(ERROR, TAG, "BLE scan has failed, error is SCAN_FAILED_FEATURE_UNSUPPORTED");
+ break;
+
+ default:
+ OIC_LOG(ERROR, TAG, "BLE scan has failed with unknown error");
+ break;
+ }
+}
+
+/*
+ * Class: org_iotivity_ca_jar_caleinterface
+ * Method: CALeGattConnectionStateChangeCallback
+ * Signature: (Landroid/bluetooth/BluetoothGatt;II)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattConnectionStateChangeCallback(JNIEnv *env,
+ jobject obj,
+ jobject gatt,
+ jint status,
+ jint newstate)
+{
+ OIC_LOG_V(INFO, TAG, "CALeGattConnectionStateChangeCallback - status %d, newstate %d", status,
+ newstate);
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
+
+ jint state_connected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_CONNECTED");
+
+ jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+ if (!jni_address)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientGetAddressFromGattObj has failed");
+ goto error_exit;
+ }
+
+ const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
+ goto error_exit;
+ }
+ OIC_LOG_V(DEBUG, TAG, "CALeGattConnectionStateChangeCallback - address [%s]", address);
+
+ if (state_connected == newstate)
+ {
+ OIC_LOG(DEBUG, TAG, "LE is connected");
+ if (GATT_SUCCESS == status)
+ {
+ CAResult_t res = CALEUpdateDeviceState(address,
+ CA_LE_CONNECTION_STATE,
+ STATE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ goto error_exit;
+ }
+
+ res = CALEClientAddGattobjToList(env, gatt);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientAddGattobjToList has failed");
+ goto error_exit;
+ }
+
+ res = CALEClientDiscoverServices(env, gatt);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientDiscoverServices has failed");
+ goto error_exit;
+ }
+ }
+ else
+ {
+ OIC_LOG(INFO, TAG, "unknown status");
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ }
+ }
+ else // STATE_DISCONNECTED == newstate
+ {
+ OIC_LOG(DEBUG, TAG, "LE is disconnected");
+
+ if (CALEIsValidState(address, CA_LE_SEND_STATE, STATE_SEND_PREPARING,
+ g_deviceStateList, g_deviceStateListMutex))
+ {
+ OIC_LOG(INFO, TAG, "current state is STATE_SEND_PREPARING");
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_FAIL,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ }
+ }
+
+ CAResult_t res = CALEUpdateDeviceState(address,
+ CA_LE_CONNECTION_STATE,
+ STATE_DISCONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ }
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+
+ res = CALEClientGattClose(env, gatt);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientGattClose has failed");
+ }
+
+ if (CALECheckConnectionStateValue(status))
+ {
+ // this state is unexpected reason to disconnect
+ // if the reason is suitable, connection logic of the device will be destroyed.
+ OIC_LOG(INFO, TAG, "connection logic destroy");
+ }
+ else
+ {
+ // other reason except for gatt_success is expected to running
+ // background connection in BT platform.
+ OIC_LOG(INFO, TAG, "unknown status or manual disconnected state");
+ }
+ CALEClientUpdateSendCnt(env);
+ }
+ return;
+
+ // error label.
+error_exit:
+ CALEClientSendFinish(env, gatt);
+ return;
+}
+
+/*
+ * Class: org_iotivity_ca_jar_caleinterface
+ * Method: CALeGattServicesDiscoveredCallback
+ * Signature: (Landroid/bluetooth/BluetoothGatt;I)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattServicesDiscoveredCallback(JNIEnv *env,
+ jobject obj,
+ jobject gatt,
+ jint status)
+{
+ OIC_LOG_V(INFO, TAG, "CALeGattServicesDiscoveredCallback - status %d", status);
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
+
+ if (GATT_SUCCESS != status) // discovery error
+ {
+ CALEClientSendFinish(env, gatt);
+ return;
+ }
+
+ jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+ if (!jni_address)
+ {
+ CALEClientSendFinish(env, gatt);
+ return;
+ }
+
+ const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ CACheckJNIException(env);
+ CALEClientSendFinish(env, gatt);
+ return;
+ }
+
+ jstring jni_uuid = (*env)->NewStringUTF(env, OIC_GATT_CHARACTERISTIC_RESPONSE_UUID);
+ if (!jni_uuid)
+ {
+ OIC_LOG(ERROR, TAG, "jni_uuid is null");
+ goto error_exit;
+ }
+
+ jobject jni_obj_GattCharacteristic = CALEClientGetGattService(env, gatt, jni_uuid);
+ if (!jni_obj_GattCharacteristic)
+ {
+ OIC_LOG(ERROR, TAG, "jni_obj_GattCharacteristic is null");
+ goto error_exit;
+ }
+
+ CAResult_t res = CALEClientSetCharacteristicNotification(env, gatt,
+ jni_obj_GattCharacteristic);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientSetCharacteristicNotification has failed");
+ goto error_exit;
+ }
+
+ res = CALEClientSetUUIDToDescriptor(env, gatt, jni_obj_GattCharacteristic);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG_V(INFO, TAG, "Descriptor is not found : %d", res);
+
+ res = CALESetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_FALSE,
+ g_deviceStateList, g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALESetFlagToState has failed");
+ goto error_exit;
+ }
+
+ res = CALEUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
+ STATE_SERVICE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ goto error_exit;
+ }
+
+ res = CALEClientRequestMTU(env, gatt, CA_SUPPORTED_BLE_MTU_SIZE);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientRequestMTU has failed");
+ goto error_exit;
+ }
+ }
+ else
+ {
+ res = CALESetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_TRUE,
+ g_deviceStateList, g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALESetFlagToState has failed");
+ goto error_exit;
+ }
+ }
+
+#ifdef SCAN_INTERVAL
+ // reset interval scan logic
+ CALERestartScanWithInterval(g_scanIntervalTimePrev, 0, BLE_SCAN_ENABLE);
+#endif
+
+ OIC_LOG(INFO, TAG, "ServicesDiscovery is successful");
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ return;
+
+ // error label.
+error_exit:
+ OIC_LOG(ERROR, TAG, "ServicesDiscovery has failed");
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ CALEClientSendFinish(env, gatt);
+ return;
+}
+
+/*
+ * Class: org_iotivity_ca_jar_caleinterface
+ * Method: CALeGattCharacteristicWritjclasseCallback
+ * Signature: (Landroid/bluetooth/BluetoothGatt;Landroid/bluetooth/BluetoothGattCharacteristic;I)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattCharacteristicWriteCallback(
+ JNIEnv *env, jobject obj, jobject gatt, jbyteArray data, jint status)
+{
+ OIC_LOG_V(INFO, TAG, "CALeGattCharacteristicWriteCallback - status : %d", status);
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
+
+ // send success & signal
+ jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+ if (!jni_address)
+ {
+ goto error_exit;
+ }
+
+ const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ CACheckJNIException(env);
+ goto error_exit;
+ }
+
+ if (GATT_SUCCESS != status) // error case
+ {
+ OIC_LOG(ERROR, TAG, "send failure");
+
+ // retry to write
+ CAResult_t res = CALEClientWriteCharacteristic(env, gatt);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "WriteCharacteristic has failed");
+ oc_mutex_lock(g_threadWriteCharacteristicMutex);
+ g_isSignalSetFlag = true;
+ oc_cond_signal(g_threadWriteCharacteristicCond);
+ oc_mutex_unlock(g_threadWriteCharacteristicMutex);
+
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_FAIL,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ }
+
+ if (g_clientErrorCallback)
+ {
+ jint length = (*env)->GetArrayLength(env, data);
+ CACheckJNIException(env);
+ g_clientErrorCallback(address, data, length, CA_SEND_FAILED);
+ CALogSendStateInfo(CA_ADAPTER_GATT_BTLE, address, 0, length,
+ false, "writeChar failure");
+ }
+
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ goto error_exit;
+ }
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "send success");
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_SUCCESS,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ }
+
+ oc_mutex_lock(g_threadWriteCharacteristicMutex);
+ OIC_LOG(DEBUG, TAG, "g_isSignalSetFlag is set true and signal");
+ g_isSignalSetFlag = true;
+ oc_cond_signal(g_threadWriteCharacteristicCond);
+ oc_mutex_unlock(g_threadWriteCharacteristicMutex);
+
+ CALogSendStateInfo(CA_ADAPTER_GATT_BTLE, address, 0,
+ (*env)->GetArrayLength(env, data),
+ true, "writeChar success");
+ }
+
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ return;
+
+ // error label.
+error_exit:
+
+ CALEClientSendFinish(env, gatt);
+ return;
+}
+
+/*
+ * Class: org_iotivity_ca_jar_caleinterface
+ * Method: CALeGattCharacteristicChangedCallback
+ * Signature: (Landroid/bluetooth/BluetoothGatt;Landroid/bluetooth/BluetoothGattCharacteristic;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattCharacteristicChangedCallback(
+ JNIEnv *env, jobject obj, jobject gatt, jbyteArray data)
+{
+ OIC_LOG(DEBUG, TAG, "CALeGattCharacteristicChangedCallback");
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
+ VERIFY_NON_NULL_VOID(data, TAG, "data is null");
+
+ // get Byte Array and convert to uint8_t*
+ jint length = (*env)->GetArrayLength(env, data);
+
+ jboolean isCopy;
+ jbyte *jni_byte_responseData = (jbyte*) (*env)->GetByteArrayElements(env, data, &isCopy);
+ CACheckJNIException(env);
+
+ uint8_t* receivedData = OICMalloc(length);
+ if (!receivedData)
+ {
+ OIC_LOG(ERROR, TAG, "receivedData is null");
+ return;
+ }
+
+ memcpy(receivedData, jni_byte_responseData, length);
+ (*env)->ReleaseByteArrayElements(env, data, jni_byte_responseData, JNI_ABORT);
+
+ jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+ if (!jni_address)
+ {
+ OIC_LOG(ERROR, TAG, "jni_address is null");
+ OICFree(receivedData);
+ return;
+ }
+
+ const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
+ OICFree(receivedData);
+ return;
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - data. : %p, %d",
+ receivedData, length);
+
+ uint32_t sentLength = 0;
+ oc_mutex_lock(g_bleServerBDAddressMutex);
+ g_CABLEClientDataReceivedCallback(address, receivedData, length, &sentLength);
+ oc_mutex_unlock(g_bleServerBDAddressMutex);
+
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+}
+
+/*
+ * Class: org_iotivity_ca_jar_caleinterface
+ * Method: CALeGattDescriptorWriteCallback
+ * Signature: (Landroid/bluetooth/BluetoothGatt;Landroid/bluetooth/BluetoothGattDescriptor;I)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattDescriptorWriteCallback(JNIEnv *env, jobject obj,
+ jobject gatt,
+ jint status)
+{
+ OIC_LOG_V(INFO, TAG, "CALeGattDescriptorWriteCallback - status %d", status);
+ VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+ VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+ VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
+
+ if (GATT_SUCCESS != status) // error
+ {
+ goto error_exit;
+ }
+
+ jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+ if (!jni_address)
+ {
+ goto error_exit;
+ }
+
+ const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ CACheckJNIException(env);
+ goto error_exit;
+ }
+
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
+ STATE_SERVICE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ goto error_exit;
+ }
+
+ res = CALEClientRequestMTU(env, gatt, CA_SUPPORTED_BLE_MTU_SIZE);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientRequestMTU has failed");
+ goto error_exit;
+ }
+ return;
+
+// error label.
+error_exit:
+
+ CALEClientSendFinish(env, gatt);
+ return;
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattMtuChangedCallback(JNIEnv *env,
+ jobject obj,
+ jobject gatt,
+ jint mtu,
+ jint status)
+{
+ OIC_LOG_V(INFO, TAG, "caLeGattMtuChangedCallback - status %d, "
+ "mtu[%d-including Header size 3 byte]", status, mtu);
+
+ (void)obj;
+
+ if (0 == status || 133 == status)
+ {
+ if (g_sendBuffer)
+ {
+ CAResult_t res = CALEClientWriteCharacteristic(env, gatt);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientWriteCharacteristic has failed");
+ }
+ }
+ else
+ {
+ OIC_LOG(INFO, TAG, "mtu nego is done");
+ jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+ if (!jni_address)
+ {
+ CALEClientSendFinish(env, gatt);
+ return;
+ }
+
+ const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ CACheckJNIException(env);
+ (*env)->DeleteLocalRef(env, jni_address);
+ CALEClientSendFinish(env, gatt);
+ return;
+ }
+
+ // update mtu size
+ CAResult_t res = CALESetMtuSize(address, mtu - CA_BLE_MTU_HEADER_SIZE,
+ g_deviceStateList, g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALESetMtuSize has failed");
+ }
+
+ res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_MTU_NEGO_SUCCESS,
+ g_deviceStateList,
+ g_deviceStateListMutex);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
+ }
+ CALEClientUpdateSendCnt(env);
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ (*env)->DeleteLocalRef(env, jni_address);
+ }
+ }
+}
--- /dev/null
+/* ****************************************************************
+ *
+ * Copyright 2014 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#define TAG BLE_CLIENT_TAG
+
+extern u_arraylist_t *g_deviceStateList;
+extern oc_mutex g_deviceStateListMutex;
+
+extern oc_mutex g_threadWriteCharacteristicMutex;
+extern oc_cond g_threadWriteCharacteristicCond;
+
+extern oc_mutex g_bleServerBDAddressMutex;
+
+extern CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback;
+
+extern jobject g_leScanCallback;
+extern jobject g_leGattCallback;
+
+extern bool g_isSignalSetFlag;
+
+extern CABLEErrorHandleCallback g_clientErrorCallback;
+
+extern jbyteArray g_sendBuffer;
{
OIC_LOG(DEBUG, TAG, "CALEServerCreateJniInterfaceObject");
- if (!g_context)
- {
- OIC_LOG(ERROR, TAG, "g_context is null");
- return CA_STATUS_FAILED;
- }
-
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_context, TAG, "g_context is null",CA_STATUS_FAILED);
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
jclass jni_LEInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeServerInterface");
return CA_STATUS_OK;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
// start advertise
CAResult_t CALEServerStopAdvertise()
{
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerStopAdvertiseImpl(env, g_leAdvertiseCallback);
CALeServerJniInit();
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALECheckPlatformVersion(env, 21);
{
OIC_LOG(DEBUG, TAG, "IN - CALEServerTerminate");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return;
- }
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
if (g_sendBuffer)
VERIFY_NON_NULL(address, TAG, "address is null");
VERIFY_NON_NULL(data, TAG, "data is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerSendUnicastMessageImpl(env, address, data, dataLen);
OIC_LOG_V(DEBUG, TAG, "CALEServerSendMulticastMessage(%p)", data);
VERIFY_NON_NULL(data, TAG, "data is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerSendMulticastMessageImpl(env, data, dataLen);
return CA_STATUS_FAILED;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
g_isStartServer = true;
{
OIC_LOG(DEBUG, TAG, "CAStopLEGattServer");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerGattClose(env, g_bluetoothGattServer);
return jni_address;
}
+
+bool CALEAttachCurrentThread(JNIEnv **env, JavaVM *g_jvm, bool *attach_status)
+{
+ jint res = (*g_jvm)->GetEnv(g_jvm, (void**) env, JNI_VERSION_1_6);
+ if (JNI_OK != res)
+ {
+ res = (*g_jvm)->AttachCurrentThread(g_jvm, env, NULL);
+
+ if (JNI_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
+ return false;
+ }
+ *attach_status = true;
+ }
+
+ return true;
+}
\ No newline at end of file
*/
jstring CALEGetAddressFromGatt(JNIEnv *env, jobject gatt);
+bool CALEAttachCurrentThread(JNIEnv **env, JavaVM *g_jvm, bool *attach_status);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
#define CALEADAPTER_TAG "OIC_CA_LE_ADAP"
/**
+ * Macro for checking CAResult_t
+ */
+#define VERIFY_CARESULT(res, func, arg1, arg2, arg3) \
+ if (CA_STATUS_OK != res) \
+ { \
+ OIC_LOG_V(ERROR, CALEADAPTER_TAG, "%s failed, result [%d]", #func, res); \
+ if (g_errorHandler) \
+ { \
+ g_errorHandler(arg1, arg2, arg3, res); \
+ } \
+ return; \
+ }
+
+/**
* Stores information of all the senders.
*
* This structure will be used to track and defragment all incoming data packet.
&totalLength,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateVariableForFragmentation failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateVariableForFragmentation, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
OIC_LOG_V(DEBUG, CALEADAPTER_TAG,
"Packet info: data size[%d] midPacketCount[%u] remainingLen[%zu] totalLength[%zu]",
}
OIC_LOG_V(INFO, CALEADAPTER_TAG, "header info: secureFlag[%X]", secureFlag);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeader failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateHeader, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
uint8_t lengthHeader[CA_BLE_LENGTH_HEADER_SIZE] = {0};
result = CAGenerateHeaderPayloadLength(lengthHeader,
CA_BLE_LENGTH_HEADER_SIZE,
bleData->dataLen);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeaderPayloadLength failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateHeaderPayloadLength, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
uint32_t length = 0;
uint32_t dataLen = 0;
bleData->data, dataLen,
dataHeader, lengthHeader);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAMakeFirstDataSegment, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
const uint32_t iter = midPacketCount;
uint32_t index = 0;
result = CAUpdateCharacteristicsToGattClient(
bleData->remoteEndpoint->addr, dataSegment, length);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR,
- CALEADAPTER_TAG,
- "Update characteristics failed, result [%d]",
- result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint,
- bleData->data,
- bleData->dataLen,
- result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAUpdateCharacteristicsToGattClient, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
OIC_LOG_V(DEBUG,
CALEADAPTER_TAG,
secureFlag,
bleData->remoteEndpoint->port);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeader failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateHeader, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
for (index = 0; index < iter; index++)
{
dataHeader,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAMakeRemainDataSegment, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
result =
CAUpdateCharacteristicsToGattClient(
dataSegment,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Update characteristics failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAUpdateCharacteristicsToGattClient, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
+
OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]",
g_mtuSize);
}
dataHeader,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAMakeRemainDataSegment, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
result = CAUpdateCharacteristicsToGattClient(
bleData->remoteEndpoint->addr,
dataSegment,
remainingLen + CA_BLE_HEADER_SIZE);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR,
- CALEADAPTER_TAG,
- "Update characteristics failed, result [%d]",
- result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint,
- bleData->data,
- bleData->dataLen,
- result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAUpdateCharacteristicsToGattClient, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
+
OIC_LOG_V(DEBUG,
CALEADAPTER_TAG,
"Server Sent Unicast Last Data - data length [%zu]",
CAResult_t res = CALEClientSendNegotiationMessage(
bleData->remoteEndpoint->addr);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG_V(ERROR,
- CALEADAPTER_TAG,
- "CALEClientSendNegotiationMessage has failed, result [%d]",
- res);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint,
- bleData->data,
- bleData->dataLen,
- res);
- }
- return;
- }
+ VERIFY_CARESULT(res, CALEClientSendNegotiationMessage, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
}
#endif
#if defined(__TIZEN__) || defined(__ANDROID__)
&totalLength,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateVariableForFragmentation failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateVariableForFragmentation, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
OIC_LOG_V(DEBUG, CALEADAPTER_TAG,
"Packet info: data size[%d] midPacketCount[%u] remainingLen[%zu] totalLength[%zu]",
OIC_LOG_V(INFO, CALEADAPTER_TAG, "header info: secureFlag[%X]", secureFlag);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeader failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateHeader, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
uint8_t lengthHeader[CA_BLE_LENGTH_HEADER_SIZE] = {0};
result = CAGenerateHeaderPayloadLength(lengthHeader,
CA_BLE_LENGTH_HEADER_SIZE,
bleData->dataLen);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeaderPayloadLength failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateHeaderPayloadLength, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
uint32_t length = 0;
uint32_t dataLen = 0;
bleData->data, dataLen,
dataHeader, lengthHeader);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAMakeFirstDataSegment, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
const uint32_t iter = midPacketCount;
uint32_t index = 0;
LE_UNICAST,
0);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR,
- CALEADAPTER_TAG,
- "Update characteristics failed, result [%d]",
- result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint,
- bleData->data,
- bleData->dataLen,
- result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAUpdateCharacteristicsToGattServer, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
OIC_LOG_V(DEBUG,
CALEADAPTER_TAG,
"Client Sent Unicast First Data - data length [%u]",
secureFlag,
bleData->remoteEndpoint->port);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeader failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAGenerateHeader, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
for (index = 0; index < iter; index++)
{
dataHeader,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAMakeRemainDataSegment, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
// Send the remaining header.
result = CAUpdateCharacteristicsToGattServer(
g_mtuSize,
LE_UNICAST, 0);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR,
- CALEADAPTER_TAG,
- "Update characteristics failed, result [%d]",
- result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAUpdateCharacteristicsToGattServer, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
OIC_LOG_V(DEBUG,
CALEADAPTER_TAG,
"Client Sent Unicast %d Data - data(mtu) length [%hu]",
dataHeader,
g_mtuSize);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAMakeRemainDataSegment, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
result = CAUpdateCharacteristicsToGattServer(
bleData->remoteEndpoint->addr,
remainingLen + CA_BLE_HEADER_SIZE,
LE_UNICAST, 0);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
- result);
- if (g_errorHandler)
- {
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- }
- return;
- }
+ VERIFY_CARESULT(result, CAUpdateCharacteristicsToGattServer, bleData->remoteEndpoint, bleData->data, bleData->dataLen);
OIC_LOG_V(DEBUG,
CALEADAPTER_TAG,
"Client Sent Unicast Last Data - data length [%zu]",
'caleutil.c',
'calenwmonitor.c']
elif 'VD' in division:
- src_files = [ 'caleclient_vd.c',
+ env.AppendUnique(CPPDEFINES = ['TIZEN_VD'])
+ src_files = [ 'caleclient.c',
'caleserver_vd.c',
'caleutil.c',
'calenwmonitor_vd.c']
static int retry_flag = 0;
uint64_t const TIMEOUT = 30 * MICROSECS_PER_SEC;
+#ifndef TIZEN_VD
/**
* Mutex to call connect only after disconnect during retry
*/
* Condition for calling connect during connection retry
*/
static oc_cond g_LEDisconnectedCond = NULL;
+#endif
/**
* Flag to check if scanning is in progress
return CA_STATUS_FAILED;
}
g_isConnectionInProgress = true;
+#ifndef TIZEN_VD
// Set gatt connect retry count
g_retrycount = RETRY_COUNT;
+#endif
oc_mutex_unlock(g_isConnectionInProgressMutex);
// Pause the scanning
if (!connected)
{
OIC_LOG_V(DEBUG, TAG, "DisConnected from [%s] ", remoteAddress);
+#ifdef TIZEN_VD
+ oc_mutex_lock(g_LEServerListMutex);
+ CARemoveLEServerInfoFromList(&g_LEServerList, remoteAddress);
+ oc_mutex_unlock(g_LEServerListMutex);
+#else
if(!retry_flag)
{
oc_mutex_lock(g_LEServerListMutex);
oc_mutex_unlock(g_isDisconnectedMutex);
}
retry_flag = 0;
+#endif
}
else
{
if (CA_STATUS_OK != CAGetLEServerInfo(g_LEServerList, remoteAddress, &serverInfo))
{
oc_mutex_unlock(g_LEServerListMutex);
- OIC_LOG_V(ERROR, TAG, "Could not get server info!");
+ OIC_LOG_V(ERROR, TAG, "Could not get server info for [%s]", remoteAddress);
return;
}
OIC_LOG(ERROR, TAG, "addr is NULL");
return;
}
+
CAResult_t ret = ca_thread_pool_add_task(g_LEClientThreadPool, CADiscoverLEServicesThread,
addr, NULL);
oc_mutex_unlock(g_LEClientThreadPoolMutex);
if (result == BT_ERROR_NONE && NULL != man_data)
{
- char *compare_man_data = OICMalloc((man_data_len*2)+1);
int pos =0;
+ char *compare_man_data = OICCalloc(1, (man_data_len*2)+1);
+ if (!compare_man_data)
+ {
+ OIC_LOG(ERROR, TAG, "Memory allocation failed for compare_man_data");
+ OICFree(man_data);
+ return false;
+ }
+
for(int i=0;i<man_data_len;i++){
- pos += sprintf(compare_man_data+pos, "%.2x", man_data[i]);
+ pos += snprintf(compare_man_data+pos, 2, "%.2x", man_data[i]);
}
- compare_man_data[(man_data_len*2)+1]='\0';
- OIC_LOG_V(DEBUG, TAG, "Manufacture Id %d Manufacture Data[%s]" ,man_id,compare_man_data);
+
if (man_id == samsung_code && 0 == strncasecmp(compare_man_data, service_uuid, CUSTOM_UUID_LEN))
{
OIC_LOG_V(DEBUG, TAG, "Manufacture Data[%s] Found in %s",
void *userData)
{
(void)userData;
-
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_VOID(scanInfo, TAG, "scanInfo");
oc_mutex_unlock(g_LEClientThreadPoolMutex);
return CA_STATUS_FAILED;
}
+
+#ifdef TIZEN_VD
+ result= ca_thread_pool_add_task(g_LEClientThreadPool, CALEClientScanThread,
+ NULL, NULL);
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "ca_thread_pool_add_task failed");
+ CATerminateGattClientMutexVariables();
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ return CA_STATUS_FAILED;
+ }
+#endif
oc_mutex_unlock(g_LEClientThreadPoolMutex);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
+#ifdef TIZEN_VD
+void CALEClientScanThread()
+{
+ oc_mutex_lock(g_scanMutex);
+ if (!g_isMulticastInProgress && !g_isUnicastScanInProgress)
+ {
+ CAResult_t result = CALEGattStartDeviceScanning();
+ if (CA_STATUS_OK != result)
+ {
+ oc_mutex_unlock(g_scanMutex);
+ OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed");
+ return ;
+ }
+ g_isUnicastScanInProgress = true;
+ // Start Timer
+ oc_cond_signal(g_startTimerCond);
+ }
+ else
+ {
+ g_isUnicastScanInProgress = true;
+ // Reset Timer
+ oc_cond_signal(g_scanningTimeCond);
+ }
+ oc_mutex_unlock(g_scanMutex);
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return ;
+}
+#endif
+
void CAStartTimerThread(void *data)
{
(void)data;
}
}
+#ifndef TIZEN_VD
if (NULL == g_isDisconnectedMutex)
{
g_isDisconnectedMutex = oc_mutex_new();
return CA_STATUS_FAILED;
}
}
+#endif
if (NULL == g_startTimerCond)
{
oc_mutex_free(g_threadMTUChangedMutex);
g_threadMTUChangedMutex = NULL;
+#ifndef TIZEN_VD
oc_mutex_free(g_isDisconnectedMutex);
g_isDisconnectedMutex = NULL;
oc_cond_free(g_LEDisconnectedCond);
g_LEDisconnectedCond = NULL;
+#endif
oc_cond_free(g_startTimerCond);
g_startTimerCond = NULL;
oc_mutex_lock(g_LEClientConnectMutex);
CAResult_t result = CA_STATUS_OK;
+#ifdef TIZEN_VD
+ int ret = bt_gatt_connect(remoteAddress, true);
+#else
int ret = bt_gatt_connect(remoteAddress, false);
+#endif
if (BT_ERROR_NONE != ret)
{
OIC_LOG_V(ERROR, TAG, "bt_gatt_connect Failed with ret value [%s] ",
OIC_LOG(DEBUG, TAG, "OUT");
}
+#ifndef TIZEN_VD
static int CALEWaittillDisconnect(oc_mutex mutex, oc_cond cv, int wait_seconds)
{
OIC_LOG(DEBUG, TAG, "Waiting for server to be disconnected...");
OIC_LOG(DEBUG, TAG, "OUT");
return result;
}
+#endif
CAResult_t CALEGattDiscoverServices(const char *remoteAddress)
{
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_get_service Failed with ret value [%s] ", CALEGetErrorMsg(ret));
+#ifdef TIZEN_VD
+ goto error_exit;
+#else
if(g_retrycount)
{
OIC_LOG(DEBUG, TAG, "Retry will be attempted to connect Gatt Server");
return CA_STATUS_FAILED;
}
}
+#endif
}
retry_flag = 0;
OIC_LOG(ERROR, TAG, "Device address is NULL");
return CA_STATUS_FAILED;
}
-
serverInfo = (LEServerInfo *)OICCalloc(1, sizeof(LEServerInfo));
if (NULL == serverInfo)
{
OICFree(addr);
return CA_STATUS_FAILED;
}
-
serverInfo->remoteAddress = addr;
serverInfo->status = LE_STATUS_UNICAST_PENDING;
else:
common_files = [
os.path.join(src_dir, 'caipadapter.c'),
- os.path.join(src_dir, 'caipserver.c') ]
+ os.path.join(src_dir, 'caipserver.c'),
+ os.path.join(src_dir, 'caipnwmonitor_common.c') ]
+
+env.AppendUnique(CPPPATH = [ src_dir ])
# Get list of target-specific source file base names, i.e. no parent
# directories prepended to the path.
#include "caadapterutils.h"
#include "caipnwmonitor.h"
+#include "caipnwmonitor_common.h"
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
return CA_STATUS_OK;
}
-int CAGetPollingInterval(int interval)
-{
- return interval;
-}
-
static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status)
{
- CAIPCBData_t *cbitem = NULL;
- LL_FOREACH(g_adapterCallbackList, cbitem)
- {
- if (cbitem && cbitem->adapter)
- {
- cbitem->callback(cbitem->adapter, status);
- }
- }
+ CAIPPassNetworkChangesToAdapterInternal(status, g_adapterCallbackList, CA_IP_NW_COMMON_ANDROID);
}
CAResult_t CAIPSetNetworkMonitorCallback(CAIPAdapterStateChangeCallback callback,
CATransportAdapter_t adapter)
{
- if (!callback)
- {
- OIC_LOG(ERROR, TAG, "callback is null");
- return CA_STATUS_INVALID_PARAM;
- }
-
- CAIPCBData_t *cbitem = NULL;
- LL_FOREACH(g_adapterCallbackList, cbitem)
- {
- if (cbitem && adapter == cbitem->adapter && callback == cbitem->callback)
- {
- OIC_LOG(DEBUG, TAG, "this callback is already added");
- return CA_STATUS_OK;
- }
- }
-
- cbitem = (CAIPCBData_t *)OICCalloc(1, sizeof(*cbitem));
- if (!cbitem)
- {
- OIC_LOG(ERROR, TAG, "Malloc failed");
- return CA_STATUS_FAILED;
- }
-
- cbitem->adapter = adapter;
- cbitem->callback = callback;
- LL_APPEND(g_adapterCallbackList, cbitem);
-
- return CA_STATUS_OK;
+ return CAIPSetNetworkMonitorCallbackInternal(callback, adapter, g_adapterCallbackList);
}
CAResult_t CAIPUnSetNetworkMonitorCallback(CATransportAdapter_t adapter)
{
- CAIPCBData_t *cbitem = NULL;
- CAIPCBData_t *tmpCbitem = NULL;
- LL_FOREACH_SAFE(g_adapterCallbackList, cbitem, tmpCbitem)
- {
- if (cbitem && adapter == cbitem->adapter)
- {
- OIC_LOG(DEBUG, TAG, "remove specific callback");
- LL_DELETE(g_adapterCallbackList, cbitem);
- OICFree(cbitem);
- return CA_STATUS_OK;
- }
- }
- return CA_STATUS_OK;
+ return CAIPUnSetNetworkMonitorCallbackInternal(adapter, g_adapterCallbackList);
}
u_arraylist_t *CAFindInterfaceChange()
--- /dev/null
+/******************************************************************
+*
+* Copyright 2019 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 "caipnwmonitor.h"
+#include "caipnwmonitor_common.h"
+
+#include "utlist.h"
+#include "logger.h"
+
+#define TAG "OIC_CA_IP_MONITOR_COMMON"
+
+/**
+ * @todo For Windows platform: Implement network interface monitoring.
+ * Not used in win32, but caipserver currently requires this function
+ * be defined. not critical.
+ */
+int CAGetPollingInterval(int interval)
+{
+ return interval;
+}
+
+void CAIPPassNetworkChangesToAdapterInternal(CANetworkStatus_t status,
+ CAIPCBData_t *adapterCallbackList, CAIPAdapterPlatform_t platform)
+{
+ CAIPCBData_t *cbitem = NULL;
+ LL_FOREACH(adapterCallbackList, cbitem)
+ {
+ if (cbitem && cbitem->adapter)
+ {
+ cbitem->callback(cbitem->adapter, status);
+ if (platform == CA_IP_NW_COMMON_LINUX)
+ {
+ CALogAdapterStateInfo(cbitem->adapter, status);
+ }
+ }
+ }
+}
+
+CAResult_t CAIPSetNetworkMonitorCallbackInternal(CAIPAdapterStateChangeCallback callback,
+ CATransportAdapter_t adapter, CAIPCBData_t *adapterCallbackList)
+{
+ if (!callback)
+ {
+ OIC_LOG(ERROR, TAG, "callback is null");
+ return CA_STATUS_INVALID_PARAM;
+ }
+
+ CAIPCBData_t *cbitem = NULL;
+ LL_FOREACH(adapterCallbackList, cbitem)
+ {
+ if (cbitem && adapter == cbitem->adapter && callback == cbitem->callback)
+ {
+ OIC_LOG(DEBUG, TAG, "this callback is already added");
+ return CA_STATUS_OK;
+ }
+ }
+
+ cbitem = (CAIPCBData_t *)OICCalloc(1, sizeof(*cbitem));
+ if (!cbitem)
+ {
+ OIC_LOG(ERROR, TAG, "Malloc failed");
+ return CA_STATUS_FAILED;
+ }
+
+ cbitem->adapter = adapter;
+ cbitem->callback = callback;
+ LL_APPEND(adapterCallbackList, cbitem);
+
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAIPUnSetNetworkMonitorCallbackInternal(CATransportAdapter_t adapter,
+ CAIPCBData_t *adapterCallbackList)
+{
+ CAIPCBData_t *cbitem = NULL;
+ CAIPCBData_t *tmpCbitem = NULL;
+ LL_FOREACH_SAFE(adapterCallbackList, cbitem, tmpCbitem)
+ {
+ if (cbitem && adapter == cbitem->adapter)
+ {
+ OIC_LOG(DEBUG, TAG, "remove specific callback");
+ LL_DELETE(adapterCallbackList, cbitem);
+ OICFree(cbitem);
+ return CA_STATUS_OK;
+ }
+ }
+ return CA_STATUS_OK;
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2019 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.
+ *
+ ******************************************************************/
+
+/**
+ * @file caipnwmonitor_common.h
+ * This file provides common APIs of IP network monitor modules.
+ */
+
+#ifndef CA_IP_NW_INTERFACE_COMMON_H_
+#define CA_IP_NW_INTERFACE_COMMON_H_
+
+#include "cacommon.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Enum for defining different platforms for internal usage.
+ */
+typedef enum
+{
+ CA_IP_NW_COMMON_ANDROID = 0,
+ CA_IP_NW_COMMON_LINUX,
+ CA_IP_NW_COMMON_TIZEN,
+ CA_IP_NW_COMMON_TIZENRT,
+ CA_IP_NW_COMMON_WINDOWS
+} CAIPAdapterPlatform_t;
+
+void CAIPPassNetworkChangesToAdapterInternal(CANetworkStatus_t status,
+ CAIPCBData_t *adapterCallbackList, CAIPAdapterPlatform_t platform);
+
+CAResult_t CAIPSetNetworkMonitorCallbackInternal(CAIPAdapterStateChangeCallback callback,
+ CATransportAdapter_t adapter, CAIPCBData_t *adapterCallbackList);
+
+CAResult_t CAIPUnSetNetworkMonitorCallbackInternal(CATransportAdapter_t adapter,
+ CAIPCBData_t *adapterCallbackList);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CA_IP_NW_INTERFACE_COMMON_H_ */
#include "octhread.h"
#include "caipnwmonitor.h"
+#include "caipnwmonitor_common.h"
#include "caadapterutils.h"
#include "logger.h"
#include "oic_malloc.h"
return CAIPUnSetNetworkMonitorCallback(adapter);
}
-int CAGetPollingInterval(int interval)
-{
- return interval;
-}
-
static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status)
{
- CAIPCBData_t *cbitem = NULL;
- LL_FOREACH(g_adapterCallbackList, cbitem)
- {
- if (cbitem && cbitem->adapter)
- {
- cbitem->callback(cbitem->adapter, status);
- CALogAdapterStateInfo(cbitem->adapter, status);
- }
- }
+ CAIPPassNetworkChangesToAdapterInternal(status, g_adapterCallbackList, CA_IP_NW_COMMON_LINUX);
}
CAResult_t CAIPSetNetworkMonitorCallback(CAIPAdapterStateChangeCallback callback,
CATransportAdapter_t adapter)
{
- if (!callback)
- {
- OIC_LOG(ERROR, TAG, "callback is null");
- return CA_STATUS_INVALID_PARAM;
- }
-
- CAIPCBData_t *cbitem = NULL;
- LL_FOREACH(g_adapterCallbackList, cbitem)
- {
- if (cbitem && adapter == cbitem->adapter && callback == cbitem->callback)
- {
- OIC_LOG(DEBUG, TAG, "this callback is already added");
- return CA_STATUS_OK;
- }
- }
-
- cbitem = (CAIPCBData_t *)OICCalloc(1, sizeof(*cbitem));
- if (!cbitem)
- {
- OIC_LOG(ERROR, TAG, "Malloc failed");
- return CA_STATUS_FAILED;
- }
-
- cbitem->adapter = adapter;
- cbitem->callback = callback;
- LL_APPEND(g_adapterCallbackList, cbitem);
-
- return CA_STATUS_OK;
+ return CAIPSetNetworkMonitorCallbackInternal(callback, adapter, g_adapterCallbackList);
}
CAResult_t CAIPUnSetNetworkMonitorCallback(CATransportAdapter_t adapter)
{
- CAIPCBData_t *cbitem = NULL;
- CAIPCBData_t *tmpCbitem = NULL;
- LL_FOREACH_SAFE(g_adapterCallbackList, cbitem, tmpCbitem)
- {
- if (cbitem && adapter == cbitem->adapter)
- {
- OIC_LOG(DEBUG, TAG, "remove specific callback");
- LL_DELETE(g_adapterCallbackList, cbitem);
- OICFree(cbitem);
- return CA_STATUS_OK;
- }
- }
- return CA_STATUS_OK;
+ return CAIPUnSetNetworkMonitorCallbackInternal(adapter, g_adapterCallbackList);
}
static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family,
#include "caipinterface.h"
#include "caipnwmonitor.h"
+#include "caipnwmonitor_common.h"
#include "caadapterutils.h"
#include "logger.h"
#include "oic_malloc.h"
*/
static void CAIPConnectionStateChangedCb(connection_type_e type, void* userData);
-int CAGetPollingInterval(int interval)
-{
- return interval;
-}
-
static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status)
{
- CAIPCBData_t *cbitem = NULL;
- LL_FOREACH(g_adapterCallbackList, cbitem)
- {
- if (cbitem && cbitem->adapter)
- {
- cbitem->callback(cbitem->adapter, status);
- }
- }
+ CAIPPassNetworkChangesToAdapterInternal(status, g_adapterCallbackList, CA_IP_NW_COMMON_TIZEN);
}
CAResult_t CAIPSetNetworkMonitorCallback(CAIPAdapterStateChangeCallback callback,
CATransportAdapter_t adapter)
{
- if (!callback)
- {
- OIC_LOG(ERROR, TAG, "callback is null");
- return CA_STATUS_INVALID_PARAM;
- }
-
- CAIPCBData_t *cbitem = NULL;
- LL_FOREACH(g_adapterCallbackList, cbitem)
- {
- if (cbitem && adapter == cbitem->adapter && callback == cbitem->callback)
- {
- OIC_LOG(DEBUG, TAG, "this callback is already added");
- return CA_STATUS_OK;
- }
- }
-
- cbitem = (CAIPCBData_t *)OICCalloc(1, sizeof(*cbitem));
- if (!cbitem)
- {
- OIC_LOG(ERROR, TAG, "Malloc failed");
- return CA_STATUS_FAILED;
- }
-
- cbitem->adapter = adapter;
- cbitem->callback = callback;
- LL_APPEND(g_adapterCallbackList, cbitem);
-
- return CA_STATUS_OK;
+ return CAIPSetNetworkMonitorCallbackInternal(callback, adapter, g_adapterCallbackList);
}
CAResult_t CAIPUnSetNetworkMonitorCallback(CATransportAdapter_t adapter)
{
- CAIPCBData_t *cbitem = NULL;
- CAIPCBData_t *tmpCbitem = NULL;
- LL_FOREACH_SAFE(g_adapterCallbackList, cbitem, tmpCbitem)
- {
- if (cbitem && adapter == cbitem->adapter)
- {
- OIC_LOG(DEBUG, TAG, "remove specific callback");
- LL_DELETE(g_adapterCallbackList, cbitem);
- OICFree(cbitem);
- return CA_STATUS_OK;
- }
- }
- return CA_STATUS_OK;
+ return CAIPUnSetNetworkMonitorCallbackInternal(adapter, g_adapterCallbackList);
}
u_arraylist_t *CAFindInterfaceChange()
* Not used in win32, but caipserver currently requires this function
* be defined. not critical.
*/
-int CAGetPollingInterval(int interval)
-{
- return interval;
-}
-
-/**
- * @todo Implement network interface monitoring.
- * Not used in win32, but caipserver currently requires this function
- * be defined. not critical.
- */
u_arraylist_t *CAFindInterfaceChange()
{
u_arraylist_t *iflist = NULL;
if target_os in ['linux', 'tizen', 'android', 'ios', 'tizenrt']:
common_files = [
os.path.join(src_dir, 'catcpadapter.c'),
- os.path.join(src_dir, 'catcpserver.c') ]
+ os.path.join(src_dir, 'catcpserver.c'),
+ os.path.join(src_dir, 'catcpserver_mutex.c'),]
else :
common_files = [os.path.join(src_dir, 'catcpadapter.c')]
#include "caipnwmonitor.h"
#include <coap/pdu.h>
#include "caadapterutils.h"
+#include "catcpserver_mutex.h"
#include "octhread.h"
#include "oic_malloc.h"
#include "oic_string.h"
static uint32_t g_taskId = 0;
/**
- * Mutex to synchronize device object list.
- */
-static oc_mutex g_mutexObjectList = NULL;
-
-/**
- * Conditional mutex to synchronize.
- */
-static oc_cond g_condObjectList = NULL;
-
-/**
- * Mutex to synchronize send.
- */
-static oc_mutex g_mutexSend = NULL;
-
-/**
- * Conditional mutex to synchronize send.
- */
-static oc_cond g_condSend = NULL;
-
-/**
* Maintains the callback to be notified when data received from remote device.
*/
static CATCPPacketReceivedCallback g_packetReceivedCallback = NULL;
FDS[COUNT].fd = caglobals.tcp.TYPE.fd; \
FDS[COUNT].events = POLLIN;
-void CATCPDestroyMutex()
-{
- if (g_mutexObjectList)
- {
- oc_mutex_free(g_mutexObjectList);
- g_mutexObjectList = NULL;
- }
-}
-
-CAResult_t CATCPCreateMutex()
-{
- if (!g_mutexObjectList)
- {
- g_mutexObjectList = oc_mutex_new_recursive();
- if (!g_mutexObjectList)
- {
- OIC_LOG(ERROR, TAG, "Failed to create mutex!");
- return CA_STATUS_FAILED;
- }
- }
-
- return CA_STATUS_OK;
-}
-
-void CATCPDestroyCond()
-{
- if (g_condObjectList)
- {
- oc_cond_free(g_condObjectList);
- g_condObjectList = NULL;
- }
-}
-
-CAResult_t CATCPCreateCond()
-{
- if (!g_condObjectList)
- {
- g_condObjectList = oc_cond_new();
- if (!g_condObjectList)
- {
- OIC_LOG(ERROR, TAG, "Failed to create cond!");
- return CA_STATUS_FAILED;
- }
- }
- return CA_STATUS_OK;
-}
-
-void CATCPDestroySendMutex()
-{
- if (g_mutexSend)
- {
- oc_mutex_free(g_mutexSend);
- g_mutexSend = NULL;
- }
-}
-
-CAResult_t CATCPCreateSendMutex()
-{
- if (!g_mutexSend)
- {
- g_mutexSend = oc_mutex_new();
- if (!g_mutexSend)
- {
- OIC_LOG(ERROR, TAG, "Failed to create send mutex!");
- return CA_STATUS_FAILED;
- }
- }
-
- return CA_STATUS_OK;
-}
-
-void CATCPDestroySendCond()
-{
- if (g_condSend)
- {
- oc_cond_free(g_condSend);
- g_condSend = NULL;
- }
-}
-
-CAResult_t CATCPCreateSendCond()
-{
- if (!g_condSend)
- {
- g_condSend = oc_cond_new();
- if (!g_condSend)
- {
- OIC_LOG(ERROR, TAG, "Failed to create send cond!");
- return CA_STATUS_FAILED;
- }
- }
- return CA_STATUS_OK;
-}
-
static void CAReceiveHandler(void *data)
{
(void)data;
--- /dev/null
+/* ****************************************************************
+ *
+ * Copyright 2019 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 "catcpserver_mutex.h"
+/**
+ * Logging tag for module name.
+ */
+//#define TAG "OIC_CA_TCP_SERVER"
+#define TAG TCP_SERVER_TAG
+
+/**
+ * Mutex to synchronize device object list.
+ */
+oc_mutex g_mutexObjectList = NULL;
+
+/**
+ * Conditional mutex to synchronize.
+ */
+oc_cond g_condObjectList= NULL;
+
+/**
+ * Mutex to synchronize send.
+ */
+oc_mutex g_mutexSend= NULL;
+
+/**
+ * Conditional mutex to synchronize send.
+ */
+oc_cond g_condSend= NULL;
+
+void CATCPDestroyMutex()
+{
+ if (g_mutexObjectList)
+ {
+ oc_mutex_free(g_mutexObjectList);
+ g_mutexObjectList = NULL;
+ }
+}
+
+CAResult_t CATCPCreateMutex()
+{
+ if (!g_mutexObjectList)
+ {
+ g_mutexObjectList = oc_mutex_new_recursive();
+ if (!g_mutexObjectList)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to create mutex!");
+ return CA_STATUS_FAILED;
+ }
+ }
+
+ return CA_STATUS_OK;
+}
+
+void CATCPDestroyCond()
+{
+ if (g_condObjectList)
+ {
+ oc_cond_free(g_condObjectList);
+ g_condObjectList = NULL;
+ }
+}
+
+CAResult_t CATCPCreateCond()
+{
+ if (!g_condObjectList)
+ {
+ g_condObjectList = oc_cond_new();
+ if (!g_condObjectList)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to create cond!");
+ return CA_STATUS_FAILED;
+ }
+ }
+ return CA_STATUS_OK;
+}
+
+void CATCPDestroySendMutex()
+{
+ if (g_mutexSend)
+ {
+ oc_mutex_free(g_mutexSend);
+ g_mutexSend = NULL;
+ }
+}
+
+CAResult_t CATCPCreateSendMutex()
+{
+ if (!g_mutexSend)
+ {
+ g_mutexSend = oc_mutex_new();
+ if (!g_mutexSend)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to create send mutex!");
+ return CA_STATUS_FAILED;
+ }
+ }
+
+ return CA_STATUS_OK;
+}
+
+void CATCPDestroySendCond()
+{
+ if (g_condSend)
+ {
+ oc_cond_free(g_condSend);
+ g_condSend = NULL;
+ }
+}
+
+CAResult_t CATCPCreateSendCond()
+{
+ if (!g_condSend)
+ {
+ g_condSend = oc_cond_new();
+ if (!g_condSend)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to create send cond!");
+ return CA_STATUS_FAILED;
+ }
+ }
+ return CA_STATUS_OK;
+}
--- /dev/null
+/* ****************************************************************
+*
+* Copyright 2019 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.
+*
+******************************************************************/
+
+#ifndef CA_TCP_SERVER_MUTEX_H_
+#define CA_TCP_SERVER_MUTEX_H_
+
+#include "octhread.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "catcpinterface.h"
+#include "caipnwmonitor.h"
+#include <coap/pdu.h>
+#include "caadapterutils.h"
+
+/**
+ * Mutex to synchronize device object list.
+ */
+extern oc_mutex g_mutexObjectList;
+
+/**
+ * Conditional mutex to synchronize.
+ */
+extern oc_cond g_condObjectList;
+
+/**
+ * Mutex to synchronize send.
+ */
+extern oc_mutex g_mutexSend;
+
+/**
+ * Conditional mutex to synchronize send.
+ */
+extern oc_cond g_condSend;
+
+void CATCPDestroyMutex();
+
+CAResult_t CATCPCreateMutex();
+
+void CATCPDestroyCond();
+
+CAResult_t CATCPCreateCond();
+
+void CATCPDestroySendMutex();
+
+CAResult_t CATCPCreateSendMutex();
+
+void CATCPDestroySendCond();
+
+CAResult_t CATCPCreateSendCond();
+
+#endif
'./src/routingutility.c',
'./src/routingmanager.c',
'./src/routingtablemanager.c',
+ './src/routingtablemanager_endpoint.c',
'./src/routingmanagerinterface.c',
'./src/routingmessageparser.c',
]
OCStackResult RTMFreeGatewayIdList(u_linklist_t **gatewayIdTable);
/**
- * Frees the endpoint table memory with nodes containing structute RTMEndpointEntry_t.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable);
-
-/**
* Adds the entry to the routing table if the entry for Gateway id is
* not preset in Routing table, Updates the Old entry if Entry for
* Gateway Id is already present in Routing table i.e routeCost and NextHop
const RTMDestIntfInfo_t *destInterfaces, u_linklist_t **gatewayTable);
/**
- * Adds the endpoint entry to the routing table.
- * @param[in/out] endpointId Endpoint Id.
- * @param[in] destAddr Destination Address.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
- u_linklist_t **endpointTable);
-
-/**
* Removes the gateway entry from the routing table and also removes
* corresponding entries having nexthop as removed gateway.
* @param[in] gatewayId Gateway id of node need to be removed.
u_linklist_t **gatewayTable);
/**
- * Removes the endpoint entry from the routing table.
- * @param[in] endpointId Endpoint id of node need to be removed.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable);
-
-/**
* Removes the gateway entry from the routing table which has gateway id and nexthop as given.
* @param[in] gatewayId Gateway Id.
* @param[in] nextHop Next Hop address.
OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable);
/**
- * Removes the endpoint nodes.
- * @param[in/out] endpointTable Endpoint Routing Table.
- * @return ::OC_STACK_OK or Appropriate error code.
- */
-OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable);
-
-/**
* Gets the neighbor nodes i.e nodes with routecost 1.
* @param[in/out] neighbourNodes link list containing neighbor nodes.
this list will be pointer to GatewayIds
RTMGatewayId_t *RTMGetNextHop(uint32_t gatewayId, const u_linklist_t *gatewayTable);
/**
- * Gets endpoint entry
- * @param[in] endpointId Endpoint id of node need to be removed.
- * @param[in] endpointTable Endpoint Routing Table.
- * @return Endpoint Destination inteface address.
- */
-CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable);
-
-/**
* Updates destination interface address of an entry with provided gateway id
* as destination.
* @param[in] gatewayId Gateway Id of Hop need to be updated.
--- /dev/null
+/* ****************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+
+/**
+ * @file
+ * This file contains the APIs for routing table manager endpoint.
+ */
+#ifndef ROUTING_TABLE_MANAGER_ENDPOINT_H_
+#define ROUTING_TABLE_MANAGER_ENDPOINT_H_
+
+#ifndef SINGLE_THREAD
+#include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#endif
+
+#if defined(__ANDROID__)
+#include <linux/time.h>
+#endif
+#include "ulinklist.h"
+#include "uarraylist.h"
+#include "octypes.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Initialize the Routing Table Manager.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMEndpointInitialize(u_linklist_t **endpointTable);
+
+/**
+ * Terminates the Routing Table Manager..
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMEndpointTerminate(u_linklist_t **endpointTable);
+
+/**
+ * Frees the endpoint table memory with nodes containing structute RTMEndpointEntry_t.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable);
+
+/**
+ * Adds the endpoint entry to the routing table.
+ * @param[in/out] endpointId Endpoint Id.
+ * @param[in] destAddr Destination Address.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
+ u_linklist_t **endpointTable);
+
+/**
+ * Removes the endpoint entry from the routing table.
+ * @param[in] endpointId Endpoint id of node need to be removed.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable);
+
+/**
+ * Removes the endpoint nodes.
+ * @param[in/out] endpointTable Endpoint Routing Table.
+ * @return ::OC_STACK_OK or Appropriate error code.
+ */
+OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable);
+
+/**
+ * Gets endpoint entry
+ * @param[in] endpointId Endpoint id of node need to be removed.
+ * @param[in] endpointTable Endpoint Routing Table.
+ * @return Endpoint Destination inteface address.
+ */
+CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable);
+
+/**
+ * Prints the routing table
+ * @param[in] endpointTable Endpoint Routing Table.
+ */
+void RTMEndpointPrintTable(const u_linklist_t *endpointTable);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ROUTING_TABLE_MANAGER_ENDPOINT_H_ */
#include <stdio.h>
#include <string.h>
#include "routingtablemanager.h"
+#include "routingtablemanager_endpoint.h"
#include "routingutility.h"
#include "oic_malloc.h"
#include "oic_string.h"
}
}
- if (NULL == *endpointTable)
+ if (OC_STACK_ERROR == RTMEndpointInitialize(endpointTable))
{
- *endpointTable = u_linklist_create();
- if (NULL == *endpointTable)
- {
- OIC_LOG(ERROR, TAG, "Creating Routing Table failed");
- RTMTerminate(gatewayTable, endpointTable);
- return OC_STACK_ERROR;
- }
+ OIC_LOG(ERROR, TAG, "Creating EndPoint Routing Table failed");
+ RTMTerminate(gatewayTable, endpointTable);
+ return OC_STACK_ERROR;
}
+
OIC_LOG(DEBUG, TAG, "RTMInitialize OUT");
return OC_STACK_OK;
}
return OC_STACK_OK;
}
-/*
- * Freeing every char pointer of endpoint entry here frees the table.
- */
-OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- if (NULL == endpointTable || NULL == *endpointTable)
- {
- return OC_STACK_OK;
- }
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(*endpointTable, &iterTable);
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *hop = u_linklist_get_data(iterTable);
- if (NULL != hop)
- {
- OICFree(hop);
- }
-
- OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
- return OC_STACK_ERROR;
- }
- }
- u_linklist_free(endpointTable);
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
OCStackResult RTMFreeGatewayIdList(u_linklist_t **gatewayIdTable)
{
OIC_LOG(DEBUG, TAG, "IN");
*gatewayTable = NULL;
}
- ret = RTMFreeEndpointRouteTable(endpointTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Deleting Endpoint Routing Table failed");
- }
- if (NULL != *endpointTable)
- {
- *endpointTable = NULL;
- }
+ RTMEndpointTerminate(endpointTable);
OIC_LOG(DEBUG, TAG, "OUT");
return OC_STACK_OK;
}
return OC_STACK_OK;
}
-OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
- u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- RM_NULL_CHECK_WITH_RET(endpointId, TAG, "endpointId");
- RM_NULL_CHECK_WITH_RET(destAddr, TAG, "destAddr");
- RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
- if (NULL == *endpointTable)
- {
- *endpointTable = u_linklist_create();
- if (NULL == *endpointTable)
- {
- OIC_LOG(ERROR, TAG, "u_linklist_create failed");
- return OC_STACK_NO_MEMORY;
- }
- }
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(*endpointTable, &iterTable);
- // Iterate over gateway list to find if already entry with this gatewayid is present.
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *entry =
- (RTMEndpointEntry_t *) u_linklist_get_data(iterTable);
-
- if (NULL != entry && (0 == memcmp(destAddr->addr, entry->destIntfAddr.addr,
- strlen(entry->destIntfAddr.addr)))
- && destAddr->port == entry->destIntfAddr.port)
- {
- *endpointId = entry->endpointId;
- OIC_LOG(ERROR, TAG, "Adding failed as Enpoint Entry Already present in Table");
- return OC_STACK_DUPLICATE_REQUEST;
- }
- u_linklist_get_next(&iterTable);
- }
-
- // Filling Entry.
- RTMEndpointEntry_t *hopEntry = (RTMEndpointEntry_t *)OICCalloc(1, sizeof(RTMEndpointEntry_t));
-
- if (NULL == hopEntry)
- {
- OIC_LOG(ERROR, TAG, "Malloc failed for hop entry");
- return OC_STACK_ERROR;
- }
-
- hopEntry->endpointId = *endpointId;
- hopEntry->destIntfAddr = *destAddr;
-
- OCStackResult ret = u_linklist_add(*endpointTable, (void *)hopEntry);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Adding Enpoint Entry to Routing Table failed");
- OICFree(hopEntry);
- return OC_STACK_ERROR;
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
OCStackResult RTMAddObserver(uint32_t obsID, CAEndpoint_t devAddr, u_linklist_t **gatewayTable)
{
OIC_LOG(DEBUG, TAG, "IN");
return OC_STACK_ERROR;
}
-OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
- RM_NULL_CHECK_WITH_RET(*endpointTable, TAG, "*endpointTable");
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(*endpointTable, &iterTable);
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
- if (NULL != entry && endpointId == entry->endpointId)
- {
- OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
- return OC_STACK_ERROR;
- }
- OICFree(entry);
- }
- else
- {
- u_linklist_get_next(&iterTable);
- }
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
OCStackResult RTMRemoveGateways(u_linklist_t **gatewayTable)
{
OIC_LOG(DEBUG, TAG, "IN");
return OC_STACK_OK;
}
-OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- if (NULL == endpointTable || NULL == *endpointTable)
- {
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
- }
-
- OCStackResult ret = RTMFreeEndpointRouteTable(endpointTable);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Freeing Endpoints failed");
- return OC_STACK_ERROR;
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return OC_STACK_OK;
-}
-
void RTMFreeGateway(RTMGatewayId_t *gateway, u_linklist_t **gatewayTable)
{
OIC_LOG(DEBUG, TAG, "IN");
return NULL;
}
-CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable)
-{
- OIC_LOG(DEBUG, TAG, "IN");
- if (NULL == endpointTable)
- {
- OIC_LOG(ERROR, TAG, "endpointTable is null");
- return NULL;
- }
-
- u_linklist_iterator_t *iterTable = NULL;
- u_linklist_init_iterator(endpointTable, &iterTable);
-
- while (NULL != iterTable)
- {
- RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
- if (NULL != entry && (endpointId == entry->endpointId))
- {
- OIC_LOG(DEBUG, TAG, "OUT");
- return &(entry->destIntfAddr);
- }
- u_linklist_get_next(&iterTable);
- }
- OIC_LOG(DEBUG, TAG, "OUT");
- return NULL;
-}
-
void RTMGetObserverList(OCObservationId **obsList, uint8_t *obsListLen,
const u_linklist_t *gatewayTable)
{
u_linklist_get_next(&iterTable);
}
- OIC_LOG(DEBUG, RM_TAG, "=================Endpoint List table============================\n");
- u_linklist_iterator_t *iterEndpointTable = NULL;
- u_linklist_init_iterator(endpointTable, &iterEndpointTable);
-
- // Iterate over endpoint list to find if already entry for gatewayid is present.
- while (NULL != iterEndpointTable)
- {
- RTMEndpointEntry_t *hop =
- (RTMEndpointEntry_t *) u_linklist_get_data(iterEndpointTable);
- if (NULL == hop)
- {
- OIC_LOG(ERROR, RM_TAG, "Printing Table Failed");
- return;
- }
- OIC_LOG_V(DEBUG, RM_TAG, "EndpointId : %u\naddr : %s Port : %d",
- hop->endpointId, hop->destIntfAddr.addr, hop->destIntfAddr.port);
-
- OIC_LOG(DEBUG, RM_TAG, "********************************************\n");
- u_linklist_get_next(&iterEndpointTable);
- }
+ RTMEndpointPrintTable(endpointTable);
}
--- /dev/null
+/* ****************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "routingtablemanager_endpoint.h"
+#include "routingtablemanager.h"
+#include "routingutility.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "include/logger.h"
+
+/**
+ * Logging tag for module name.
+ */
+#define TAG "OIC_RM_TM"
+
+/**
+ * Tag for printing the Routing table.
+ */
+#define RM_TAG "OIC_RM_RAP"
+
+OCStackResult RTMEndpointInitialize(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "RTMEndpointInitialize IN");
+ if (NULL == *endpointTable)
+ {
+ *endpointTable = u_linklist_create();
+ if (NULL == *endpointTable)
+ {
+ OIC_LOG(ERROR, TAG, "Creating Routing Table failed");
+ return OC_STACK_ERROR;
+ }
+ }
+ OIC_LOG(DEBUG, TAG, "RTMEndpointInitialize OUT");
+ return OC_STACK_OK;
+}
+
+/*
+ * Freeing every char pointer of endpoint entry here frees the table.
+ */
+OCStackResult RTMFreeEndpointRouteTable(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == endpointTable || NULL == *endpointTable)
+ {
+ return OC_STACK_OK;
+ }
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(*endpointTable, &iterTable);
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *hop = u_linklist_get_data(iterTable);
+ if (NULL != hop)
+ {
+ OICFree(hop);
+ }
+
+ OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
+ return OC_STACK_ERROR;
+ }
+ }
+ u_linklist_free(endpointTable);
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+/*
+ * Freeing memory first and then Freeing linked list for gateway and endpoint.
+ */
+OCStackResult RTMEndpointTerminate(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ OCStackResult ret = RTMFreeEndpointRouteTable(endpointTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Deleting Endpoint Routing Table failed");
+ }
+ if (NULL != *endpointTable)
+ {
+ *endpointTable = NULL;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+OCStackResult RTMAddEndpointEntry(uint16_t *endpointId, const CAEndpoint_t *destAddr,
+ u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ RM_NULL_CHECK_WITH_RET(endpointId, TAG, "endpointId");
+ RM_NULL_CHECK_WITH_RET(destAddr, TAG, "destAddr");
+ RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
+ if (NULL == *endpointTable)
+ {
+ *endpointTable = u_linklist_create();
+ if (NULL == *endpointTable)
+ {
+ OIC_LOG(ERROR, TAG, "u_linklist_create failed");
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(*endpointTable, &iterTable);
+ // Iterate over gateway list to find if already entry with this gatewayid is present.
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *entry =
+ (RTMEndpointEntry_t *) u_linklist_get_data(iterTable);
+
+ if (NULL != entry && (0 == memcmp(destAddr->addr, entry->destIntfAddr.addr,
+ strlen(entry->destIntfAddr.addr)))
+ && destAddr->port == entry->destIntfAddr.port)
+ {
+ *endpointId = entry->endpointId;
+ OIC_LOG(ERROR, TAG, "Adding failed as Enpoint Entry Already present in Table");
+ return OC_STACK_DUPLICATE_REQUEST;
+ }
+ u_linklist_get_next(&iterTable);
+ }
+
+ // Filling Entry.
+ RTMEndpointEntry_t *hopEntry = (RTMEndpointEntry_t *)OICCalloc(1, sizeof(RTMEndpointEntry_t));
+
+ if (NULL == hopEntry)
+ {
+ OIC_LOG(ERROR, TAG, "Malloc failed for hop entry");
+ return OC_STACK_ERROR;
+ }
+
+ hopEntry->endpointId = *endpointId;
+ hopEntry->destIntfAddr = *destAddr;
+
+ OCStackResult ret = u_linklist_add(*endpointTable, (void *)hopEntry);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Adding Enpoint Entry to Routing Table failed");
+ OICFree(hopEntry);
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+OCStackResult RTMRemoveEndpointEntry(uint16_t endpointId, u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ RM_NULL_CHECK_WITH_RET(endpointTable, TAG, "endpointTable");
+ RM_NULL_CHECK_WITH_RET(*endpointTable, TAG, "*endpointTable");
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(*endpointTable, &iterTable);
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
+ if (NULL != entry && endpointId == entry->endpointId)
+ {
+ OCStackResult ret = u_linklist_remove(*endpointTable, &iterTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Deleting Entry from Routing Table failed");
+ return OC_STACK_ERROR;
+ }
+ OICFree(entry);
+ }
+ else
+ {
+ u_linklist_get_next(&iterTable);
+ }
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+OCStackResult RTMRemoveEndpoints(u_linklist_t **endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == endpointTable || NULL == *endpointTable)
+ {
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+ }
+
+ OCStackResult ret = RTMFreeEndpointRouteTable(endpointTable);
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "Freeing Endpoints failed");
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return OC_STACK_OK;
+}
+
+CAEndpoint_t *RTMGetEndpointEntry(uint16_t endpointId, const u_linklist_t *endpointTable)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == endpointTable)
+ {
+ OIC_LOG(ERROR, TAG, "endpointTable is null");
+ return NULL;
+ }
+
+ u_linklist_iterator_t *iterTable = NULL;
+ u_linklist_init_iterator(endpointTable, &iterTable);
+
+ while (NULL != iterTable)
+ {
+ RTMEndpointEntry_t *entry = u_linklist_get_data(iterTable);
+ if (NULL != entry && (endpointId == entry->endpointId))
+ {
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return &(entry->destIntfAddr);
+ }
+ u_linklist_get_next(&iterTable);
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return NULL;
+}
+
+void RTMEndpointPrintTable(const u_linklist_t *endpointTable)
+{
+ RM_NULL_CHECK_VOID(endpointTable, TAG, "endpointTable");
+
+ OIC_LOG(DEBUG, RM_TAG, "=================Endpoint List table============================\n");
+ u_linklist_iterator_t *iterEndpointTable = NULL;
+ u_linklist_init_iterator(endpointTable, &iterEndpointTable);
+
+ // Iterate over endpoint list to find if already entry for gatewayid is present.
+ while (NULL != iterEndpointTable)
+ {
+ RTMEndpointEntry_t *hop =
+ (RTMEndpointEntry_t *) u_linklist_get_data(iterEndpointTable);
+ if (NULL == hop)
+ {
+ OIC_LOG(ERROR, RM_TAG, "Printing Table Failed");
+ return;
+ }
+ OIC_LOG_V(DEBUG, RM_TAG, "EndpointId : %u\naddr : %s Port : %d Flags : %d",
+ hop->endpointId, hop->destIntfAddr.addr, hop->destIntfAddr.port, hop->destIntfAddr.flags);
+
+ OIC_LOG(DEBUG, RM_TAG, "********************************************\n");
+ u_linklist_get_next(&iterEndpointTable);
+ }
+}
*/
void printACL(const OicSecAcl_t* acl);
+/**
+ * Check if Security ACE permission property matched
+ * @param permission value for matching
+ * @return OC_STACK_OK if permissions matched, else::OC_STACK_ERROR.
+ */
+OCStackResult CheckSecurityACEPermission(uint16_t permission);
+
#ifdef __cplusplus
}
#endif
PS_NO_EXTERNAL_DB_SET = 99, // no external DB set (initial state)
} PSStatus_t;
+//SVR DB Validity status
+typedef enum
+{
+ SVRDB_NOT_VALID = 0,
+ SVRDB_VALID = 1,
+ SVRDB_NOT_CHECKED = 255
+} SVRDBValidStatus_t;
+
/**
* Reads the Secure Virtual Database from PS into dynamically allocated
* memory buffer.
void SetPSStatus(PSStatus_t status);
/**
+ * This function return SVR DB state: valid, not valid or was not checked yet
+ *
+ * @return Status of SVR DB
+ */
+SVRDBValidStatus_t GetSVRDBValidStatus(void);
+
+/**
* This method prints debug log that displays persistent storage status.
*/
void PrintPSStatus(void);
*
* @return pointer on resetSVRDB structure for manipulating with callback
*/
-resetSVRDBCB_t* const GetResetSVRDBCB(void);
+resetSVRDBCB_t* GetResetSVRDBCB(void);
+
+/**
+ * API to validate data in SVR DB.
+ * @return ::OC_STACK_OK on success and other value otherwise.
+ */
+OCStackResult CheckSVRDBValidity(void);
+
+/**
+ * This function check if ResetPF are created
+ * @return true in positive case, false otherwise.
+ */
+bool isResetPFExist(void);
#endif //IOTVT_SRM_PSI_H
*/
OCStackResult SetPstatSelfOwnership(const OicUuid_t* newROwner);
+/**
+ * Gets the cm value for pstat resource.
+ *
+ * @param[out] cm pointer for pstat.cm copy value.
+ *
+ * @retval ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult GetPstatCm(OicSecDpm_t *cm);
+
#ifdef __cplusplus
}
#endif
}
#endif // __cplusplus
+/**
+ * cbor default init
+ */
+#ifndef OC_DEFAULT_CBOR_VALUE
+# if (__STDC_VERSION__ >= 199901L)
+# define OC_DEFAULT_CBOR_VALUE {.parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0}
+# else
+# define OC_DEFAULT_CBOR_VALUE {NULL, NULL, 0, 0, 0, 0}
+# endif
+#endif
+
+#ifndef OC_DEFAULT_CBOR_PARSER
+# if (__STDC_VERSION__ >= 199901L)
+# define OC_DEFAULT_CBOR_PARSER {.end = NULL, .flags = 0}
+# else
+# define OC_DEFAULT_CBOR_PARSER {NULL, 0}
+# endif
+#endif
+
+#ifndef OC_DEFAULT_OICUUID
+# if (__STDC_VERSION__ >= 199901L)
+# define OC_DEFAULT_OICUUID {.id= { 0 } }
+# else
+# define OC_DEFAULT_OICUUID {{ 0 }}
+# endif
+#endif
+
#endif //IOTVT_SRM_UTILITY_H
}
return retVal;
}
+
+OCStackResult CheckSecurityACEPermission(uint16_t permission)
+{
+ OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
+
+ OCStackResult ret = OC_STACK_ERROR;
+ OicSecAce_t *ace = NULL;
+ OicSecAce_t *tempAce = NULL;
+
+ if(NULL == gAcl)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - gAcl is NULL!", __func__);
+ ret = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ LL_FOREACH_SAFE(gAcl->aces, ace, tempAce)
+ {
+ if(0 != memcmp(&ace->subjectuuid, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t)))
+ {
+ continue;
+ }
+
+ OicSecRsrc_t* rsrc = NULL;
+ int flag = 0;
+ LL_FOREACH(ace->resources, rsrc)
+ {
+ if(strncmp(rsrc->href, OIC_RSRC_DOXM_URI, strlen(OIC_RSRC_DOXM_URI) + 1) == 0 ||
+ strncmp(rsrc->href, OIC_RSRC_CRED_URI, strlen(OIC_RSRC_CRED_URI) + 1) == 0 ||
+ strncmp(rsrc->href, OIC_RSRC_PSTAT_URI, strlen(OIC_RSRC_PSTAT_URI) + 1) == 0)
+ {
+ flag = 1;
+ break;
+ }
+ }
+
+ if (flag && !(permission & ace->permission) )
+ {
+ ret = OC_STACK_ERROR;
+ goto exit;
+ }
+ }
+ ret = OC_STACK_OK;
+
+ exit:
+ OIC_LOG_V(DEBUG, TAG, "OUT: %s", __func__);
+ return ret;
+}
{
OIC_LOG_V(DEBUG, TAG, "GetDoxmDevOwnerId(): gDoxm owned = %d.", \
gDoxm->owned);
- if (gDoxm->owned)
+ //if (gDoxm->owned)
{
*devownerid = gDoxm->owner;
retVal = OC_STACK_OK;
OCStackResult retVal = OC_STACK_ERROR;
if (gDoxm)
{
- if( gDoxm->owned )
+ // if( gDoxm->owned )
{
*rowneruuid = gDoxm->rownerID;
retVal = OC_STACK_OK;
#include "psinterface.h"
#include "doxmresource.h"
#include "octhread.h"
+#include "aclresource.h"
+#include "credresource.h"
#define TAG "OIC_SRM_PSI"
// Persistent Storage status
static PSStatus_t g_psStatus = PS_NO_EXTERNAL_DB_SET;
+//SVR DB Validation status
+static SVRDBValidStatus_t g_svrdbValidStatus = SVRDB_NOT_CHECKED;
+
static resetSVRDBCB_t g_resetSVRDBCB = {0};
-resetSVRDBCB_t* const GetResetSVRDBCB(void)
+resetSVRDBCB_t* GetResetSVRDBCB(void)
{
return &g_resetSVRDBCB;
}
+
+/**
+ * Set status of SVR DB after call CheckSVRDBValidity() API
+ */
+static void SetSVRDBValidStatus(SVRDBValidStatus_t status)
+{
+ g_svrdbValidStatus = status;
+}
+
/**
* Update the Persistent Storage Database size.
*/
g_psStatus = status;
}
+SVRDBValidStatus_t GetSVRDBValidStatus()
+{
+ return g_svrdbValidStatus;
+}
+
void PrintPSStatus(void)
{
switch(g_psStatus)
}
}
+
+OCStackResult CheckSVRDBValidity(void)
+{
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+ OCStackResult res = OC_STACK_ERROR;
+ OicUuid_t emptyUuid = OC_DEFAULT_OICUUID;
+ OicUuid_t devOwnerUuid = OC_DEFAULT_OICUUID;
+ OicUuid_t devRownerUuid = OC_DEFAULT_OICUUID;
+ OicUuid_t resRowneruuid = OC_DEFAULT_OICUUID;
+ bool isDevOwnerUuidEmpty = false;
+ bool isDevRownerUuidEmpty = false;
+ bool isPstatRownerUuidEmpty = false;
+ bool isAclRownerUuidEmpty = false;
+ bool isCredRownerUuidEmpty = false;
+ OicSecDpm_t cm = NORMAL;
+
+ bool isOwned = false;
+ res = GetDoxmIsOwned(&isOwned);
+
+ if( OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - doxm is NULL!", __func__);
+ goto exit;
+ }
+
+ if(OC_STACK_OK != GetDoxmDevOwnerId(&devOwnerUuid) ||
+ OC_STACK_OK != GetDoxmRownerId(&devRownerUuid))
+ {
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (0 == memcmp(&devOwnerUuid, &emptyUuid, sizeof(devOwnerUuid)))
+ {
+ isDevOwnerUuidEmpty = true;
+ }
+ else
+ {
+ isDevOwnerUuidEmpty = false;
+ }
+
+ if (0 == memcmp(&devRownerUuid, &emptyUuid, sizeof(devRownerUuid)))
+ {
+ isDevRownerUuidEmpty = true;
+ }
+ else
+ {
+ isDevRownerUuidEmpty = false;
+ }
+
+ if (OC_STACK_OK != GetPstatRownerId(&resRowneruuid))
+ {
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (0 == memcmp(&resRowneruuid, &emptyUuid, sizeof(resRowneruuid)))
+ {
+ isPstatRownerUuidEmpty = true;
+ }
+ else
+ {
+ isPstatRownerUuidEmpty = false;
+ }
+
+ VERIFY_SUCCESS(TAG, OC_STACK_OK == GetPstatCm(&cm), ERROR);
+
+ if (OC_STACK_OK != GetAclRownerId(&resRowneruuid))
+ {
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (0 == memcmp(&resRowneruuid, &emptyUuid, sizeof(resRowneruuid)))
+ {
+ isAclRownerUuidEmpty = true;
+ }
+ else
+ {
+ isAclRownerUuidEmpty = false;
+ }
+
+ if (OC_STACK_OK != GetCredRownerId(&resRowneruuid))
+ {
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (0 == memcmp(&resRowneruuid, &emptyUuid, sizeof(resRowneruuid)))
+ {
+ isCredRownerUuidEmpty = true;
+ }
+ else
+ {
+ isCredRownerUuidEmpty = false;
+ }
+
+ if(true == isOwned)
+ {
+ if ( isDevOwnerUuidEmpty ||isDevRownerUuidEmpty )
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - uuid is empty for owned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if(!GetPstatIsop() || (cm & TAKE_OWNER))
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - isop or cm properties are incorrect!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (isPstatRownerUuidEmpty)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - pstatRownerUuid is empty for owned device!", __func__);
+ res = OC_STACK_ERROR;;
+ goto exit;
+ }
+
+ if (isAclRownerUuidEmpty)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - aclRownerUuid is empty for owned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (isCredRownerUuidEmpty)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - credRownerUuid is empty for owned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (OC_STACK_OK != CheckSecurityACEPermission(PERMISSION_READ))
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - ACE permission doesn't match to READ", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+ }
+ else
+ {
+ if ( !isDevOwnerUuidEmpty ||!isDevRownerUuidEmpty )
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - uuid is not empty for unOwned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (!isPstatRownerUuidEmpty)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - pstatRownerUuid is not empty for unOwned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if(GetPstatIsop() || !(cm & TAKE_OWNER))
+ {
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (!isAclRownerUuidEmpty)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - aclRownerUuid is not empty for unOwned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (!isCredRownerUuidEmpty)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - credRownerUuid is not empty for unOwned device!", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ if (OC_STACK_OK != CheckSecurityACEPermission(PERMISSION_READ | PERMISSION_WRITE))
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - ACE permission doesn't match to READ|WRITE", __func__);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ }
+ res = OC_STACK_OK;
+
+ exit:
+
+ if (OC_STACK_OK != res)
+ {
+ if (isResetPFExist() && !isOwned)
+ {
+ res = ResetSecureResourceInPS();
+ OIC_LOG_V(INFO, TAG, "%s - Secure resources reseted (%d)", __func__, res);
+ }
+ else
+ {
+ res = OC_STACK_INCONSISTENT_DB;
+ }
+ }
+
+ if(OC_STACK_OK == res)
+ {
+ SetSVRDBValidStatus(SVRDB_VALID);
+ }
+ else
+ {
+ SetSVRDBValidStatus(SVRDB_NOT_VALID);
+ }
+ OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+
+ return res;
+}
+
+bool isResetPFExist(void)
+{
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+ bool ret = false;
+ size_t dbSize = 0;
+ uint8_t *dbData = NULL;
+
+ OCStackResult ocRes = OC_STACK_ERROR;
+
+ ocRes = GetSecureVirtualDatabaseFromPS(NULL, &dbData, &dbSize);
+ if (OC_STACK_OK != ocRes)
+ {
+ OIC_LOG_V(ERROR, TAG, "GetSecureVirtualDatabaseFromPS() is failed(%d)", ocRes);
+ }
+ if (dbData && dbSize)
+ {
+ ocRes = OC_STACK_ERROR;
+ {
+ CborParser parser = OC_DEFAULT_CBOR_PARSER;
+ CborValue cbor = OC_DEFAULT_CBOR_VALUE;
+ cbor_parser_init(dbData, dbSize, 0, &parser, &cbor);
+ CborValue curVal = OC_DEFAULT_CBOR_VALUE;
+ CborError cborFindResult = CborNoError;
+
+ cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_RESET_PF_NAME, &curVal);
+ if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+ {
+ OIC_LOG(DEBUG, TAG, "Reset Profile already exists!");
+ ret = true;
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "Reset Profile doesn't exists!");
+ ret = false;
+ }
+ }
+ }
+ OICFree(dbData);
+ OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+
+ return ret;
+}
return ret;
}
+OCStackResult GetPstatCm(OicSecDpm_t *cm)
+{
+ if (gPstat && cm)
+ {
+ *cm = gPstat->cm;
+ return OC_STACK_OK;
+ }
+ return OC_STACK_ERROR;
+}
OCSetRAInfo(&rainfo);
#endif
+#ifdef WITH_PROCESS_EVENT
+ processEvent = oc_event_new();
+ if (!processEvent)
+ {
+ OIC_LOG(INFO, TAG, "oc_event_new failed!");
+ exit (EXIT_FAILURE);
+ }
+#endif
+
OIC_LOG(DEBUG, TAG, "OCServer is starting...");
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
OIC_LOG(INFO, TAG, "Device Registration failed!");
exit (EXIT_FAILURE);
}
-#ifdef WITH_PROCESS_EVENT
- processEvent = oc_event_new();
- if (!processEvent)
- {
- OIC_LOG(INFO, TAG, "oc_event_new failed!");
- exit (EXIT_FAILURE);
- }
+#ifdef WITH_PROCESS_EVENT
OCRegisterProcessEvent(processEvent);
#endif
OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
+ if (OCStop() != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, TAG, "OCStack process error");
+ }
+
#ifdef WITH_PROCESS_EVENT
if (processEvent)
{
}
#endif
- if (OCStop() != OC_STACK_OK)
- {
- OIC_LOG(ERROR, TAG, "OCStack process error");
- }
-
return 0;
}
return OC_STACK_OK;
}
+// TODO: headResource needs to be accessed in a thread-safe manner
OCResource *FindResourceByUri(const char* resourceUri)
{
if(!resourceUri)
OCResource * pointer = headResource;
while (pointer)
{
- if (strcmp(resourceUri, pointer->uri) == 0)
+ if (pointer->uri && strcmp(resourceUri, pointer->uri) == 0)
{
return pointer;
}
}
#endif
+ //check SVR DB Validity
+ OCStackResult validRes = CheckSVRDBValidity();
+
+ if( OC_STACK_INCONSISTENT_DB == validRes)
+ {
+ OIC_LOG_V(ERROR, TAG,"%s - SVR DB is not valid!",__func__);
+ }
+
if(result == OC_STACK_OK)
{
CreateResetProfile();
while (pointer)
{
- if (strncmp(uri, pointer->uri, MAX_URI_LENGTH) == 0)
+ if (pointer->uri && strncmp(uri, pointer->uri, MAX_URI_LENGTH) == 0)
{
OIC_LOG_V(DEBUG, TAG, "Found Resource %s", uri);
return pointer;
if (m_cfg.mode == ModeType::Client)
{
+#ifdef WITH_PROCESS_EVENT
+ if (false == m_threadRun)
+ {
+ m_processEvent = oc_event_new();
+ if (!m_processEvent)
+ {
+ OIC_LOG(INFO, TAG, "oc_event_new failed!");
+ return OC_STACK_ERROR;
+ }
+ }
+#endif
OCTransportFlags serverFlags =
static_cast<OCTransportFlags>(m_cfg.serverConnectivity & CT_MASK_FLAGS);
OCTransportFlags clientFlags =
{
m_threadRun = true;
#ifdef WITH_PROCESS_EVENT
- m_processEvent = oc_event_new();
- if (!m_processEvent)
- {
- OIC_LOG(INFO, TAG, "oc_event_new failed!");
- return OC_STACK_ERROR;
- }
OCRegisterProcessEvent(m_processEvent);
#endif
m_listeningThread = std::thread(&InProcClientWrapper::listeningFunc, this);
#endif
m_listeningThread.join();
}
+ OCStackResult result = OCStop();
+
+ if (OC_STACK_OK != result)
+ {
+ throw InitializeException(OC::InitException::STACK_TERMINATE_ERROR, result);
+ }
#ifdef WITH_PROCESS_EVENT
if (m_processEvent)
m_processEvent = NULL;
}
#endif
- OCStackResult result = OCStop();
-
- if (OC_STACK_OK != result)
- {
- throw InitializeException(OC::InitException::STACK_TERMINATE_ERROR, result);
- }
}
return OC_STACK_OK;
}
OC_STACK_INVALID_PARAM);
}
+#ifdef WITH_PROCESS_EVENT
+ if (false == m_threadRun)
+ {
+ m_processEvent = oc_event_new();
+ if (!m_processEvent)
+ {
+ OIC_LOG(INFO, TAG, "oc_event_new failed!");
+ return OC_STACK_ERROR;
+ }
+ }
+#endif
+
OCTransportFlags serverFlags =
static_cast<OCTransportFlags>(m_cfg.serverConnectivity & CT_MASK_FLAGS);
OCTransportFlags clientFlags =
{
m_threadRun = true;
#ifdef WITH_PROCESS_EVENT
- m_processEvent = oc_event_new();
- if (!m_processEvent)
- {
- OIC_LOG(INFO, TAG, "oc_event_new failed!");
- return OC_STACK_ERROR;
- }
OCRegisterProcessEvent(m_processEvent);
#endif
m_processThread = std::thread(&InProcServerWrapper::processFunc, this);
m_processThread.join();
}
+ OCStackResult res = OCStop();
+
+ if (OC_STACK_OK != res)
+ {
+ throw InitializeException(OC::InitException::STACK_TERMINATE_ERROR, res);
+ }
+
#ifdef WITH_PROCESS_EVENT
if (m_processEvent)
{
}
#endif
- OCStackResult res = OCStop();
-
- if (OC_STACK_OK != res)
- {
- throw InitializeException(OC::InitException::STACK_TERMINATE_ERROR, res);
- }
-
return OC_STACK_OK;
}
OICFree(devConfData);
}
+static OCRepPayload *constructPolicy(OCEntityHandlerRequest *ehRequest, OCResourceHandle handle)
+{
+ OCResourceProperty p = OCGetResourceProperties(handle);
+ OCRepPayload *policy = OCRepPayloadCreate();
+ if (!policy)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+ return NULL;
+ }
+
+ OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
+ ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
+ if (p & OC_SECURE)
+ {
+ OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
+ uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
+ ehRequest->devAddr.flags);
+ OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
+ }
+
+ return policy;
+}
+
OCRepPayload* constructResponseOfWiFiConf(char *interface)
{
OCRepPayload* payload = OCRepPayloadCreate();
OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
(const char **)resourceInterface, dimensions);
- OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESWiFiConfResource.handle);
- OCRepPayload *policy = OCRepPayloadCreate();
- if (!policy)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
- return NULL;
- }
-
- OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
- ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
- if (p & OC_SECURE)
- {
- OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
- uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
- ehRequest->devAddr.flags);
- OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
- }
-
+ OCRepPayload *policy = constructPolicy(ehRequest,
+ (OCResourceHandle *)g_ESWiFiConfResource.handle);
OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
arrayPayload[childResCnt++] = add;
OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
(const char **)resourceInterface, dimensions);
- OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESDevConfResource.handle);
- OCRepPayload *policy = OCRepPayloadCreate();
- if (!policy)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
- return NULL;
- }
-
- OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
- ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
- if (p & OC_SECURE)
- {
- OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
- uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
- ehRequest->devAddr.flags);
- OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
- }
-
+ OCRepPayload *policy = constructPolicy(ehRequest,
+ (OCResourceHandle *)g_ESDevConfResource.handle);
OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
arrayPayload[childResCnt++] = add;
buildscript {
repositories {
+ mavenCentral()
jcenter()
}
dependencies {
allprojects {
repositories {
- jcenter {
- url "http://jcenter.bintray.com/"
- }
+ mavenCentral()
+ jcenter { url "http://jcenter.bintray.com/" }
flatDir {
dirs "../../../../../../android/android_api/base/build/outputs/aar/"
}
std::string bssid;
} SCCandidateAPInfo;
+ static std::vector<SCCandidateAPInfo> getCandidateAPListHelper(OCRepresentation rep)
+ {
+ if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
+ {
+ std::vector<OC::OCRepresentation> candidateInfo =
+ rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
+ std::vector<SCCandidateAPInfo> postcandidateInfo;
+ for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
+ it != candidateInfo.end(); ++it)
+ {
+ OC::OCRepresentation rep = *it;
+ SCCandidateAPInfo candidateInfotemp;
+ if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID))
+ {
+ candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID);
+ }
+ if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE))
+ {
+ candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE);
+ }
+ if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
+ {
+ candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
+ }
+ if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID))
+ {
+ candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID);
+ }
+ postcandidateInfo.push_back(candidateInfotemp);
+ }
+ return postcandidateInfo;
+ }
+ return {};
+ }
+
+ static std::string getEasySetupPropHelper(OCRepresentation easySetupRep, std::string propName)
+ {
+ std::vector<OCRepresentation> children = easySetupRep.getChildren();
+ for(auto child = children.begin(); child != children.end(); ++child)
+ {
+ if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
+ {
+ OCRepresentation rep;
+ if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+ {
+ rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+ }
+ else
+ {
+ return std::string("");
+ }
+
+ if(rep.hasAttribute(propName))
+ {
+ return rep.getValue<std::string>(propName);
+ }
+ }
+ }
+ return std::string("");
+ }
+
+
/**
* @brief Properties of provisioning resource. It includes a provisioning status and last
* error code.
*/
std::vector<SCCandidateAPInfo> getCandidateAPList()
{
- if (m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
- {
- std::vector<OC::OCRepresentation> candidateInfo=
- m_rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
- std::vector<SCCandidateAPInfo> postcandidateInfo;
- for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
- it != candidateInfo.end(); ++it)
- {
- OC::OCRepresentation rep = *it;
- SCCandidateAPInfo candidateInfotemp;
- if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID))
- {
- candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID);
- }
- if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE))
- {
- candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE);
- }
- if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
- {
- candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
-
- }
- if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID))
- {
- candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID);
- }
- postcandidateInfo.push_back(candidateInfotemp);
- }
- return postcandidateInfo;
- }
- return {};
+ return getCandidateAPListHelper(m_rep);
}
/**
*/
std::string getDeviceType() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEVICE_TYPE))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEVICE_TYPE);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_DEVICE_TYPE);
}
/**
*/
std::string getDeviceSubType() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE);
}
/**
*/
std::string getRegisterSetDevice() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV);
}
/**
std::vector<SCCandidateAPInfo> getCandidateAPList() const
{
std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
+ for (auto child = children.begin(); child != children.end(); ++child)
{
- if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
+ if (child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
{
OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+ if (child->hasAttribute(OC_RSRVD_REPRESENTATION))
{
rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
}
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
+ if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
{
- std::vector<OC::OCRepresentation> candidateInfo=rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
- std::vector<SCCandidateAPInfo> postcandidateInfo;
- for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
- it != candidateInfo.end(); ++it)
- {
- OC::OCRepresentation rep = *it;
- SCCandidateAPInfo candidateInfotemp;
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID))
- {
- candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID);
- }
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE))
- {
- candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE);
- }
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
- {
- candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
-
- }
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID))
- {
- candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID);
- }
- postcandidateInfo.push_back(candidateInfotemp);
- }
- return postcandidateInfo;
+ return getCandidateAPListHelper(rep);
}
}
}
*/
std::string getNetworkProvisioningInfo() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO);
}
/**
*/
std::string getSSOList() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSO_LIST))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SSO_LIST);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_SSO_LIST);
}
/**
*/
std::string getTCHeader()
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_HEADER))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_HEADER);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_TC_HEADER);
}
/**
*/
std::string getTCVersion()
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_VERSION))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_VERSION);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_TC_VERSION);
}
/**
*/
std::string getPnpPin() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PNP_PIN))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_PNP_PIN);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_PNP_PIN);
}
/**
*/
std::string getUTCDatetime() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME);
- }
- }
- }
- return {};
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_UTC_DATE_TIME);
}
/**
*/
std::string getRegionalDatetime() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME);
- }
- }
- }
- return {};
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME);
}
/**
*/
std::string getESProtocolVersion() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION);
}
/**
*/
std::string getCountry() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_COUNTRY))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_COUNTRY);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_COUNTRY);
}
/**
*/
std::string getHubId() const
{
- std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
- for(auto child = children.begin(); child != children.end(); ++child)
- {
- if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OCRepresentation rep;
- if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
- {
- rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
- }
- else
- {
- return std::string("");
- }
-
- if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_HUB_ID))
- {
- return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_HUB_ID);
- }
- }
- }
- return std::string("");
+ return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_HUB_ID);
}
-
};
}
}
buildscript {
repositories {
+ mavenCentral()
jcenter()
}
dependencies {
allprojects {
repositories {
+ mavenCentral()
jcenter {
url "http://jcenter.bintray.com/"
}
buildscript {
repositories {
+ mavenCentral()
jcenter()
}
dependencies {
allprojects {
repositories {
+ mavenCentral()
jcenter {
url "http://jcenter.bintray.com/"
}
buildscript {
repositories {
+ mavenCentral()
jcenter()
}
dependencies {
allprojects {
repositories {
+ mavenCentral()
jcenter {
url "http://jcenter.bintray.com/"
}
std::vector< std::string > getInterfaces() const;
private:
+ std::weak_ptr< RCSRemoteResourceObject > weakFromThis();
std::shared_ptr< PrimitiveResource > m_primitiveResource;
CacheID m_cacheId;
BrokerID m_brokerId;
{
SCOPE_LOG_F(DEBUG, TAG);
+ std::shared_ptr<RCSRemoteResourceObject> resource = resourcePtr.lock();
+ if(!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Resource object is null");
+ return OC_STACK_OK;
+ }
+
//If error code is failure then RE Cache module should
//do clean up for caching flags, maps etc.
if(eCode > 4)
{
- OIC_LOG_V(ERROR, TAG, "Error code: %d",eCode);
+ OIC_LOG_V(ERROR, TAG, "Error code: %d", eCode);
try
{
- std::shared_ptr<RCSRemoteResourceObject> resource = resourcePtr.lock();
- if(resource)
- {
- resource->stopCaching();
- }
- else
- {
- OIC_LOG(ERROR, TAG, "Resource object is null");
- }
+ resource->stopCaching();
}
catch(...)
{
//Exception will be thrown: stack will return OC_STACK_ERROR
- // if it already stopped observe. This call is reqired for clearing
+ //if it already stopped observe. This call is reqired for clearing
//Cache manager.
OIC_LOG(DEBUG, TAG, "Cleared Cache");
}
}
}
+ std::weak_ptr< RCSRemoteResourceObject > RCSRemoteResourceObject::weakFromThis()
+ {
+ return shared_from_this();
+ }
+
RCSRemoteResourceObject::Ptr RCSRemoteResourceObject::fromOCResource(
std::shared_ptr< OC::OCResource > ocResource)
{
m_primitiveResource,
std::bind(cachingCallback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
- std::move(cb), shared_from_this()), CACHE_METHOD::OBSERVE_ONLY,
+ std::move(cb), weakFromThis()), CACHE_METHOD::OBSERVE_ONLY,
freq, 0);
}
-
else if (cb)
{
m_cacheId = ResourceCacheManager::getInstance()->requestResourceCache(
m_primitiveResource,
std::bind(cachingCallback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
- std::move(cb), shared_from_this()), CACHE_METHOD::ITERATED_GET,
+ std::move(cb), weakFromThis()), CACHE_METHOD::ITERATED_GET,
freq, 0);
}
else