return fopen("./aircon_controlee.dat", mode);
}
+OCStackResult SetDeviceInfo()
+{
+ OCStackResult result = OC_STACK_ERROR;
+
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+
+ if (handle == NULL)
+ {
+ cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << endl;
+ return result;
+ }
+
+ result = OCBindResourceTypeToResource(handle, "oic.d.airconditioner");
+
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to add device type" << endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "FAC_2016");
+
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
+
+ return OC_STACK_OK;
+}
+
int main(int argc, char *argv[])
{
if (argc != 4 && argc != 5)
, &binarySwitch, placeholders::_1),
OC_OBSERVABLE);
+ if (result != OC_STACK_OK)
+ {
+ exit(EXIT_FAILURE);
+ }
+
uri = temperature.getResourceUri();
rt = temperature.getResourceType()[0];
itf = temperature.getInterfaces()[0];
, &temperature, placeholders::_1),
OC_OBSERVABLE);
+ if (result != OC_STACK_OK)
+ {
+ exit(EXIT_FAILURE);
+ }
+
result = airConditioner.addChildResource(&binarySwitch);
- result = airConditioner.addChildResource(&temperature);
+ if (result != OC_STACK_OK)
+ {
+ exit(EXIT_FAILURE);
+ }
- cout << "Publishing resources to cloud ";
+ result = airConditioner.addChildResource(&temperature);
+ if (result != OC_STACK_OK)
+ {
+ exit(EXIT_FAILURE);
+ }
- ResourceHandles resourceHandles;
+ cout << "Publishing resources to cloud ";
- OCDeviceInfo devInfoAirConditioner;
- OCStringLL deviceType;
+ result = SetDeviceInfo();
- deviceType.value = "oic.d.airconditioner";
- deviceType.next = NULL;
- devInfoAirConditioner.deviceName = "FAC_2016";
- devInfoAirConditioner.types = &deviceType;
- devInfoAirConditioner.specVersion = NULL;
- devInfoAirConditioner.dataModelVersions = NULL;
+ if (result != OC_STACK_OK)
+ {
+ exit(EXIT_FAILURE);
+ }
- OCPlatform::registerDeviceInfo(devInfoAirConditioner);
+ ResourceHandles resourceHandles;
result = RDClient::Instance().publishResourceToRD(host, OCConnectivityType::CT_ADAPTER_TCP,
resourceHandles,
#include "ocstack.h"
#include "ocpayload.h"
#include "rd_client.h"
+#include "OCPlatform.h"
using namespace std;
+#define VERIFY_SUCCESS(op) \
+{ \
+ if (op != OC_STACK_OK) \
+ { \
+ cout << #op << " failed!!" << endl; \
+ goto exit; \
+ } \
+}
+
#define DEFAULT_CONTEXT_VALUE 0x99
#define DEFAULT_AUTH_SIGNUP "/oic/account"
#define DEFAULT_AUTH_SESSION "/oic/account/session"
return OC_STACK_KEEP_TRANSACTION;
}
+OCStackResult SetDeviceInfo()
+{
+ OCResourceHandle resourceHandle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ if (resourceHandle == NULL)
+ {
+ cout << "Device Resource does not exist." << endl;
+ goto exit;
+ }
+
+ VERIFY_SUCCESS(OCBindResourceTypeToResource(resourceHandle, "oic.d.light"));
+
+ if (OCGetServerInstanceIDString() == NULL)
+ {
+ cout << "Device ID generation failed" << endl;
+ goto exit;
+ }
+
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Living Room Light"));
+
+ cout << "Device information published successfully." << endl;
+ return OC_STACK_OK;
+
+exit:
+ return OC_STACK_ERROR;
+}
+
void PublishResources(string host)
{
cout << "Publishing resources..." << endl;
cbData.context = (void *) DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- cout << "Publish default resources" << endl;
-
- OCDeviceInfo devInfoRoomLight;
- OCStringLL deviceType;
-
- deviceType.value = "oic.d.light";
- deviceType.next = NULL;
- devInfoRoomLight.deviceName = "Living Room Light";
- devInfoRoomLight.types = &deviceType;
- devInfoRoomLight.specVersion = NULL;
- devInfoRoomLight.dataModelVersions = NULL;
+ cout << "Publishing default resources" << endl;
- OCStackResult res = OCSetDeviceInfo(devInfoRoomLight);
+ OCStackResult res = SetDeviceInfo();
if (res != OC_STACK_OK)
{
- cout << "Setting device info failed" << endl;
+ cout << "Publishing device info failed" << endl;
}
res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, NULL, 0, &cbData, OC_LOW_QOS);
cout << "Unable to publish default resources to cloud" << endl;
}
- cout << "Publish user resources" << endl;
+ cout << "Publishing user resources" << endl;
res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, resourceHandles, 1, &cbData, OC_LOW_QOS);
if (res != OC_STACK_OK)
#define TAG "IoTivityZigbeeServer"
#define defaultComPort "/dev/ttyUSB0"
+
+#define VERIFY_SUCCESS(op) \
+{ \
+ if (op != OC_STACK_OK) \
+ { \
+ OIC_LOG_V(FATAL, TAG, "%s failed!!", #op); \
+ goto exit; \
+ } \
+}
+
int main()
{
OIC_LOG(INFO, TAG, "Initializing IoTivity...");
OCStackResult SetDeviceInfo()
{
- static OCDeviceInfo deviceInfo =
- {
- .deviceName = "IoTivity/Zigbee Server Sample",
- .specVersion = "IoTivity/Zigbee Device Spec Version",
- };
- char *dmv = OICStrdup("IoTivity/Zigbee Data Model Version");
- deviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
- deviceInfo.dataModelVersions->value = dmv;
- char *dup = OICStrdup("oic.wk.d");
- deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
- deviceInfo.types->value = dup;
- return OCSetDeviceInfo(deviceInfo);
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ "IoTivity/Zigbee Server Sample"));
+
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
+ "IoTivity/Zigbee Device Spec Version"));
+
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ "IoTivity/Zigbee Data Model Version"));
+
+ OIC_LOG(INFO, TAG, "Device information initialized successfully.");
+ return OC_STACK_OK;
+
+exit:
+ return OC_STACK_ERROR;
+
}
bool processSignal(bool set)
* list. The default Device Type is mandatory and always specified by this Device as the first
* Device Type.
*
+ * @deprecated Use OCSetPropertyValue instead.
+ *
* @param deviceInfo Structure passed by the server application containing the device
* information.
*
#include "common.h"
#include "oic_string.h"
-//string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
+#define VERIFY_SUCCESS(op) \
+{ \
+ if (op != OC_STACK_OK) \
+ { \
+ OIC_LOG_V(FATAL, TAG, "%s failed!!", #op); \
+ goto exit; \
+ } \
+}
+
+// string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
// 9 + 9 + 1 = 19
const int URI_MAXSIZE = 19;
static bool observeThreadStarted = false;
#ifdef WITH_PRESENCE
-#define numPresenceResources (2)
+#define NUM_PRESENCE_RESOURCES 2
#endif
-char *gResourceUri= (char *)"/a/light";
+char *gResourceUri = (char *)"/a/light";
const char *dateOfManufacture = "2016-01-15";
const char *deviceName = "myDeviceName";
const char *deviceUUID = "51b55ddc-ccbb-4cb3-a57f-494eeca13a21";
const char *systemTime = "2015-05-15T11.04";
const char *specVersion = "core.1.1.0";
const char *dataModelVersions = "res.1.1.0,sh.1.1.0";
-
-// Entity handler should check for resourceTypeName and ResourceInterface in order to GET
-// the existence of a known resource
-const char *resourceTypeName = "core.light";
-const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
+const char *deviceType = "oic.d.tv";
OCPlatformInfo platformInfo;
-OCDeviceInfo deviceInfo;
OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
{
int powerRequested = atoi(pointerToOperator + 1);
if (Light.power > powerRequested)
{
- OIC_LOG_V(INFO, TAG, "Current power: %d. Requested: <%d", Light.power
- , powerRequested);
+ OIC_LOG_V(INFO, TAG, "Current power: %d. Requested: <%d", Light.power,
+ powerRequested);
return false;
}
}
}
}
if (clientStillObserving == false)
+ {
gLightUnderObservation = 0;
+ }
}
OCEntityHandlerResult
OIC_LOG_V(INFO, TAG, "Will send out presence in %u seconds", secondsBeforePresence);
sleep(secondsBeforePresence);
(void)param;
- OCDoHandle presenceNotificationHandles[numPresenceResources];
+ OCDoHandle presenceNotificationHandles[NUM_PRESENCE_RESOURCES];
OCStackResult res = OC_STACK_OK;
- std::array<std::string, numPresenceResources> presenceNotificationResources { {
+ std::array<std::string, NUM_PRESENCE_RESOURCES> presenceNotificationResources { {
std::string("core.fan"),
std::string("core.led") } };
- std::array<std::string, numPresenceResources> presenceNotificationUris { {
+ std::array<std::string, NUM_PRESENCE_RESOURCES> presenceNotificationUris { {
std::string("/a/fan"),
std::string("/a/led") } };
- for(int i=0; i<numPresenceResources; i++)
+ for(int i=0; i<NUM_PRESENCE_RESOURCES; i++)
{
if(res == OC_STACK_OK)
{
presenceNotificationUris[i].c_str());
}
sleep(5);
- for(int i=0; i<numPresenceResources; i++)
+ for(int i=0; i<NUM_PRESENCE_RESOURCES; i++)
{
if(res == OC_STACK_OK)
{
void DeletePlatformInfo()
{
- free (platformInfo.platformID);
- free (platformInfo.manufacturerName);
- free (platformInfo.manufacturerUrl);
- free (platformInfo.modelNumber);
- free (platformInfo.dateOfManufacture);
- free (platformInfo.platformVersion);
- free (platformInfo.operatingSystemVersion);
- free (platformInfo.hardwareVersion);
- free (platformInfo.firmwareVersion);
- free (platformInfo.supportUrl);
- free (platformInfo.systemTime);
-}
-
-void DeleteDeviceInfo()
-{
- free (deviceInfo.deviceName);
- free (deviceInfo.specVersion);
- OCFreeOCStringLL (deviceInfo.dataModelVersions);
+ free(platformInfo.platformID);
+ free(platformInfo.manufacturerName);
+ free(platformInfo.manufacturerUrl);
+ free(platformInfo.modelNumber);
+ free(platformInfo.dateOfManufacture);
+ free(platformInfo.platformVersion);
+ free(platformInfo.operatingSystemVersion);
+ free(platformInfo.hardwareVersion);
+ free(platformInfo.firmwareVersion);
+ free(platformInfo.supportUrl);
+ free(platformInfo.systemTime);
}
bool DuplicateString(char** targetString, const char* sourceString)
return OC_STACK_ERROR;
}
-OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- if(!DuplicateString(&deviceInfo.deviceName, deviceName))
- {
- return OC_STACK_ERROR;
- }
- if(!DuplicateString(&deviceInfo.specVersion, specVersion))
+ OCResourceHandle resourceHandle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ if (resourceHandle == NULL)
{
- return OC_STACK_ERROR;
- }
- OCFreeOCStringLL(deviceInfo.dataModelVersions);
- deviceInfo.dataModelVersions = OCCreateOCStringLL(dataModelVersions);
- if (!deviceInfo.dataModelVersions)
- {
- return OC_STACK_ERROR;
+ OIC_LOG(ERROR, TAG, "Device Resource does not exist.");
+ goto exit;
}
+
+ VERIFY_SUCCESS(OCBindResourceTypeToResource(resourceHandle, deviceType));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions));
+
+ OIC_LOG(INFO, TAG, "Device information initialized successfully.");
return OC_STACK_OK;
+
+exit:
+ return OC_STACK_ERROR;
}
static void PrintUsage()
OCStackResult registrationResult =
SetPlatformInfo(platformID, manufacturerName, manufacturerLink, modelNumber,
- dateOfManufacture, platformVersion, operatingSystemVersion, hardwareVersion,
- firmwareVersion, supportLink, systemTime);
+ dateOfManufacture, platformVersion, operatingSystemVersion,
+ hardwareVersion, firmwareVersion, supportLink, systemTime);
if (registrationResult != OC_STACK_OK)
{
exit (EXIT_FAILURE);
}
- registrationResult = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-
- if (registrationResult != OC_STACK_OK)
- {
- OIC_LOG(INFO, TAG, "Device info setting failed locally!");
- exit (EXIT_FAILURE);
- }
-
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
-
- registrationResult = OCSetDeviceInfo(deviceInfo);
+ registrationResult = SetDeviceInfo();
if (registrationResult != OC_STACK_OK)
{
OIC_LOG(INFO, TAG, "Device Registration failed!");
exit (EXIT_FAILURE);
}
-
+
/*
* Declare and create the example resource: Light
*/
* Create a thread for generating changes that cause presence notifications
* to be sent to clients
*/
-
#ifdef WITH_PRESENCE
pthread_create(&threadId_presence, NULL, presenceNotificationGenerator, (void *)NULL);
#endif
OIC_LOG(INFO, TAG, "Entering ocserver main loop...");
DeletePlatformInfo();
- DeleteDeviceInfo();
signal(SIGINT, handleSigInt);
#include "ocserver.h"
using namespace std;
+#define VERIFY_SUCCESS(op) \
+{ \
+ if (op != OC_STACK_OK) \
+ { \
+ cout << #op << " failed!!" << endl; \
+ goto exit; \
+ } \
+}
+
//string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
// 9 + 9 + 1 = 19
const int URI_MAXSIZE = 19;
const char *systemTime = "2015-05-15T11.04";
const char *specVersion = "core.1.1.0";
const char *dataModelVersions = "res.1.1.0,sh.1.1.0";
+const char *deviceType = "oic.d.tv";
// Entity handler should check for resourceTypeName and ResourceInterface in order to GET
// the existence of a known resource
const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
OCPlatformInfo platformInfo;
-OCDeviceInfo deviceInfo;
OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
{
free (platformInfo.systemTime);
}
-void DeleteDeviceInfo()
-{
- free (deviceInfo.deviceName);
- free (deviceInfo.specVersion);
- OCFreeOCStringLL (deviceInfo.dataModelVersions);
-}
-
bool DuplicateString(char** targetString, const char* sourceString)
{
if(!sourceString)
return OC_STACK_ERROR;
}
-OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- if(!DuplicateString(&deviceInfo.deviceName, deviceName))
+ OCResourceHandle resourceHandle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ if (resourceHandle == NULL)
{
- return OC_STACK_ERROR;
- }
- if(!DuplicateString(&deviceInfo.specVersion, specVersion))
- {
- return OC_STACK_ERROR;
- }
- OCFreeOCStringLL(deviceInfo.dataModelVersions);
- deviceInfo.dataModelVersions = OCCreateOCStringLL(dataModelVersions);
- if (!deviceInfo.dataModelVersions)
- {
- return OC_STACK_ERROR;
+ OIC_LOG(ERROR, TAG, "Device Resource does not exist.");
+ goto exit;
}
+
+ VERIFY_SUCCESS(OCBindResourceTypeToResource(resourceHandle, deviceType));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions));
+
+ OIC_LOG(INFO, TAG, "Device information initialized successfully.");
return OC_STACK_OK;
+
+exit:
+ return OC_STACK_ERROR;
}
static void PrintUsage()
exit (EXIT_FAILURE);
}
- registrationResult = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-
- if (registrationResult != OC_STACK_OK)
- {
- cout << "\nDevice info setting failed locally!";
- exit (EXIT_FAILURE);
- }
-
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
-
- registrationResult = OCSetDeviceInfo(deviceInfo);
+ registrationResult = SetDeviceInfo();
if (registrationResult != OC_STACK_OK)
{
cout << "\nEntering ocserver main loop...";
DeletePlatformInfo();
- DeleteDeviceInfo();
signal(SIGINT, handleSigInt);
// Set of strings for each of device info fields
std::string deviceName = "Bill's Battlestar";
std::string specVersion = "core.1.1.0";
-std::string dataModelVersions = "res.1.1.0,sh.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0", "sh.1.1.0"};
+
+// Device type
+std::string deviceType = "oic.d.tv";
// 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;
- delete[] deviceInfo.specVersion;
- OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
void DuplicateString(char ** targetString, std::string sourceString)
{
*targetString = new char[sourceString.length() + 1];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OC_STACK_ERROR;
+
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ if (handle == NULL)
+ {
+ std::cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << std::endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCBindResourceTypeToResource(handle, deviceType.c_str());
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ std::cout << "Failed to add device type" << std::endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ std::cout << "Failed to set device name" << std::endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
+ {
+ std::cout << "Failed to set data model versions" << std::endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
+ {
+ std::cout << "Failed to set spec version" << std::endl;
+ return result;
}
return OC_STACK_OK;
result = OCPlatform::registerPlatformInfo(platformInfo);
- if(result != OC_STACK_OK)
+ if (result != OC_STACK_OK)
{
std::cout << "Platform Registration failed\n";
return -1;
}
+ result = SetDeviceInfo();
- 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)
+ if (result != OC_STACK_OK)
{
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
// 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";
+std::vector<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:
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];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName);
+ if (result != OC_STACK_OK)
+ {
+ std::cout << "Failed to set device name" << std::endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ std::cout << "Failed to set data model versions" << std::endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ std::cout << "Failed to set spec version" << std::endl;
+ return result;
}
return OC_STACK_OK;
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
+ result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
}
DeletePlatformInfo();
- DeleteDeviceInfo();
// we will keep the server alive for at most 30 minutes
std::this_thread::sleep_for(std::chrono::minutes(30));
return 0;
// 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";
+std::vector<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);
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];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ cout << "Failed to set data model versions" << endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ cout << "Failed to set spec version" << endl;
+ return result;
}
return OC_STACK_OK;
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
-
+ result = SetDeviceInfo();
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
// 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";
+std::vector<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
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];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ cout << "Failed to set data model versions" << endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ cout << "Failed to set spec version" << endl;
+ return result;
}
return OC_STACK_OK;
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
+ result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
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
std::string resourceInterface = DEFAULT_INTERFACE;
/* Device Information */
- char* deviceName = "IoTivity Media Server";
- char* specVersion = "core.1.1.0";
- OCStringLL types{ nullptr, const_cast<char*>(resourceTypeName.c_str()) };
- OCDeviceInfo deviceInfo{ deviceName, &types, specVersion, nullptr };
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
+ result = SetDeviceInfo();
if (OC_STACK_OK != result)
{
cout << "Device information registration was unsuccessful\n";
return ehResult;
}
+OCStackResult SetDeviceInfo()
+{
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ "IoTivity Media Server");
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, "core.1.1.0");
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set spec version" << endl;
+ return result;
+ }
+
+ return OC_STACK_OK;
+}
+
};
// ChangeMediaRepresentaion is an observation function,
// 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";
+std::vector<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);
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];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ cout << "Failed to set data model versions" << endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ cout << "Failed to set spec version" << endl;
+ return result;
}
return OC_STACK_OK;
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
-
+ result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
std::cout << "Device Registration failed\n";
return -1;
}
+
try
{
using namespace OC::OCPlatform;
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
// 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";
+std::vector<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:
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];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ cout << "Failed to set data model versions" << endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ cout << "Failed to set spec version" << endl;
+ return result;
}
return OC_STACK_OK;
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
+ result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
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
// Set of strings for each of device info fields
std::string deviceName = "IoTivity Simple Server";
+std::string deviceType = "oic.wk.tv";
std::string specVersion = "core.1.1.0";
-std::string dataModelVersions = "res.1.1.0,sh.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0", "sh.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
return OC_STACK_OK;
}
+OCStackResult SetDeviceInfo()
+{
+ OCStackResult result = OC_STACK_ERROR;
+
+ OCResourceHandle handle = OCGetResourceHandleAtUri(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());
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to add device type" << endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set data model versions" << endl;
+ return result;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set spec version" << endl;
+ return result;
+ }
+
+ return OC_STACK_OK;
+}
+
void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequest)
{
// This function handles slow response case
return -1;
}
- result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
- result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
- result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
- dataModelVersions);
- OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
- if (handle)
- {
- OCBindResourceTypeToResource(handle, "oic.wk.tv");
- }
-
+ result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
std::cout << "Device Registration failed\n";
// 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";
+std::vector<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
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];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
{
- DuplicateString(&deviceInfo.deviceName, deviceName);
+ OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName);
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set device name" << endl;
+ return result;
+ }
- if (!specVersion.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ if (result != OC_STACK_OK)
{
- DuplicateString(&deviceInfo.specVersion, specVersion);
+ cout << "Failed to set data model versions" << endl;
+ return result;
}
- if (!dataModelVersions.empty())
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ if (result != OC_STACK_OK)
{
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+ cout << "Failed to set spec version" << endl;
+ return result;
}
return OC_STACK_OK;
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
-
+ result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
std::cout << "Device Registration failed\n";
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
EntityHandler& entityHandler,
uint8_t resourceProperty) = 0;
+ // @deprecated: Use setPropertyValue instead.
virtual OCStackResult registerDeviceInfo(
const OCDeviceInfo deviceInfo) = 0;
EntityHandler& entityHandler,
uint8_t resourceProperty);
+ // @deprecated: Use setPropertyValue instead.
virtual OCStackResult registerDeviceInfo(
const OCDeviceInfo deviceInfo);
/**
* Register Device Info
*
+ * @deprecated: Use setPropertyValue instead.
+ *
* @param deviceInfo structure containing all the device specific information
* @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
*/
/**
* This API registers all the device specific information
*
+ * @deprecated: Use setPropertyValue instead.
+ *
* @param deviceInfo Structure containing all the device related information
*
* @return Returns ::OC_STACK_OK if success