aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Sachs <larry.j.sachs@intel.com>2017-05-25 14:35:21 -0700
committerRick Bell <richard.s.bell@intel.com>2017-05-30 21:10:42 +0000
commitcc2fca24587b26c3112a92515e423e551b644e31 (patch)
tree58170e0e4739f019a6fbf439d65f6d6347be2e42
parent48b6c48462347c869e4d77eb0a6f8d5279005a70 (diff)
Add devices to upnp bridge resource collection1.3.0
The bridge device has a upnp-bridge resource which hosts the discovered devices. The hosted devices are in a links array. The bridge resource has rt of oic.d.bridge and oic.wk.col, the if now includes oic.if.ll Change-Id: I16c31635154d4608565c6ce7e972105b9b88bcba Signed-off-by: Larry Sachs <larry.j.sachs@intel.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/20401 Tested-by: jenkins-iotivity <jenkins@iotivity.org> Reviewed-by: George Nash <george.nash@intel.com> Reviewed-by: Rick Bell <richard.s.bell@intel.com>
-rw-r--r--plugins/upnp_plugin/UpnpBridgeDevice.cpp101
-rw-r--r--plugins/upnp_plugin/UpnpBridgeDevice.h3
-rw-r--r--plugins/upnp_plugin/UpnpConnector.cpp5
-rw-r--r--plugins/upnp_plugin/UpnpConnector.h2
-rw-r--r--plugins/upnp_plugin/UpnpInternal.h4
-rw-r--r--plugins/upnp_plugin/upnp_plugin.cpp2
6 files changed, 103 insertions, 14 deletions
diff --git a/plugins/upnp_plugin/UpnpBridgeDevice.cpp b/plugins/upnp_plugin/UpnpBridgeDevice.cpp
index 4fc4f86..817160e 100644
--- a/plugins/upnp_plugin/UpnpBridgeDevice.cpp
+++ b/plugins/upnp_plugin/UpnpBridgeDevice.cpp
@@ -39,10 +39,20 @@ using namespace OC::Bridging;
static const string MODULE = "UpnpBridgeDevice";
static const string BRIDGE_RESOURCE_TYPE = "oic.d.bridge";
+static const string SECUREMODE_RESOURCE_TYPE = "oic.r.securemode";
-static string s_bridgeUri = "/oic/upnp-bridge/0";
+const uint SECUREMODE_CALLBACK = 0;
+const uint COLLECTION_CALLBACK = 1;
+
+static const string SECUREMODE_PROPERTY_KEY = "secureMode";
+static const string SECUREMODE_RESOURCE_URI = "/securemode";
+static const string BRIDGE_RESOURCE_URI_PREFIX = "/upnp-bridge/";
+
+static string s_bridgeUri = BRIDGE_RESOURCE_URI_PREFIX + "0";
static vector<_link> s_links;
+static UpnpManager *s_upnpManager;
+
OCStackResult createResource(const string uri, const string resourceTypeName,
const char *resourceInterfaceName, OCEntityHandler resourceEntityHandler,
void* callbackParam, uint8_t resourceProperties)
@@ -96,13 +106,14 @@ UpnpBridgeDevice::UpnpBridgeDevice()
DEBUG_PRINT("Convert UUID to string for Upnp Bridge Device failed");
}
- s_bridgeUri = "/oic/upnp-bridge/" + string(uuidString);
+ s_bridgeUri = BRIDGE_RESOURCE_URI_PREFIX + string(uuidString);
- OCStackResult result = OCBindResourceTypeToResource(handle, "oic.d.bridge");
+ OCStackResult result = OCBindResourceTypeToResource(handle, BRIDGE_RESOURCE_TYPE.c_str());
if (result != OC_STACK_OK)
{
DEBUG_PRINT("OCBindResourceTypeToResource() = " << result);
}
+
handle = OCGetResourceHandleAtUri(OC_RSRVD_WELL_KNOWN_URI);
if (!handle)
{
@@ -113,14 +124,35 @@ UpnpBridgeDevice::UpnpBridgeDevice()
{
DEBUG_PRINT("OCSetResourceProperties() = " << result);
}
- result = createResource("/securemode", "oic.r.securemode",
- OC_RSRVD_INTERFACE_READ,
- entityHandler, (void *) 0, resourceProperties);
+
+ result = createResource(SECUREMODE_RESOURCE_URI, SECUREMODE_RESOURCE_TYPE.c_str(),
+ OC_RSRVD_INTERFACE_READ, entityHandler, (void *) SECUREMODE_CALLBACK, resourceProperties);
if (result != OC_STACK_OK)
{
DEBUG_PRINT("CreateResource() = " << result);
}
+ result = createResource(s_bridgeUri, BRIDGE_RESOURCE_TYPE.c_str(),
+ OC_RSRVD_INTERFACE_READ, entityHandler, (void *) COLLECTION_CALLBACK, resourceProperties);
+ if (result == OC_STACK_OK)
+ {
+ OCResourceHandle bridgeHandle = OCGetResourceHandleAtUri(s_bridgeUri.c_str());
+ result = OCBindResourceTypeToResource(bridgeHandle, OC_RSRVD_RESOURCE_TYPE_COLLECTION);
+ if (result != OC_STACK_OK)
+ {
+ DEBUG_PRINT("Failed to bind collection resource type to " << bridgeHandle << " " << result);
+ }
+
+ result = OCBindResourceInterfaceToResource(bridgeHandle, OC_RSRVD_INTERFACE_LL);
+ if (result != OC_STACK_OK)
+ {
+ DEBUG_PRINT("Failed to bind ll resource interface to " << bridgeHandle << " " << result);
+ }
+ }
+ else {
+ DEBUG_PRINT("CreateResource() = " << result);
+ }
+
DEBUG_PRINT("di=" << OCGetServerInstanceIDString());
}
@@ -130,12 +162,17 @@ UpnpBridgeDevice::~UpnpBridgeDevice()
DEBUG_PRINT("Plugin stop queueDeleteResource() result = " << result);
}
+void UpnpBridgeDevice::setUpnpManager(UpnpManager *upnpManager)
+{
+ s_upnpManager = upnpManager;
+}
+
void UpnpBridgeDevice::addResource(UpnpResource::Ptr pResource)
{
_link singleLink;
singleLink.href = pResource->m_uri;
- singleLink.rel = "contains";
+ singleLink.rel = LINK_REL_CONTAINS;
singleLink.rt = pResource->getResourceType();
s_links.push_back(singleLink);
@@ -156,9 +193,27 @@ void UpnpBridgeDevice::removeResource(string uri)
OCEntityHandlerResult UpnpBridgeDevice::entityHandler(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *entityHandlerRequest, void *callback)
{
+ DEBUG_PRINT("");
uintptr_t callbackParamResourceType = (uintptr_t)callback;
- (void)callbackParamResourceType;
- return handleEntityHandlerRequests(flag, entityHandlerRequest, "oic.r.securemode");
+ string resourceType;
+
+ if (callbackParamResourceType == SECUREMODE_CALLBACK)
+ {
+ resourceType = SECUREMODE_RESOURCE_TYPE;
+ }
+ else if (callbackParamResourceType == COLLECTION_CALLBACK)
+ {
+ resourceType = OC_RSRVD_RESOURCE_TYPE_COLLECTION;
+ }
+
+ if (! resourceType.empty()) {
+ return handleEntityHandlerRequests(flag, entityHandlerRequest, resourceType);
+ }
+ else {
+ ERROR_PRINT("Unknown callback type " << callbackParamResourceType);
+ }
+
+ return OC_EH_ERROR;
}
OCEntityHandlerResult UpnpBridgeDevice::handleEntityHandlerRequests(OCEntityHandlerFlag,
@@ -221,14 +276,34 @@ OCEntityHandlerResult UpnpBridgeDevice::processGetRequest(string uri, string res
throw "payload is null";
}
- if ("oic.r.securemode" == resType)
+ if (SECUREMODE_RESOURCE_TYPE == resType)
{
bool secureMode = false;
- if (!OCRepPayloadSetPropBool(payload, "secureMode", secureMode))
+ if (!OCRepPayloadSetPropBool(payload, SECUREMODE_PROPERTY_KEY.c_str(), secureMode))
{
- throw "Failed to set 'secureMode' in payload";
+ string message = "Failed to set '" + SECUREMODE_PROPERTY_KEY + "' in payload";
+ throw message;
+ }
+ DEBUG_PRINT(uri << " -- " << SECUREMODE_PROPERTY_KEY << ": " << (secureMode ? "true" : "false"));
+ }
+ else if (OC_RSRVD_RESOURCE_TYPE_COLLECTION == resType)
+ {
+ DEBUG_PRINT("Setting bridge device links");
+ const OCRepPayload *links[s_upnpManager->m_devices.size()];
+ size_t dimensions[MAX_REP_ARRAY_DEPTH] = {s_upnpManager->m_devices.size(), 0, 0};
+ int linksIndex = 0;
+ for (const auto& device : s_upnpManager->m_devices) {
+ DEBUG_PRINT(OC_RSRVD_LINKS << "[" << linksIndex << "]");
+ DEBUG_PRINT("\t" << OC_RSRVD_HREF << "=" << device.second->m_uri);
+ DEBUG_PRINT("\t" << OC_RSRVD_RESOURCE_TYPE << "=" << device.second->m_resourceType);
+ OCRepPayload *linkPayload = OCRepPayloadCreate();
+ OCRepPayloadSetPropString(linkPayload, OC_RSRVD_HREF, device.second->m_uri.c_str());
+ OCRepPayloadSetPropString(linkPayload, OC_RSRVD_REL, LINK_REL_HOSTS.c_str());
+ OCRepPayloadSetPropString(linkPayload, OC_RSRVD_RESOURCE_TYPE, device.second->m_resourceType.c_str());
+ links[linksIndex] = linkPayload;
+ ++linksIndex;
}
- DEBUG_PRINT(uri << " -- secureMode: " << (secureMode ? "true" : "false"));
+ OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_LINKS, links, dimensions);
}
else
{
diff --git a/plugins/upnp_plugin/UpnpBridgeDevice.h b/plugins/upnp_plugin/UpnpBridgeDevice.h
index ca5eb91..1c7a012 100644
--- a/plugins/upnp_plugin/UpnpBridgeDevice.h
+++ b/plugins/upnp_plugin/UpnpBridgeDevice.h
@@ -22,6 +22,7 @@
#define UPNP_BRIDGE_DEVICE_H_
#include "UpnpResource.h"
+#include "UpnpManager.h"
class UpnpBridgeDevice
{
@@ -44,6 +45,8 @@ class UpnpBridgeDevice
void addResource(UpnpResource::Ptr resource);
void removeResource(std::string uri);
+
+ void setUpnpManager(UpnpManager *upnpManager);
};
#endif
diff --git a/plugins/upnp_plugin/UpnpConnector.cpp b/plugins/upnp_plugin/UpnpConnector.cpp
index 5546a46..32ecfe2 100644
--- a/plugins/upnp_plugin/UpnpConnector.cpp
+++ b/plugins/upnp_plugin/UpnpConnector.cpp
@@ -87,6 +87,11 @@ UpnpConnector::~UpnpConnector()
s_manager = NULL;
}
+UpnpManager* UpnpConnector::getUpnpManager()
+{
+ return s_manager;
+}
+
void UpnpConnector::disconnect()
{
DEBUG_PRINT("");
diff --git a/plugins/upnp_plugin/UpnpConnector.h b/plugins/upnp_plugin/UpnpConnector.h
index ff52dd7..dbbe070 100644
--- a/plugins/upnp_plugin/UpnpConnector.h
+++ b/plugins/upnp_plugin/UpnpConnector.h
@@ -43,6 +43,8 @@ class UpnpConnector
UpnpConnector(DiscoveryCallback discoveryCallback, LostCallback lostCallback);
virtual ~UpnpConnector();
+ UpnpManager* getUpnpManager();
+
void connect();
void disconnect();
void onScan();
diff --git a/plugins/upnp_plugin/UpnpInternal.h b/plugins/upnp_plugin/UpnpInternal.h
index 8a8f836..156be33 100644
--- a/plugins/upnp_plugin/UpnpInternal.h
+++ b/plugins/upnp_plugin/UpnpInternal.h
@@ -30,7 +30,9 @@
#include <UpnpConstants.h>
-
+//IoTivity Link Relationships
+static const std::string LINK_REL_CONTAINS = "contains";
+static const std::string LINK_REL_HOSTS = "hosts";
//From UPNP spec
static const std::string UPNP_PREFIX_DEVICE = "urn:schemas-upnp-org:device";
diff --git a/plugins/upnp_plugin/upnp_plugin.cpp b/plugins/upnp_plugin/upnp_plugin.cpp
index 734a1b9..c7fd665 100644
--- a/plugins/upnp_plugin/upnp_plugin.cpp
+++ b/plugins/upnp_plugin/upnp_plugin.cpp
@@ -119,6 +119,8 @@ extern "C" DLL_PUBLIC MPMResult pluginStart(MPMPluginCtx *ctx)
s_upnpConnector = new UpnpConnector(discoveryCb, lostCb);
s_upnpConnector->connect();
+ s_bridge->setUpnpManager(s_upnpConnector->getUpnpManager());
+
return MPM_RESULT_OK;
}