(void)clazz;
CAUtilCreateBond(env, device);
}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass clazz,
+ jint intervalTime, jint workignCount)
+{
+ LOGI("setLeScanIntervalTimeImpl");
+ (void)env;
+ (void)clazz;
+ CAUtilSetLEScanInterval(intervalTime, workignCount);
+}
+
JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_initialize
(JNIEnv *, jclass, jobject, jobject);
+ /*
+ * Class: Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl
+ * Method: setLeScanIntervalTimeImpl
+ * Signature: (II)V
+ */
+ JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl
+ (JNIEnv *, jclass, jint, jint);
+
#ifdef __cplusplus
}
#endif
#include "JniOcResourceResponse.h"
#include "JniOcSecurity.h"
#include "JniUtils.h"
+#include "ocpayload.h"
using namespace OC;
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0(
JNIEnv *env,
jclass clazz,
- jstring jDeviceName)
+ jstring jDeviceName,
+ jobjectArray jDeviceTypes)
{
LOGI("OcPlatform_registerDeviceInfo");
- std::string deviceName;
- if (jDeviceName)
+ if (!jDeviceName)
{
- deviceName = env->GetStringUTFChars(jDeviceName, nullptr);
+ ThrowOcException(OC_STACK_INVALID_PARAM, "deviceName cannot be null");
+ return;
+ }
+
+ if (!jDeviceTypes)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "deviceTypes cannot be null");
+ return;
}
OCDeviceInfo deviceInfo;
try
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ DuplicateString(&deviceInfo.deviceName, env->GetStringUTFChars(jDeviceName, nullptr));
+ deviceInfo.types = NULL;
+
+ jsize len = env->GetArrayLength(jDeviceTypes);
+ for (jsize i = 0; i < len; ++i)
+ {
+ jstring jStr = (jstring)env->GetObjectArrayElement(jDeviceTypes, i);
+ if (!jStr)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "device type cannot be null");
+ return;
+ }
+
+ OCResourcePayloadAddStringLL(&deviceInfo.types, env->GetStringUTFChars(jStr, nullptr));
+ if (env->ExceptionCheck()) return;
+
+ env->DeleteLocalRef(jStr);
+ }
}
catch (std::exception &e)
{
/*
* Class: org_iotivity_base_OcPlatform
* Method: registerDeviceInfo0
- * Signature: (Ljava/lang/String;)V
+ * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0
- (JNIEnv *, jclass, jstring);
+ (JNIEnv *, jclass, jstring, jobjectArray);
/*
* Class: org_iotivity_base_OcPlatform
* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
+
+#include <map>
+
#include "JniOcRepresentation.h"
#include "JniUtils.h"
/*
* Class: org_iotivity_base_OcRepresentation
+* Method: getValues
+* Signature: ()Ljava/util/Map;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+(JNIEnv *env, jobject thiz)
+{
+ LOGD("OcRepresentation_getValues");
+ OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+ if (!rep) return nullptr;
+
+ std::map<std::string, AttributeValue> values = rep->getValues();
+ jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor);
+ if (!jHashMap) return nullptr;
+
+ for (std::map<std::string, AttributeValue>::const_iterator it = values.begin(); it != values.end(); it++) {
+ jobject key = static_cast<jobject>(env->NewStringUTF(it->first.c_str()));
+ jobject val = boost::apply_visitor(JObjectConverter(env), it->second);
+ env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val);
+ }
+ return jHashMap;
+}
+
+/*
+* Class: org_iotivity_base_OcRepresentation
* Method: getValueN
* Signature: (Ljava/lang/String;)Ljava/lang/Object;
*/
/*
* Class: org_iotivity_base_OcRepresentation
+ * Method: getValues
+ * Signature: ()Ljava/util/Map;
+ */
+ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+ (JNIEnv *, jobject);
+
+ /*
+ * Class: org_iotivity_base_OcRepresentation
* Method: getValueN
* Signature: (Ljava/lang/String;)Ljava/lang/Object;
*/
import android.test.InstrumentationTestCase;
import android.util.Log;
+import java.util.Arrays;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
}
};
- OcDeviceInfo devInfo = new OcDeviceInfo("myDeviceName");
+ OcDeviceInfo devInfo = new OcDeviceInfo(
+ "myDeviceName",
+ Arrays.asList(new String[]{"oic.d.test"})
+ );
try {
//server
package org.iotivity.base;
+import java.util.List;
+
/**
- * This class is expected as input for device properties. Device name is mandatory and expected
- * from the application. Device id of type UUID will be generated by the stack.
+ * This class is expected as input for device properties. Device name and types are mandatory
+ * and expected from the application. Device id of type UUID will be generated by the stack.
*/
public class OcDeviceInfo {
private String mDeviceName;
+ private List<String> mDeviceTypes;
- public OcDeviceInfo(String deviceName) {
-
+ public OcDeviceInfo(String deviceName, List<String> deviceTypes) {
this.mDeviceName = deviceName;
+ this.mDeviceTypes = deviceTypes;
}
public String getDeviceName() {
return mDeviceName;
}
+
+ public List<String> getDeviceTypes() {
+ return mDeviceTypes;
+ }
}
OcDeviceInfo ocDeviceInfo) throws OcException {
OcPlatform.initCheck();
OcPlatform.registerDeviceInfo0(
- ocDeviceInfo.getDeviceName()
+ ocDeviceInfo.getDeviceName(),
+ ocDeviceInfo.getDeviceTypes().toArray(
+ new String[ocDeviceInfo.getDeviceTypes().size()]
+ )
);
}
private static native void registerDeviceInfo0(
- String deviceName
+ String deviceName,
+ String[] deviceTypes
) throws OcException;
/**
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
/**
*
this.mNativeNeedsDelete = nativeNeedsDelete;
}
+ public native Map<String, Object> getValues();
+
public <T> T getValue(String key) throws OcException {
Object obj = this.getValueN(key);
@SuppressWarnings("unchecked")
private static native void caBtPairingStartScan();
private static native void caBtPairingStopScan();
private static native void caBtPairingCreateBond(BluetoothDevice device);
+
+ /**
+ * set BLE scan interval time and working count.
+ * scanning logic (start scan -> stop scan) will be worked repeatly for workingCount.
+ * and if you choose '0' value for workingCount parameter,
+ * scanning will be worked continually as interval time.
+ * @param intervalTime interval time(Seconds).
+ * @param workingCount working count with interval time.
+ */
+
+ public synchronized static void setLeScanIntervalTime(int intervalTime, int workingCount){
+ CaInterface.setLeScanIntervalTimeImpl(intervalTime, workingCount);
+ }
+
+ private static native void setLeScanIntervalTimeImpl(int intervalTime, int workingCount);
}
private final static Map<String, String> DEVICE_INFO_KEYS = new HashMap<String, String>() {{
put("di", "Device ID: ");
put("n", "Device name: ");
- put("lcv", "Spec version url: ");
+ put("icv", "Spec version url: ");
put("dmv", "Data Model: ");
}};
for (String key : DEVICE_INFO_KEYS.keySet()) {
msg("\t" + DEVICE_INFO_KEYS.get(key) + ocRepresentation.getValue(key));
}
+
+ msg("\tDevice types:");
+
+ for (String type : ocRepresentation.getResourceTypes()) {
+ msg("\t\t" + type);
+ }
} catch (OcException e) {
Log.e(TAG, e.toString());
msg("Failed to read device info values.");
import org.iotivity.base.QualityOfService;
import org.iotivity.base.ServiceType;
+import java.util.Arrays;
+
/**
* This sample demonstrates platform and device discovery feature.
* The server sets the platform and device related info. which can be later retrieved by a client.
msg("Configuring platform.");
OcPlatform.Configure(platformConfig);
- OcDeviceInfo deviceInfo = new OcDeviceInfo("myDeviceName");
+ OcDeviceInfo deviceInfo = new OcDeviceInfo(
+ "myDeviceName",
+ Arrays.asList(new String[]{"oic.d.phone"})
+ );
+
try {
msg("Registering device info");
OcPlatform.registerDeviceInfo(deviceInfo);
rm -rf $sourcedir/tmp/extlibs/tinycbor/tinycbor/.git
cp -R ./extlibs/cjson $sourcedir/tmp/extlibs
+cp -R ./extlibs/gtest $sourcedir/tmp/extlibs
cp -R ./extlibs/tinydtls $sourcedir/tmp/extlibs
cp -R ./extlibs/sqlite3 $sourcedir/tmp/extlibs
cp -R ./extlibs/timer $sourcedir/tmp/extlibs
* @param[in] listener callback listener
*/
void CAUtilSetFoundDeviceListener(jobject listener);
+
+/**
+ * set interval time and working count for LE scan.
+ * @param[in] intervalTime interval time(Seconds).
+ * @param[in] workingCount working cycle for selected interval time.
+ *
+ * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
+ */
+CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
+
#endif
#ifdef __cplusplus
static CAGetDTLSPskCredentialsHandler g_getCredentialsCallback = NULL;
/**
- * @var MAX_RETRANSMISSION_TIME
+ * @var RETRANSMISSION_TIME
* @brief Maximum timeout value (in seconds) to start DTLS retransmission.
*/
-#define MAX_RETRANSMISSION_TIME 1
+#define RETRANSMISSION_TIME 1
/**
* @var g_dtlsHandshakeCallback
static void CAStartRetransmit()
{
static int timerId = -1;
- clock_time_t nextSchedule = MAX_RETRANSMISSION_TIME;
-
- OIC_LOG(DEBUG, NET_DTLS_TAG, "CAStartRetransmit IN");
-
if (timerId != -1)
{
//clear previous timer
ca_mutex_unlock(g_dtlsContextMutex);
return;
}
-
- OIC_LOG(DEBUG, NET_DTLS_TAG, "Check retransmission");
- dtls_check_retransmit(g_caDtlsContext->dtlsContext, &nextSchedule);
+ dtls_check_retransmit(g_caDtlsContext->dtlsContext, NULL);
ca_mutex_unlock(g_dtlsContextMutex);
-
- //re-transmission timeout should not be greater then max one
- //this will cover case when several clients start dtls sessions
- nextSchedule /= CLOCKS_PER_SEC;
- if (nextSchedule > MAX_RETRANSMISSION_TIME)
- {
- nextSchedule = MAX_RETRANSMISSION_TIME;
- }
}
-
//start new timer
- OIC_LOG(DEBUG, NET_DTLS_TAG, "Start new timer");
- registerTimer(nextSchedule, &timerId, CAStartRetransmit);
-
- OIC_LOG(DEBUG, NET_DTLS_TAG, "CAStartRetransmit OUT");
+ registerTimer(RETRANSMISSION_TIME, &timerId, CAStartRetransmit);
}
CAResult_t CAAdapterNetDtlsInit()
#define MICROSECS_PER_SEC 1000000
#define WAIT_TIME_WRITE_CHARACTERISTIC 10 * MICROSECS_PER_SEC
+#define WAIT_TIME_SCAN_INTERVAL_DEFAULT 10
+#define WAIT_TIME_SCANNED_CHECKING 30
#define GATT_CONNECTION_PRIORITY_BALANCED 0
#define GATT_FAILURE 257
// it will be prevent to start send logic when adapter has stopped.
static bool g_isStartedLEClient = false;
-static bool g_isStartedScan = false;
static jbyteArray g_sendBuffer = NULL;
static uint32_t g_targetCnt = 0;
static ca_mutex g_deviceScanRetryDelayMutex = NULL;
static ca_cond g_deviceScanRetryDelayCond = NULL;
-static ca_mutex g_scanMutex = NULL;
+static ca_mutex g_threadScanIntervalMutex = NULL;
+static ca_cond g_threadScanIntervalCond = NULL;
+
static ca_mutex g_threadSendStateMutex = NULL;
+static int32_t g_scanIntervalTime = WAIT_TIME_SCAN_INTERVAL_DEFAULT;
+static int32_t g_scanIntervalTimePrev = WAIT_TIME_SCAN_INTERVAL_DEFAULT;
+static int32_t g_intervalCount = 0;
+static bool g_isWorkingScanThread = false;
+static CALEScanState_t g_scanningStep = BLE_SCAN_DISABLE;
+
static CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback = NULL;
/**
return false;
}
+void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount)
+{
+ OIC_LOG_V(DEBUG, TAG, "CALEClientSetScanInterval : %d -> %d",
+ g_scanIntervalTime, intervalTime);
+
+ // previous time should be stored.
+ if (0 < workingCount)
+ {
+ g_scanIntervalTimePrev = g_scanIntervalTime;
+ }
+ g_scanIntervalTime = intervalTime;
+ g_intervalCount = workingCount;
+}
+
+void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount)
+{
+ // restart scan with interval
+ CALEClientSetScanInterval(intervalTime, workingCount);
+ ca_cond_signal(g_threadScanIntervalCond);
+}
+
+static void CALEScanThread(void* object)
+{
+ (void)object;
+
+ bool isAttached = false;
+ JNIEnv* env;
+ 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;
+ }
+
+ ca_mutex_lock(g_threadScanIntervalMutex);
+ while(g_isWorkingScanThread)
+ {
+ OIC_LOG(DEBUG, TAG, "scan waiting time out");
+ if (BLE_SCAN_ENABLE == g_scanningStep)
+ {
+ //stop scan
+ CAResult_t ret = CALEClientStopScan();
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG(INFO, TAG, "CALEClientStopScan has failed");
+ }
+ }
+ else
+ {
+ //start scan
+ CAResult_t ret = CALEClientStartScan();
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG(INFO, TAG, "CALEClientStartScan has failed");
+ }
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "wait for Scan Interval Time during %d sec", g_scanIntervalTime);
+ if (CA_WAIT_SUCCESS == ca_cond_wait_for(g_threadScanIntervalCond,
+ g_threadScanIntervalMutex,
+ g_scanIntervalTime * MICROSECS_PER_SEC))
+ {
+ // called signal scan thread will be terminated
+ OIC_LOG(DEBUG, TAG, "signal scanInterval waiting");
+ g_scanningStep = BLE_SCAN_DISABLE;
+ }
+ else
+ {
+ if (BLE_SCAN_ENABLE == g_scanningStep)
+ {
+ if (g_intervalCount > 0)
+ {
+ if (g_intervalCount == 1)
+ {
+ OIC_LOG(DEBUG, TAG, "reset default time");
+ CALEClientSetScanInterval(g_scanIntervalTimePrev, 0);
+ }
+ g_intervalCount--;
+ OIC_LOG_V(DEBUG, TAG, "interval count : %d", g_intervalCount);
+ }
+ g_scanningStep = BLE_SCAN_DISABLE;
+ }
+ else
+ {
+ g_scanningStep = BLE_SCAN_ENABLE;
+ }
+ }
+ }
+ ca_mutex_unlock(g_threadScanIntervalMutex);
+
+ if (isAttached)
+ {
+ (*g_jvm)->DetachCurrentThread(g_jvm);
+ }
+}
+
+CAResult_t CALEClientStartScanWithInterval()
+{
+ OIC_LOG(DEBUG, TAG, "IN - CALEClientStartScanWithInterval");
+
+ if (g_isWorkingScanThread)
+ {
+ OIC_LOG(DEBUG, TAG, "scan interval logic already running");
+ return CA_STATUS_OK;
+ }
+
+ // initialize scan flags
+ g_scanningStep = BLE_SCAN_DISABLE;
+ g_isWorkingScanThread = true;
+ g_intervalCount = 0;
+ g_scanIntervalTime = g_scanIntervalTimePrev;
+
+ if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle,
+ CALEScanThread, NULL))
+ {
+ OIC_LOG(ERROR, TAG, "Failed to create read thread!");
+ g_isWorkingScanThread = false;
+ return CA_STATUS_FAILED;
+ }
+
+ OIC_LOG(DEBUG, TAG, "OUT - CALEClientStartScanWithInterval");
+ return CA_STATUS_OK;
+}
+
+void CALEClientStopScanWithInterval()
+{
+ g_isWorkingScanThread = false;
+ ca_cond_signal(g_threadScanIntervalCond);
+}
+
//getting jvm
void CALEClientJniInit()
{
g_threadCond = ca_cond_new();
g_threadWriteCharacteristicCond = ca_cond_new();
g_deviceScanRetryDelayCond = ca_cond_new();
+ g_threadScanIntervalCond = ca_cond_new();
CALEClientCreateDeviceList();
CALEClientJNISetContext();
OIC_LOG(ERROR, TAG, "CALEClientRemoveAllGattObjs has failed");
}
- CALEClientSetScanFlag(false);
CALEClientSetSendFinishFlag(true);
CALEClientTerminateGattMutexVariables();
ca_cond_free(g_threadCond);
ca_cond_free(g_threadWriteCharacteristicCond);
ca_cond_free(g_deviceScanRetryDelayCond);
+ ca_cond_free(g_threadScanIntervalCond);
g_deviceDescCond = NULL;
g_threadCond = NULL;
g_threadWriteCharacteristicCond = NULL;
g_deviceScanRetryDelayCond = NULL;
+ g_threadScanIntervalCond = NULL;
g_isSignalSetFlag = false;
+ // stop scanning
+ CALEClientStopScanWithInterval();
+
if (isAttached)
{
(*g_jvm)->DetachCurrentThread(g_jvm);
static uint64_t const TIMEOUT =
2 * MICROSECS_PER_SEC; // Microseconds
+ // set scan interval and start scan
+ CALERestartScanWithInterval(WAIT_TIME_SCANNED_CHECKING, 1);
+
bool devicesDiscovered = false;
for (size_t i = 0; i < RETRIES; ++i)
{
}
}
+ // reset scan interval time after checking scanned devices
+ CALERestartScanWithInterval(g_scanIntervalTimePrev, 0);
+
// time out for scanning devices
if (!devicesDiscovered)
{
CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t* data,
- const uint32_t dataLen)
+ const uint32_t dataLen)
{
OIC_LOG_V(DEBUG, TAG, "CALEClientSendUnicastMessageImpl, address: %s, data: %p", address,
data);
(*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
(*env)->DeleteLocalRef(env, jni_setAddress);
- // connect to gatt server
- ret = CALEClientStopScan();
- if (CA_STATUS_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
- goto error_exit;
- }
+ // stop scan while sending
+ CALEClientStopScanWithInterval();
if (g_sendBuffer)
{
}
// start LE Scan again
- ret = CALEClientStartScan();
+ ret = CALEClientStartScanWithInterval();
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+ OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
ca_mutex_unlock(g_threadSendMutex);
return ret;
}
error_exit:
// start LE Scan again
- ret = CALEClientStartScan();
+ ret = CALEClientStartScanWithInterval();
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+ OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
ca_mutex_unlock(g_threadSendMutex);
if (isAttached)
{
goto error_exit;
}
- // connect to gatt server
- res = CALEClientStopScan();
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
- ca_mutex_unlock(g_threadSendMutex);
- return res;
- }
+ // stop scan while sending
+ CALEClientStopScanWithInterval();
+
uint32_t length = u_arraylist_length(g_deviceList);
g_targetCnt = length;
ca_mutex_unlock(g_threadMutex);
// start LE Scan again
- res = CALEClientStartScan();
+ res = CALEClientStartScanWithInterval();
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+ OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
ca_mutex_unlock(g_threadSendMutex);
return res;
}
return CA_STATUS_OK;
error_exit:
- res = CALEClientStartScan();
+ res = CALEClientStartScanWithInterval();
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+ OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
ca_mutex_unlock(g_threadSendMutex);
return res;
}
return CA_STATUS_FAILED;
}
- if (g_isStartedScan)
- {
- OIC_LOG(INFO, TAG, "scanning is already started");
- return CA_STATUS_OK;
- }
-
bool isAttached = false;
JNIEnv* env;
jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_mid_startLeScan)
{
OIC_LOG(ERROR, TAG, "startLeScan: jni_mid_startLeScan is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_obj_BTAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
else
{
OIC_LOG(DEBUG, TAG, "LeScan has started");
- CALEClientSetScanFlag(true);
}
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return CA_STATUS_OK;
}
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_mid_startLeScan)
{
OIC_LOG(ERROR, TAG, "startLeScan: jni_mid_startLeScan is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_obj_BTAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
else
{
OIC_LOG(DEBUG, TAG, "LeScan has started");
- CALEClientSetScanFlag(true);
}
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return CA_STATUS_OK;
}
return CA_STATUS_FAILED;
}
- if (!g_isStartedScan)
- {
- OIC_LOG(INFO, TAG, "scanning is already stopped");
- return CA_STATUS_OK;
- }
-
bool isAttached = false;
JNIEnv* env;
jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
OIC_LOG(ERROR, TAG, "CALEClientStopScanImpl has failed");
}
}
- else
- {
- CALEClientSetScanFlag(false);
- }
if (isAttached)
{
return ret;
}
-void CALEClientSetScanFlag(bool flag)
-{
- ca_mutex_lock(g_scanMutex);
- g_isStartedScan = flag;
- ca_mutex_unlock(g_scanMutex);
-}
-
CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback)
{
OIC_LOG(DEBUG, TAG, "CALEClientStopScanImpl");
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_mid_stopLeScan)
{
OIC_LOG(ERROR, TAG, "stopLeScan: jni_mid_stopLeScan is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if ((*env)->ExceptionCheck(env))
{
OIC_LOG(ERROR, TAG, "stopLeScan has failed");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return CA_STATUS_OK;
}
if (!g_deviceList)
{
OIC_LOG(ERROR, TAG, "gdevice_list is null");
-
- CALEClientSetScanFlag(false);
- if (CA_STATUS_OK != CALEClientStopScan())
- {
- OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
- }
+ CALEClientStopScanWithInterval();
ca_mutex_unlock(g_deviceListMutex);
return CA_STATUS_FAILED;
}
}
- if (NULL == g_scanMutex)
- {
- g_scanMutex = ca_mutex_new();
- if (NULL == g_scanMutex)
- {
- OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
- return CA_STATUS_FAILED;
- }
- }
-
if (NULL == g_threadWriteCharacteristicMutex)
{
g_threadWriteCharacteristicMutex = ca_mutex_new();
}
}
+ if (NULL == g_threadScanIntervalMutex)
+ {
+ g_threadScanIntervalMutex = ca_mutex_new();
+ if (NULL == g_threadScanIntervalMutex)
+ {
+ OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
+ return CA_STATUS_FAILED;
+ }
+ }
+
return CA_STATUS_OK;
}
ca_mutex_free(g_SendFinishMutex);
g_SendFinishMutex = NULL;
- ca_mutex_free(g_scanMutex);
- g_scanMutex = NULL;
-
ca_mutex_free(g_threadWriteCharacteristicMutex);
g_threadWriteCharacteristicMutex = NULL;
ca_mutex_free(g_threadSendStateMutex);
g_threadSendStateMutex = NULL;
+
+ ca_mutex_free(g_threadScanIntervalMutex);
+ g_threadScanIntervalMutex = NULL;
}
void CALEClientSetSendFinishFlag(bool flag)
g_threadWriteCharacteristicCond = ca_cond_new();
}
- CAResult_t ret = CALEClientStartScan();
+ CAResult_t ret = CALEClientStartScanWithInterval();
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+ OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
return ret;
}
OIC_LOG(ERROR, TAG, "CALEClientDisconnectAll has failed");
}
- ret = CALEClientStopScan();
- if(CA_STATUS_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
- }
+ CALEClientStopScanWithInterval();
ca_mutex_lock(g_threadMutex);
OIC_LOG(DEBUG, TAG, "signal - connection cond");
ca_cond_signal(g_deviceScanRetryDelayCond);
ca_mutex_unlock(g_deviceScanRetryDelayMutex);
+ ca_mutex_lock(g_threadScanIntervalMutex);
+ OIC_LOG(DEBUG, TAG, "signal - delay cond");
+ ca_cond_signal(g_threadScanIntervalCond);
+ ca_mutex_unlock(g_threadScanIntervalMutex);
+
ca_cond_free(g_deviceDescCond);
ca_cond_free(g_threadCond);
ca_cond_free(g_threadWriteCharacteristicCond);
ca_cond_free(g_deviceScanRetryDelayCond);
+ ca_cond_free(g_threadScanIntervalCond);
g_deviceDescCond = NULL;
g_threadCond = NULL;
g_threadWriteCharacteristicCond = NULL;
g_deviceScanRetryDelayCond = NULL;
+ g_threadScanIntervalCond = NULL;
if (isAttached)
{
} CALEState_t;
/**
+ * BLE Scanning State.
+ */
+typedef enum
+{
+ BLE_SCAN_ENABLE = 0, /**< BLE scan is working */
+ BLE_SCAN_DISABLE /**< BLE scan is not working */
+} CALEScanState_t;
+
+/**
* Callback to be notified on reception of any data from remote devices.
* @param[in] address MAC address of remote device.
* @param[in] data Data received from remote device.
CAResult_t CALEClientStopScan();
/**
- * set ble scanning flag.
- * @param[in] flag scan flag.
- */
-void CALEClientSetScanFlag(bool flag);
-
-/**
* stop scan (implement).
* @param[in] env JNI interface pointer.
* @param[in] callback callback to receive device object by scanning.
*/
CAResult_t CALEClientDirectConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect);
+/**
+ * set new interval time and working count.
+ * @param[in] intervalTime interval time(Seconds).
+ * @param[in] workingCount working count for selected interval time.
+ */
+void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount);
+
+/**
+ * restart scanning with new interval time and working count.
+ * @param[in] intervalTime interval time(Seconds).
+ * @param[in] workingCount working count for selected interval time.
+ */
+void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount);
+
+/**
+ * start LE scanning logic with interval time and working count.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientStartScanWithInterval();
+
+/**
+ * stop LE scanning logic with interval time and cycle.
+ */
+void CALEClientStopScanWithInterval();
+
#ifdef __cplusplus
} /* extern "C" */
#endif
OIC_LOG(ERROR, TAG, "CALEServerRemoveAllDevices has failed");
}
- CALEClientSetScanFlag(false);
-
CANetworkStatus_t newStatus = CA_INTERFACE_DOWN;
g_bleDeviceStateChangedCallback(newStatus);
}
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return JNI_FALSE;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return JNI_FALSE;
}
if (!jni_mid_isEnable)
{
OIC_LOG(ERROR, TAG, "jni_mid_isEnable is null");
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return JNI_FALSE;
}
jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
OIC_LOG_V(DEBUG, TAG, "adapter state is %d", jni_isEnable);
+ (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return jni_isEnable;
}
* @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CAManagerLEClientTerminate(JNIEnv *env);
+
+/**
+ * set BLE scan interval time and working count.
+ * @param[in] intervalTime interval time(Seconds).
+ * @param[in] workingCount working count for selected interval time.
+ */
+void CAManagerLESetScanInterval(jint intervalTime, jint workingCount);
+
#endif
#ifdef __cplusplus
return res;
}
+void CAManagerLESetScanInterval(jint interval, jint count)
+{
+ OIC_LOG(DEBUG, TAG, "CAManagerLESetScanInterval");
+ CALERestartScanWithInterval(interval, count);
+}
+
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback(
JNIEnv *env, jobject obj, jint state)
static void CAManagerConnectionMonitorHandler(const CAEndpoint_t *info, bool isConnected)
{
- if (!info || !info->addr)
+ if (!info || !info->addr[0])
{
OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
return;
(void)listener;
#endif
}
+
+CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount)
+{
+ OIC_LOG(DEBUG, TAG, "CAUtilSetLEScanInterval");
+#ifdef LE_ADAPTER
+ CAManagerLESetScanInterval(intervalTime, workingCount);
+ return CA_STATUS_OK;
+#else
+ OIC_LOG(DEBUG, TAG, "it is not supported");
+ return CA_NOT_SUPPORTED;
+#endif
+}
#endif
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerTransferModeToResource(OTMContext_t* otmCtx);
/**
* Function to send request to resource to get its pstat resource information.
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx);
/**
* Function to update the operation mode. As per the spec. Operation mode in client driven
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx);
+static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx);
/**
* Function to update the owner credential to new device
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx);
+static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx);
/**
* Function to update pstat as Ready for provisioning.
* @param[in] selectedDevice selected device information to performing provisioning.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx);
+static OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx);
/**
* Function to update pstat as Ready for Normal Operation.
* @param[in] selectedDevice selected device information to performing provisioning.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx);
+static OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx);
static bool IsComplete(OTMContext_t* otmCtx)
{
false == newDevDoxm->owned &&
memcmp(&(newDevDoxm->owner), &emptyUuid, sizeof(OicUuid_t)) == 0)
{
- //Send request : PUT /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
- res = PutOwnerUuid(g_otmCtx);
+ //Send request : POST /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
+ res = PostOwnerUuid(g_otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "OperationModeUpdate : Failed to send owner information");
//Select operation mode (Currently supported SINGLE_SERVICE_CLIENT_DRIVEN only)
SelectOperationMode(otmCtx->selectedDeviceInfo, &(otmCtx->selectedDeviceInfo->pstat->om));
- //Send request : PUT /oic/sec/pstat [{"om":"bx11", .. }]
- OCStackResult res = PutUpdateOperationMode(otmCtx);
+ //Send request : POST /oic/sec/pstat [{"om":"bx11", .. }]
+ OCStackResult res = PostUpdateOperationMode(otmCtx);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Error while updating operation mode.");
}
}
- //PUT /oic/sec/doxm [{ ..., "owned":"TRUE" }]
- res = PutOwnershipInformation(otmCtx);
+ //POST /oic/sec/doxm [{ ..., "owned":"TRUE" }]
+ res = PostOwnershipInformation(otmCtx);
if(OC_STACK_OK != res)
{
- OIC_LOG(ERROR, TAG, "Failed to put ownership information to new device");
+ OIC_LOG(ERROR, TAG, "Failed to post ownership information to new device");
SetResult(otmCtx, res);
return OC_STACK_DELETE_TRANSACTION;
}
OIC_LOG(INFO, TAG, "Ownership transfer was successfully completed.");
OIC_LOG(INFO, TAG, "Set Ready for provisioning state .");
- res = PutProvisioningStatus(otmCtx);
+ res = PostProvisioningStatus(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to update pstat");
{
OIC_LOG(INFO, TAG, "Device state is in Ready for Provisionig.");
- res = PutNormalOperationStatus(otmCtx);
+ res = PostNormalOperationStatus(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to update pstat");
return OC_STACK_OK;
}
-static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerTransferModeToResource(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutOwnerTransferModeToResource");
+ OIC_LOG(DEBUG, TAG, "IN PostOwnerTransferModeToResource");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI))
{
- OIC_LOG(ERROR, TAG, "PutOwnerTransferModeToResource : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostOwnerTransferModeToResource : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
cbData.cb = &OwnerTransferModeHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- res = OCDoResource(NULL, OC_REST_PUT, query,
+ res = OCDoResource(NULL, OC_REST_POST, query,
&deviceInfo->endpoint, (OCPayload *)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutOwnerTransferModeToResource");
+ OIC_LOG(DEBUG, TAG, "OUT PostOwnerTransferModeToResource");
return res;
}
return res;
}
-static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutOwnerUuid");
+ OIC_LOG(DEBUG, TAG, "IN PostOwnerUuid");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI))
{
- OIC_LOG(ERROR, TAG, "PutOwnershipInformation : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostOwnerUuid : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
- //PUT PT's uuid to new device
+ //Post PT's uuid to new device
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload *)secPayload,
+ res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload *)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutOwnerUuid");
+ OIC_LOG(DEBUG, TAG, "OUT PostOwnerUuid");
return res;
}
-static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx)
+static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutOwnershipInformation");
+ OIC_LOG(DEBUG, TAG, "IN PostOwnershipInformation");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI))
{
- OIC_LOG(ERROR, TAG, "PutOwnershipInformation : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostOwnershipInformation : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+ res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutOwnershipInformation");
+ OIC_LOG(DEBUG, TAG, "OUT PostOwnershipInformation");
return res;
}
-static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx)
+static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutUpdateOperationMode");
+ OIC_LOG(DEBUG, TAG, "IN PostUpdateOperationMode");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
- OIC_LOG(ERROR, TAG, "PutUpdateOperationMode : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostUpdateOperationMode : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
cbData.cb = &OperationModeUpdateHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload *)secPayload,
+ res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload *)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutUpdateOperationMode");
+ OIC_LOG(DEBUG, TAG, "OUT PostUpdateOperationMode");
return res;
}
}
OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
- //Send Req: PUT /oic/sec/doxm [{..."OxmSel" :g_OTMDatas[Index of Selected OxM].OXMString,...}]
- res = PutOwnerTransferModeToResource(otmCtx);
+ //Send Req: POST /oic/sec/doxm [{..."OxmSel" :g_OTMDatas[Index of Selected OxM].OXMString,...}]
+ res = PostOwnerTransferModeToResource(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(WARNING, TAG, "Failed to select the provisioning method");
return res;
}
-OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
+OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
{
- OIC_LOG(INFO, TAG, "IN PutProvisioningStatus");
+ OIC_LOG(INFO, TAG, "IN PostProvisioningStatus");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
otmCtx->selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
- OIC_LOG(ERROR, TAG, "PutProvisioningStatus : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostProvisioningStatus : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
cbData.cb = &ProvisioningStatusHandler;
cbData.context = (void*)otmCtx;
cbData.cd = NULL;
- OCStackResult ret = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+ OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
if (ret != OC_STACK_OK)
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(INFO, TAG, "OUT PutProvisioningStatus");
+ OIC_LOG(INFO, TAG, "OUT PostProvisioningStatus");
return ret;
}
-OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx)
+OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
{
- OIC_LOG(INFO, TAG, "IN PutNormalOperationStatus");
+ OIC_LOG(INFO, TAG, "IN PostNormalOperationStatus");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
otmCtx->selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
- OIC_LOG(ERROR, TAG, "PutNormalOperationStatus : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostNormalOperationStatus : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
cbData.cb = &ReadyForNomalStatusHandler;
cbData.context = (void*)otmCtx;
cbData.cd = NULL;
- OCStackResult ret = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+ OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
if (ret != OC_STACK_OK)
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(INFO, TAG, "OUT PutNormalOperationStatus");
+ OIC_LOG(INFO, TAG, "OUT PostNormalOperationStatus");
return ret;
}
#define TAG "SRM-ACL"
#define NUMBER_OF_SEC_PROV_RSCS 4
#define NUMBER_OF_DEFAULT_SEC_RSCS 2
+#define STRING_UUID_SIZE (UUID_LENGTH * 2 + 5)
static const uint8_t ACL_MAP_SIZE = 2;
static const uint8_t ACL_ACLIST_MAP_SIZE = 1;
{
if (strncasecmp((char *) parseIter.attrPos, OIC_JSON_SUBJECTID_NAME, parseIter.attrLen) == 0)
{
+ char strUuid[STRING_UUID_SIZE] = {0};
VERIFY_SUCCESS(TAG, 0 != parseIter.valLen, ERROR);
- memcpy(subject->id, parseIter.valPos, parseIter.valLen);
+ memcpy(strUuid, parseIter.valPos, parseIter.valLen);
+ OCStackResult res = ConvertStrToUuid(strUuid, subject);
+ VERIFY_SUCCESS(TAG, OC_STACK_OK == res, ERROR);
return true;
}
}
return ehRet;
}
-static OCEntityHandlerResult HandleDoxmPutRequest(const OCEntityHandlerRequest * ehRequest)
+static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest * ehRequest)
{
- OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing PUT request");
+ OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing POST request");
OCEntityHandlerResult ehRet = OC_EH_ERROR;
OicUuid_t emptyOwner = {.id = {0} };
ehRet = HandleDoxmGetRequest(ehRequest);
break;
- case OC_REST_PUT:
- ehRet = HandleDoxmPutRequest(ehRequest);
+ case OC_REST_POST:
+ ehRet = HandleDoxmPostRequest(ehRequest);
break;
default:
* resource or create a new resource.
* For pstat, it updates only tm and om.
*/
-static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest *ehRequest)
+static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest *ehRequest)
{
OCEntityHandlerResult ehRet = OC_EH_ERROR;
- OIC_LOG(INFO, TAG, "HandlePstatPutRequest processing PUT request");
+ OIC_LOG(INFO, TAG, "HandlePstatPostRequest processing POST request");
OicSecPstat_t *pstat = NULL;
if (ehRequest->payload)
case OC_REST_GET:
ehRet = HandlePstatGetRequest(ehRequest);
break;
- case OC_REST_PUT:
- ehRet = HandlePstatPutRequest(ehRequest);
+ case OC_REST_POST:
+ ehRet = HandlePstatPostRequest(ehRequest);
break;
default:
ehRet = OC_EH_ERROR;
ASSERT_TRUE(convertedAcl != NULL);
EXPECT_EQ(defaultAcl->resourcesLen, convertedAcl->resourcesLen);
- for(int i = 0; i < convertedAcl->resourcesLen; i++)
+ for(size_t i = 0; i < convertedAcl->resourcesLen; i++)
{
EXPECT_EQ(0, strcmp(defaultAcl->resources[i], convertedAcl->resources[i]));
}
// Create Entity Handler DELETE request
ehReq.method = OC_REST_DELETE;
- char query[] = "subjectuuid=2222222222222222;resources=/a/led";
+ char query[] = "subjectuuid=32323232-3232-3232-3232-323232323232;resources=/a/led";
ehReq.query = (char *)OICMalloc(strlen(query)+1);
ASSERT_TRUE(NULL != ehReq.query);
OICStrcpy(ehReq.query, strlen(query)+1, query);
// Create Entity Handler DELETE request
ehReq.method = OC_REST_DELETE;
- char query[] = "subjectuuid=2222222222222222;resources=/a/led";
+ char query[] = "subjectuuid=32323232-3232-3232-3232-323232323232;resources=/a/led";
ehReq.query = (char *)OICMalloc(strlen(query)+1);
ASSERT_TRUE(NULL != ehReq.query);
OICStrcpy(ehReq.query, strlen(query)+1, query);
//Create Entity Handler GET request wit query
ehReq.method = OC_REST_GET;
- char query[] = "subjectuuid=2222222222222222;resources=/a/led";
+ char query[] = "subjectuuid=32323232-3232-3232-3232-323232323232;resources=/a/led";
ehReq.query = (char*)OICMalloc(strlen(query)+1);
ASSERT_TRUE(NULL != ehReq.query);
OICStrcpy(ehReq.query, strlen(query)+1, query);
OCPayload base;
char* uri;
OCPlatformInfo info;
- char* rt;
+ OCStringLL* rt;
OCStringLL* interfaces;
} OCPlatformPayload;
if (payload->rt)
{
OIC_LOG(level, PL_TAG, "\tResource Types:");
- OIC_LOG_V(level, PL_TAG, "\t\t%s", payload->rt);
+ for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ }
}
if (payload->interfaces)
{
case OCREP_PROP_STRING:
dest->str = OICStrdup(source->str);
break;
+ case OCREP_PROP_BYTE_STRING:
+ dest->ocByteStr.bytes = (uint8_t*)OICMalloc(source->ocByteStr.len * sizeof(uint8_t));
+ VERIFY_PARAM_NON_NULL(TAG, dest->ocByteStr.bytes, "Failed allocating memory");
+ dest->ocByteStr.len = source->ocByteStr.len;
+ memcpy(dest->ocByteStr.bytes, source->ocByteStr.bytes, dest->ocByteStr.len);
+ break;
case OCREP_PROP_OBJECT:
dest->obj = OCRepPayloadClone(source->obj);
break;
// Nothing to do for the trivially copyable types.
break;
}
+exit:
+ return;
}
static void OCFreeRepPayloadValueContents(OCRepPayloadValue* val)
return NULL;
}
-static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort,
- uint16_t tcpPort)
+static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort)
{
OCResourcePayload* pl = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
if (!pl)
void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
uint16_t securePort, uint16_t tcpPort)
{
- OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, tcpPort));
+ OC_UNUSED(tcpPort);
+ OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort));
}
bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, const char *value)
return NULL;
}
payload->interfaces->value = OICStrdup(OC_RSRVD_INTERFACE_READ);
- payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
+ payload->rt = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
+ if (!payload->rt)
+ {
+ return NULL;
+ }
+ payload->rt->value = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
payload->info = *platformInfo;
return payload;
}
payload->base.type = PAYLOAD_TYPE_PLATFORM;
- payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
+ OCResourcePayloadAddStringLL(&payload->rt, OC_RSRVD_RESOURCE_TYPE_PLATFORM);
OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_DEFAULT);
OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_READ);
}
OICFree(payload->uri);
OCPlatformInfoDestroy(&payload->info);
- OICFree(payload->rt);
+ OCFreeOCStringLL(payload->rt);
OCFreeOCStringLL(payload->interfaces);
OICFree(payload);
}
// Resource type
if (payload->rt)
{
- err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_RESOURCE_TYPE,
- sizeof(OC_RSRVD_RESOURCE_TYPE) - 1, payload->rt);
+ err |= OCStringLLJoin(&repMap, OC_RSRVD_RESOURCE_TYPE, payload->rt);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding resource type.");
}
OCStackResult ret = OC_STACK_INVALID_PARAM;
CborError err = CborNoError;
OCPlatformInfo info = {0};
- char* rt = NULL;
+ OCStringLL* rt = NULL;
OCStringLL* interfaces = NULL;
OCPlatformPayload* out = NULL;
if(cbor_value_is_valid(&repVal))
{
- err = cbor_value_dup_text_string(&repVal, &rt, &len, NULL);
+ err = OCParseStringLL(rootValue, OC_RSRVD_RESOURCE_TYPE, &rt);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find resource type in the platform payload");
}
extern "C"
{
+ #include "ocpayload.h"
#include "ocstack.h"
#include "ocstackinternal.h"
#include "logger.h"
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+
+TEST(StackPayload, CloneByteString)
+{
+ uint8_t bytes[] = { 0, 1, 2, 3 };
+ OCByteString byteString;
+ byteString.bytes = bytes;
+ byteString.len = sizeof(bytes);
+
+ OCRepPayload *original = OCRepPayloadCreate();
+ ASSERT_TRUE(original != NULL);
+ EXPECT_TRUE(OCRepPayloadSetPropByteString(original, "name", byteString));
+
+ OCRepPayload *clone = OCRepPayloadClone(original);
+ ASSERT_TRUE(clone != NULL);
+
+ OCRepPayloadDestroy(original);
+
+ OCByteString cloneByteString;
+ EXPECT_TRUE(OCRepPayloadGetPropByteString(clone, "name", &cloneByteString));
+ ASSERT_TRUE(cloneByteString.bytes != NULL);
+ EXPECT_EQ(sizeof(bytes), cloneByteString.len);
+ EXPECT_TRUE(0 == memcmp(bytes, cloneByteString.bytes, sizeof(bytes)));
+ OICFree(cloneByteString.bytes);
+
+ OCRepPayloadDestroy(clone);
+}
m_values[str] = std::forward<T>(val);
}
+ const std::map<std::string, AttributeValue>& getValues() const {
+ return m_values;
+ }
+
/**
* Retrieve the attribute value associated with the supplied name
*
std::string(payload->info.systemTime) :
std::string();
- if (payload->rt)
+ for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
{
- rep.addResourceType(payload->rt);
+ rep.addResourceType(strll->value);
}
for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
{
EXPECT_STREQ(time1, platform->info.systemTime);
EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, platform->interfaces->value);
EXPECT_STREQ(OC_RSRVD_INTERFACE_READ, platform->interfaces->next->value);
- EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt);
+ EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt->value);
uint8_t* cborData;
size_t cborSize;
EXPECT_STREQ(platform->info.supportUrl, platform->info.supportUrl);
EXPECT_STREQ(platform->info.systemTime, platform2->info.systemTime);
EXPECT_STREQ(platform->interfaces->value, platform2->interfaces->value);
- EXPECT_STREQ(platform->rt, platform2->rt);
+ EXPECT_STREQ(platform->rt->value, platform2->rt->value);
OCPayloadDestroy((OCPayload*)platform);