//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
///
-///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.
///
std::string supportUrl = "www.mysupporturl.com";
std::string systemTime = "mySystemTime";
+//Set of strings for each of platform info fields
+std::string deviceName = "Bill's Battlestar";
+
//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;
delete[] platformInfo.systemTime;
}
+
+void DeleteDeviceInfo()
+{
+ delete[] deviceInfo.deviceName;
+}
+
void DuplicateString(char ** targetString, std::string sourceString)
{
*targetString = new char[sourceString.length() + 1];
}
+OCStackResult SetDeviceInfo(std::string deviceName)
+{
+ DuplicateString(&deviceInfo.deviceName, deviceName);
+ return OC_STACK_OK;
+}
+
int main()
{
-
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
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);
+
+ 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