Add device and platform information in sample codes.
authorZiran Sun <ziran.sun@samsung.com>
Thu, 6 Oct 2016 12:48:51 +0000 (13:48 +0100)
committerZiran Sun <ziran.sun@samsung.com>
Wed, 12 Oct 2016 09:21:01 +0000 (09:21 +0000)
Bug: https://jira.iotivity.org/browse/IOT-1384
Change-Id: I8f8e69716534dddb77d6069394267e730a02c14f
Signed-off-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12909
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Alex Kelley <alexke@microsoft.com>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
16 files changed:
resource/examples/devicediscoveryserver.cpp
resource/examples/fridgeclient.cpp
resource/examples/fridgeserver.cpp
resource/examples/garageclient.cpp
resource/examples/garageserver.cpp
resource/examples/lightserver.cpp
resource/examples/mediaserver.cpp
resource/examples/presenceclient.cpp
resource/examples/presenceserver.cpp
resource/examples/roomclient.cpp
resource/examples/roomserver.cpp
resource/examples/simpleclient.cpp
resource/examples/simpleclientHQ.cpp
resource/examples/simpleserver.cpp
resource/examples/simpleserverHQ.cpp
resource/examples/winuiclient.cpp

index dba1515..1c85547 100644 (file)
 
 using namespace OC;
 
-//Set of strings for each of platform Info fields
+// Set of strings for each of platform Info fields
 std::string dateOfManufacture = "myDateOfManufacture";
 std::string firmwareVersion = "my.Firmware.Version";
 std::string manufacturerName = "myName";
 std::string operatingSystemVersion = "myOS";
 std::string hardwareVersion = "myHardwareVersion";
 std::string platformID = "myPlatformID";
-std::string manufacturerUrl = "www.myurl.com";
+std::string manufacturerLink = "www.myurl.com";
 std::string modelNumber = "myModelNumber";
 std::string platformVersion = "platformVersion";
-std::string supportUrl = "www.mysupporturl.com";
+std::string supportLink = "www.mysupporturl.com";
 std::string systemTime = "mySystemTime";
 
-//Set of strings for each of device info fields
+// Set of strings for each of device info fields
 std::string deviceName = "Bill's Battlestar";
 std::string specVersion = "myDeviceSpecVersion";
 std::string dataModelVersions = "myDeviceModelVersion";
 
-//OCPlatformInfo Contains all the platform info to be stored
+// OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-//OCDeviceInfo Contains all the device info to be stored
+// OCDeviceInfo Contains all the device info to be stored
 OCDeviceInfo deviceInfo;
 
 void DeletePlatformInfo()
@@ -102,24 +102,27 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
     DuplicateString(&platformInfo.supportUrl, supportUrl);
     DuplicateString(&platformInfo.systemTime, systemTime);
+
     return OC_STACK_OK;
 }
 
