*/
OCStackResult OCBindResourceTypeToResource(OCResourceHandle handle,
const char *resourceTypeName);
+
+/**
+ * This function clears all bound resource types and bind newly passing
+ * resource type to resource.
+ *
+ * @param handle Handle to the resource.
+ * @param newResourceType Name of resource type. Example: "core.led".
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult OCResetResourceTypes(OCResourceHandle handle,
+ const char *newResourceType);
+
/**
* This function binds a resource interface to a resource.
*
const char *resourceInterfaceName);
/**
+ * This function clears all bound interfaces and bind newly passing
+ * interface to resource.
+ *
+ * @param handle Handle to the resource.
+ * @param newResourceInterface Name of resource interface. Example: "core.rw".
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult OCResetResourceInterfaces(OCResourceHandle handle,
+ const char *newResourceInterface);
+
+/**
* This function binds an entity handler to the resource.
*
* @param handle Handle to the resource that the contained resource is to be bound.
return result;
}
+OCStackResult OCResetResourceTypes(OCResourceHandle handle,
+ const char *newResourceType)
+{
+ OCStackResult result = OC_STACK_ERROR;
+ OCResource *resource = NULL;
+
+ resource = findResource((OCResource *) handle);
+ if (!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Resource not found");
+ return OC_STACK_ERROR;
+ }
+
+ // Clear all bound resource types
+ deleteResourceType(resource->rsrcType);
+ resource->rsrcType = NULL;
+
+ // Bind new resource type to resource
+ result = BindResourceTypeToResource(resource, newResourceType);
+
+#ifdef WITH_PRESENCE
+ if(presenceResource.handle)
+ {
+ ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
+ SendPresenceNotification(resource->rsrcType, OC_PRESENCE_TRIGGER_CHANGE);
+ }
+#endif
+
+ return result;
+}
+
OCStackResult OCBindResourceInterfaceToResource(OCResourceHandle handle,
const char *resourceInterfaceName)
{
return result;
}
+OCStackResult OCResetResourceInterfaces(OCResourceHandle handle,
+ const char *newResourceInterface)
+{
+ OCStackResult result = OC_STACK_ERROR;
+ OCResource *resource = NULL;
+
+ resource = findResource((OCResource *) handle);
+ if (!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Resource not found");
+ return OC_STACK_ERROR;
+ }
+
+ // Clear all bound interface
+ deleteResourceInterface(resource->rsrcInterface);
+ resource->rsrcInterface = NULL;
+
+ // Bind new interface to resource
+ result = BindResourceInterfaceToResource(resource, newResourceInterface);
+
+#ifdef WITH_PRESENCE
+ if (presenceResource.handle)
+ {
+ ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
+ SendPresenceNotification(resource->rsrcType, OC_PRESENCE_TRIGGER_CHANGE);
+ }
+#endif
+
+ return result;
+}
+
OCStackResult OCGetNumberOfResources(uint8_t *numResources)
{
OCResource *pointer = headResource;
virtual OCStackResult unregisterResource(
const OCResourceHandle& resourceHandle) = 0;
+
virtual OCStackResult bindTypeToResource(
const OCResourceHandle& resourceHandle,
const std::string& resourceTypeName) = 0;
+ virtual OCStackResult resetResourceTypes(
+ const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType) = 0;
+
virtual OCStackResult bindInterfaceToResource(
const OCResourceHandle& resourceHandle,
const std::string& resourceInterfaceName) = 0;
+ virtual OCStackResult resetResourceInterfaces(
+ const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface) = 0;
+
virtual OCStackResult startPresence(const unsigned int seconds) = 0;
virtual OCStackResult stopPresence() = 0;
const OCResourceHandle& resourceHandle,
const std::string& resourceTypeName);
+ virtual OCStackResult resetResourceTypes(
+ const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType);
+
virtual OCStackResult bindInterfaceToResource(
const OCResourceHandle& resourceHandle,
const std::string& resourceInterface);
+ virtual OCStackResult resetResourceInterfaces(
+ const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface);
+
virtual OCStackResult startPresence(const unsigned int seconds);
virtual OCStackResult stopPresence();
const std::string& resourceTypeName);
/**
+ * Reset resource types of resource to newly passed resource type.
+ *
+ * @param resourceHandle handle to the resource
+ * @param newResourceType new typename to bind to the resource
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ */
+ OCStackResult resetResourceTypes(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType);
+
+ /**
* Binds an interface to a particular resource
* @param resourceHandle handle to the resource
* @param resourceInterfaceName new interface to bind to the resource
OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
const std::string& resourceInterfaceName);
+ /**
+ * Reset resource interfaces of resource to newly passed interface.
+ *
+ * @param resourceHandle handle to the resource
+ * @param newResourceInterface new interface to bind to the resource
+ *
+ * @return Returns ::OC_STACK_OK if success.
+ */
+ OCStackResult resetResourceInterfaces(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface);
/**
* Start Presence announcements.
OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
const std::string& resourceTypeName) const;
+ OCStackResult resetResourceTypes(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType) const;
+
OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
const std::string& resourceInterfaceName) const;
+ OCStackResult resetResourceInterfaces(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface) const;
+
OCStackResult startPresence(const unsigned int ttl);
OCStackResult stopPresence();
return result;
}
+ OCStackResult InProcServerWrapper::resetResourceTypes(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType)
+ {
+ auto cLock = m_csdkLock.lock();
+ OCStackResult result;
+ if(cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCResetResourceTypes(resourceHandle, newResourceType.c_str());
+ }
+ else
+ {
+ result = OC_STACK_ERROR;
+ }
+
+ if (result != OC_STACK_OK)
+ {
+ throw OCException(OC::Exception::BIND_TYPE_FAILED, result);
+ }
+ return result;
+ }
+
OCStackResult InProcServerWrapper::bindInterfaceToResource(
const OCResourceHandle& resourceHandle,
const std::string& resourceInterfaceName)
return result;
}
+ OCStackResult InProcServerWrapper::resetResourceInterfaces(
+ const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface)
+ {
+ auto cLock = m_csdkLock.lock();
+ OCStackResult result;
+ if(cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCResetResourceInterfaces(resourceHandle,
+ newResourceInterface.c_str());
+ }
+ else
+ {
+ result = OC_STACK_ERROR;
+ }
+
+ if (result != OC_STACK_OK)
+ {
+ throw OCException(OC::Exception::BIND_INTERFACE_FAILED, result);
+ }
+ return result;
+ }
+
OCStackResult InProcServerWrapper::startPresence(const unsigned int seconds)
{
auto cLock = m_csdkLock.lock();
return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
}
+ OCStackResult resetResourceTypes(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType)
+ {
+ return OCPlatform_impl::Instance().resetResourceTypes(resourceHandle,newResourceType);
+ }
+
OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
const std::string& resourceInterfaceName)
{
resourceInterfaceName);
}
+ OCStackResult resetResourceInterfaces(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface)
+ {
+ return OCPlatform_impl::Instance().resetResourceInterfaces(resourceHandle,
+ newResourceInterface);
+ }
+
OCStackResult startPresence(const unsigned int announceDurationSeconds)
{
return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
resourceHandle, resourceTypeName);
}
+ OCStackResult OCPlatform_impl::resetResourceTypes(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceType) const
+ {
+ return checked_guard(m_server, &IServerWrapper::resetResourceTypes,
+ resourceHandle, newResourceType);
+ }
+
OCStackResult OCPlatform_impl::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
const std::string& resourceInterfaceName) const
{
resourceHandle, resourceInterfaceName);
}
+ OCStackResult OCPlatform_impl::resetResourceInterfaces(const OCResourceHandle& resourceHandle,
+ const std::string& newResourceInterface) const
+ {
+ return checked_guard(m_server, &IServerWrapper::resetResourceInterfaces,
+ resourceHandle, newResourceInterface);
+ }
+
OCStackResult OCPlatform_impl::startPresence(const unsigned int announceDurationSeconds)
{
return checked_guard(m_server, &IServerWrapper::startPresence,