X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fexamples%2Fdevicediscoveryserver.cpp;h=dba1515a56e10d9a9710a92c19a83da7bf94a3a8;hb=1cee1631595cac6a6394ac2e0b365c6dd5a42c68;hp=3c091400708460333852cbf0fdc85b6d153eb4f0;hpb=935fdb9b67b6c10d007e652e9e2e028fd6ccfe09;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/examples/devicediscoveryserver.cpp b/resource/examples/devicediscoveryserver.cpp index 3c09140..dba1515 100644 --- a/resource/examples/devicediscoveryserver.cpp +++ b/resource/examples/devicediscoveryserver.cpp @@ -19,8 +19,8 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /// -///This sample demonstrates the device discovery feature -///The server sets the device related info. which can +///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. /// @@ -29,10 +29,11 @@ #include "OCPlatform.h" #include "OCApi.h" +#include "ocpayload.h" using namespace OC; -//Set of strings for each of deviceInfo fields +//Set of strings for each of platform Info fields std::string dateOfManufacture = "myDateOfManufacture"; std::string firmwareVersion = "my.Firmware.Version"; std::string manufacturerName = "myName"; @@ -45,9 +46,17 @@ std::string platformVersion = "platformVersion"; std::string supportUrl = "www.mysupporturl.com"; std::string systemTime = "mySystemTime"; +//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 platformInfo; +//OCDeviceInfo Contains all the device info to be stored +OCDeviceInfo deviceInfo; + void DeletePlatformInfo() { delete[] platformInfo.platformID; @@ -63,6 +72,14 @@ void DeletePlatformInfo() 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]; @@ -89,10 +106,22 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa } +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 PlatformConfig cfg { OC::ServiceType::InProc, @@ -110,21 +139,29 @@ int main() modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion, hardwareVersion, firmwareVersion, supportUrl, systemTime); + result = OCPlatform::registerPlatformInfo(platformInfo); + if(result != OC_STACK_OK) { std::cout << "Platform Registration failed\n"; return -1; } - result = OCPlatform::registerPlatformInfo(platformInfo); + + result = SetDeviceInfo(deviceName, specVersion, dataModelVersions); + OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d"); + OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv"); + + result = OCPlatform::registerDeviceInfo(deviceInfo); if(result != OC_STACK_OK) { - std::cout << "Platform Registration failed\n"; + std::cout << "Device Registration failed\n"; return -1; } 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 @@ -141,7 +178,3 @@ int main() return 0; } - - - -