-
 OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
 {
     DuplicateString(&deviceInfo.deviceName, deviceName);
 
     if (!specVersion.empty())
+    {
         DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
 
     if (!dataModelVersions.empty())
+    {
         OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
 
     return OC_STACK_OK;
 }
 
-
 int main()
 {
     // Create PlatformConfig object
@@ -135,9 +138,9 @@ int main()
 
     std::cout<<"Starting server & setting platform info\n";
 
-    OCStackResult result = SetPlatformInfo(platformID, manufacturerName, manufacturerUrl,
+    OCStackResult result = SetPlatformInfo(platformID, manufacturerName, manufacturerLink,
             modelNumber, dateOfManufacture, platformVersion,  operatingSystemVersion,
-            hardwareVersion, firmwareVersion,  supportUrl, systemTime);
+            hardwareVersion, firmwareVersion,  supportLink, systemTime);
 
     result = OCPlatform::registerPlatformInfo(platformInfo);
 
index bbbc748..5f2dc4b 100644 (file)
@@ -76,6 +76,8 @@ class ClientFridge
     void foundDevice(std::shared_ptr<OCResource> resource)
     {
         using namespace OC::OCPlatform;
+        std::string platformDiscoveryURI = "/oic/p";
+        std::string deviceDiscoveryURI   = "/oic/d";
         if(resource && resource->uri() == "/device")
         {
             std::cout << "Discovered a device object"<<std::endl;
@@ -83,6 +85,34 @@ class ClientFridge
             std::cout << "\tURI:  "<<resource->uri() <<std::endl;
         }
 
+        OCStackResult ret;
+
+        std::cout << "Querying for platform information... " << std::endl;
+
+        ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP, NULL);
+
+        if (ret == OC_STACK_OK)
+        {
+            std::cout << "Get platform information is done." << std::endl;
+        }
+        else
+        {
+            std::cout << "Get platform information failed." << std::endl;
+        }
+
+        std::cout << "Querying for device information... " << std::endl;
+
+        ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP, NULL);
+
+        if (ret == OC_STACK_OK)
+        {
+            std::cout << "Getting device information is done." << std::endl;
+        }
+        else
+        {
+            std::cout << "Getting device information failed." << std::endl;
+        }
+
         // we have now found a resource, so lets create a few resource objects
         // for the other resources that we KNOW are associated with the intel.fridge
         // server, and query them.
index 556b34c..e981c90 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "OCPlatform.h"
 #include "OCApi.h"
+#include "ocpayload.h"
 
 using namespace OC;
 namespace PH = std::placeholders;
@@ -45,6 +46,30 @@ const uint16_t TOKEN = 3000;
 const std::string FRIDGE_CLIENT_API_VERSION = "v.1.0";
 const std::string FRIDGE_CLIENT_TOKEN = "21ae43gf";
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Fridge Server";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 class Resource
 {
     protected:
@@ -464,6 +489,71 @@ class Refrigerator
     DoorResource m_rightdoor;
 };
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+    std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+    std::string platformVersion, std::string operatingSystemVersion, std::string hardwareVersion,
+    std::string firmwareVersion, std::string supportUrl, std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
+
 int main ()
 {
     PlatformConfig cfg
@@ -478,6 +568,33 @@ int main ()
     OCPlatform::Configure(cfg);
     Refrigerator rf;
 
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
+
+    DeletePlatformInfo();
+    DeleteDeviceInfo();
     // we will keep the server alive for at most 30 minutes
     std::this_thread::sleep_for(std::chrono::minutes(30));
     return 0;
index 9a91da9..d7efa96 100644 (file)
@@ -241,6 +241,9 @@ void foundResource(std::shared_ptr<OCResource> resource)
 
     std::string resourceURI;
     std::string hostAddress;
+    std::string platformDiscoveryURI = "/oic/p";
+    std::string deviceDiscoveryURI   = "/oic/d";
+
     try
     {
         // Do some operations with resource object.
@@ -269,6 +272,34 @@ void foundResource(std::shared_ptr<OCResource> resource)
                 std::cout << "\t\t" << resourceInterfaces << std::endl;
             }
 
+            OCStackResult ret;
+            std::cout << "Querying for platform information... " << std::endl;
+
+            ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP, NULL);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Get platform information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Get platform information failed." << std::endl;
+            }
+
+            std::cout << "Querying for device information... " << std::endl;
+
+            ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP,
+                    NULL);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Getting device information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Getting device information failed." << std::endl;
+            }
+  
             if(resourceURI == "/a/garage")
             {
                 curResource = resource;
index 95faea3..6f833d7 100644 (file)
 
 #include "OCPlatform.h"
 #include "OCApi.h"
+#include "ocpayload.h"
 
 using namespace OC;
 using namespace std;
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Garage Server";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 // Forward declaring the entityHandler
 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request);
 
@@ -241,6 +266,71 @@ OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
     return ehResult;
 }
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+    std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+    std::string platformVersion, std::string operatingSystemVersion, std::string hardwareVersion,
+    std::string firmwareVersion, std::string supportUrl, std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
+
 int main(int /*argc*/, char** /*argv[1]*/)
 {
     // Create PlatformConfig object
@@ -253,11 +343,37 @@ int main(int /*argc*/, char** /*argv[1]*/)
     };
 
     OCPlatform::Configure(cfg);
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
     try
     {
         // Invoke createResource function of class light.
         myGarage.createResource();
 
+        DeletePlatformInfo();
+        DeleteDeviceInfo();
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
         // don't ever call cv.notify, this should be a non-processor intensive version
index 1ce1e6b..ab7591f 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "OCPlatform.h"
 #include "OCApi.h"
+#include "ocpayload.h"
 
 using namespace OC;
 using namespace std;
@@ -45,6 +46,30 @@ int gObservation = 0;
 void * ChangeLightRepresentation (void *param);
 void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequest);
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Light Server";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 // Specifies secure or non-secure
 // false: non-secure resource
 // true: secure resource
