IOT-3010 Add OCPlatform::getResourceHandleAtUri 81/24381/5
authorGeorge Nash <george.nash@intel.com>
Mon, 12 Mar 2018 22:26:26 +0000 (15:26 -0700)
committerC.J. Collier <cjcollier@linuxfoundation.org>
Wed, 14 Mar 2018 23:03:58 +0000 (23:03 +0000)
This makes is possible to do things like get
the resource at `/oic/d` when to add the device
type.

This helps developers to avoid mixing C and C++
code in their projects.

Updated Cpp samples and unit test code to use
the new function.

Bug: https://jira.iotivity.org/browse/IOT-3010
Change-Id: I781081a5889807cea59ca5b569561da5d7d748e4
Signed-off-by: George Nash <george.nash@intel.com>
cloud/samples/client/airconditioner/aircon_controlee.cpp
resource/examples/devicediscoveryserver.cpp
resource/examples/simpleserver.cpp
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h
resource/src/OCPlatform.cpp
resource/src/OCPlatform_impl.cpp
resource/unittests/OCPlatformTest.cpp

index d56b083..c0fcda4 100644 (file)
@@ -774,7 +774,7 @@ OCStackResult SetDeviceInfo()
 {
     OCStackResult result = OC_STACK_ERROR;
 
-    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    OCResourceHandle handle = OCPlatform::getResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
 
     if (handle == NULL)
     {
@@ -782,7 +782,7 @@ OCStackResult SetDeviceInfo()
         return result;
     }
 
-    result = OCBindResourceTypeToResource(handle, "oic.d.airconditioner");
+    result = OCPlatform::bindTypeToResource(handle, "oic.d.airconditioner");
 
     if (result != OC_STACK_OK)
     {
index dcfcb41..04df4d7 100644 (file)
@@ -103,14 +103,14 @@ OCStackResult SetDeviceInfo()
 {
     OCStackResult result = OC_STACK_ERROR;
 
-    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    OCResourceHandle handle = OCPlatform::getResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
     if (handle == NULL)
     {
         std::cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << std::endl;
         return result;
     }
 
-    result = OCBindResourceTypeToResource(handle, deviceType.c_str());
+    result = OCPlatform::bindTypeToResource(handle, deviceType);
     if (result != OC_STACK_OK)
     {
         std::cout << "Failed to add device type" << std::endl;
index 06e408d..8bd322c 100644 (file)
@@ -538,14 +538,14 @@ OCStackResult SetDeviceInfo()
 {
     OCStackResult result = OC_STACK_ERROR;
 
-    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    OCResourceHandle handle = OCPlatform::getResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
     if (handle == NULL)
     {
         cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << endl;
         return result;
     }
 
-    result = OCBindResourceTypeToResource(handle, deviceType.c_str());
+    result = OCPlatform::bindTypeToResource(handle, deviceType);
     if (result != OC_STACK_OK)
     {
         cout << "Failed to add device type" << endl;
index e0bec2f..4b5360f 100644 (file)
@@ -124,6 +124,15 @@ namespace OC
                     const std::shared_ptr<OCResourceResponse> responsePtr,
                     QualityOfService QoS);
 
+        /**
+        * Gets a resource handle by resource uri.
+        *
+        * @param uri   Uri of Resource to get Resource handle.
+        *
+        * @return Found  resource handle or NULL if not found.
+        */
+        OCResourceHandle getResourceHandleAtUri(const std::string& uri);
+
         /**
          * API for Service and Resource Discovery.
          * @note This API applies to client side only.
index 9ec48c4..ec8da58 100644 (file)
@@ -76,6 +76,8 @@ namespace OC
                     const std::shared_ptr<OCResourceResponse> responsePtr,
                     QualityOfService QoS);
 
+        OCResourceHandle getResourceHandleAtUri(const std::string& uri);
+
         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
                     OCConnectivityType connectivityType, FindCallback resourceHandler);
 
index bce9e79..101b170 100644 (file)
@@ -80,6 +80,12 @@ namespace OC
                                      observationIds, pResponse, QoS);
         }
 
+
+        OCResourceHandle getResourceHandleAtUri(const std::string& uri)
+        {
+            return OCPlatform_impl::Instance().getResourceHandleAtUri(uri);
+        }
+
         OCResource::Ptr constructResourceObject(const std::string& host,
                                      const std::string& uri,
                                      OCConnectivityType connectivityType,
index f1dd08b..1d4c49f 100644 (file)
@@ -306,6 +306,11 @@ namespace OC
         return result_guard(result);
     }
 
+    OCResourceHandle OCPlatform_impl::getResourceHandleAtUri(const std::string& uri)
+    {
+        return OCGetResourceHandleAtUri(uri.c_str());
+    }
+
     OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
                                                 const std::string& uri,
                                                 OCConnectivityType connectivityType,
index e3054f0..871910e 100644 (file)
@@ -912,9 +912,9 @@ namespace OCPlatformTest
             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);
+        OCResourceHandle handle = OCPlatform::getResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
         ASSERT_TRUE(NULL != handle);
-        EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
+        EXPECT_EQ(OC_STACK_OK, OCPlatform::bindTypeToResource(handle, "oic.wk.tv"));
     }
 
 
@@ -929,9 +929,9 @@ namespace OCPlatformTest
             "mySpecVersion"));
         EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
             "myDataModelVersions"));
-        OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+        OCResourceHandle handle = OCPlatform::getResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
         ASSERT_TRUE(NULL != handle);
-        EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
+        EXPECT_EQ(OC_STACK_OK, OCPlatform::bindTypeToResource(handle, "oic.wk.tv"));
 
         std::string value;
         EXPECT_EQ(OC_STACK_OK, OCPlatform::getPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,