Removed dependency on the OCPlatform object. We turned it into an internal-singleton(renamed to OCPlatform_impl so that we can use OCPlatform for the namespace, making it more consistent with previous code) with the expectation that people are to use OC::OCPlatform::<functionname> to control the API.
Change-Id: I3f0e13a27021f7454da68add93aaf562506e08ec
class ClientFridge
{
public:
- ClientFridge(PlatformConfig &cfg) : m_platform(cfg)
+ ClientFridge()
{
std::cout << "Fridge Client has started " <<std::endl;
FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
- OCStackResult result = m_platform.findResource(
+ OCStackResult result = OCPlatform::findResource(
"", "coap://224.0.1.187/oc/core?rt=intel.fridge", f);
if(OC_STACK_OK != result)
private:
void foundDevice(std::shared_ptr<OCResource> resource)
{
+ using namespace OC::OCPlatform;
if(resource && resource->uri() == "/device")
{
std::cout << "Discovered a device object"<<std::endl;
// server, and query them.
std::vector<std::string> lightTypes = {"intel.fridge.light"};
std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
- OCResource::Ptr light = m_platform.constructResourceObject(resource->host(),
+ OCResource::Ptr light = constructResourceObject(resource->host(),
"/light", false, lightTypes, ifaces);
std::vector<std::string> doorTypes = {"intel.fridge.door"};
- OCResource::Ptr leftdoor = m_platform.constructResourceObject(resource->host(),
+ OCResource::Ptr leftdoor = constructResourceObject(resource->host(),
"/door/left", false, doorTypes, ifaces);
- OCResource::Ptr rightdoor = m_platform.constructResourceObject(resource->host(),
+ OCResource::Ptr rightdoor = constructResourceObject(resource->host(),
"/door/right", false, doorTypes, ifaces);
- OCResource::Ptr randomdoor = m_platform.constructResourceObject(resource->host(),
+ OCResource::Ptr randomdoor = constructResourceObject(resource->host(),
"/door/random", false, doorTypes, ifaces);
// Set header options with API version and token
}
}
- OCPlatform m_platform;
std::mutex m_mutex;
std::condition_variable m_cv;
};
QualityOfService::LowQos
};
- ClientFridge cf (cfg);
+ OCPlatform::Configure(cfg);
+ ClientFridge cf ();
return 0;
}
class DeviceResource : public Resource
{
public:
- OCPlatform& m_platform;
- DeviceResource(OCPlatform& platform): m_platform(platform)
+ DeviceResource()
{
std::string resourceURI = "/device";
std::string resourceTypeName = "intel.fridge";
PH::_1, PH::_2);
std::cout << "Setting device default entity handler\n";
- m_platform.setDefaultDeviceEntityHandler(defaultEH);
+ OCPlatform::setDefaultDeviceEntityHandler(defaultEH);
uint8_t resourceProperty = OC_DISCOVERABLE;
- OCStackResult result = m_platform.registerResource(m_resourceHandle,
+ OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
resourceURI,
resourceTypeName,
resourceInterface,
void deleteDeviceResource()
{
- OCStackResult result = m_platform.unregisterResource(m_resourceHandle);
+ OCStackResult result = OCPlatform::unregisterResource(m_resourceHandle);
if(OC_STACK_OK != result)
{
throw std::runtime_error(
class LightResource : public Resource
{
public:
- LightResource(OCPlatform& platform)
+ LightResource()
{
std::string resourceURI = "/light";
std::string resourceTypeName = "intel.fridge.light";
std::string resourceInterface = DEFAULT_INTERFACE;
EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
uint8_t resourceProperty = 0;
- OCStackResult result = platform.registerResource(m_resourceHandle,
+ OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
resourceURI,
resourceTypeName,
resourceInterface,
class DoorResource : public Resource
{
public:
- DoorResource(OCPlatform& platform, const std::string& side):m_side(side)
+ DoorResource(const std::string& side):m_side(side)
{
std::string resourceURI = "/door/"+ side;
EntityHandler cb = std::bind(&DoorResource::entityHandler, this,PH::_1, PH::_2);
uint8_t resourceProperty = 0;
- OCStackResult result = platform.registerResource(m_resourceHandle,
+ OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
resourceURI,
resourceTypeName,
resourceInterface,
};
-class Refridgerator
+class Refrigerator
{
public:
- Refridgerator(PlatformConfig &cfg)
- : m_platform(cfg),
- m_light(m_platform),
- m_device(m_platform),
- m_leftdoor(m_platform, "left"),
- m_rightdoor(m_platform, "right")
+ Refrigerator()
+ :
+ m_light(),
+ m_device(),
+ m_leftdoor("left"),
+ m_rightdoor("right")
{
}
private:
- OCPlatform m_platform;
LightResource m_light;
DeviceResource m_device;
DoorResource m_leftdoor;
QualityOfService::LowQos
};
- Refridgerator rf(cfg);
+ OCPlatform::Configure(cfg);
+ Refrigerator rf();
// we will keep the server alive for at most 30 minutes
std::this_thread::sleep_for(std::chrono::minutes(30));
#include <string>
#include <cstdlib>
-#include <pthread.h>
#include "OCPlatform.h"
#include "OCApi.h"
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
-
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
- std::cout << "Created Platform..."<<std::endl;
// Find all resources
- platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.garage", &foundResource);
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.garage",
+ &foundResource);
std::cout<< "Finding Resource... " <<std::endl;
while(true)
{
}
catch(OCException& e)
{
- //log(e.what());
+ std::cerr << "Exception in GarageClient: "<<e.what();
}
return 0;
access to, you can accomplish this with a free function: */
/// This function internally calls registerResource API.
- void createResource(OC::OCPlatform& platform)
+ void createResource()
{
std::string resourceURI = m_garageUri; // URI of the resource
std::string resourceTypeName = "core.garage"; // resource type name.
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
// This will internally create and register the resource.
- OCStackResult result = platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
m_resourceHandle, resourceURI, resourceTypeName,
resourceInterface, &entityHandler, resourceProperty);
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
-
// Invoke createResource function of class light.
- myGarage.createResource(platform);
+ myGarage.createResource();
// Perform app tasks
while(true)
//log(e.what());
}
- // No explicit call to stop the platform.
- // When OCPlatform destructor is invoked, internally we do platform cleanup
+ // No explicit call to stop the OCPlatform
+ // When OCPlatform destructor is invoked, internally we do Platform cleanup
}
{
using namespace std;
- OC::OCPlatform platform({
+ OC::OCPlatform::Configure({
OC::ServiceType::InProc, // in-process server
OC::ModeType::Client, // client mode
vm["host_ip"].as<string>(), // host
for(const auto& resource_URI : resource_URIs)
cout << resource_URI << '\n';
- Intel::OCDemo::client::resource_handler resources(platform, resource_URIs);
+ Intel::OCDemo::client::resource_handler resources(resource_URIs);
// Register callbacks and wait for resources:
resources.find_resources();
class resource_handler
{
- OC::OCPlatform& platform;
static std::vector<std::shared_ptr<resource_handle>> resources; // URI -> Maybe resource
public:
- resource_handler(OC::OCPlatform& platform_, const std::vector<std::string>& resource_URIs_);
- resource_handler(OC::OCPlatform& platform_);
+ resource_handler(const std::vector<std::string>& resource_URIs_);
+ resource_handler();
public:
bool has(const std::string& URI)
call_timer.mark("find_resources");
- platform.findResource("", resource->URI,
+ OC::OCPlatform::findResource("", resource->URI,
std::bind(&resource_handle::onFoundResource, resource, std::placeholders::_1));
}
}
std::vector<std::shared_ptr<resource_handle>> resource_handler::resources;
-resource_handler::resource_handler(OC::OCPlatform& platform_, const std::vector<std::string>& resource_URIs)
- : platform(platform_)
+resource_handler::resource_handler(const std::vector<std::string>& resource_URIs)
{
for(const auto& URI : resource_URIs)
add(URI);
}
-resource_handler::resource_handler(OC::OCPlatform& platform_)
- : platform(platform_)
-{}
-
void resource_handle::onFoundResource(std::shared_ptr<OC::OCResource> in_resource)
{
using std::cout;
return m_rep;
}
-void LightResource::addType(const OC::OCPlatform& platform, const std::string& type) const
+void LightResource::addType(const std::string& type) const
{
- OCStackResult result = platform.bindTypeToResource(m_resourceHandle, type);
+ OCStackResult result = OC::OCPlatform::bindTypeToResource(m_resourceHandle, type);
if(OC_STACK_OK != result)
cout << "Binding TypeName to Resource was unsuccessful, result was " << result << '\n';
}
-void LightResource::addInterface(const OC::OCPlatform& platform, const std::string& interface) const
+void LightResource::addInterface(const std::string& interface) const
{
- OCStackResult result = platform.bindInterfaceToResource(m_resourceHandle, interface);
+ OCStackResult result = OC::OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
if(OC_STACK_OK != result)
cout << "Binding TypeName to Resource was unsuccessful, result was " << result << '\n';
}
-void LightResource::createResource(OC::OCPlatform& platform, const unsigned int resource_number)
+void LightResource::createResource(const unsigned int resource_number)
{
string resourceURI { make_URI(resource_number) };
string resourceTypeName { "core.light" };
cout << "registering resource: " << resourceURI << '\n';
cout << "registering type name \"" << resourceTypeName << "\".\n";
// This will internally create and register the resource, binding the current instance's method as a callback:
- OCStackResult result = platform.registerResource(
+ OCStackResult result = OC::OCPlatform::registerResource(
m_resourceHandle, resourceURI, resourceTypeName,
DEFAULT_INTERFACE,
std::bind(&LightResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2),
m_power += 10;
- const auto result = m_platform.notifyAllObservers(getHandle());
+ const auto result = OC::OCPlatform::notifyAllObservers(getHandle());
// Stop notifications when there are no more observers:
if(OC_STACK_NO_OBSERVERS == result)
cerr << "Observation thread is shutting down.\n";
}
-void LightResource::unregisterResource(OC::OCPlatform& platform)
+void LightResource::unregisterResource()
{
std::cout << "Unregistering light resource"<<std::endl;
- OCStackResult result = platform.unregisterResource(m_resourceHandle);
+ OCStackResult result = OC::OCPlatform::unregisterResource(m_resourceHandle);
if(result == OC_STACK_OK)
{
class LightResource
{
public:
- OCPlatform& m_platform;
bool m_state; // off or on?
int m_power; // power level
OCRepresentation m_rep;
OCResourceHandle m_resourceHandle;
public:
- LightResource(OCPlatform& platform)
- : m_platform(platform),
- m_state(false),
+ LightResource()
+ : m_state(false),
m_power(0),
m_observation(false)
{}
public:
// This function internally calls registerResource API.
- void createResource(OC::OCPlatform& platform, const unsigned int resource_number);
- void unregisterResource(OC::OCPlatform& platform);
+ void createResource(const unsigned int resource_number);
+ void unregisterResource();
OCResourceHandle getHandle() const { return m_resourceHandle; }
void setRepresentation(const OCRepresentation& rep);
OCRepresentation getRepresentation(void);
- void addType(const OC::OCPlatform& platform, const std::string& type) const;
- void addInterface(const OC::OCPlatform& platform, const std::string& interface) const;
+ void addType(const std::string& type) const;
+ void addInterface(const std::string& interface) const;
private:
OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request,
struct client_t
{
const boost::program_options::variables_map m_vm;
- std::shared_ptr<OC::OCPlatform> m_platform_ptr;
- OC::OCPlatform& m_platform; // reference to *m_platform_ptr
atomic<bool>& quit_flag;
public:
client_t(const boost::program_options::variables_map vm,
- std::shared_ptr<OC::OCPlatform> platform_ptr,
atomic<bool>& quit_flag_)
: m_vm(vm),
- m_platform_ptr(platform_ptr),
- m_platform(*m_platform_ptr),
quit_flag(quit_flag_)
{}
for(const auto& resource_URI : resource_URIs)
cout << resource_URI << '\n';
- Intel::OCDemo::client::resource_handler resources(m_platform, resource_URIs);
+ Intel::OCDemo::client::resource_handler resources(resource_URIs);
// Register callbacks and wait for resources:
resources.find_resources();
struct server_t
{
const boost::program_options::variables_map m_vm;
- std::shared_ptr<OC::OCPlatform> m_platform_ptr;
- OC::OCPlatform& m_platform;
atomic<bool>& quit_flag;
public:
server_t(const boost::program_options::variables_map& vm,
- std::shared_ptr<OC::OCPlatform> platform,
atomic<bool>& quit_flag_)
: m_vm(vm),
- m_platform_ptr(platform),
- m_platform(*m_platform_ptr),
quit_flag(quit_flag_)
{
m_nresources = vm["nres"].as<unsigned long>();
{
cout << "Registering resource " << resource_number << ": " << std::flush;
- auto lr = make_shared<Intel::OCDemo::LightResource>(m_platform);
+ auto lr = make_shared<Intel::OCDemo::LightResource>();
- lr->createResource(m_platform, resource_number);
- lr->addType(m_platform, "core.brightlight");
- lr->addInterface(m_platform, "oc.mi.ll");
+ lr->createResource(resource_number);
+ lr->addType("core.brightlight");
+ lr->addInterface("oc.mi.ll");
lights.push_back(lr);
std::cout << "Starting platform: " << std::flush;
- auto platform = make_shared<OC::OCPlatform>(OC::PlatformConfig {
- OC::ServiceType::InProc, // in-process server
+ OC::OCPlatform::Configure(OC::PlatformConfig {
+ OC::ServiceType::InProc,
OC::ModeType::Both, // run in client/server mode
vm["host_ip"].as<string>(), // host
vm["host_port"].as<uint16_t>(), // port
OC::QualityOfService::LowQos
});
-
std::cout << "Ok." << std::endl;
std::atomic<bool> quit_flag;
- server_t server(vm, platform, quit_flag);
- client_t client(vm, platform, quit_flag);
+ server_t server(vm, quit_flag);
+ client_t client(vm, quit_flag);
std::cout << "JFW: TODO: don't need to separate these any more\n";
server.init();
std::cout << "Starting platform: " << std::flush;
- OC::OCPlatform platform({
+ OC::OCPlatform::Configure({
OC::ServiceType::InProc, // in-process server
OC::ModeType::Server, // run in server mode
vm["host_ip"].as<string>(), // host
{
cout << "Registering resource " << resource_number << ": " << std::flush;
- auto lr = make_shared<Intel::OCDemo::LightResource>(platform);
+ auto lr = make_shared<Intel::OCDemo::LightResource>();
- lr->createResource(platform, resource_number);
- lr->addType(platform, std::string("core.brightlight"));
- lr->addInterface(platform, std::string("oc.mi.ll"));
+ lr->createResource(resource_number);
+ lr->addType(std::string("core.brightlight"));
+ lr->addInterface(std::string("oc.mi.ll"));
lights.push_back(lr);
for(auto light: lights)
{
- light->unregisterResource(platform);
+ light->unregisterResource();
}
return 1;
std::shared_ptr<OCResource> curResource;
-OCPlatform* platformPtr;
-
// Callback to presence
void presenceHandler(OCStackResult result, const unsigned int nonce)
{
{
curResource = resource;
OCPlatform::OCPresenceHandle presenceHandle;
- platformPtr->subscribePresence(presenceHandle, hostAddress, &presenceHandler);
+ OCPlatform::subscribePresence(presenceHandle, hostAddress, &presenceHandler);
}
}
else
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
- // PlatformPtr is used in another function
- platformPtr = &platform;
std::cout << "Created Platform..."<<std::endl;
// Find all resources
- platform.findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
std::cout<< "Finding Resource... " <<std::endl;
while(true)
{
access to, you can accomplish this with a free function: */
/// This function internally calls registerResource API.
- void createResource(OC::OCPlatform& platform)
+ void createResource()
{
std::string resourceURI = m_lightUri; // URI of the resource
std::string resourceTypeName = "core.light"; // resource type name.
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
// This will internally create and register the resource.
- OCStackResult result = platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
m_resourceHandle, resourceURI, resourceTypeName,
resourceInterface, &entityHandler, resourceProperty);
}
/// This function internally calls registerResource API.
- void createResource2(OC::OCPlatform& platform)
+ void createResource2()
{
std::string resourceURI = m_lightUri2; // URI of the resource
std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
// This will internally create and register the resource.
- OCStackResult result = platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
m_resourceHandle2, resourceURI, resourceTypeName,
resourceInterface, &entityHandler, resourceProperty);
}
}
- void createResource3(OC::OCPlatform& platform)
+ void createResource3()
{
std::string resourceURI = m_lightUri3; // URI of the resource
std::string resourceTypeName = "core.light";
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
// This will internally create and register the resource.
- OCStackResult result = platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
m_resourceHandle3, resourceURI, resourceTypeName,
resourceInterface, &entityHandler, resourceProperty);
return m_resourceHandle;
}
- void addType(const OC::OCPlatform& platform, const std::string& type) const
+ void addType(const std::string& type) const
{
- OCStackResult result = platform.bindTypeToResource(m_resourceHandle, type);
+ OCStackResult result = OC::OCPlatform::bindTypeToResource(m_resourceHandle, type);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
}
}
- void addInterface(const OC::OCPlatform& platform, const std::string& interface) const
+ void addInterface(const std::string& interface) const
{
- OCStackResult result = platform.bindInterfaceToResource(m_resourceHandle, interface);
+ OCStackResult result = OC::OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
-
+ using namespace OC::OCPlatform;
// Time to Live is 30 seconds
- platform.startPresence(30);
+ startPresence(30);
// Invoke createResource function of class light.
- myLightResource.createResource(platform);
+ myLightResource.createResource();
printf("\nEnter a key to create the second resource\n");
getchar();
- myLightResource.createResource2(platform);
+ myLightResource.createResource2();
printf("\nEnter a key to stop the presence\n");
getchar();
- platform.stopPresence();
+ stopPresence();
printf("\nEnter a key to restart the presence\n");
getchar();
- platform.startPresence(30);
+ startPresence(30);
printf("\nEnter a key to create the third resource\n");
getchar();
- myLightResource.createResource3(platform);
+ myLightResource.createResource3();
// Perform app tasks
while(true)
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
- std::cout << "Created Platform..."<<std::endl;
// Find all resources
- platform.findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
std::cout<< "Finding Resource... " <<std::endl;
while(true)
{
}
/// This function internally calls registerResource API.
- void createResources(OC::OCPlatform& platform)
+ void createResources()
{
+ using namespace OC::OCPlatform;
// This will internally create and register the resource.
- OCStackResult result = platform.registerResource(
+ OCStackResult result = registerResource(
m_roomHandle, m_roomUri, m_roomTypes[0],
m_roomInterfaces[0], entityHandlerRoom,
OC_DISCOVERABLE | OC_OBSERVABLE
cout << "Resource creation (room) was unsuccessful\n";
}
- result = platform.bindInterfaceToResource(m_roomHandle, m_roomInterfaces[1]);
+ result = bindInterfaceToResource(m_roomHandle, m_roomInterfaces[1]);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
}
- result = platform.bindInterfaceToResource(m_roomHandle, m_roomInterfaces[2]);
+ result = bindInterfaceToResource(m_roomHandle, m_roomInterfaces[2]);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
}
- result = platform.registerResource(
+ result = registerResource(
m_lightHandle, m_lightUri, m_lightTypes[0],
m_lightInterfaces[0], entityHandlerLight,
OC_DISCOVERABLE | OC_OBSERVABLE
cout << "Resource creation (light) was unsuccessful\n";
}
- result = platform.registerResource(
+ result = registerResource(
m_fanHandle, m_fanUri, m_fanTypes[0],
m_fanInterfaces[0], entityHandlerFan,
OC_DISCOVERABLE | OC_OBSERVABLE
cout << "Resource creation (fan) was unsuccessful\n";
}
- result = platform.bindResource(m_roomHandle, m_lightHandle);
+ result = bindResource(m_roomHandle, m_lightHandle);
if (OC_STACK_OK != result)
{
cout << "Binding fan resource to room was unsuccessful\n";
}
- result = platform.bindResource(m_roomHandle, m_fanHandle);
+ result = bindResource(m_roomHandle, m_fanHandle);
if (OC_STACK_OK != result)
{
cout << "Binding light resource to room was unsuccessful\n";
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
- myRoomResource.createResources(platform);
+ myRoomResource.createResources();
// Perform app tasks
while(true)
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
-
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
- std::cout << "Created Platform..."<<std::endl;
// Find all resources
- platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
std::cout<< "Finding Resource... " <<std::endl;
while(true)
{
OC::QualityOfService::LowQos
};
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ OCPlatform::Configure(cfg);
try
{
- OCPlatform platform(cfg);
- std::cout << "Created Platform..."<<std::endl;
// Find all resources
- platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
OC::QualityOfService::LowQos);
std::cout<< "Finding Resource... " <<std::endl;
while(true)
}
public:
- void start(OCPlatform& platform)
+ void start()
{
std::cout<<"Starting Client find:"<<std::endl;
FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
- std::cout<<"result:" << platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)<< std::endl;
+ std::cout<<"result:" <<
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)
+ << std::endl;
std::cout<<"Finding Resource..."<<std::endl;
{
m_rep.setValue("barCount", m_barCount);
}
- bool createResource(OCPlatform& platform)
+ bool createResource()
{
std::string resourceURI = "/q/foo";
std::string resourceTypeName = "core.foo";
uint8_t resourceProperty = OC_DISCOVERABLE;
- EntityHandler eh(std::bind(&FooResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2));
- OCStackResult result = platform.registerResource(m_resourceHandle, resourceURI, resourceTypeName,
+ EntityHandler eh(std::bind(&FooResource::entityHandler,
+ this, std::placeholders::_1, std::placeholders::_2));
+ OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
+ resourceURI, resourceTypeName,
resourceInterface,
eh, resourceProperty);
if(OC_STACK_OK != result)
OC::QualityOfService::LowQos
};
+ OCPlatform::Configure(cfg);
FooResource fooRes;
try
{
- OCPlatform platform(cfg);
- if(!fooRes.createResource(platform))
+ if(!fooRes.createResource())
{
return -1;
}
ClientWorker cw;
- cw.start(platform);
+ cw.start();
}
catch(OCException& e)
{
public:
/// Access this property from a TB client
- OCPlatform m_platform;
std::string m_name;
bool m_state;
int m_power;
public:
/// Constructor
- LightResource(PlatformConfig& cfg): m_platform(cfg),
- m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
+ LightResource()
+ :m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
// Initialize representation
m_lightRep.setUri(m_lightUri);
EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
// This will internally create and register the resource.
- OCStackResult result = m_platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
m_resourceHandle, resourceURI, resourceTypeName,
resourceInterface, cb, resourceProperty);
OCResourceHandle resHandle;
// This will internally create and register the resource.
- OCStackResult result = m_platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
resHandle, resourceURI, resourceTypeName,
resourceInterface, cb, resourceProperty);
void addType(const std::string& type) const
{
- OCStackResult result = m_platform.bindTypeToResource(m_resourceHandle, type);
+ OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
void addInterface(const std::string& interface) const
{
- OCStackResult result = m_platform.bindInterfaceToResource(m_resourceHandle, interface);
+ OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
resourceResponse->setErrorCode(200);
resourceResponse->setResourceRepresentation(lightPtr->get(), DEFAULT_INTERFACE);
- result = lightPtr->m_platform.notifyListOfObservers( lightPtr->getHandle(),
+ result = OCPlatform::notifyListOfObservers( lightPtr->getHandle(),
lightPtr->m_interestedObservers,
resourceResponse);
}
else
{
- result = lightPtr->m_platform.notifyAllObservers(lightPtr->getHandle());
+ result = OCPlatform::notifyAllObservers(lightPtr->getHandle());
}
if(OC_STACK_NO_OBSERVERS == result)
OC::QualityOfService::LowQos
};
+ OCPlatform::Configure(cfg);
try
{
// Create the instance of the resource class (in this case instance of class 'LightResource').
- LightResource myLight(cfg);
+ LightResource myLight;
// Invoke createResource function of class light.
myLight.createResource();
}
// No explicit call to stop the platform.
- // When OCPlatform destructor is invoked, internally we do platform cleanup
+ // When OCPlatform::destructor is invoked, internally we do platform cleanup
}
public:
/// Access this property from a TB client
- OCPlatform m_platform;
std::string m_name;
bool m_state;
int m_power;
public:
/// Constructor
- LightResource(PlatformConfig& cfg): m_platform(cfg),
- m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
+ LightResource(PlatformConfig& cfg)
+ :m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
// Initialize representation
m_lightRep.setUri(m_lightUri);
EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
// This will internally create and register the resource.
- OCStackResult result = m_platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
m_resourceHandle, resourceURI, resourceTypeName,
resourceInterface, cb, resourceProperty);
OCResourceHandle resHandle;
// This will internally create and register the resource.
- OCStackResult result = m_platform.registerResource(
+ OCStackResult result = OCPlatform::registerResource(
resHandle, resourceURI, resourceTypeName,
resourceInterface, cb, resourceProperty);
void addType(const std::string& type) const
{
- OCStackResult result = m_platform.bindTypeToResource(m_resourceHandle, type);
+ OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
void addInterface(const std::string& interface) const
{
- OCStackResult result = m_platform.bindInterfaceToResource(m_resourceHandle, interface);
+ OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
if (OC_STACK_OK != result)
{
cout << "Binding TypeName to Resource was unsuccessful\n";
resourceResponse->setErrorCode(200);
resourceResponse->setResourceRepresentation(lightPtr->get(), DEFAULT_INTERFACE);
- result = lightPtr->m_platform.notifyListOfObservers( lightPtr->getHandle(),
- lightPtr->m_interestedObservers,
- resourceResponse, OC::QualityOfService::HighQos);
+ result = OCPlatform::notifyListOfObservers(
+ lightPtr->getHandle(),
+ lightPtr->m_interestedObservers,
+ resourceResponse,
+ OC::QualityOfService::HighQos);
}
else
{
- result = lightPtr->m_platform.notifyAllObservers(lightPtr->getHandle(), OC::QualityOfService::HighQos);
+ result = OCPlatform::notifyAllObservers(lightPtr->getHandle(),
+ OC::QualityOfService::HighQos);
}
if(OC_STACK_NO_OBSERVERS == result)
OC::QualityOfService::LowQos
};
+ OCPlatform::Configure(cfg);
+
try
{
// Create the instance of the resource class (in this case instance of class 'LightResource').
namespace OC
{
- class OCPlatform;
+ class OCPlatform_impl;
class IClientWrapper : public std::enable_shared_from_this<IClientWrapper>
{
protected:
- OCPlatform& m_owner;
+ OCPlatform_impl& m_owner;
public:
typedef std::shared_ptr<IClientWrapper> Ptr;
- IClientWrapper(OCPlatform& owner)
+ IClientWrapper(OCPlatform_impl& owner)
: m_owner(owner)
{}
class IServerWrapper
{
protected:
- OCPlatform& m_owner;
+ OCPlatform_impl& m_owner;
public:
typedef std::shared_ptr<IServerWrapper> Ptr;
- IServerWrapper(OCPlatform& owner)
+ IServerWrapper(OCPlatform_impl& owner)
: m_owner(owner)
{}
class InProcClientWrapper : public IClientWrapper
{
public:
- InProcClientWrapper(OC::OCPlatform& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
+ InProcClientWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
PlatformConfig cfg);
virtual ~InProcClientWrapper();
std::weak_ptr<std::recursive_mutex> m_csdkLock;
private:
- OC::OCPlatform& m_owner;
+ OC::OCPlatform_impl& m_owner;
PlatformConfig m_cfg;
};
}
class InProcServerWrapper : public IServerWrapper
{
public:
- InProcServerWrapper(OC::OCPlatform& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
+ InProcServerWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
PlatformConfig cfg);
virtual ~InProcServerWrapper();
namespace OC
{
- class OCPlatform;
class OCResource;
class OCResourceRequest;
class OCResourceResponse;
QualityOfService QoS;
public:
+ PlatformConfig()
+ : serviceType(ServiceType::InProc),
+ mode(ModeType::Both),
+ ipAddress("0.0.0.0"),
+ port(0),
+ QoS(QualityOfService::NaQos)
+ {}
PlatformConfig(const ServiceType serviceType_,
const ModeType mode_,
const std::string& ipAddress_,
#ifndef __OCPLATFORM_H
#define __OCPLATFORM_H
-
-#include <map>
-
-#include "OCApi.h"
-#include "OCResource.h"
-#include "OCPlatformHandler.h"
-#include "WrapperFactory.h"
-#include "OCResourceRequest.h"
-#include "OCResourceResponse.h"
-#include "OCRepresentation.h"
-
-#include "oc_logger.hpp"
-
+#include <OCApi.h>
+#include <OCPlatform_impl.h>
namespace OC
{
/**
- * @brief Both server and client must initialize the core platform by instantiating OCPlatform.
- * On successful initialization, an instance of the OCPlatform is returned.
- * APIs in OCPlatform provide mechanism to register a resource and host the resource
- * on the server, find resources on the network etc.
+ * @brief: This namespace contains the main entrance/functionality of the product.
+ * It may be used with OC::OCPlatform::functionName. To set a custom configuration,
+ * the implementer must make a call to OCPlatform::Configure before the first usage
+ * of a function in this namespace.
*/
- class OCPlatform
+ namespace OCPlatform
{
- public:
- // typedef for handle to cancel presence info with
- typedef OCDoHandle OCPresenceHandle;
-
/**
- * Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
- * appropriate fields
- * @param config PlatformConfig struct which has details such as modeType (server/client/both),
- * in-proc/out-of-proc etc.
- */
- OCPlatform(const PlatformConfig& config);
+ * API for overwriting the default configuration of the OCPlatform object.
+ * Note: Any calls made to this AFTER the first call to OCPlatform::Instance
+ * will have no affect
+ */
+ void Configure(const PlatformConfig& config);
- /**
- * Virtual destructor
- */
- virtual ~OCPlatform(void);
+ // typedef for handle to cancel presence info with
+ typedef OCDoHandle OCPresenceHandle;
/**
* API for notifying base that resource's attributes have changed.
*
* @param host - Host IP Address of a service to direct resource discovery query. If null or
* empty, performs multicast resource discovery query
- * @param resourceURI - name of the resource. If null or empty, performs search for all resource names
+ * @param resourceURI - name of the resource. If null or empty, performs search for all
+ * resource names
* @param handler - Handles callbacks, success states and failure states.
*
* Four modes of discovery defined as follows:
- * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource discovery.
- * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
- * from ALL services.
+ * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
+ * discovery.
+ * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
+ * resource(s) from ALL services.
* (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
- * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
+ * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
+ * resource(s)
* from a particular service.
* @param QualityOfService the quality of communication
*
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
- * NOTE: First parameter 'host' currently represents an IP address. This will change in future
- * and will refer to endpoint interface so that we can refer to other transports such as BTH etc.
+ * NOTE: First parameter 'host' currently represents an IP address. This will change in
+ * future and will refer to endpoint interface so that we can refer to other transports such
+ * as BTH etc.
* NOTE: OCStackResult is defined in ocstack.h.
*/
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
* @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
* setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
* setting resourceProperty as OC_OBSERVABLE will allow observation
- * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and observation
+ * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
+ * observation
*
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
* NOTE: "a/light" is a relative URI.
* Above relative URI will be prepended (by core) with a host IP + namespace "oc"
* Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
- * Example, a relative URI: 'a/light' will result in a fully qualified URI: //192.168.1.1/oc/a/light"
- * First parameter can take a relative URI and core will take care of preparing the fully qualified URI
- * OR
- * first paramter can take fully qualified URI and core will take that as is for further operations
+ * Example, a relative URI: 'a/light' will result in a fully qualified URI:
+ * //192.168.1.1/oc/a/light"
+ * First parameter can take a relative URI and core will take care of preparing the fully
+ * qualified URI OR
+ * first paramter can take fully qualified URI and core will take that as is for further
+ * operations
* NOTE: OCStackResult is defined in ocstack.h.
*/
OCStackResult registerResource(OCResourceHandle& resourceHandle,
* This API unregisters a resource with the server
* NOTE: This API applies to server side only.
*
- * @param resourceHandle - This is the resource handle which we which to unregister from the server
+ * @param resourceHandle - This is the resource handle which we which to unregister from the
+ * server
*
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
* NOTE: OCStackResult is defined in ocstack.h.
*/
- OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
+ OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
/**
* Add a resource to a collection resource.
* NOTE: bindResource must be used only after the both collection resource and
* resource to add under a collections are created and respective handles obtained<br>
* <b>Example:</b> <br>
- * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
* Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
* At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
*/
- OCStackResult bindResource(const OCResourceHandle collectionHandle, const OCResourceHandle resourceHandle);
+ OCStackResult bindResource(const OCResourceHandle collectionHandle,
+ const OCResourceHandle resourceHandle);
/**
* Add multiple resources to a collection resource.
*
* @param collectionHandle - handle to the collection resource
- * @param addedResourceHandleList reference to list of resource handles to be added to the collection resource
+ * @param addedResourceHandleList reference to list of resource handles to be added to the
+ * collection resource
*
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
* NOTE: OCStackResult is defined in ocstack.h. <br>
* NOTE: bindResources must be used only after the both collection resource and
- * list of resources to add under a collection are created and respective handles obtained <br>
+ * list of resources to add under a collection are created and respective handles
+ * obtained <br>
* <b> Example: </b> <br>
- * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface, roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle); rList.push_back(roomResourceHandle);<br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+ * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+ * rList.push_back(roomResourceHandle);<br>
* Step 5: bindResource(homeResourceHandle, rList);<br>
- * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and "a/room" <br>
+ * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
+ * "a/room" <br>
*/
- OCStackResult bindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& addedResourceHandleList);
+ OCStackResult bindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& addedResourceHandleList);
/**
* Unbind a resource from a collection resource.
* NOTE: unbindResource must be used only after the both collection resource and
* resource to unbind from a collection are created and respective handles obtained<br>
* <b> Example </b> <br>
- * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
* Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
* Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
* At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
*/
- OCStackResult unbindResource(const OCResourceHandle collectionHandle, const OCResourceHandle resourceHandle);
+ OCStackResult unbindResource(const OCResourceHandle collectionHandle,
+ const OCResourceHandle resourceHandle);
/**
* Unbind resources from a collection resource.
*
* @param collectionHandle - handle to the collection resource
- * @param resourceHandleList List of resource handles to be unbound from the collection resource
+ * @param resourceHandleList List of resource handles to be unbound from the collection
+ * resource
*
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
*
* NOTE: OCStackResult is defined in ocstack.h.<br>
* NOTE: unbindResources must be used only after the both collection resource and
- * list of resources resource to unbind from a collection are created and respective handles obtained. <br>
+ * list of resources resource to unbind from a collection are created and respective handles
+ * obtained. <br>
* <b>Example</b> <br>
- * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface, roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
- * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle); rList.push_back(roomResourceHandle);<br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+ * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+ * rList.push_back(roomResourceHandle);<br>
* Step 5: bindResource(homeResourceHandle, rList);<br>
* Step 6: unbindResources(homeResourceHandle, rList);<br>
- * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and "a/room"<br>
+ * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
+ * "a/room"<br>
*/
- OCStackResult unbindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& resourceHandleList);
+ OCStackResult unbindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& resourceHandleList);
/**
* Binds a type to a particular resource
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
- const std::string& resourceTypeName) const;
+ const std::string& resourceTypeName);
/**
* Binds an interface to a particular resource
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
- const std::string& resourceInterfaceName) const;
+ const std::string& resourceInterfaceName);
+
- public:
/**
* Start Presence announcements.
*
* request. It can be used to unsubscribe from these events in the future.
* It will be set upon successful return of this method.
* @param host - The IP address/addressable name of the server to subscribe to.
- * @param presenceHandler - callback function that will receive notifications/subscription events
+ * @param presenceHandler - callback function that will receive notifications/subscription
+ * events
*
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
* you may for a short time still receive events from the server since it may take time
* for the unsubscribe to take effect.
*
- * @param presenceHandle - the handle object provided by the subscribePresence call that identifies
- * this subscription.
+ * @param presenceHandle - the handle object provided by the subscribePresence call that
+ * identifies this subscription.
*
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
bool isObservable, const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces);
-
- private:
- PlatformConfig m_cfg;
-
- private:
- std::unique_ptr<WrapperFactory> m_WrapperInstance;
- IServerWrapper::Ptr m_server;
- IClientWrapper::Ptr m_client;
- std::shared_ptr<std::recursive_mutex> m_csdkLock;
-
- private:
- /**
- * Private function to initalize the platfrom
- */
- void init(const PlatformConfig& config);
-
- /**
- * Private constructor/operators to prevent copying
- * of this object
- */
- OCPlatform(const OCPlatform& other)= delete;
- OCPlatform& operator=(const OCPlatform&) = delete;
- OCPlatform& operator=(const OCPlatform&&) = delete;
- };
+ }
}
#endif //__OCPLATFORM_H
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/// @file OCPlatformHandler.h
-
-/// @brief This file contains the declaration of classes and its members related to
-/// OCPlatformHandler.
-
-#ifndef __OCPLATFORMHANDLER_H
-#define __OCPLATFORMHANDLER_H
-
-#include "OCApi.h"
-
-namespace OC
-{
- class OCPlatform;
-
- /**
- * @brief OCPlatformHandler is a pure abstract class and it can be used for
- * registering and getting callbacks
- */
- class OCPlatformHandler
- {
- public:
- OCPlatformHandler(void);
-
- virtual ~OCPlatformHandler(void);
-
- /**
- * @fn This function is called when the platform gets initialzed
- *
- * @param platform pointer to OCPlatform object
- */
- virtual void onPlatformInitialized(OCPlatform *platform) = 0;
-
- /**
- * @fn This function is called when platform status is changed
- *
- * @param platform - pointer to OCPlatform object
- * @param status - OCPlatform status
- */
- virtual void onPlatformStatusChanged(OCPlatform *platform, OCPlatformStatus status) = 0;
- };
-}
-
-#endif // __OCPLATFORMHANDLER_H
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OCPlatform_impl.h
+
+/// @brief Implementation of the OCPlatform functionality. It contains
+/// a singleton interface that is used only by the OCPlatform namespace and is the
+/// central entrance to the stack.
+
+#ifndef __OCPLATFORM_IMPL_H
+#define __OCPLATFORM_IMPL_H
+
+#include <map>
+
+#include "OCApi.h"
+#include "OCResource.h"
+#include "WrapperFactory.h"
+#include "OCResourceRequest.h"
+#include "OCResourceResponse.h"
+#include "OCRepresentation.h"
+
+#include "oc_logger.hpp"
+
+namespace OC
+{
+ /**
+ * @brief Both server and client must initialize the core platform by instantiating OCPlatform.
+ * On successful initialization, an instance of the OCPlatform is returned.
+ * APIs in OCPlatform provide mechanism to register a resource and host the resource
+ * on the server, find resources on the network etc.
+ */
+ class OCPlatform_impl
+ {
+ private:
+ static PlatformConfig& globalConfig();
+ public:
+ /**
+ * API for overwriting the default configuration of the OCPlatform object.
+ * Note: Any calls made to this AFTER the first call to OCPlatform::Instance
+ * will have no affect
+ */
+ static void Configure(const PlatformConfig& config);
+
+ /**
+ * API for retrieving the current OCPlatform object. This will use the
+ * default platform config, unless the default is over-written using the
+ * Configure method before the first call to instance.
+ */
+ static OCPlatform_impl& Instance();
+
+ public:
+ // typedef for handle to cancel presence info with
+ typedef OCDoHandle OCPresenceHandle;
+
+ /**
+ * Virtual destructor
+ */
+ virtual ~OCPlatform_impl(void);
+
+ /**
+ * API for notifying base that resource's attributes have changed.
+ *
+ * @param OCResourceHandle resource handle of the resource
+ * @param QualityOfService the quality of communication
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ * NOTE: This API is for server side only.
+ * NOTE: OCResourceHandle is defined in ocstack.h.
+ * NOTE: OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
+ OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
+
+ /**
+ * API for notifying only specific clients that resource's attributes have changed.
+ *
+ * @param OCResourceHandle resource handle of the resource
+ * @param observationIds std vector of observationIds. These set of ids are ones which
+ * which will be notified upon resource change.
+ * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
+ * resource change.
+ * @param QualityOfService the quality of communication
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ *
+ * NOTE: This API is for server side only.
+ * NOTE: OCResourceHandle is defined in ocstack.h.
+ * NOTE: OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult notifyListOfObservers(
+ OCResourceHandle resourceHandle,
+ ObservationIds& observationIds,
+ const std::shared_ptr<OCResourceResponse> responsePtr);
+ OCStackResult notifyListOfObservers(
+ OCResourceHandle resourceHandle,
+ ObservationIds& observationIds,
+ const std::shared_ptr<OCResourceResponse> responsePtr,
+ QualityOfService QoS);
+
+ /**
+ * API for Service and Resource Discovery.
+ * NOTE: This API applies to client side only.
+ *
+ * @param host - Host IP Address of a service to direct resource discovery query. If null or
+ * empty, performs multicast resource discovery query
+ * @param resourceURI - name of the resource. If null or empty, performs search for all
+ * resource names
+ * @param handler - Handles callbacks, success states and failure states.
+ *
+ * Four modes of discovery defined as follows:
+ * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
+ * discovery.
+ * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
+ * resource(s) from ALL services.
+ * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
+ * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
+ * resource(s) from a particular service.
+ * @param QualityOfService the quality of communication
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ * NOTE: First parameter 'host' currently represents an IP address. This will change in
+ * future and will refer to endpoint interface so that we can refer to other transports such
+ * as BTH etc.
+ * NOTE: OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ FindCallback resourceHandler);
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ FindCallback resourceHandler, QualityOfService QoS);
+
+ /**
+ * This API registers a resource with the server
+ * NOTE: This API applies to server side only.
+ *
+ * @param resourceHandle - Upon successful registration, resourceHandle will be filled
+ * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
+ * @param resourceTypeName - The resource type. Example: "light"
+ * @param resourceInterface - The resource interface (whether it is collection etc).
+ * @param entityHandler - entity handler callback.
+ * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
+ * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
+ * setting resourceProperty as OC_OBSERVABLE will allow observation
+ * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
+ * and observation
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ * NOTE: "a/light" is a relative URI.
+ * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
+ * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
+ * Example, a relative URI: 'a/light' will result in a fully qualified URI:
+ * //192.168.1.1/oc/a/light"
+ * First parameter can take a relative URI and core will take care of preparing the fully
+ * qualified URI OR
+ * first paramter can take fully qualified URI and core will take that as is for further
+ * operations
+ * NOTE: OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult registerResource(OCResourceHandle& resourceHandle,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler entityHandler,
+ uint8_t resourceProperty);
+
+ /**
+ * Set default device entity handler
+ *
+ * @param entityHandler - entity handler to handle requests for
+ * any undefined resources or default actions.
+ * if NULL is passed it removes the device default entity handler.
+ *
+ * @return
+ * OC_STACK_OK - no errors
+ * OC_STACK_ERROR - stack process error
+ */
+ OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
+
+ /**
+ * This API unregisters a resource with the server
+ * NOTE: This API applies to server side only.
+ *
+ * @param resourceHandle - This is the resource handle which we which to unregister from the
+ * server
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ * NOTE: OCStackResult is defined in ocstack.h.
+ */
+ OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
+
+ /**
+ * Add a resource to a collection resource.
+ *
+ * @param collectionHandle - handle to the collection resource
+ * @param addedResourceHandle - handle to resource to be added to the collection resource
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.<br>
+ * NOTE: OCStackResult is defined in ocstack.h. <br>
+ * NOTE: bindResource must be used only after the both collection resource and
+ * resource to add under a collections are created and respective handles obtained<br>
+ * <b>Example:</b> <br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
+ * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
+ */
+ OCStackResult bindResource(const OCResourceHandle collectionHandle,
+ const OCResourceHandle resourceHandle);
+
+ /**
+ * Add multiple resources to a collection resource.
+ *
+ * @param collectionHandle - handle to the collection resource
+ * @param addedResourceHandleList reference to list of resource handles to be added to
+ * the collection resource
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+ * NOTE: OCStackResult is defined in ocstack.h. <br>
+ * NOTE: bindResources must be used only after the both collection resource and
+ * list of resources to add under a collection are created and respective handles
+ * obtained<br>
+ * <b> Example: </b> <br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+ * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+ * rList.push_back(roomResourceHandle);<br>
+ * Step 5: bindResource(homeResourceHandle, rList);<br>
+ * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen"
+ * and "a/room" <br>
+ */
+ OCStackResult bindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& addedResourceHandleList);
+
+ /**
+ * Unbind a resource from a collection resource.
+ *
+ * @param collectionHandle - handle to the collection resource
+ * @param resourceHandle resource handle to be unbound from the collection resource
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+ * NOTE: OCStackResult is defined in ocstack.h.<br>
+ * NOTE: unbindResource must be used only after the both collection resource and
+ * resource to unbind from a collection are created and respective handles obtained<br>
+ * <b> Example </b> <br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
+ * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
+ * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
+ */
+ OCStackResult unbindResource(const OCResourceHandle collectionHandle,
+ const OCResourceHandle resourceHandle);
+
+ /**
+ * Unbind resources from a collection resource.
+ *
+ * @param collectionHandle - handle to the collection resource
+ * @param resourceHandleList List of resource handles to be unbound from the collection
+ * resource
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+ *
+ * NOTE: OCStackResult is defined in ocstack.h.<br>
+ * NOTE: unbindResources must be used only after the both collection resource and
+ * list of resources resource to unbind from a collection are created and respective handles
+ * obtained. <br>
+ * <b>Example</b> <br>
+ * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+ * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+ * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+ * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+ * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+ * rList.push_back(roomResourceHandle);<br>
+ * Step 5: bindResource(homeResourceHandle, rList);<br>
+ * Step 6: unbindResources(homeResourceHandle, rList);<br>
+ * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen"
+ * and "a/room"<br>
+ */
+ OCStackResult unbindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& resourceHandleList);
+
+ /**
+ * Binds a type to a particular resource
+ * @param resourceHandle - handle to the resource
+ * @param resourceTypeName - new typename to bind to the resource
+
+ * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
+ */
+ OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName) const;
+
+ /**
+ * Binds an interface to a particular resource
+ * @param resourceHandle - handle to the resource
+ * @param resourceTypeName - new interface to bind to the resource
+
+ * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
+ */
+ OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName) const;
+
+ /**
+ * Start Presence announcements.
+ *
+ * @param ttl - time to live
+ * @return OCStackResult - Returns OCSTACK_OK if success <br>
+ *
+ * Server can call this function when it comes online for the
+ * first time, or when it comes back online from offline mode,
+ * or when it re enters network.
+ *
+ */
+ OCStackResult startPresence(const unsigned int ttl);
+
+ /**
+ * Stop Presence announcements.
+ *
+ * @return OCStackResult - Returns OCSTACK_OK if success <br>
+ *
+ * Server can call this function when it is terminating,
+ * going offline, or when going away from network.
+ *
+ */
+ OCStackResult stopPresence();
+
+ /**
+ * subscribes to a server's presence change events. By making this subscription,
+ * every time a server adds/removes/alters a resource, starts or is intentionally
+ * stopped (potentially more to be added later).
+ *
+ * @param presenceHandle - a handle object that can be used to identify this subscription
+ * request. It can be used to unsubscribe from these events in the future.
+ * It will be set upon successful return of this method.
+ * @param host - The IP address/addressable name of the server to subscribe to.
+ * @param presenceHandler - callback function that will receive notifications/subscription
+ * events
+ *
+ * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
+ */
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ SubscribeCallback presenceHandler);
+
+ /**
+ * unsubscribes from a previously subscribed server's presence events. Note that
+ * you may for a short time still receive events from the server since it may take time
+ * for the unsubscribe to take effect.
+ *
+ * @param presenceHandle - the handle object provided by the subscribePresence call that
+ * identifies this subscription.
+ *
+ * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
+ */
+ OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
+
+ /**
+ * Creates a resource proxy object so that get/put/observe functionality
+ * can be used without discovering the object in advance. Note that the
+ * consumer of this method needs to provide all of the details required to
+ * correctly contact and observe the object. If the consumer lacks any of
+ * this information, they should discover the resource object normally.
+ * Additionally, you can only create this object if OCPlatform was initialized
+ * to be a Client or Client/Server. Otherwise, this will return an empty
+ * shared ptr.
+ *
+ * @param host - a string containing a resolvable host address of the server
+ * holding the resource. Currently this should be in the format
+ * coap://address:port, though in the future, we expect this to
+ * change to //address:port
+ *
+ * @param uri - the rest of the resource's URI that will permit messages to be
+ * properly routed. Example: /a/light
+ *
+ * @param isObservable - a boolean containing whether the resource supports observation
+ *
+ * @param resourceTypes - a collection of resource types implemented by the resource
+ *
+ * @param interfaces - a collection of interfaces that the resource supports/implements
+ * @return OCResource::Ptr - a shared pointer to the new resource object
+ */
+ OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
+ bool isObservable, const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces);
+
+ private:
+ PlatformConfig m_cfg;
+
+ private:
+ std::unique_ptr<WrapperFactory> m_WrapperInstance;
+ IServerWrapper::Ptr m_server;
+ IClientWrapper::Ptr m_client;
+ std::shared_ptr<std::recursive_mutex> m_csdkLock;
+
+ private:
+ /**
+ * Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
+ * appropriate fields
+ * @param config PlatformConfig struct which has details such as modeType
+ * (server/client/both), in-proc/out-of-proc etc.
+ */
+ OCPlatform_impl(const PlatformConfig& config);
+
+ /**
+ * Private function to initalize the platfrom
+ */
+ void init(const PlatformConfig& config);
+
+ /**
+ * Private constructor/operators to prevent copying
+ * of this object
+ */
+ OCPlatform_impl(const OCPlatform_impl& other)= delete;
+ OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
+ OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
+ };
+}
+
+#endif //__OCPLATFORM_IMPL_H
+
+
*/
class OCResource
{
- friend class OCPlatform;
+ friend class OCPlatform_impl;
friend class InProcClientWrapper;
public:
class OutOfProcClientWrapper : public IClientWrapper
{
public:
- OutOfProcClientWrapper(OC::OCPlatform& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
+ OutOfProcClientWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
PlatformConfig cfg)
: IClientWrapper(owner)
{}
class OutOfProcServerWrapper : public IServerWrapper
{
public:
- OutOfProcServerWrapper(OC::OCPlatform& owner, PlatformConfig cfg)
+ OutOfProcServerWrapper(OC::OCPlatform_impl& owner, PlatformConfig cfg)
: IServerWrapper(owner)
{};
public:
typedef std::shared_ptr<IWrapperFactory> Ptr;
- virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform& owner,
+ virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform_impl& owner,
std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg) =0;
- virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform& owner,
+ virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform_impl& owner,
std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg) =0;
virtual ~IWrapperFactory(){}
};
public:
WrapperFactory(){}
- virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform& owner,
+ virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform_impl& owner,
std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
{
switch(cfg.serviceType)
return nullptr;
}
- virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform& owner,
+ virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform_impl& owner,
std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
{
switch(cfg.serviceType)
examples: liboc.a
cd examples && $(MAKE) apps "BUILD=$(BUILD)"
-liboc.a: OCPlatform.o OCResource.o OCException.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o
- ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCException.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
+liboc.a: OCPlatform_impl.o OCPlatform.o OCResource.o OCException.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o
+ ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform_impl.o $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCException.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
+
+OCPlatform_impl.o: src/OCPlatform_impl.cpp
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCPlatform_impl.cpp $(CXX_INC)
OCPlatform.o: src/OCPlatform.cpp
$(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCPlatform.cpp $(CXX_INC)
namespace OC
{
- InProcClientWrapper::InProcClientWrapper(OC::OCPlatform& owner,
+ InProcClientWrapper::InProcClientWrapper(OC::OCPlatform_impl& owner,
std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
: IClientWrapper(owner),
m_threadRun(false), m_csdkLock(csdkLock),
{
FindCallback callback;
IClientWrapper::Ptr clientWrapper;
- OC::OCPlatform const* owner; // observing ptr
};
ListenContext* context = new ListenContext();
context->callback = callback;
context->clientWrapper = shared_from_this();
- context->owner = &m_owner;
cbdata.context = static_cast<void*>(context);
cbdata.cb = listenCallback;
namespace OC
{
- InProcServerWrapper::InProcServerWrapper(OC::OCPlatform& owner,
+ InProcServerWrapper::InProcServerWrapper(OC::OCPlatform_impl& owner,
std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
: IServerWrapper(owner),
m_csdkLock(csdkLock)
//
//
//*********************************************************************
-
-#include <random>
-#include <utility>
-#include <functional>
-
-#include "ocstack.h"
-
-#include "OCPlatform.h"
-#include "OCApi.h"
-#include "OCException.h"
-#include "OCUtilities.h"
-
-#include "oc_logger.hpp"
-
+#include <OCPlatform.h>
namespace OC
{
-void OCPlatform::init(const PlatformConfig& config)
-{
- switch(config.mode)
- {
- case ModeType::Server:
- m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
- break;
-
- case ModeType::Client:
- m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
- break;
-
- case ModeType::Both:
- m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
- m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
- break;
- }
-}
-
-OCPlatform::OCPlatform(const PlatformConfig& config)
- : m_cfg { config },
- m_WrapperInstance { make_unique<WrapperFactory>() },
- m_csdkLock { make_shared<std::recursive_mutex>() }
-{
- init(m_cfg);
-}
-
-OCPlatform::~OCPlatform(void)
-{
-}
-
-OCStackResult OCPlatform::setDefaultDeviceEntityHandler(EntityHandler entityHandler)
-{
- return checked_guard(m_server, &IServerWrapper::setDefaultDeviceEntityHandler,
- entityHandler);
-}
-
-OCStackResult OCPlatform::notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS)
-{
- return result_guard(OCNotifyAllObservers(resourceHandle, static_cast<OCQualityOfService>(QoS)));
-}
-
-OCStackResult OCPlatform::notifyAllObservers(OCResourceHandle resourceHandle)
-{
- return notifyAllObservers(resourceHandle, m_cfg.QoS);
-}
-
-OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
- ObservationIds& observationIds,
- const std::shared_ptr<OCResourceResponse> pResponse)
-{
- return notifyListOfObservers(resourceHandle, observationIds, pResponse, m_cfg.QoS);
-}
-
-OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
- ObservationIds& observationIds,
- const std::shared_ptr<OCResourceResponse> pResponse,
- QualityOfService QoS)
-{
- if(!pResponse)
- {
- return result_guard(OC_STACK_ERROR);
- }
-
- std::string payload(pResponse->getPayload());
-
- return result_guard(
- OCNotifyListOfObservers(resourceHandle,
- &observationIds[0], observationIds.size(),
- reinterpret_cast<unsigned char *>(const_cast<char *>(payload.c_str())),
- static_cast<OCQualityOfService>(QoS)));
-}
-
-OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, const std::string& uri,
- bool isObservable, const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces)
-{
- if(!m_client)
+ namespace OCPlatform
{
- return std::shared_ptr<OCResource>();
- }
-
- return std::shared_ptr<OCResource>(new OCResource(m_client, host, uri, isObservable, resourceTypes, interfaces));
-}
-
-OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
- FindCallback resourceHandler)
-{
- return findResource(host, resourceName, resourceHandler, m_cfg.QoS);
-}
-
-OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
- FindCallback resourceHandler, QualityOfService QoS)
-{
- return checked_guard(m_client, &IClientWrapper::ListenForResource,
- host, resourceName, resourceHandler, QoS);
-}
-
-
-OCStackResult OCPlatform::registerResource(OCResourceHandle& resourceHandle,
- std::string& resourceURI,
- const std::string& resourceTypeName,
- const std::string& resourceInterface,
- EntityHandler entityHandler,
- uint8_t resourceProperty)
-{
- return checked_guard(m_server, &IServerWrapper::registerResource,
- ref(resourceHandle), resourceURI, resourceTypeName,
- resourceInterface, entityHandler, resourceProperty);
-}
-
-OCStackResult OCPlatform::unregisterResource(const OCResourceHandle& resourceHandle) const
-{
- return checked_guard(m_server, &IServerWrapper::unregisterResource,
- resourceHandle);
-}
-
-OCStackResult OCPlatform::unbindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle)
-{
- return result_guard(OCUnBindResource(ref(collectionHandle), ref(resourceHandle)));
-}
-
-OCStackResult OCPlatform::unbindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& resourceHandles)
-{
- for(const auto& h : resourceHandles)
- {
- OCStackResult r;
-
- if(OC_STACK_OK != (r = result_guard(OCUnBindResource(collectionHandle, h))))
- {
- return r;
- }
- }
-
- return OC_STACK_OK;
-}
-
-OCStackResult OCPlatform::bindResource(const OCResourceHandle collectionHandle, const OCResourceHandle resourceHandle)
-{
- return result_guard(OCBindResource(collectionHandle, resourceHandle));
-}
-
-OCStackResult OCPlatform::bindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& resourceHandles)
-{
- for(const auto& h : resourceHandles)
- {
- OCStackResult r;
-
- if(OC_STACK_OK != (r = result_guard(OCBindResource(collectionHandle, h))))
- {
- return r;
- }
- }
-
- return OC_STACK_OK;
-}
-
-OCStackResult OCPlatform::bindTypeToResource(const OCResourceHandle& resourceHandle,
- const std::string& resourceTypeName) const
-{
- return checked_guard(m_server, &IServerWrapper::bindTypeToResource,
- resourceHandle, resourceTypeName);
-}
-
-OCStackResult OCPlatform::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
- const std::string& resourceInterfaceName) const
-{
- return checked_guard(m_server, &IServerWrapper::bindInterfaceToResource,
- resourceHandle, resourceInterfaceName);
-}
-
-OCStackResult OCPlatform::startPresence(const unsigned int announceDurationSeconds)
-{
- return checked_guard(m_server, &IServerWrapper::startPresence,
- announceDurationSeconds);
-}
-
-OCStackResult OCPlatform::stopPresence()
-{
- return checked_guard(m_server, &IServerWrapper::stopPresence);
-}
-
-OCStackResult OCPlatform::subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- SubscribeCallback presenceHandler)
-{
- return checked_guard(m_client, &IClientWrapper::SubscribePresence,
- &presenceHandle, host, presenceHandler);
-}
-
-OCStackResult OCPlatform::unsubscribePresence(OCPresenceHandle presenceHandle)
-{
- return checked_guard(m_client, &IClientWrapper::UnsubscribePresence,
- ref(presenceHandle));
-}
-
+ void Configure(const PlatformConfig& config)
+ {
+ OCPlatform_impl::Configure(config);
+ }
+
+ OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler)
+ {
+ return OCPlatform_impl::Instance().setDefaultDeviceEntityHandler(entityHandler);
+ }
+
+ OCStackResult notifyAllObservers(OCResourceHandle resourceHandle,
+ QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle, QoS);
+ }
+
+ OCStackResult notifyAllObservers(OCResourceHandle resourceHandle)
+ {
+ return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle);
+ }
+
+ OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
+ ObservationIds& observationIds,
+ const std::shared_ptr<OCResourceResponse> pResponse)
+ {
+ return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
+ observationIds, pResponse);
+ }
+
+ OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
+ ObservationIds& observationIds,
+ const std::shared_ptr<OCResourceResponse> pResponse,
+ QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
+ observationIds, pResponse, QoS);
+ }
+
+ OCResource::Ptr constructResourceObject(const std::string& host,
+ const std::string& uri,
+ bool isObservable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces)
+ {
+ return OCPlatform_impl::Instance().constructResourceObject(host, uri, isObservable,
+ resourceTypes, interfaces);
+ }
+
+ OCStackResult findResource(const std::string& host,
+ const std::string& resourceName,
+ FindCallback resourceHandler)
+ {
+ return OCPlatform_impl::Instance().findResource(host, resourceName, resourceHandler);
+ }
+
+ OCStackResult findResource(const std::string& host,
+ const std::string& resourceName,
+ FindCallback resourceHandler, QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().findResource(host, resourceName,
+ resourceHandler, QoS);
+ }
+
+
+ OCStackResult registerResource(OCResourceHandle& resourceHandle,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler entityHandler,
+ uint8_t resourceProperty)
+ {
+ return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
+ resourceTypeName, resourceInterface,
+ entityHandler, resourceProperty);
+ }
+
+ OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
+ {
+ return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
+ }
+
+ OCStackResult unbindResource(OCResourceHandle collectionHandle,
+ OCResourceHandle resourceHandle)
+ {
+ return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
+ }
+
+ OCStackResult unbindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& resourceHandles
+ )
+ {
+ return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
+ }
+
+ OCStackResult bindResource(const OCResourceHandle collectionHandle,
+ const OCResourceHandle resourceHandle)
+ {
+ return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
+ }
+
+ OCStackResult bindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& resourceHandles
+ )
+ {
+ return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
+ }
+
+ OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName)
+ {
+ return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
+ }
+
+ OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName)
+ {
+ return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
+ resourceInterfaceName);
+ }
+
+ OCStackResult startPresence(const unsigned int announceDurationSeconds)
+ {
+ return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
+ }
+
+ OCStackResult stopPresence()
+ {
+ return OCPlatform_impl::Instance().stopPresence();
+ }
+
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ SubscribeCallback presenceHandler)
+ {
+ return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
+ presenceHandler);
+ }
+
+ OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
+ {
+ return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
+ }
+ } // namespace OCPlatform
} //namespace OC
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+//******************************************************************
+// File name:
+// OCPlatform_impl.cpp
+//
+// Description: Implementation of the OCPlatform functionality. It contains
+// a singleton interface that is used only by the OCPlatform namespace and is the
+// central entrance to the stack.
+//
+//
+//
+//*********************************************************************
+
+#include <random>
+#include <utility>
+#include <functional>
+
+#include "ocstack.h"
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "OCException.h"
+#include "OCUtilities.h"
+
+#include "oc_logger.hpp"
+
+namespace OC
+{
+
+ PlatformConfig& OCPlatform_impl::globalConfig()
+ {
+ static PlatformConfig s_config;
+ return s_config;
+ }
+
+ void OCPlatform_impl::Configure(const PlatformConfig& config)
+ {
+ globalConfig() = config;
+ }
+
+ OCPlatform_impl& OCPlatform_impl::Instance()
+ {
+ static OCPlatform_impl platform(globalConfig());
+ return platform;
+ }
+
+ void OCPlatform_impl::init(const PlatformConfig& config)
+ {
+ switch(config.mode)
+ {
+ case ModeType::Server:
+ m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
+ break;
+
+ case ModeType::Client:
+ m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
+ break;
+
+ case ModeType::Both:
+ m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
+ m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
+ break;
+ }
+ }
+
+ OCPlatform_impl::OCPlatform_impl(const PlatformConfig& config)
+ : m_cfg { config },
+ m_WrapperInstance { make_unique<WrapperFactory>() },
+ m_csdkLock { make_shared<std::recursive_mutex>() }
+ {
+ init(m_cfg);
+ }
+
+ OCPlatform_impl::~OCPlatform_impl(void)
+ {
+ }
+
+ OCStackResult OCPlatform_impl::setDefaultDeviceEntityHandler(EntityHandler entityHandler)
+ {
+ return checked_guard(m_server, &IServerWrapper::setDefaultDeviceEntityHandler,
+ entityHandler);
+ }
+
+ OCStackResult OCPlatform_impl::notifyAllObservers(OCResourceHandle resourceHandle,
+ QualityOfService QoS)
+ {
+ return result_guard(OCNotifyAllObservers(resourceHandle,
+ static_cast<OCQualityOfService>(QoS)));
+ }
+
+ OCStackResult OCPlatform_impl::notifyAllObservers(OCResourceHandle resourceHandle)
+ {
+ return notifyAllObservers(resourceHandle, m_cfg.QoS);
+ }
+
+ OCStackResult OCPlatform_impl::notifyListOfObservers(OCResourceHandle resourceHandle,
+ ObservationIds& observationIds,
+ const std::shared_ptr<OCResourceResponse> pResponse)
+ {
+ return notifyListOfObservers(resourceHandle, observationIds, pResponse, m_cfg.QoS);
+ }
+
+ OCStackResult OCPlatform_impl::notifyListOfObservers(OCResourceHandle resourceHandle,
+ ObservationIds& observationIds,
+ const std::shared_ptr<OCResourceResponse> pResponse,
+ QualityOfService QoS)
+ {
+ if(!pResponse)
+ {
+ return result_guard(OC_STACK_ERROR);
+ }
+
+ std::string payload(pResponse->getPayload());
+
+ return result_guard(
+ OCNotifyListOfObservers(resourceHandle,
+ &observationIds[0], observationIds.size(),
+ reinterpret_cast<unsigned char *>(const_cast<char *>(payload.c_str())),
+ static_cast<OCQualityOfService>(QoS)));
+ }
+
+ OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
+ const std::string& uri,
+ bool isObservable,
+ const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces)
+ {
+ if(!m_client)
+ {
+ return std::shared_ptr<OCResource>();
+ }
+
+ return std::shared_ptr<OCResource>(new OCResource(m_client,
+ host,
+ uri,
+ isObservable,
+ resourceTypes,
+ interfaces));
+ }
+
+ OCStackResult OCPlatform_impl::findResource(const std::string& host,
+ const std::string& resourceName,
+ FindCallback resourceHandler)
+ {
+ return findResource(host, resourceName, resourceHandler, m_cfg.QoS);
+ }
+
+ OCStackResult OCPlatform_impl::findResource(const std::string& host,
+ const std::string& resourceName,
+ FindCallback resourceHandler, QualityOfService QoS)
+ {
+ return checked_guard(m_client, &IClientWrapper::ListenForResource,
+ host, resourceName, resourceHandler, QoS);
+ }
+
+
+ OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler entityHandler,
+ uint8_t resourceProperty)
+ {
+ return checked_guard(m_server, &IServerWrapper::registerResource,
+ ref(resourceHandle), resourceURI, resourceTypeName,
+ resourceInterface, entityHandler, resourceProperty);
+ }
+
+ OCStackResult OCPlatform_impl::unregisterResource(const OCResourceHandle& resourceHandle) const
+ {
+ return checked_guard(m_server, &IServerWrapper::unregisterResource,
+ resourceHandle);
+ }
+
+ OCStackResult OCPlatform_impl::unbindResource(OCResourceHandle collectionHandle,
+ OCResourceHandle resourceHandle)
+ {
+ return result_guard(OCUnBindResource(ref(collectionHandle), ref(resourceHandle)));
+ }
+
+ OCStackResult OCPlatform_impl::unbindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& resourceHandles)
+ {
+ for(const auto& h : resourceHandles)
+ {
+ OCStackResult r;
+
+ if(OC_STACK_OK != (r = result_guard(OCUnBindResource(collectionHandle, h))))
+ {
+ return r;
+ }
+ }
+
+ return OC_STACK_OK;
+ }
+
+ OCStackResult OCPlatform_impl::bindResource(const OCResourceHandle collectionHandle,
+ const OCResourceHandle resourceHandle)
+ {
+ return result_guard(OCBindResource(collectionHandle, resourceHandle));
+ }
+
+ OCStackResult OCPlatform_impl::bindResources(const OCResourceHandle collectionHandle,
+ const std::vector<OCResourceHandle>& resourceHandles)
+ {
+ for(const auto& h : resourceHandles)
+ {
+ OCStackResult r;
+
+ if(OC_STACK_OK != (r = result_guard(OCBindResource(collectionHandle, h))))
+ {
+ return r;
+ }
+ }
+
+ return OC_STACK_OK;
+ }
+
+ OCStackResult OCPlatform_impl::bindTypeToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName) const
+ {
+ return checked_guard(m_server, &IServerWrapper::bindTypeToResource,
+ resourceHandle, resourceTypeName);
+ }
+
+ OCStackResult OCPlatform_impl::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName) const
+ {
+ return checked_guard(m_server, &IServerWrapper::bindInterfaceToResource,
+ resourceHandle, resourceInterfaceName);
+ }
+
+ OCStackResult OCPlatform_impl::startPresence(const unsigned int announceDurationSeconds)
+ {
+ return checked_guard(m_server, &IServerWrapper::startPresence,
+ announceDurationSeconds);
+ }
+
+ OCStackResult OCPlatform_impl::stopPresence()
+ {
+ return checked_guard(m_server, &IServerWrapper::stopPresence);
+ }
+
+ OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ SubscribeCallback presenceHandler)
+ {
+ return checked_guard(m_client, &IClientWrapper::SubscribePresence,
+ &presenceHandle, host, presenceHandler);
+ }
+
+ OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle)
+ {
+ return checked_guard(m_client, &IClientWrapper::UnsubscribePresence,
+ ref(presenceHandle));
+ }
+
+} //namespace OC
0, // Uses randomly available port
OC::QualityOfService::LowQos
};
- OCPlatform platform(cfg);
+ OCPlatform::Configure(cfg);
std::string resourceURI = "/a/res";
std::string resourceTypeName = "core.res";
OCResourceHandle resourceHandle;
// This will internally create and register the resource.
- if(OC_STACK_OK == platform.registerResource(
+ if(OC_STACK_OK == OCPlatform::registerResource(
resourceHandle, resourceURI, resourceTypeName,
resourceInterface, entityHandler_rf, resourceProperty))
{
- platform.findResource("","coap://224.0.1.187/oc/core?rt=core.res", foundResource_rf);
+ OCPlatform::findResource("","coap://224.0.1.187/oc/core?rt=core.res", foundResource_rf);
{
std::unique_lock<std::mutex> lk(mutex_rf);