@@ -286,6 +311,71 @@ void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequ
     return NULL;
 }
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+        std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+        std::string platformVersion, std::string operatingSystemVersion,
+        std::string hardwareVersion, std::string firmwareVersion, std::string supportUrl,
+        std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
 
 int main(int /*argc*/, char** /*argv[]*/)
 {
@@ -299,6 +389,31 @@ int main(int /*argc*/, char** /*argv[]*/)
     };
 
     OCPlatform::Configure(cfg);
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
+
     try
     {
         // Create the instance of the resource class
@@ -311,6 +426,9 @@ int main(int /*argc*/, char** /*argv[]*/)
         myLight.addType(std::string("core.brightlight"));
         myLight.addInterface(std::string(LINK_INTERFACE));
 
+        DeletePlatformInfo();
+        DeleteDeviceInfo();
+
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
         // don't ever call cv.notify, this should be a non-processor intensive version
index 4063961..37211ee 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "OCPlatform.h"
 #include "OCApi.h"
+#include "ocpayload.h"
 #include <windows.h>
 #include <objbase.h>
 
index 72b672a..859fe11 100644 (file)
@@ -102,6 +102,9 @@ void foundResource(std::shared_ptr<OCResource> resource)
 
     std::string resourceURI;
     std::string hostAddress;
+    std::string platformDiscoveryURI = "/oic/p";
+    std::string deviceDiscoveryURI   = "/oic/d";
+
     try
     {
         // Do some operations with resource object.
@@ -130,6 +133,35 @@ void foundResource(std::shared_ptr<OCResource> resource)
                 std::cout << "\t\t" << resourceInterfaces << std::endl;
             }
 
+            OCStackResult ret;
+
+             std::cout << "Querying for platform information... " << std::endl;
+
+             ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP, NULL);
+
+             if (ret == OC_STACK_OK)
+             {
+                 std::cout << "Get platform information is done." << std::endl;
+             }
+             else
+             {
+                 std::cout << "Get platform information failed." << std::endl;
+             }
+
+             std::cout << "Querying for device information... " << std::endl;
+
+             ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP,
+                     NULL);
+
+             if (ret == OC_STACK_OK)
+             {
+                 std::cout << "Getting device information is done." << std::endl;
+             }
+             else
+             {
+                 std::cout << "Getting device information failed." << std::endl;
+             }
+
             if(resourceURI == "/a/light")
             {
                 OCStackResult result = OC_STACK_OK;
index 228e6af..c8c7f9c 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "OCPlatform.h"
 #include "OCApi.h"
+#include "ocpayload.h"
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
@@ -45,6 +46,30 @@ using namespace std;
 
 #define numPresenceResources (2)
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Presence Server";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 // Forward declaring the entityHandler
 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request);
 
