From 2dfa7e3e2fa58140f41bebe1ffdc021f6bb337df Mon Sep 17 00:00:00 2001 From: Dan Mihai Date: Thu, 12 Jan 2017 16:52:43 -0800 Subject: [PATCH] [IOT-1538] Add support for Protocol-Independent ID Per OCF Core CR 64: add support for a protocol-independent ID of a device, in /oic/d, for use with de-duping information discovered via more than one protocol (OCF, AllJoyn, UPnP, WS-Discovery, etc.). The other protocols already carry a UUID for this purpose. Change-Id: I2c6f5f2a29d09b2a120d450708360bcd61c08b3c Signed-off-by: Dave Thaler Signed-off-by: Dan Mihai Reviewed-on: https://gerrit.iotivity.org/gerrit/14261 Reviewed-by: George Nash Tested-by: jenkins-iotivity Reviewed-by: Mike Fenelon --- .../client/airconditioner/aircon_controlee.cpp | 9 +++++++++ .../samples/client/thin_light/thin_room_light.cpp | 2 ++ plugins/samples/linux/IotivityandZigbeeServer.c | 3 +++ resource/csdk/include/octypes.h | 4 ++++ .../samples/linux/SimpleClientServer/ocserver.cpp | 5 ++++- .../samples/tizen/SimpleClientServer/ocserver.cpp | 3 +++ resource/examples/devicediscoveryserver.cpp | 9 +++++++++ resource/examples/fridgeserver.cpp | 9 +++++++++ resource/examples/garageserver.cpp | 10 ++++++++++ resource/examples/lightserver.cpp | 9 +++++++++ resource/examples/mediaserver.cpp | 8 ++++++++ resource/examples/presenceserver.cpp | 10 ++++++++++ resource/examples/roomserver.cpp | 9 +++++++++ resource/examples/simpleserver.cpp | 10 ++++++++++ resource/examples/simpleserverHQ.cpp | 10 ++++++++++ resource/unittests/OCPlatformTest.cpp | 7 ++++++- .../unittests/OCRepresentationEncodingTest.cpp | 8 +++++++- .../simulator/examples/server/simulator_server.cpp | 3 ++- service/simulator/inc/simulator_manager.h | 10 ++++++++++ .../simulator/java/jni/simulator_manager_jni.cpp | 22 ++++++++++++++++++++++ .../src/org/oic/simulator/SimulatorManager.java | 22 ++++++++++++++++++++++ service/simulator/src/simulator_manager.cpp | 13 +++++++++++++ 22 files changed, 191 insertions(+), 4 deletions(-) diff --git a/cloud/samples/client/airconditioner/aircon_controlee.cpp b/cloud/samples/client/airconditioner/aircon_controlee.cpp index 201f89e..a18f1fd 100644 --- a/cloud/samples/client/airconditioner/aircon_controlee.cpp +++ b/cloud/samples/client/airconditioner/aircon_controlee.cpp @@ -528,6 +528,15 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + "d7d2b492-83ac-4783-9dcc-b1b54587ebed"); + + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } diff --git a/cloud/samples/client/thin_light/thin_room_light.cpp b/cloud/samples/client/thin_light/thin_room_light.cpp index 9927362..d8df6d0 100644 --- a/cloud/samples/client/thin_light/thin_room_light.cpp +++ b/cloud/samples/client/thin_light/thin_room_light.cpp @@ -475,6 +475,8 @@ OCStackResult SetDeviceInfo() } VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Living Room Light")); + VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + "91debd4b-c875-47e1-9e1d-b1cd32baeb01")); cout << "Device information published successfully." << endl; return OC_STACK_OK; diff --git a/plugins/samples/linux/IotivityandZigbeeServer.c b/plugins/samples/linux/IotivityandZigbeeServer.c index da7a793..0abd561 100644 --- a/plugins/samples/linux/IotivityandZigbeeServer.c +++ b/plugins/samples/linux/IotivityandZigbeeServer.c @@ -155,6 +155,9 @@ OCStackResult SetDeviceInfo() VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, "IoTivity/Zigbee Data Model Version")); + VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + "4ea65ac9-59a3-4eb8-8d77-76c3ee72c250")); + OIC_LOG(INFO, TAG, "Device information initialized successfully."); return OC_STACK_OK; diff --git a/resource/csdk/include/octypes.h b/resource/csdk/include/octypes.h index d02a569..481db4c 100755 --- a/resource/csdk/include/octypes.h +++ b/resource/csdk/include/octypes.h @@ -306,6 +306,10 @@ extern "C" { /** Device Data Model version.*/ #define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.1.0" + +/** Protocol-Independent ID.*/ +#define OC_RSRVD_PROTOCOL_INDEPENDENT_ID "piid" + /** * These provide backward compatibility - their use is deprecated. */ diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp index 0e53bdc..2e8f9fe 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp @@ -90,6 +90,7 @@ const char *manufacturerName = "myName"; const char *operatingSystemVersion = "myOS"; const char *hardwareVersion = "myHardwareVersion"; const char *platformID = "0A3E0D6F-DBF5-404E-8719-D6880042463A"; +const char *protocolIndependentID = "6ef9211d-2d5c-401e-8e5d-4b3af48a054f"; const char *manufacturerLink = "https://www.iotivity.org"; const char *modelNumber = "myModelNumber"; const char *platformVersion = "myPlatformVersion"; @@ -1006,6 +1007,8 @@ OCStackResult SetDeviceInfo() VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion)); VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersions)); + VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID)); OIC_LOG(INFO, TAG, "Device information initialized successfully."); return OC_STACK_OK; @@ -1189,7 +1192,7 @@ int main(int argc, char* argv[]) OIC_LOG(INFO, TAG, "Device Registration failed!"); exit (EXIT_FAILURE); } - + /* * Declare and create the example resource: Light */ diff --git a/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp b/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp index ae36f7a..387e27a 100644 --- a/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp @@ -80,6 +80,7 @@ const char *manufacturerName = "myName"; const char *operatingSystemVersion = "myOS"; const char *hardwareVersion = "myHardwareVersion"; const char *platformID = "0A3E0D6F-DBF5-404E-8719-D6880042463A"; +const char *protocolIndependentID = "45a908e9-c06c-4935-b2dd-4195da863a11"; const char *manufacturerLink = "https://www.iotivity.org"; const char *modelNumber = "myModelNumber"; const char *platformVersion = "myPlatformVersion"; @@ -932,6 +933,8 @@ OCStackResult SetDeviceInfo() VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion)); VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersions)); + VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID)); OIC_LOG(INFO, TAG, "Device information initialized successfully."); return OC_STACK_OK; diff --git a/resource/examples/devicediscoveryserver.cpp b/resource/examples/devicediscoveryserver.cpp index 7bb24a2..6923172 100644 --- a/resource/examples/devicediscoveryserver.cpp +++ b/resource/examples/devicediscoveryserver.cpp @@ -50,6 +50,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "Bill's Battlestar"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0", "sh.1.1.0"}; +std::string protocolIndependentID = "4cae60c1-48cb-47dc-882e-dedec114f45c"; // Device type std::string deviceType = "oic.d.tv"; @@ -138,6 +139,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + std::cout << "Failed to set piid" << std::endl; + return result; + } + return OC_STACK_OK; } diff --git a/resource/examples/fridgeserver.cpp b/resource/examples/fridgeserver.cpp index d1622b0..9ab20d7 100644 --- a/resource/examples/fridgeserver.cpp +++ b/resource/examples/fridgeserver.cpp @@ -63,6 +63,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "IoTivity Fridge Server"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0"}; +std::string protocolIndependentID = "054718eb-b1e7-4e9e-9892-30e718a6a8f3"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -552,6 +553,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + std::cout << "Failed to set piid" << std::endl; + return result; + } + return OC_STACK_OK; } diff --git a/resource/examples/garageserver.cpp b/resource/examples/garageserver.cpp index ab4072d..f333d45 100644 --- a/resource/examples/garageserver.cpp +++ b/resource/examples/garageserver.cpp @@ -52,6 +52,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "IoTivity Garage Server"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0"}; +std::string protocolIndependentID = "1cbab786-ca5f-4eb9-89b2-e90eb4820145"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -328,6 +329,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } @@ -358,6 +367,7 @@ int main(int /*argc*/, char** /*argv[1]*/) } result = SetDeviceInfo(); + if (result != OC_STACK_OK) { std::cout << "Device Registration failed\n"; diff --git a/resource/examples/lightserver.cpp b/resource/examples/lightserver.cpp index 55188e9..2baf79f 100644 --- a/resource/examples/lightserver.cpp +++ b/resource/examples/lightserver.cpp @@ -63,6 +63,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "IoTivity Light Server"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0"}; +std::string protocolIndependentID = "b0ed9259-ec95-4ac6-8f62-241d0da02683"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -375,6 +376,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } diff --git a/resource/examples/mediaserver.cpp b/resource/examples/mediaserver.cpp index 18f353c..457349b 100644 --- a/resource/examples/mediaserver.cpp +++ b/resource/examples/mediaserver.cpp @@ -421,6 +421,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + "9f9752ed-b4ab-4662-af22-7e541bbee2fb"); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } diff --git a/resource/examples/presenceserver.cpp b/resource/examples/presenceserver.cpp index 2ed2359..da1d937 100644 --- a/resource/examples/presenceserver.cpp +++ b/resource/examples/presenceserver.cpp @@ -63,6 +63,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "IoTivity Presence Server"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0"}; +std::string protocolIndependentID = "41a75d38-83c3-4b83-a794-f2174990b30b"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -286,6 +287,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } @@ -316,6 +325,7 @@ int main() } result = SetDeviceInfo(); + if (result != OC_STACK_OK) { std::cout << "Device Registration failed\n"; diff --git a/resource/examples/roomserver.cpp b/resource/examples/roomserver.cpp index 07e8f51..8295401 100644 --- a/resource/examples/roomserver.cpp +++ b/resource/examples/roomserver.cpp @@ -60,6 +60,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "IoTivity Room Server"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0"}; +std::string protocolIndependentID = "ac1b42a7-0518-448f-9b11-bfe328837bbf"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -618,6 +619,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } diff --git a/resource/examples/simpleserver.cpp b/resource/examples/simpleserver.cpp index 04c7649..6185e3d 100644 --- a/resource/examples/simpleserver.cpp +++ b/resource/examples/simpleserver.cpp @@ -69,6 +69,7 @@ std::string deviceName = "IoTivity Simple Server"; std::string deviceType = "oic.wk.tv"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0", "sh.1.1.0"}; +std::string protocolIndependentID = "fa008167-3bbf-4c9d-8604-c9bcb96cb712"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -573,6 +574,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } @@ -678,6 +687,7 @@ int main(int argc, char* argv[]) } result = SetDeviceInfo(); + if (result != OC_STACK_OK) { std::cout << "Device Registration failed\n"; diff --git a/resource/examples/simpleserverHQ.cpp b/resource/examples/simpleserverHQ.cpp index e4db483..013dbd9 100644 --- a/resource/examples/simpleserverHQ.cpp +++ b/resource/examples/simpleserverHQ.cpp @@ -65,6 +65,7 @@ std::string systemTime = "2016-01-15T11.01"; std::string deviceName = "IoTivity Simple Server HQ"; std::string specVersion = "core.1.1.0"; std::vector dataModelVersions = {"res.1.1.0"}; +std::string protocolIndependentID = "88b3584f-d7bc-4e56-9210-0e8b305202c3"; // OCPlatformInfo Contains all the platform info to be stored OCPlatformInfo platformInfo; @@ -500,6 +501,14 @@ OCStackResult SetDeviceInfo() return result; } + result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID); + if (result != OC_STACK_OK) + { + cout << "Failed to set piid" << endl; + return result; + } + return OC_STACK_OK; } @@ -558,6 +567,7 @@ int main(int argc, char* argv[]) } result = SetDeviceInfo(); + if (result != OC_STACK_OK) { std::cout << "Device Registration failed\n"; diff --git a/resource/unittests/OCPlatformTest.cpp b/resource/unittests/OCPlatformTest.cpp index 05c497d..5a26944 100644 --- a/resource/unittests/OCPlatformTest.cpp +++ b/resource/unittests/OCPlatformTest.cpp @@ -802,12 +802,15 @@ namespace OCPlatformTest OCDeviceInfo deviceInfo; DuplicateString(&deviceInfo.deviceName, "myDeviceName"); deviceInfo.types = NULL; - OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d"); + OCResourcePayloadAddStringLL(&deviceInfo.types, OC_RSRVD_RESOURCE_TYPE_DEVICE); OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv"); DuplicateString(&deviceInfo.specVersion, "mySpecVersion"); deviceInfo.dataModelVersions = nullptr; OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions"); EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo)); + EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue( + PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + "bda0e016-fe64-41dc-871e-c7e94cc143b9")); EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo)); } @@ -829,6 +832,8 @@ namespace OCPlatformTest dmv.push_back("myDataModelVersions"); EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dmv)); + EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + "99a74220-73d3-426f-8397-3c06d586a865")); OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI); ASSERT_TRUE(NULL != handle); EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv")); diff --git a/resource/unittests/OCRepresentationEncodingTest.cpp b/resource/unittests/OCRepresentationEncodingTest.cpp index ba5b29f..f2e2df5 100644 --- a/resource/unittests/OCRepresentationEncodingTest.cpp +++ b/resource/unittests/OCRepresentationEncodingTest.cpp @@ -64,6 +64,7 @@ namespace OCRepresentationEncodingTest TEST(DeviceDiscoveryEncoding, Normal) { sid1 = OCGetServerInstanceIDString(); + static const char piid1[] = "e987b8f5-527a-454e-98c1-1eef2e5f1cf5"; const char devicename1[] = "device name"; OCRepPayload *device = OCRepPayloadCreate(); EXPECT_TRUE(device); @@ -72,6 +73,7 @@ namespace OCRepresentationEncodingTest EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_ID, sid1)); EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_NAME, devicename1)); EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_SPEC_VERSION, OC_SPEC_VERSION)); + EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, piid1)); EXPECT_TRUE(OCRepPayloadSetPropString(device, "x.org.iotivity.newproperty", "value")); size_t dim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0}; @@ -94,6 +96,9 @@ namespace OCRepresentationEncodingTest EXPECT_TRUE(OCRepPayloadGetPropString(parsedRep, OC_RSRVD_DEVICE_ID, &value)); EXPECT_STREQ(sid1, value); OICFree(value); + EXPECT_TRUE(OCRepPayloadGetPropString(parsedRep, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, &value)); + EXPECT_STREQ(piid1, value); + OICFree(value); EXPECT_TRUE(OCRepPayloadGetPropString(parsedRep, OC_RSRVD_DEVICE_NAME, &value)); EXPECT_STREQ(devicename1, value); OICFree(value); @@ -108,7 +113,7 @@ namespace OCRepresentationEncodingTest EXPECT_STREQ(OC_DATA_MODEL_VERSION, dmv[0]); OICFree(dmv[0]); OICFree(dmv); - EXPECT_STREQ("oic.wk.d", parsedRep->types->value); + EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_DEVICE, parsedRep->types->value); EXPECT_STREQ("oic.d.tv", parsedRep->types->next->value); EXPECT_EQ(device->base.type, parsedRep->base.type); @@ -133,6 +138,7 @@ namespace OCRepresentationEncodingTest EXPECT_TRUE(OCRepPayloadAddResourceType(device, "oic.d.tv")); EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_NAME, devicename1)); EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_ID, sid1)); + EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, piid1)); EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_SPEC_VERSION, OC_SPEC_VERSION)); size_t dim1[MAX_REP_ARRAY_DEPTH] = {2, 0, 0}; char **dt1 = (char **)OICMalloc(sizeof(char *) * 2); diff --git a/service/simulator/examples/server/simulator_server.cpp b/service/simulator/examples/server/simulator_server.cpp index a02c24d..576cc33 100644 --- a/service/simulator/examples/server/simulator_server.cpp +++ b/service/simulator/examples/server/simulator_server.cpp @@ -398,7 +398,8 @@ void setDeviceInfo() { try { - SimulatorManager::getInstance()->setDeviceInfo("IoTivity Simulator Linux Sample"); + SimulatorManager::getInstance()->setDeviceInfo("IoTivity Simulator Linux Sample", + "c49f7cba-3b3d-490b-9d3f-d4f17a3dad26"); std::cout << "Setting Device Info is successful" << std::endl; } catch (InvalidArgsException &e) diff --git a/service/simulator/inc/simulator_manager.h b/service/simulator/inc/simulator_manager.h index 2ebb10a..53d22c9 100644 --- a/service/simulator/inc/simulator_manager.h +++ b/service/simulator/inc/simulator_manager.h @@ -162,6 +162,16 @@ class SimulatorManager void setDeviceInfo(const std::string &deviceName); /** + * API for registering device information with stack. + * + * @param deviceName - Device name to be registered. + * @param protocolIndependentID - Protocol-independent UUID to be registered. + * + * NOTE: API throws @InvalidArgsException and @SimulatorException on error. + */ + void setDeviceInfo(const std::string &deviceName, const std::string &protocolIndependentID); + + /** * API for getting platform information from remote device. * Received platform information will be notified through the callback set using * @callback parameter. diff --git a/service/simulator/java/jni/simulator_manager_jni.cpp b/service/simulator/java/jni/simulator_manager_jni.cpp index a5b135e..b5f8b07 100644 --- a/service/simulator/java/jni/simulator_manager_jni.cpp +++ b/service/simulator/java/jni/simulator_manager_jni.cpp @@ -328,6 +328,28 @@ Java_org_oic_simulator_SimulatorManager_nativeSetDeviceInfo } JNIEXPORT void JNICALL +Java_org_oic_simulator_SimulatorManager_nativeSetDeviceInfo2 +(JNIEnv *env, jobject /*object*/, jstring jDeviceName, jstring jProtocolIndependentID) +{ + VALIDATE_INPUT(env, !jDeviceName, "Device name is null!") + + try + { + JniString jniDeviceName(env, jDeviceName); + JniString jniProtocolIndependentID(env, jProtocolIndependentID); + SimulatorManager::getInstance()->setDeviceInfo(jniDeviceName.get(), jniProtocolIndependentID.get()); + } + catch (InvalidArgsException &e) + { + ThrowInvalidArgsException(env, e.code(), e.what()); + } + catch (SimulatorException &e) + { + ThrowSimulatorException(env, e.code(), e.what()); + } +} + +JNIEXPORT void JNICALL Java_org_oic_simulator_SimulatorManager_nativeFindDevices (JNIEnv *env, jobject /*object*/, jstring jHostUri, jobject jListener) { diff --git a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java index ed20a9c..a3351d5 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java @@ -153,6 +153,8 @@ public class SimulatorManager { /** * API to set the device information. * + * @deprecated Use setDeviceInfo2 instead. + * * @param deviceInfo * Device information. * @@ -167,6 +169,24 @@ public class SimulatorManager { } /** + * API to set the device information. + * + * @param deviceInfo + * Device information. + * @param protocolIndependentID + * Protocol-independent UUID of the device. + * + * @throws InvalidArgsException + * Thrown if the input parameter is empty. + * @throws SimulatorException + * Thrown for other errors. + */ + public static void setDeviceInfo2(String deviceInfo, String protocolIndependentID) + throws InvalidArgsException, SimulatorException { + nativeSetDeviceInfo2(deviceInfo, protocolIndependentID); + } + + /** * API to search for devices on the given host in the network. * * @param hostUri @@ -248,6 +268,8 @@ public class SimulatorManager { FindResourceListener listener); private static native void nativeSetDeviceInfo(String deviceInfo); + private static native void nativeSetDeviceInfo2(String deviceInfo, + String protocolIndependentID); private static native void nativeFindDevices(String hostUri, DeviceListener listener); diff --git a/service/simulator/src/simulator_manager.cpp b/service/simulator/src/simulator_manager.cpp index 2f0fb29..789fd39 100644 --- a/service/simulator/src/simulator_manager.cpp +++ b/service/simulator/src/simulator_manager.cpp @@ -184,6 +184,19 @@ void SimulatorManager::setDeviceInfo(const std::string &deviceName) ocDeviceInfo); } +void SimulatorManager::setDeviceInfo(const std::string &deviceName, const std::string &protocolIndependentID) +{ + setDeviceInfo(deviceName); + + typedef OCStackResult (*SetPropertyValue)(OCPayloadType, const std::string&, + const std::string&); + + invokeocplatform(static_cast(OC::OCPlatform::setPropertyValue), + PAYLOAD_TYPE_DEVICE, + OC_RSRVD_PROTOCOL_INDEPENDENT_ID, + protocolIndependentID.c_str()); +} + void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCallback callback) { VALIDATE_CALLBACK(callback) -- 2.7.4