to a resource. The API names may change after review.
- Removed unwanted trailing whitespaces at the end of lines.
- Updated according to review comments.
Change-Id: I13f7fcd07386d4a13d42f00254f870cfbd8ca4b4
}
OCStackResult entityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest ) {
-
- // TODO @SASHI we need to have a better way of logging (with various levels of logging)
+
+ // TODO @SASHI we need to have a better way of logging (with various levels of logging)
cout << "\nIn C entity handler: " << endl;
// TODO @SASHI dow we need shared pointer?
// TODO @SASHI Why strings : "GET"??
pRequest->setRequestType("GET");
}
-
+
if(OC_REST_PUT == entityHandlerRequest->method)
{
pRequest->setRequestType("PUT");
// TODO @SASHI we could use const reference
std::string payLoad = pResponse->getPayload();
- if(OC_REST_GET == entityHandlerRequest->method)
+ if(OC_REST_GET == entityHandlerRequest->method)
{
- cout << "\t\t\tGoing from stack for GET: " << payLoad << endl;
+ cout << "\t\t\tGoing from stack for GET: " << payLoad << endl;
}
else if (OC_REST_PUT == entityHandlerRequest->method)
{
- cout << "\t\t\tGoing from stack for PUT: " << payLoad << endl;
+ cout << "\t\t\tGoing from stack for PUT: " << payLoad << endl;
}
+ else
+ {
+ cout << "\t\t\t Unknown method...!!!" << endl;
+ }
// TODO @SASHI Now there is memory that needs to be freed.
entityHandlerRequest->resJSONPayload = reinterpret_cast<unsigned char *>(OC::OCReflect::OCStack::strdup(payLoad.c_str()));
if(nullptr == entityHandlerRequest->resJSONPayload)
{
// TODO @SASHI throw std::runtime_error("out of memory");
- cout << "Out of memory in copying to resJSONPayload" << endl;
- }
+ cout << "Out of memory in copying to resJSONPayload" << endl;
+ }
}
-
+
return OC_STACK_OK;
}
OCResourceHandle& resourceHandle,
std::string& resourceURI,
const std::string& resourceTypeName,
- const std::string& resourceInterface,
+ const std::string& resourceInterface,
std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> eHandler,
uint8_t resourceProperties)
entityHandlerMap[resourceHandle] = eHandler;
}
}
-
+
+ return result;
+ }
+
+ OCStackResult InProcServerWrapper::bindTypeToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName)
+ {
+ cout << "Binding Type to Resource: \n";
+ cout << "\tTypeName: " << resourceTypeName << endl;
+
+ OCStackResult result = OCBindResourceTypeToResource(resourceHandle, resourceTypeName.c_str());
+ if (result != OC_STACK_OK)
+ {
+ throw OCException("Bind Type to resource failed", result);
+ }
return result;
}
+ OCStackResult InProcServerWrapper::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName)
+ {
+ cout << "Binding Interface to Resource: \n";
+ cout << "\tInterfaceName: " << resourceInterfaceName << endl;
+
+ OCStackResult result = OCBindResourceInterfaceToResource(resourceHandle, resourceInterfaceName.c_str());
+ if (result != OC_STACK_OK)
+ {
+ throw OCException("Bind Interface to resource failed", result);
+ }
+ return result;
+ }
+
+
InProcServerWrapper::~InProcServerWrapper()
{
if(m_processThread.joinable())
#include "OCPlatform.h"
#include "OCApi.h"
+#include "OCException.h"
-namespace OC
+namespace OC
{
// Constructor. Internally calls private init function
OCPlatform::OCPlatform(const PlatformConfig& config)
if(config.mode == ModeType::Server)
{
- // Call server wrapper init
+ // Call server wrapper init
m_server = m_WrapperInstance->CreateServerWrapper(config);
}
else if(config.mode == ModeType::Client)
// Call client wrapper init
m_client = m_WrapperInstance->CreateClientWrapper(config);
}
- else
+ else
{
// This must be both server and client
m_server = m_WrapperInstance->CreateServerWrapper(config);
}
}
-
- OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
+
+ OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
std::function<void(OCResource::Ptr)> resourceHandler)
{
if(m_client)
{
return m_client->ListenForResource(host, resourceName, resourceHandler);
}
-
return OC_STACK_ERROR;
}
-
- OCStackResult OCPlatform::registerResource(OCResourceHandle& resourceHandle,
- std::string& resourceURI,
- const std::string& resourceTypeName,
- const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
+
+ OCStackResult OCPlatform::registerResource(OCResourceHandle& resourceHandle,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
uint8_t resourceProperty)
{
OCStackResult result = OC_STACK_OK;
if(m_server)
{
try{
- result = m_server->registerResource(resourceHandle, resourceURI, resourceTypeName, resourceInterface, entityHandler, resourceProperty);
+ result = m_server->registerResource(resourceHandle, resourceURI, resourceTypeName, resourceInterface, entityHandler, resourceProperty);
}
- catch(std::exception e) // define our own expception.
+ catch(std::exception e) // define our own expception.
{
throw e;
}
OCStackResult result = OC_STACK_OK;
return result;
}
+
+ OCStackResult OCPlatform::bindTypeToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName) const
+ {
+ OCStackResult result = OC_STACK_ERROR;
+ if(m_server)
+ {
+ try
+ {
+ result = m_server->bindTypeToResource(resourceHandle, resourceTypeName);
+ }
+ catch (OCException& e)
+ {
+ cout << "Caught an exception..." << endl;
+ cout << "\tMessage: " << e.what() << endl;
+ cout << "\t Reason: " << e.reason() << endl;
+ }
+ }
+ return result;
+ }
+
+ OCStackResult OCPlatform::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName) const
+ {
+ OCStackResult result = OC_STACK_ERROR;
+ if(m_server)
+ {
+ try
+ {
+ result = m_server->bindInterfaceToResource(resourceHandle, resourceInterfaceName);
+ }
+ catch (OCException& e)
+ {
+ cout << "Caught an exception..." << endl;
+ cout << "\tMessage: " << e.what() << endl;
+ cout << "\t Reason: " << e.reason() << endl;
+ }
+ }
+ return result;
+
+ }
+
} //namespace OC
#include <iterator>
#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/split.hpp>
#include "OCReflect.h"
if(nullptr == ret)
return nullptr;
- return strcpy(ret, s);
+ return strcpy(ret, s);
}
char *strdup(const std::string& s)
if(nullptr == ret)
return nullptr;
- return strcpy(ret, s.c_str());
+ return strcpy(ret, s.c_str());
}
// Count the number of elements in a NULL-terminated C array of char*:
size_t ret = 0;
for(char **cursor = in; nullptr != *cursor; ++cursor)
- ++ret;
+ ++ret;
- return ret;
+ return ret;
}
// Note: caller is responsible for the returned memory:
{
case property_type::nil:
case property_type::rational:
- case property_type::list:
- case property_type::string:
+ case property_type::list:
+ case property_type::string:
// Sashi commented this line to fix the build error
//os << "convert(): request to convert valid, but unimplemented type: " << ps.type;
throw std::runtime_error(os.str());
break;
- case property_type::INVALID:
+ case property_type::INVALID:
throw std::runtime_error("convert(): request to convert invalid type");
break;
- case property_type::boolean: os << "bt." << 'b';
+ case property_type::boolean: os << "bt." << 'b';
break;
- case property_type::integer: os << "bt." << 'i';
+ case property_type::integer: os << "bt." << 'i';
break;
}
{
// We expect: "oc.bt.<char typecode>":
const size_t code_length = 7,
- code_pos = 6;
+ code_pos = 6;
if(code_length != pb_code.length())
return OC::OCReflect::property_type::INVALID;
/* These don't have codes yet:
case property_type::nil:
case property_type::rational:
- case property_type::string:
- case property_type::list:
+ case property_type::string:
+ case property_type::list:
*/
}
auto delim_pos = pb_rep.find_first_of(':');
if(pb_rep.length() == delim_pos)
- throw OC::OCReflect::reflection_exception("convert(): invalid property string (missing delimiter)");
-
+ throw OC::reflection_exception("convert(): invalid property string (missing delimiter)");
+
std::string pname { pb_rep.substr(0, delim_pos) };
auto ptype = as_property_type(pb_rep.substr(1 + delim_pos));
auto pattr = OC::OCReflect::property_attribute::rw; // We aren't handling attributes right now...
-
+
return OC::OCReflect::property_binding { pname, { ptype, pattr } };
}
for(const auto& s : pb_reps)
pbv.emplace_back(as_property_binding(s));
- return pbv;
+ return pbv;
}
std::vector<std::string> convert(const OC::OCReflect::property_binding_vector& psv)
std::vector<std::string> expand(const char *flattened_string, const std::string& delim)
{
if(nullptr == flattened_string)
- throw OC::OCReflect::reflection_exception("nullptr passed to expand()");
+ throw OC::reflection_exception("nullptr passed to expand()");
std::vector<std::string> ret;
std::string flattened = flattened_string;
using namespace OC;
-const int SUCCESS_RESPONSE = 0;
+const int SUCCESS_RESPONSE = 0;
std::shared_ptr<OCResource> curResource;
int observe_count()
std::cout << std::endl;
}
-
+
if(observe_count() > 3)
{
std::cout<<"Cancelling Observe..."<<std::endl;
if(eCode == SUCCESS_RESPONSE)
{
std::cout << "PUT request was successful" << std::endl;
- std::cout << "Put count: "<< attributeMap.size()<<std::endl;
+
for(auto it = attributeMap.begin(); it != attributeMap.end(); ++it)
{
std::cout << "\tAttribute name: "<< it->first << " value: ";
// Create AttributeMap
AttributeMap attributeMap;
// Add the attribute name and values in the attribute map
- AttributeValues stateVal;
+ AttributeValues stateVal;
stateVal.push_back("true");
- AttributeValues powerVal;
+ AttributeValues powerVal;
powerVal.push_back("10");
attributeMap["state"] = stateVal;
- attributeMap["power"] = powerVal;
+ attributeMap["power"] = powerVal;
// Create QueryParameters Map and add query params (if any)
- QueryParamsMap queryParamsMap;
-
+ QueryParamsMap queryParamsMap;
+
// Invoke resource's pit API with attribute map, query map and the callback parameter
resource->put(attributeMap, queryParamsMap, &onPut);
}
std::string hostAddress;
try
{
- // Do some operations with resource object.
+ // Do some operations with resource object.
if(resource)
{
std::cout<<"DISCOVERED Resource:"<<std::endl;
// Get the resource URI
resourceURI = resource->uri();
std::cout << "\tURI of the resource: " << resourceURI << std::endl;
-
+
// Get the resource host address
hostAddress = resource->host();
- std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
+ std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
if(resourceURI == "/a/light")
{
curResource = resource;
// Call a local function which will internally invoke get API on the resource pointer
- getLightRepresentation(resource);
+ getLightRepresentation(resource);
}
}
else
{
// Resource is invalid
std::cout << "Resource is invalid" << std::endl;
- }
-
+ }
+
}
catch(std::exception& e)
{
cfg.mode = ModeType::Client;
cfg.serviceType = ServiceType::InProc;
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+ // Create a OCPlatform instance.
+ // Note: Platform creation is synchronous call.
try
{
// some operations
}
- }catch(OCException e)
+ }catch(OCException& e)
{
//log(e.what());
}
///
/// This sample provides steps to define an interface for a resource
-/// (properties and methods) and host this resource on the server.
+/// (properties and methods) and host this resource on the server.
///
#include <functional>
// Forward declaring the entityHandler
void entityHandler(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
-/// This class represents a single resource named 'lightResource'. This resource has
-/// two simple properties named 'state' and 'power'
+/// This class represents a single resource named 'lightResource'. This resource has
+/// two simple properties named 'state' and 'power'
class LightResource
{
public:
- /// Access this property from a TB client
+ /// Access this property from a TB client
bool m_state;
int m_power;
OCResourceHandle m_resourceHandle;
/* Note that this does not need to be a member function: for classes you do not have
access to, you can accomplish this with a free function: */
-
+
/// This function internally calls registerResource API.
void createResource(OC::OCPlatform& platform)
{
// OCResourceProperty is defined ocstack.h
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
- // This will internally create and register the resource.
+ // This will internally create and register the resource.
OCStackResult result = platform.registerResource(
- m_resourceHandle, resourceURI, resourceTypeName,
- resourceInterface, &entityHandler, resourceProperty);
+ m_resourceHandle, resourceURI, resourceTypeName,
+ resourceInterface, &entityHandler, resourceProperty);
if (OC_STACK_OK != result)
{
attributeMap["state"] = stateVal;
attributeMap["power"] = powerVal;
}
+
+ void addType(const OC::OCPlatform& platform, const std::string& type) const
+ {
+ OCStackResult result = platform.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
+ {
+ OCStackResult result = platform.bindInterfaceToResource(m_resourceHandle, interface);
+ if (OC_STACK_OK != result)
+ {
+ cout << "Binding TypeName to Resource was unsuccessful\n";
+ }
+ }
};
-// Create the instance of the resource class (in this case instance of class 'LightResource').
+// Create the instance of the resource class (in this case instance of class 'LightResource').
LightResource myLightResource;
// ChangeLightRepresentaion is an observation function,
while (1)
{
sleep (5);
-
+
if (gObservation)
{
// If under observation if there are any changes to the light resource
// we call notifyObservors
//
// For demostration we are changing the power value and notifying.
- myLightResource.m_power += 10;
+ myLightResource.m_power += 10;
cout << "\nPower updated to : " << myLightResource.m_power << endl;
cout << "Notifying observers with resource handle: " << myLightResource.getHandle() << endl;
-
+
OCStackResult result = OCPlatform::notifyObservers(myLightResource.getHandle());
if(OC_STACK_NO_OBSERVERS == result)
}
-// This is just a sample implementation of entity handler.
+// This is just a sample implementation of entity handler.
// Entity handler can be implemented in several ways by the manufacturer
void entityHandler(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
{
// Process query params and do required operations ..
// Get the representation of this resource at this point and send it as response
- AttributeMap attributeMap;
+ AttributeMap attributeMap;
myLightResource.getRepresentation(attributeMap);
if(response)
- {
+ {
// TODO Error Code
response->setErrorCode(200);
response->setResourceRepresentation(attributeMap);
myLightResource.setRepresentation(attributeMap);
- // Do related operations related to PUT request
-
+ // Do related operations related to PUT request
+
myLightResource.getRepresentation(attributeMap);
if(response)
else if(requestFlag == RequestHandlerFlag::ObserverFlag)
{
pthread_t threadId;
-
+
cout << "\t\trequestFlag : Observer\n";
gObservation = 1;
static int startedThread = 0;
-
+
// Observation happens on a different thread in ChangeLightRepresentation function.
// If we have not created the thread already, we will create one here.
if(!startedThread)
pthread_create (&threadId, NULL, ChangeLightRepresentation, (void *)NULL);
startedThread = 1;
}
-
+
}
}
else
cfg.port = 56832;
cfg.mode = ModeType::Server;
cfg.serviceType = ServiceType::InProc;
-
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
+
+ // Create a OCPlatform instance.
+ // Note: Platform creation is synchronous call.
try
{
OCPlatform platform(cfg);
- // Invoke createResource function of class light.
+ // Invoke createResource function of class light.
myLightResource.createResource(platform);
-
+ myLightResource.addType(platform, std::string("core.brightlight"));
+ myLightResource.addInterface(platform, std::string("oc.mi.ll"));
// Perform app tasks
while(true)
{
//log(e.what());
}
-
- // No explicit call to stop the platform.
+
+ // No explicit call to stop the platform.
// When OCPlatform destructor is invoked, internally we do platform cleanup
}
virtual OCStackResult registerResource(
OCResourceHandle& resourceHandle,
- std::string& resourceURI,
- const std::string& resourceTypeName,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
const std::string& resourceInterface,
std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
uint8_t resourceProperty) = 0;
+ virtual OCStackResult bindTypeToResource(
+ const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName) = 0;
+
+ virtual OCStackResult bindInterfaceToResource(
+ const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName) = 0;
};
}
std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
uint8_t resourceProperty);
- private:
- void processFunc();
- std::thread m_processThread;
+ virtual OCStackResult bindTypeToResource(
+ const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName);
+
+ virtual OCStackResult bindInterfaceToResource(
+ const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterface);
+ private:
+ void processFunc();
+ std::thread m_processThread;
bool m_threadRun;
- std::mutex m_csdkLock;
+ std::mutex m_csdkLock;
};
}
#define __INTEL_OCEXCEPTION_H_2014_07_10
#include <stdexcept>
-
-namespace OC { namespace OCReflect {
+#include <ocstack.h>
+namespace OC {
typedef std::runtime_error reflection_exception;
-class OCException : public std::exception
+class OCException : public std::runtime_error
{
+ public:
+ OCException(const std::string& msg, OCStackResult reason = OC_STACK_ERROR): std::runtime_error(msg), m_reason(reason) {}
+ std::string reason()
+ {
+ switch(m_reason)
+ {
+ case OC_STACK_OK:
+ return "No Error";
+ case OC_STACK_INVALID_URI:
+ return "Invalid URI";
+ case OC_STACK_INVALID_IP:
+ return "Invalid IP";
+ case OC_STACK_INVALID_PORT:
+ return "Invalid Port";
+ case OC_STACK_INVALID_CALLBACK:
+ return "Invalid Callback";
+ case OC_STACK_INVALID_METHOD:
+ return "Invalid Method";
+ case OC_STACK_INVALID_QUERY:
+ return "Invalid Query";
+ case OC_STACK_INVALID_PARAM:
+ return "Invalid Param";
+ case OC_STACK_INVALID_OBSERVE_PARAM:
+ return "Invalid Observe Param";
+ case OC_STACK_NO_MEMORY:
+ return "No Memory";
+ case OC_STACK_COMM_ERROR:
+ return "Communication Error";
+ case OC_STACK_NOTIMPL:
+ return "Not Implemented";
+ case OC_STACK_NO_RESOURCE:
+ return "Resource Not Found";
+ case OC_STACK_RESOURCE_ERROR:
+ return "Resource Error";
+ case OC_STACK_SLOW_RESOURCE:
+ return "Slow Resource";
+ case OC_STACK_NO_OBSERVERS:
+ return "No Observers";
+ case OC_STACK_ERROR:
+ return "General Fault";
+ default:
+ return "Unknown Error";
+ }
+ }
+ private:
+ OCStackResult m_reason;
};
-}} // namespace OC::OCReflect
+} // namespace OC
#endif
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-/// @file OCPlatform.h
+/// @file OCPlatform.h
-/// @brief This file contains the declaration of classes and its members related to
+/// @brief This file contains the declaration of classes and its members related to
/// OCPlatform.
#ifndef __OCPLATFORM_H
{
/**
* @brief Both server and client must initialize the core platform by instantiating OCPlatform.
- * On successful initialization, an instance of the OCPlatform is returned.
+ * 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.
*/
{
public:
/**
- * Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
+ * 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.
+ * in-proc/out-of-proc etc.
*/
OCPlatform(const PlatformConfig& config);
virtual ~OCPlatform(void);
/**
- * API for notifying core that resource's attributes have changed.
+ * API for notifying core that resource's attributes have changed.
*
* @param OCResourceHandle resource handle of the resource
*
- * @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.
+ * @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.
*/
static OCStackResult notifyObservers(OCResourceHandle resourceHandle);
/**
- * API for Service and Resource Discovery.
+ * 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
+ * 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)
+ *
+ * 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.
- *
+ *
* @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.
+ * NOTE: OCStackResult is defined in ocstack.h.
*/
- OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+ OCStackResult findResource(const std::string& host, const std::string& resourceURI,
std::function<void(OCResource::Ptr)> resourceHandler);
/**
* 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.
+ * @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.
+ * 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: //134.134.161.33/oc/a/light"
- * First parameter can take a relative URI and core will take care of preparing the fully qualified URI
+ * 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.
+ * NOTE: OCStackResult is defined in ocstack.h.
*/
- OCStackResult registerResource(OCResourceHandle& resourceHandle,
- std::string& resourceURI,
- const std::string& resourceTypeName,
- const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
+ OCStackResult registerResource(OCResourceHandle& resourceHandle,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
uint8_t resourceProperty);
/**
* At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
*/
OCStackResult unbindResource(OCResourceHandle containerHandle, OCResourceHandle resourceHandle);
-
+
/**
* Unbind resources from a container resource.
*
*/
OCStackResult unbindResources(OCResourceHandle containerHandle, 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;
+
+
private:
std::unique_ptr<WrapperFactory> m_WrapperInstance;
IServerWrapper::Ptr m_server;
IClientWrapper::Ptr m_client;
/**
- * Private function to initalize the platfrom
+ * Private function to initalize the platfrom
*/
void init(const PlatformConfig& config);
// Not implemented
return OC_STACK_ERROR;
}
+ virtual OCStackResult bindTypeToResource(
+ const OCResourceHandle& resourceHandle,
+ const std::string& resourceTypeName)
+ { //Not implemented yet
+ return OC_STACK_ERROR;
+ }
+
+ virtual OCStackResult bindInterfaceToResource(
+ const OCResourceHandle& resourceHandle,
+ const std::string& resourceInterfaceName)
+ { //Not implemented yet
+ return OC_STACK_ERROR;
+ }
};
}