@@ -197,6 +222,72 @@ OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request
     return OC_EH_OK;
 }
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+        std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+        std::string platformVersion, std::string operatingSystemVersion,
+        std::string hardwareVersion, std::string firmwareVersion, std::string supportUrl,
+        std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
+
 int main()
 {
     // Create PlatformConfig object
@@ -209,6 +300,30 @@ int main()
     };
 
     OCPlatform::Configure(cfg);
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
     try
     {
         using namespace OC::OCPlatform;
@@ -247,6 +362,9 @@ int main()
 
         createPresenceResources();
 
+        DeletePlatformInfo();
+        DeleteDeviceInfo();
+
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
         // don't ever call cv.notify, this should be a non-processor intensive version
index fbb661d..6ce3591 100644 (file)
@@ -179,6 +179,8 @@ void foundResource(std::shared_ptr<OCResource> resource)
 
     std::string resourceURI;
     std::string hostAddress;
+    std::string platformDiscoveryURI = "/oic/p";
+    std::string deviceDiscoveryURI   = "/oic/d";
     try
     {
         // Do some operations with resource object.
@@ -207,6 +209,34 @@ void foundResource(std::shared_ptr<OCResource> resource)
                 std::cout << "\t\t" << resourceInterfaces << std::endl;
             }
 
+            OCStackResult ret;
+            std::cout << "Querying for platform information... " << std::endl;
+
+            ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP, NULL);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Get platform information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Get platform information failed." << std::endl;
+            }
+
+            std::cout << "Querying for device information... " << std::endl;
+
+            ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP,
+                    NULL);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Getting device information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Getting device information failed." << std::endl;
+            }
+
             if(resourceURI == "/a/room")
             {
                 curResource = resource;
index 7768b3f..3fc30e9 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "OCPlatform.h"
 #include "OCApi.h"
+#include "ocpayload.h"
 
 using namespace OC;
 using namespace std;
@@ -42,6 +43,30 @@ OCEntityHandlerResult entityHandlerFan(std::shared_ptr<OCResourceRequest> reques
 /// Specifies whether default collection entity handler is used or not
 bool useDefaultCollectionEH = false;
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Room Server";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 class RoomResource
 {
 public:
@@ -528,6 +553,72 @@ void printUsage()
     std::cout << "2 : Create room resource with application collection entity handler.\n";
 }
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+        std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+        std::string platformVersion, std::string operatingSystemVersion,
+        std::string hardwareVersion, std::string firmwareVersion, std::string supportUrl,
+        std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
+
 int main(int argc, char* argv[])
 {
     printUsage();
@@ -560,11 +651,38 @@ int main(int argc, char* argv[])
     };
 
     OCPlatform::Configure(cfg);
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+    
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
+
     try
     {
 
         myRoomResource.createResources();
 
+        DeletePlatformInfo();
+        DeleteDeviceInfo();
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
         // don't ever call cv.notify, this should be a non-processor intensive version
index 924e88c..aec34e3 100644 (file)
@@ -338,12 +338,65 @@ void getLightRepresentation(std::shared_ptr<OCResource> resource)
     }
 }
 
+void receivedPlatformInfo(const OCRepresentation& rep)
+{
+    std::cout << "\nPlatform Information received ---->\n";
+    std::string value;
+    std::string values[] =
+    {
+        "pi",   "Platform ID                    ",
+        "mnmn", "Manufacturer name              ",
+        "mnml", "Manufacturer url               ",
+        "mnmo", "Manufacturer Model No          ",
+        "mndt", "Manufactured Date              ",
+        "mnpv", "Manufacturer Platform Version  ",
+        "mnos", "Manufacturer OS version        ",
+        "mnhw", "Manufacturer hardware version  ",
+        "mnfv", "Manufacturer firmware version  ",
+        "mnsl", "Manufacturer support url       ",
+        "st",   "Manufacturer system time       "
+    };
+
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]) ; i += 2)
+    {
+        if(rep.getValue(values[i], value))
+        {
+            std::cout << values[i + 1] << " : "<< value << std::endl;
+        }
+    }
+}
+
+void receivedDeviceInfo(const OCRepresentation& rep)
+{
+    std::cout << "\nDevice Information received ---->\n";
+    std::string value;
+    std::string values[] =
+    { 
+        "di",  "Device ID        ",
+        "n",   "Device name      ",
+        "lcv", "Spec version url ",
+        "dmv", "Data Model Model ", 
+    };
+
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]); i += 2)
+    {
+        if (rep.getValue(values[i], value))
+        {
+            std::cout << values[i + 1] << " : " << value << std::endl;
+        }
+    }
+}
+
 // Callback to found resources
 void foundResource(std::shared_ptr<OCResource> resource)
 {
     std::cout << "In foundResource\n";
     std::string resourceURI;
     std::string hostAddress;
+
+    std::string platformDiscoveryURI = "/oic/p";
+    std::string deviceDiscoveryURI   = "/oic/d";
+
     try
     {
         {
@@ -378,6 +431,36 @@ void foundResource(std::shared_ptr<OCResource> resource)
             hostAddress = resource->host();
             std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
 
+            OCStackResult ret;
+
+            std::cout << "Querying for platform information... " << std::endl;
+
+            ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP,
+                    &receivedPlatformInfo);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Get platform information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Get platform information failed." << std::endl;
+            }
+
+            std::cout << "Querying for device information... " << std::endl;
+
+            ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP,
+                    &receivedDeviceInfo);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Getting device information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Getting device information failed." << std::endl;
+            }
+  
             // Get the resource types
             std::cout << "\tList of resource types: " << std::endl;
             for(auto &resourceTypes : resource->getResourceTypes())
