Commit ebd8cf7f authored by Larry Sachs's avatar Larry Sachs Committed by Rick Bell

Add oic.d.virtual resource type to each UPnP virtual resource.

Per Bridging Spec, each virtual resource should have the
resource type oic.d.virtual

UPnP virtual resources will also have their smart home
resource types as well (eg. oic.d.light).

Change-Id: I438c75914185b97a89bb0992047978fc34ac231e
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18939Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent f85ed299
......@@ -720,15 +720,13 @@ void UpnpConnector::onAdd(std::string uri)
if (service.second->m_uri == uri) {
if (service.second->m_resourceType == UPNP_OIC_TYPE_POWER_SWITCH) {
DEBUG_PRINT("Adding binary switch resource");
ConcurrentIotivityUtils::queueCreateResource(uri, UPNP_OIC_TYPE_POWER_SWITCH, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler,
(void *) BINARY_SWITCH_CALLBACK, resourceProperties);
createResource(uri, UPNP_OIC_TYPE_POWER_SWITCH, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler, (void *) BINARY_SWITCH_CALLBACK, resourceProperties);
}
else if (service.second->m_resourceType == UPNP_OIC_TYPE_BRIGHTNESS) {
DEBUG_PRINT("Adding brightness resource");
ConcurrentIotivityUtils::queueCreateResource(uri, UPNP_OIC_TYPE_BRIGHTNESS, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler,
(void *) BRIGHTNESS_CALLBACK, resourceProperties);
createResource(uri, UPNP_OIC_TYPE_BRIGHTNESS, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler, (void *) BRIGHTNESS_CALLBACK, resourceProperties);
}
else
{
......@@ -741,9 +739,8 @@ void UpnpConnector::onAdd(std::string uri)
if (device.second->m_uri == uri) {
if (device.second->m_resourceType == UPNP_OIC_TYPE_DEVICE_LIGHT) {
DEBUG_PRINT("Adding light device");
ConcurrentIotivityUtils::queueCreateResource(uri, UPNP_OIC_TYPE_DEVICE_LIGHT, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler,
(void *) LIGHT_CALLBACK, resourceProperties);
createResource(uri, UPNP_OIC_TYPE_DEVICE_LIGHT, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler, (void *) LIGHT_CALLBACK, resourceProperties);
}
else
{
......@@ -752,3 +749,41 @@ void UpnpConnector::onAdd(std::string uri)
}
}
}
OCStackResult UpnpConnector::createResource(const string uri, const string resourceTypeName,
const char *resourceInterfaceName, OCEntityHandler resourceEntityHandler,
void* callbackParam, uint8_t resourceProperties)
{
OCStackResult result = OC_STACK_ERROR;
OCResourceHandle handle = OCGetResourceHandleAtUri(uri.c_str());
if (!handle)
{
result = OCCreateResource(&handle, resourceTypeName.c_str(), resourceInterfaceName,
uri.c_str(), resourceEntityHandler, callbackParam, resourceProperties);
if (result == OC_STACK_OK)
{
DEBUG_PRINT("Created resource " << uri);
result = OCBindResourceTypeToResource(handle, "oic.d.virtual");
if (result == OC_STACK_OK)
{
DEBUG_PRINT("Bound virtual resource type to " << uri);
}
else
{
DEBUG_PRINT("Failed to bind virtual resource type to " << uri);
}
}
else
{
DEBUG_PRINT("Failed to create resource " << uri);
}
}
else
{
DEBUG_PRINT("Not creating resource " << uri << " (already exists)");
result = OC_STACK_OK;
}
return result;
}
......@@ -71,6 +71,10 @@ class UpnpConnector
gpointer userContext);
static void unregisterDeviceResource(string udn);
static void initResourceCallbackHandler();
OCStackResult createResource(const string uri, const string resourceTypeName,
const char *resourceInterfaceName, OCEntityHandler resourceEntityHandler,
void* callbackParam, uint8_t resourceProperties);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment