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
OCEntityHandler entityHandler,
uint8_t resourceProperties);
-/**
- * Create a resource. with host ip address for remote resource.
- *
- * @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 remote 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 on success, some other value upon failure.
- */
-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.
return result;
}
-OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
- const char *resourceTypeName,
- const char *resourceInterfaceName,
- const char *host,
- const char *uri,
- OCEntityHandler entityHandler,
- uint8_t resourceProperties)
-{
- OC_LOG(INFO, TAG, PCF("Entering OCCreateResourceWithHost"));
- char *str = NULL;
- size_t size = 0;
-
- if(!host)
- {
- OC_LOG(ERROR, TAG, PCF("Added resource host is NULL."));
- return OC_STACK_INVALID_PARAM;
- }
-
- OCStackResult result = OC_STACK_ERROR;
-
- result = OCCreateResource(handle, resourceTypeName, resourceInterfaceName,
- uri, entityHandler, resourceProperties);
-
- if (result == OC_STACK_OK)
- {
- // Set the uri
- size = strlen(host) + 1;
- str = (char *) OCMalloc(size);
- if (!str)
- {
- OC_LOG(ERROR, TAG, PCF("Memory could not be allocated."));
- return OC_STACK_NO_MEMORY;
- }
- strncpy(str, host, size);
-
- ((OCResource *) *handle)->host = str;
- }
-
- return result;
-}
OCStackResult OCBindResource(
OCResourceHandle collectionHandle, OCResourceHandle resourceHandle)
virtual OCStackResult registerPlatformInfo(
const OCPlatformInfo PlatformInfo) = 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(
virtual OCStackResult registerPlatformInfo(
const OCPlatformInfo PlatformInfo);
- 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);
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
- resourceHOST.c_str(), // const char * host
- (resourceHOST + 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
- resourceHOST.c_str(), // const char * host
- (resourceHOST + resourceURI).c_str(), // const char * uri
- nullptr, // OCEntityHandler entityHandler
- resourceProperties // uint8_t resourceProperties
- );
- }
-
- if (result != OC_STACK_OK)
- {
- resourceHandle = nullptr;
- }
- else
- {
- std::lock_guard<std::mutex> lock(OC::details::serverWrapperLock);
- OC::details::entityHandlerMap[resourceHandle] = eHandler;
- OC::details::resourceUriMap[resourceHandle] = resourceURI;
- }
- }
- else
- {
- result = OC_STACK_ERROR;
- }
-
- return result;
- }
OCStackResult InProcServerWrapper::setDefaultDeviceEntityHandler
(EntityHandler entityHandler)
uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
std::vector<std::string> resourceTypes = resource->getResourceTypes();
- return checked_guard(m_server, &IServerWrapper::registerResourceWithHost,
- std::ref(resourceHandle), resource->host(), resource->uri(),
+ return checked_guard(m_server, &IServerWrapper::registerResource,
+ std::ref(resourceHandle), resource->uri(),
resourceTypes[0]/*"core.remote"*/, DEFAULT_INTERFACE,
(EntityHandler) nullptr, resourceProperty);
}