index 6d631d3..954d0c8 100644 (file)
@@ -302,11 +302,64 @@ void getLightRepresentation(std::shared_ptr<OCResource> resource)
     }
 }
 
+void receivedPlatformInfo(const OCRepresentation& rep)
+{
+    std::cout << "\nPlatform Information received ---->\n";
+    std::string value;
+    std::string values[] =
+    {
+        "pi",   "Platform ID                    ",
+        "mnmn", "Manufacturer name              ",
+        "mnml", "Manufacturer url               ",
+        "mnmo", "Manufacturer Model No          ",
+        "mndt", "Manufactured Date              ",
+        "mnpv", "Manufacturer Platform Version  ",
+        "mnos", "Manufacturer OS version        ",
+        "mnhw", "Manufacturer hardware version  ",
+        "mnfv", "Manufacturer firmware version  ",
+        "mnsl", "Manufacturer support url       ",
+        "st",   "Manufacturer system time       "
+    };
+
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]) ; i += 2)
+    {
+        if(rep.getValue(values[i], value))
+        {
+            std::cout << values[i + 1] << " : "<< value << std::endl;
+        }
+    }
+}
+
+void receivedDeviceInfo(const OCRepresentation& rep)
+{
+    std::cout << "\nDevice Information received ---->\n";
+    std::string value;
+    std::string values[] =
+    { 
+        "di",  "Device ID        ",
+        "n",   "Device name      ",
+        "lcv", "Spec version url ",
+        "dmv", "Data Model Model ", 
+    };
+
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]); i += 2)
+    {
+        if (rep.getValue(values[i], value))
+        {
+            std::cout << values[i + 1] << " : " << value << std::endl;
+        }
+    }
+}
+
 // Callback to found resources
 void foundResource(std::shared_ptr<OCResource> resource)
 {
     std::string resourceURI;
     std::string hostAddress;
+
+    std::string platformDiscoveryURI = "/oic/p";
+    std::string deviceDiscoveryURI   = "/oic/d";
+
     try
     {
         // Do some operations with resource object.
@@ -340,6 +393,36 @@ void foundResource(std::shared_ptr<OCResource> resource)
             hostAddress = resource->host();
             std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
 
+            OCStackResult ret;
+
+            std::cout << "Querying for platform information... " << std::endl;
+
+            ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP,
+                    &receivedPlatformInfo);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Get platform information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Get platform information failed." << std::endl;
+            }
+
+            std::cout << "Querying for device information... " << std::endl;
+
+            ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP,
+                    &receivedDeviceInfo);
+
+            if (ret == OC_STACK_OK)
+            {
+                std::cout << "Getting device information is done." << std::endl;
+            }
+            else
+            {
+                std::cout << "Getting device information failed." << std::endl;
+            }
+  
             // Get the resource types
             std::cout << "\tList of resource types: " << std::endl;
             for(auto &resourceTypes : resource->getResourceTypes())
index b005900..11d4f54 100644 (file)
@@ -40,6 +40,8 @@
 #include <windows.h>
 #endif
 
+#include "ocpayload.h"
+
 using namespace OC;
 using namespace std;
 namespace PH = std::placeholders;
@@ -49,6 +51,30 @@ int gObservation = 0;
 void * ChangeLightRepresentation (void *param);
 void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequest);
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Simple Server";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 // Specifies where to notify all observers or list of observers
 // false: notifies all observers
 // true: notifies list of observers
