typedef struct rsrc_t {
struct rsrc_t *next; // Points to next resource in list
// Relative path on the device; will be combined with base url to create fully qualified path
+ char *host;
char *uri;
OCResourceType *rsrcType; // Resource type(s); linked list
OCResourceInterface *rsrcInterface; // Resource interface(s); linked list
uint8_t resourceProperties);
/**
+ * Create a resource. with host ip address for rsrc_t
+ *
+ * @param handle - pointer to handle to newly created resource. Set by ocstack. Used to refer to resource
+ * @param resourceTypeName - name of resource type. Example: "core.led"
+ * @param resourceInterfaceName - name of resource interface. Example: "core.rw"
+ * @param host - HOST address of the resource. Example: "coap://xxx.xxx.xxx.xxx:xxxxx"
+ * @param uri - URI of the resource. Example: "/a/led"
+ * @param entityHandler - entity handler function that is called by ocstack to handle requests, etc
+ * NULL for default entity handler
+ * @param resourceProperties - properties supported by resource. Example: OC_DISCOVERABLE|OC_OBSERVABLE
+ *
+ * @return
+ * OC_STACK_OK - no errors
+ * OC_STACK_ERROR - stack process error
+ */
+OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
+ const char *resourceTypeName,
+ const char *resourceInterfaceName,
+ const char *host,
+ const char *uri,
+ OCEntityHandler entityHandler,
+ uint8_t resourceProperties);
+
+/**
* Add a resource to a collection resource.
*
* @param collectionHandle - handle to the collection resource
return result;
}
+
+
+/**
+ * Create a resource. with host ip address for rsrc_t
+ *
+ * @param handle - pointer to handle to newly created resource. Set by ocstack. Used to refer to resource
+ * @param resourceTypeName - name of resource type. Example: "core.led"
+ * @param resourceInterfaceName - name of resource interface. Example: "core.rw"
+ * @param host - HOST address of the resource. Example: "coap://xxx.xxx.xxx.xxx:xxxxx"
+ * @param uri - URI of the resource. Example: "/a/led"
+ * @param entityHandler - entity handler function that is called by ocstack to handle requests, etc
+ * NULL for default entity handler
+ * @param resourceProperties - properties supported by resource. Example: OC_DISCOVERABLE|OC_OBSERVABLE
+ *
+ * @return
+ * OC_STACK_OK - no errors
+ * OC_STACK_ERROR - stack process error
+ */
+
+OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
+ const char *resourceTypeName,
+ const char *resourceInterfaceName,
+ const char *host,
+ const char *uri,
+ OCEntityHandler entityHandler,
+ uint8_t resourceProperties) {
+
+
+ char *str = NULL;
+ size_t size;
+ OCStackResult result = OC_STACK_ERROR;
+
+ result = OCCreateResource(handle,resourceTypeName,resourceInterfaceName,uri,entityHandler,resourceProperties);
+
+ if( result != OC_STACK_ERROR)
+ {
+ // Set the uri
+ size = strlen(host) + 1;
+ str = (char *) OCMalloc(size);
+ if (!str) {
+ return OC_STACK_ERROR;
+ }
+ strncpy(str, host, size);
+ ((OCResource *)*handle)->host = str;
+ }
+
+ return result;
+}
+
/**
* Add a resource to a collection resource.
*
OC_LOG(ERROR, TAG, PCF("Invalid param"));
return OC_STACK_INVALID_PARAM;
}
-
+
OCResource *resource = findResource((OCResource *) handle);
if (resource == NULL) {
OC_LOG(ERROR, TAG, PCF("Resource not found"));
const std::string& resourceInterface,
EntityHandler& entityHandler,
uint8_t resourceProperty) = 0;
+
+
+ virtual OCStackResult registerResourceWithHost(
+ OCResourceHandle& resourceHandle,
+ std::string& resourceHOST,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler& entityHandler,
+ uint8_t resourceProperty) = 0;
+
virtual OCStackResult unregisterResource(
const OCResourceHandle& resourceHandle) = 0;
virtual OCStackResult bindTypeToResource(
EntityHandler& entityHandler,
uint8_t resourceProperty);
+ virtual OCStackResult registerResourceWithHost(
+ OCResourceHandle& resourceHandle,
+ std::string& resourceHOST,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler& entityHandler,
+ uint8_t resourceProperty);
+
virtual OCStackResult unregisterResource(
const OCResourceHandle& resourceHandle);
uint8_t resourceProperty);
/**
+ * This API registers a resource with the server
+ * NOTE: This API applies to server & client side.
+
+ * @param resourceHandle - Upon successful registration, resourceHandle will be filled
+ * @param resource - The resource that all data filled.
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ */
+
+ OCStackResult registerResource(OCResourceHandle& resourceHandle,
+ const std::shared_ptr<OCResource> resource);
+
+ /**
* Set default device entity handler
*
* @param entityHandler - entity handler to handle requests for
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);
+
+
+
}
}
EntityHandler entityHandler,
uint8_t resourceProperty);
+ /**
+ * This API registers a resource with the server
+ * NOTE: This API applies to server & client side.
+
+ * @param resourceHandle - Upon successful registration, resourceHandle will be filled
+ * @param resource - The resource that all data filled.
+ *
+ * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+ */
+
+ OCStackResult registerResource(OCResourceHandle& resourceHandle,
+ const std::shared_ptr<OCResource> resource);
+
/**
* Set default device entity handler
*
// Not implemented
return OC_STACK_NOTIMPL;
}
+ virtual OCStackResult registerResourceWithHost(
+ OCResourceHandle& resourceHandle,
+ std::string& resourceHOST,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler& entityHandler,
+ uint8_t resourceProperty)
+ {
+ return OC_STACK_NOTIMPL;
+ }
virtual OCStackResult unregisterResource(
const OCResourceHandle& resourceHandle)
return result;
}
+ OCStackResult InProcServerWrapper::registerResourceWithHost(
+ OCResourceHandle& resourceHandle,
+ std::string& resourceHOST,
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ EntityHandler& eHandler,
+ uint8_t resourceProperties)
+
+ {
+ OCStackResult result = OC_STACK_ERROR;
+
+ auto cLock = m_csdkLock.lock();
+
+ if(cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+
+ if(NULL != eHandler)
+ {
+ result = OCCreateResourceWithHost(&resourceHandle, // OCResourceHandle *handle
+ resourceTypeName.c_str(), // const char * resourceTypeName
+ resourceInterface.c_str(), //const char * resourceInterfaceName //TODO fix this
+ resourceHOST.c_str(), // const char * host
+ resourceURI.c_str(), // const char * uri
+ EntityHandlerWrapper, // OCEntityHandler entityHandler
+ resourceProperties // uint8_t resourceProperties
+ );
+ }
+ else
+ {
+ result = OCCreateResourceWithHost(&resourceHandle, // OCResourceHandle *handle
+ resourceTypeName.c_str(), // const char * resourceTypeName
+ resourceInterface.c_str(), //const char * resourceInterfaceName //TODO fix this
+ resourceHOST.c_str(), // const char * host
+ resourceURI.c_str(), // const char * uri
+ NULL, // OCEntityHandler entityHandler
+ resourceProperties // uint8_t resourceProperties
+ );
+ }
+
+ if(result != OC_STACK_OK)
+ {
+ resourceHandle = (OCResourceHandle) 0;
+ }
+ else
+ {
+ entityHandlerMap[resourceHandle] = eHandler;
+ resourceUriMap[resourceHandle] = resourceURI;
+ }
+ }
+ else
+ {
+ result = OC_STACK_ERROR;
+ }
+
+ return result;
+ }
OCStackResult InProcServerWrapper::setDefaultDeviceEntityHandler
(EntityHandler entityHandler)
{
entityHandler, resourceProperty);
}
+ OCStackResult registerResource(OCResourceHandle& resourceHandle,
+ const std::shared_ptr<OCResource> resource)
+ {
+ return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
+ }
+
OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
{
return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
resourceInterface, entityHandler, resourceProperty);
}
+
+ OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
+ const std::shared_ptr<OCResource> resource)
+ {
+ uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+
+ return checked_guard(m_server, &IServerWrapper::registerResourceWithHost,
+ ref(resourceHandle), resource->host(), resource->uri(), "core.remote",
+ "oc.mi.def", (EntityHandler) NULL, resourceProperty);
+
+
+ }
OCStackResult OCPlatform_impl::unregisterResource(const OCResourceHandle& resourceHandle) const
{
return checked_guard(m_server, &IServerWrapper::unregisterResource,