#include "ocstack.h"
#include "ocpayload.h"
-#include "oicresourcedirectory.h"
+#include "RDClient.h"
#include <OCApi.h>
#include <OCPlatform.h>
pResponse->setResourceRepresentation(getRepresentation(), DEFAULT_INTERFACE);
}
- pResponse->setErrorCode(200);
pResponse->setResponseResult(OC_EH_OK);
return OCPlatform::sendResponse(pResponse);
shared_ptr<OCResourceResponse> resourceResponse =
{ make_shared<OCResourceResponse>() };
- resourceResponse->setErrorCode(200);
resourceResponse->setResourceRepresentation(getRepresentation(), DEFAULT_INTERFACE);
return OCPlatform::notifyListOfObservers(m_handle,
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;
+ }
+
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID,
+ "d7d2b492-83ac-4783-9dcc-b1b54587ebed");
+
+ if (result != OC_STACK_OK)
+ {
+ cout << "Failed to set piid" << 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 = OCPlatform::publishResourceToRD(host, OCConnectivityType::CT_ADAPTER_TCP,
+ result = RDClient::Instance().publishResourceToRD(host, OCConnectivityType::CT_ADAPTER_TCP,
resourceHandles,
&onPublish);
resourceHandles.push_back(airConditioner.m_handle);
- result = OCPlatform::publishResourceToRD(host, OCConnectivityType::CT_ADAPTER_TCP,
+ result = RDClient::Instance().publishResourceToRD(host, OCConnectivityType::CT_ADAPTER_TCP,
resourceHandles,
&onPublish);
case 'q':
goto exit;
- break;
}
}