@@ -468,6 +494,72 @@ void * ChangeLightRepresentation (void *param)
     return NULL;
 }
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+        std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+        std::string platformVersion, std::string operatingSystemVersion,
+        std::string hardwareVersion, std::string firmwareVersion, std::string supportUrl,
+        std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
+
 void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequest)
 {
     // This function handles slow response case
@@ -555,6 +647,31 @@ int main(int argc, char* argv[])
     };
 
     OCPlatform::Configure(cfg);
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
+
     try
     {
         // Create the instance of the resource class
@@ -569,6 +686,8 @@ int main(int argc, char* argv[])
         myLight.addInterface(std::string(LINK_INTERFACE));
         std::cout << "Added Interface and Type" << std::endl;
 
+        DeletePlatformInfo();
+        DeleteDeviceInfo();
 
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
index 6d641e7..b50bc5b 100644 (file)
@@ -39,6 +39,8 @@
 #include <windows.h>
 #endif
 
+#include "ocpayload.h"
+
 using namespace OC;
 using namespace std;
 namespace PH = std::placeholders;
@@ -46,6 +48,30 @@ namespace PH = std::placeholders;
 int gObservation = 0;
 void * ChangeLightRepresentation (void *param);
 
+// Set of strings for each of platform Info fields
+std::string  platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A";
+std::string  manufacturerName = "OCF";
+std::string  manufacturerLink = "https://www.iotivity.org";
+std::string  modelNumber = "myModelNumber";
+std::string  dateOfManufacture = "2016-01-15";
+std::string  platformVersion = "myPlatformVersion";
+std::string  operatingSystemVersion = "myOS";
+std::string  hardwareVersion = "myHardwareVersion";
+std::string  firmwareVersion = "1.0";
+std::string  supportLink = "https://www.iotivity.org";
+std::string  systemTime = "2016-01-15T11.01";
+
+// Set of strings for each of device info fields
+std::string  deviceName = "IoTivity Simple Server HQ";
+std::string  specVersion = "core.1.1.0";
+std::string  dataModelVersions = "res.1.1.0";
+
+// OCPlatformInfo Contains all the platform info to be stored
+OCPlatformInfo platformInfo;
+
+// OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 // Specifies where to notify all observers or list of observers
 // 0 - notifies all observers
 // 1 - notifies list of observers
@@ -411,6 +437,72 @@ void * ChangeLightRepresentation (void *param)
     return NULL;
 }
 
+void DeletePlatformInfo()
+{
+    delete[] platformInfo.platformID;
+    delete[] platformInfo.manufacturerName;
+    delete[] platformInfo.manufacturerUrl;
+    delete[] platformInfo.modelNumber;
+    delete[] platformInfo.dateOfManufacture;
+    delete[] platformInfo.platformVersion;
+    delete[] platformInfo.operatingSystemVersion;
+    delete[] platformInfo.hardwareVersion;
+    delete[] platformInfo.firmwareVersion;
+    delete[] platformInfo.supportUrl;
+    delete[] platformInfo.systemTime;
+}
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    OCFreeOCStringLL(deviceInfo.dataModelVersions);
+}
+
+void DuplicateString(char ** targetString, std::string sourceString)
+{
+    *targetString = new char[sourceString.length() + 1];
+    strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
+}
+
+OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerName,
+        std::string manufacturerUrl, std::string modelNumber, std::string dateOfManufacture,
+        std::string platformVersion, std::string operatingSystemVersion,
+        std::string hardwareVersion, std::string firmwareVersion, std::string supportUrl,
+        std::string systemTime)
+{
+    DuplicateString(&platformInfo.platformID, platformID);
+    DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+    DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+    DuplicateString(&platformInfo.modelNumber, modelNumber);
+    DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+    DuplicateString(&platformInfo.platformVersion, platformVersion);
+    DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+    DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+    DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+    DuplicateString(&platformInfo.supportUrl, supportUrl);
+    DuplicateString(&platformInfo.systemTime, systemTime);
+
+    return OC_STACK_OK;
+}
+
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+    {
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+    }
+
+    if (!dataModelVersions.empty())
+    {
+        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+    }
+
+    return OC_STACK_OK;
+}
+
 void PrintUsage()
 {
     std::cout << std::endl;
@@ -451,6 +543,30 @@ int main(int argc, char* argv[])
     };
 
     OCPlatform::Configure(cfg);
+    std::cout << "Starting server & setting platform info\n";
+
+    OCStackResult result = SetPlatformInfo(platformId, manufacturerName, manufacturerLink,
+            modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion,
+            hardwareVersion, firmwareVersion, supportLink, systemTime);
+
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Platform Registration failed\n";
+        return -1;
+    }
+
+    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
+    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Device Registration failed\n";
+        return -1;
+    }
 
     try
     {
@@ -464,6 +580,9 @@ int main(int argc, char* argv[])
         myLight.addType(std::string("core.brightlight"));
         myLight.addInterface(std::string(LINK_INTERFACE));
 
+        DeletePlatformInfo();
+        DeleteDeviceInfo();
+
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
         // don't ever call cv.notify, this should be a non-processor intensive version
index 1b892cd..a187fab 100644 (file)
@@ -82,6 +82,55 @@ void WinUIClientApp::Run()
     }\r
 }\r
 \r
+void receivedPlatformInfo(const OCRepresentation& rep)\r
+{\r
+    std::cout << "\nPlatform Information received ---->\n";\r
+    std::string value;\r
+    std::string values[] =\r
+    {\r
+        "pi",   "Platform ID                    ",\r
+        "mnmn", "Manufacturer name              ",\r
+        "mnml", "Manufacturer url               ",\r
+        "mnmo", "Manufacturer Model No          ",\r
+        "mndt", "Manufactured Date              ",\r
+        "mnpv", "Manufacturer Platform Version  ",\r
+        "mnos", "Manufacturer OS version        ",\r
+        "mnhw", "Manufacturer hardware version  ",\r
+        "mnfv", "Manufacturer firmware version  ",\r
+        "mnsl", "Manufacturer support url       ",\r
+        "st",   "Manufacturer system time       "\r
+    };\r
+\r
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]) ; i += 2)\r
+    {\r
+        if(rep.getValue(values[i], value))\r
+        {\r
+            std::cout << values[i + 1] << " : "<< value << std::endl;\r
+        }\r
+    }\r
+}\r
+\r
+void receivedDeviceInfo(const OCRepresentation& rep)\r
+{\r
+    std::cout << "\nDevice Information received ---->\n";\r
+    std::string value;\r
+    std::string values[] =\r
+    {\r
+        "di",  "Device ID        ",\r
+        "n",   "Device name      ",\r
+        "lcv", "Spec version url ",\r
+        "dmv", "Data Model Model ",\r
+    };\r
+\r
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]); i += 2)\r
+    {\r
+        if (rep.getValue(values[i], value))\r
+        {\r
+            std::cout << values[i + 1] << " : " << value << std::endl;\r
+        }\r
+    }\r
+}\r
+\r
 void WinUIClientApp::FindResources()\r
 {\r
     std::ostringstream requestURI;\r
@@ -97,6 +146,8 @@ void WinUIClientApp::foundResource(std::shared_ptr<OCResource> resource)
     std::cout << "In foundResource\n";\r
     std::string resourceURI;\r
     std::string hostAddress;\r
+    std::string platformDiscoveryURI = "/oic/p";\r
+    std::string deviceDiscoveryURI   = "/oic/d";\r
     try\r
     {\r
         {\r
@@ -144,7 +195,36 @@ void WinUIClientApp::foundResource(std::shared_ptr<OCResource> resource)
             {\r
                 std::cout << "\t\t" << resourceInterfaces << std::endl;\r
             }\r
+            \r
+            OCStackResult ret;\r
+            std::cout << "Querying for platform information... " << std::endl;\r
 \r
+            ret = OCPlatform::getPlatformInfo("", platformDiscoveryURI, CT_ADAPTER_IP,\r
+                    &receivedPlatformInfo);\r
+\r
+            if (ret == OC_STACK_OK)\r
+            {\r
+                std::cout << "Get platform information is done." << std::endl;\r
+            }\r
+            else\r
+            {\r
+                std::cout << "Get platform information failed." << std::endl;\r
+            }\r
+\r
+            std::cout << "Querying for device information... " << std::endl;\r
+\r
+            ret = OCPlatform::getDeviceInfo(resource->host(), deviceDiscoveryURI, CT_ADAPTER_IP,\r
+                    &receivedDeviceInfo);\r
+\r
+            if (ret == OC_STACK_OK)\r
+            {\r
+                std::cout << "Getting device information is done." << std::endl;\r
+            }\r
+            else\r
+            {\r
+                std::cout << "Getting device information failed." << std::endl;\r
+            }\r
+   \r
             if (resourceURI == "/a/media")\r
             {\r
                 curResource = resource;\r