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

Add Generic Upnp Devices and Services to Upnp Bridge

Generic upnp devices are now included in the 'links' of
the upnp bridge.  Generic upnp services are now included
in the 'links' of each generic device.

Change-Id: I97583eef53999c5e262328cd4b44444217bccb68
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20523Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent 803e842d
......@@ -27,6 +27,7 @@
// i.e. vetted by OIC and UPNP. Each section needs TBD and expanded.
// Resource type: devices
static const std::string UPNP_OIC_TYPE_DEVICE_PREFIX = "oic.d.";
static const std::string UPNP_OIC_TYPE_DEVICE_LIGHT = "oic.d.light";
static const std::string UPNP_OIC_TYPE_DEVICE_INET_GATEWAY = "oic.d.inet.gateway";
static const std::string UPNP_OIC_TYPE_DEVICE_WAN = "oic.d.wan";
......@@ -36,6 +37,7 @@ static const std::string UPNP_OIC_TYPE_DEVICE_MEDIA_RENDERER = "oic.d.media
static const std::string UPNP_OIC_TYPE_DEVICE_MEDIA_SERVER = "oic.d.media.server";
// Resource type: services
static const std::string UPNP_OIC_TYPE_SERVICE_PREFIX = "oic.r.";
static const std::string UPNP_OIC_TYPE_BRIGHTNESS = "oic.r.light.brightness";
static const std::string UPNP_OIC_TYPE_POWER_SWITCH = "oic.r.switch.binary";
static const std::string UPNP_OIC_TYPE_CONNECTION_MANAGER = "oic.r.connection.manager";
......@@ -63,15 +65,15 @@ static const std::string UPNP_OIC_URI_PREFIX_LAYER3_FORWARDING = "/upnp/l3f
static const std::string UPNP_OIC_URI_PREFIX_DEVICE_PROTECTION = "/upnp/device-protection/";
static const std::string UPNP_OIC_URI_PREFIX_WAN = "/upnp/wan/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_IF_CONFIG = "/upnp/wan/ifconfig/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_CABLE_LINK_CONFIG = "/upnp/wan/cableconfig";
static const std::string UPNP_OIC_URI_PREFIX_WAN_DSL_LINK_CONFIG = "/upnp/wan/dslconfig";
static const std::string UPNP_OIC_URI_PREFIX_WAN_ETHERNET_CONFIG = "/upnp/wan/ethernetconfig";
static const std::string UPNP_OIC_URI_PREFIX_WAN_POTS_LINK_CONFIG = "/upnp/wan/potsconfig";
static const std::string UPNP_OIC_URI_PREFIX_WAN_CONNECTION = "/upnp/wan/connection";
static const std::string UPNP_OIC_URI_PREFIX_WAN_IP_CONNECTION = "/upnp/wan/ip";
static const std::string UPNP_OIC_URI_PREFIX_WAN_PPP_CONNECTION = "/upnp/wan/ppp";
static const std::string UPNP_OIC_URI_PREFIX_LAN = "/upnp/lan";
static const std::string UPNP_OIC_URI_PREFIX_LAN_HOST_CONFIG = "/upnp/lan/hostconfig";
static const std::string UPNP_OIC_URI_PREFIX_WAN_CABLE_LINK_CONFIG = "/upnp/wan/cableconfig/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_DSL_LINK_CONFIG = "/upnp/wan/dslconfig/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_ETHERNET_CONFIG = "/upnp/wan/ethernetconfig/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_POTS_LINK_CONFIG = "/upnp/wan/potsconfig/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_CONNECTION = "/upnp/wan/connection/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_IP_CONNECTION = "/upnp/wan/ip/";
static const std::string UPNP_OIC_URI_PREFIX_WAN_PPP_CONNECTION = "/upnp/wan/ppp/";
static const std::string UPNP_OIC_URI_PREFIX_LAN = "/upnp/lan/";
static const std::string UPNP_OIC_URI_PREFIX_LAN_HOST_CONFIG = "/upnp/lan/hostconfig/";
static const std::string UPNP_OIC_URI_PREFIX_MEDIA_RENDERER = "/upnp/media/renderer/";
static const std::string UPNP_OIC_URI_PREFIX_MEDIA_SERVER = "/upnp/media/server/";
static const std::string UPNP_OIC_URI_PREFIX_CONNECTION_MANAGER = "/upnp/connection-manager/";
......
......@@ -101,6 +101,7 @@ upnp_src = [
'UpnpDevice.cpp',
'UpnpDimmingService.cpp',
'UpnpException.cpp',
'UpnpGenericService.cpp',
'UpnpManager.cpp',
'UpnpPowerSwitchService.cpp',
'UpnpResource.cpp',
......
......@@ -299,7 +299,13 @@ OCEntityHandlerResult UpnpBridgeDevice::processGetRequest(string uri, string res
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());
if (device.second->m_resourceType == UPNP_OIC_TYPE_DEVICE_LIGHT)
{
OCRepPayloadSetPropString(linkPayload, OC_RSRVD_RESOURCE_TYPE, device.second->m_resourceType.c_str());
}
else {
OCRepPayloadSetPropString(linkPayload, OC_RSRVD_RESOURCE_TYPE, UPNP_DEVICE_RESOURCE.c_str());
}
links[linksIndex] = linkPayload;
++linksIndex;
}
......
......@@ -66,6 +66,9 @@ const uint LIGHT_CALLBACK = 0;
const uint BINARY_SWITCH_CALLBACK = 1;
const uint BRIGHTNESS_CALLBACK = 2;
const uint GENERIC_DEVICE_CALLBACK = 1000;
const uint GENERIC_SERVICE_CALLBACK = 1001;
UpnpConnector::UpnpConnector(DiscoveryCallback discoveryCallback, LostCallback lostCallback)
{
DEBUG_PRINT("");
......@@ -292,11 +295,10 @@ void UpnpConnector::onDeviceProxyAvailable(GUPnPControlPoint *controlPoint,
DEBUG_PRINT("Device type: " << gupnp_device_info_get_device_type(deviceInfo));
// For now, lights only
// If not a light then use Generic UPnP Data Model
if (! boost::regex_match(gupnp_device_info_get_device_type(deviceInfo), boost::regex(".*[Ll]ight.*")))
{
ERROR_PRINT("Device type " << gupnp_device_info_get_device_type(deviceInfo) << " not implemented");
return;
DEBUG_PRINT("Device type " << gupnp_device_info_get_device_type(deviceInfo) << " implemented as generic upnp device");
}
#ifndef NDEBUG
......@@ -628,7 +630,7 @@ OCEntityHandlerResult handleEntityHandlerRequests( OCEntityHandlerRequest *entit
{
case OC_REST_GET:
DEBUG_PRINT(" GET Request for: " << uri);
ehResult = service.second->processGetRequest(payload);
ehResult = service.second->processGetRequest(payload, resourceType);
break;
case OC_REST_PUT:
......@@ -652,7 +654,7 @@ OCEntityHandlerResult handleEntityHandlerRequests( OCEntityHandlerRequest *entit
{
case OC_REST_GET:
DEBUG_PRINT(" GET Request for: " << uri);
ehResult = device.second->processGetRequest(payload);
ehResult = device.second->processGetRequest(payload, resourceType);
break;
case OC_REST_PUT:
......@@ -708,6 +710,18 @@ OCEntityHandlerResult resourceEntityHandler(OCEntityHandlerFlag,
{
return handleEntityHandlerRequests(entityHandlerRequest, UPNP_OIC_TYPE_BRIGHTNESS);
}
else if (callbackParamResourceType == GENERIC_DEVICE_CALLBACK)
{
return handleEntityHandlerRequests(entityHandlerRequest, UPNP_DEVICE_RESOURCE);
}
else if (callbackParamResourceType == GENERIC_SERVICE_CALLBACK)
{
return handleEntityHandlerRequests(entityHandlerRequest, UPNP_SERVICE_RESOURCE);
}
else
{
DEBUG_PRINT("TODO: Handle callback for " << callbackParamResourceType);
}
return OC_EH_ERROR;
}
......@@ -735,7 +749,9 @@ void UpnpConnector::onAdd(std::string uri)
}
else
{
DEBUG_PRINT("No resource added for " << service.second->m_resourceType);
DEBUG_PRINT("Adding generic upnp service");
createResource(uri, UPNP_SERVICE_RESOURCE, OC_RSRVD_INTERFACE_ACTUATOR,
resourceEntityHandler, (void *) GENERIC_SERVICE_CALLBACK, resourceProperties);
}
}
}
......@@ -749,7 +765,9 @@ void UpnpConnector::onAdd(std::string uri)
}
else
{
DEBUG_PRINT("No device added for " << device.second->m_resourceType);
DEBUG_PRINT("Adding generic upnp device");
createResource(uri, UPNP_DEVICE_RESOURCE, OC_RSRVD_INTERFACE_READ,
resourceEntityHandler, (void *) GENERIC_DEVICE_CALLBACK, resourceProperties);
}
}
}
......@@ -779,7 +797,7 @@ OCStackResult UpnpConnector::createResource(const string uri, const string resou
// {
// DEBUG_PRINT("Failed to bind virtual resource type to " << uri);
// }
if (UPNP_OIC_TYPE_DEVICE_LIGHT == resourceTypeName) {
if (UPNP_OIC_TYPE_DEVICE_LIGHT == resourceTypeName || UPNP_DEVICE_RESOURCE == resourceTypeName) {
result = OCBindResourceTypeToResource(handle, OC_RSRVD_RESOURCE_TYPE_COLLECTION);
if (result == OC_STACK_OK)
{
......@@ -803,7 +821,7 @@ OCStackResult UpnpConnector::createResource(const string uri, const string resou
}
else
{
DEBUG_PRINT("Failed to create resource " << uri);
DEBUG_PRINT("Failed to create resource " << uri << " result = " << result);
}
}
else
......
......@@ -59,7 +59,6 @@ UpnpDevice::UpnpDevice(GUPnPDeviceInfo *deviceInfo,
m_registered = false;
m_deviceList.clear();
m_serviceList.clear();
initBasicAttributes(deviceInfo);
}
UpnpDevice::~UpnpDevice()
......@@ -103,29 +102,6 @@ static const map< string, function< char *(GUPnPDeviceInfo *deviceInfo)>> s_devi
{"upc", gupnp_device_info_get_upc}
};
void UpnpDevice::initBasicAttributes(GUPnPDeviceInfo *deviceInfo)
{
for (auto const &kv : s_deviceInfo2AttributesMap)
{
char *c_field = kv.second(deviceInfo);
if (c_field != NULL)
{
string s_field = string(c_field);
g_free(c_field);
}
}
char *iconUrl = gupnp_device_info_get_icon_url(deviceInfo, NULL, -1, -1, -1, false, NULL, NULL, NULL, NULL);
if (iconUrl != NULL)
{
g_free(iconUrl);
}
}
void UpnpDevice::initAttributes()
{
}
void UpnpDevice::setProxy(GUPnPDeviceProxy *proxy)
{
m_proxy = proxy;
......@@ -160,45 +136,49 @@ string UpnpDevice::getStringField(function< char *(GUPnPDeviceInfo *deviceInfo)>
return "";
}
OCEntityHandlerResult UpnpDevice::processGetRequest(OCRepPayload *payload)
OCEntityHandlerResult UpnpDevice::processGetRequest(OCRepPayload *payload, string resourceType)
{
if (payload == NULL)
{
throw "payload is null";
}
GUPnPDeviceInfo *deviceInfo = GUPNP_DEVICE_INFO(m_proxy);
if (!OCRepPayloadSetPropString(payload, "device_type", m_deviceType.c_str()))
if (UPNP_DEVICE_RESOURCE == resourceType)
{
throw "Failed to set device_type value in payload";
}
DEBUG_PRINT("device_type: " << m_deviceType);
GUPnPDeviceInfo *deviceInfo = GUPNP_DEVICE_INFO(m_proxy);
for (auto const &kv : s_deviceInfo2AttributesMap)
{
char *c_field = kv.second(deviceInfo);
if (c_field != NULL)
if (!OCRepPayloadSetPropString(payload, "device_type", m_deviceType.c_str()))
{
string s_field = string(c_field);
if (!OCRepPayloadSetPropString(payload, kv.first.c_str(), s_field.c_str()))
throw "Failed to set device_type value in payload";
}
DEBUG_PRINT("device_type: " << m_deviceType);
for (auto const &kv : s_deviceInfo2AttributesMap)
{
char *c_field = kv.second(deviceInfo);
if (c_field != NULL)
{
throw "Failed to set property value in payload";
string s_field = string(c_field);
if (!OCRepPayloadSetPropString(payload, kv.first.c_str(), s_field.c_str()))
{
throw "Failed to set property value in payload";
}
DEBUG_PRINT(kv.first << ": " << s_field);
g_free(c_field);
}
DEBUG_PRINT(kv.first << ": " << s_field);
g_free(c_field);
}
}
char *iconUrl = gupnp_device_info_get_icon_url(deviceInfo, NULL, -1, -1, -1, false, NULL, NULL, NULL, NULL);
if (iconUrl != NULL)
{
if (!OCRepPayloadSetPropString(payload, "icon_url", iconUrl))
char *iconUrl = gupnp_device_info_get_icon_url(deviceInfo, NULL, -1, -1, -1, false, NULL, NULL, NULL, NULL);
if (iconUrl != NULL)
{
throw "Failed to set icon_url value in payload";
if (!OCRepPayloadSetPropString(payload, "icon_url", iconUrl))
{
throw "Failed to set icon_url value in payload";
}
DEBUG_PRINT("icon_url: " << iconUrl);
g_free(iconUrl);
}
DEBUG_PRINT("icon_url: " << iconUrl);
g_free(iconUrl);
}
if (!m_links.empty())
......@@ -207,17 +187,17 @@ OCEntityHandlerResult UpnpDevice::processGetRequest(OCRepPayload *payload)
const OCRepPayload *links[m_links.size()];
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {m_links.size(), 0, 0};
for (unsigned int i = 0; i < m_links.size(); ++i) {
DEBUG_PRINT("link[" << i << "]");
DEBUG_PRINT("\thref=" << m_links[i].href);
DEBUG_PRINT("\trel=" << m_links[i].rel);
DEBUG_PRINT("\trt=" << m_links[i].rt);
DEBUG_PRINT(OC_RSRVD_LINKS << "[" << i << "]");
DEBUG_PRINT("\t" << OC_RSRVD_HREF << "=" << m_links[i].href);
DEBUG_PRINT("\t" << OC_RSRVD_REL << "=" << m_links[i].rel);
DEBUG_PRINT("\t" << OC_RSRVD_RESOURCE_TYPE << "=" << m_links[i].rt);
OCRepPayload *linkPayload = OCRepPayloadCreate();
OCRepPayloadSetPropString(linkPayload, "href", m_links[i].href.c_str());
OCRepPayloadSetPropString(linkPayload, "rel", m_links[i].rel.c_str());
OCRepPayloadSetPropString(linkPayload, "rt", m_links[i].rt.c_str());
OCRepPayloadSetPropString(linkPayload, OC_RSRVD_HREF, m_links[i].href.c_str());
OCRepPayloadSetPropString(linkPayload, OC_RSRVD_REL, m_links[i].rel.c_str());
OCRepPayloadSetPropString(linkPayload, OC_RSRVD_RESOURCE_TYPE, m_links[i].rt.c_str());
links[i] = linkPayload;
}
OCRepPayloadSetPropObjectArray(payload, "links", links, dimensions);
OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_LINKS, links, dimensions);
}
return OC_EH_OK;
......
......@@ -37,8 +37,6 @@ class UpnpDevice: public UpnpResource
virtual ~UpnpDevice();
void initAttributes();
void insertDevice(string udn);
void insertService(string id);
......@@ -51,7 +49,7 @@ class UpnpDevice: public UpnpResource
std::vector<string> &getDeviceList();
std::vector<string> &getServiceList();
OCEntityHandlerResult processGetRequest(OCRepPayload *payload);
OCEntityHandlerResult processGetRequest(OCRepPayload *payload, string resourceType);
private:
......@@ -67,7 +65,6 @@ class UpnpDevice: public UpnpResource
UpnpRequestState *m_requestState;
void initBasicAttributes(GUPnPDeviceInfo *deviceInfo);
string getStringField(function< char *(GUPnPDeviceInfo *deviceInfo)> f,
GUPnPDeviceInfo *deviceInfo);
};
......
......@@ -66,12 +66,13 @@ vector <UpnpAttributeInfo> UpnpDimming::Attributes =
static const char* brightnessLevelName = "brightness";
OCEntityHandlerResult UpnpDimming::processGetRequest(OCRepPayload *payload)
OCEntityHandlerResult UpnpDimming::processGetRequest(OCRepPayload *payload, string resourceType)
{
if (payload == NULL)
{
throw "payload is null";
}
(void) resourceType;
//TODO use async version with callback
int64_t brightnessLevelValue = 0;
......@@ -98,7 +99,7 @@ OCEntityHandlerResult UpnpDimming::processGetRequest(OCRepPayload *payload)
}
DEBUG_PRINT(brightnessLevelName << ": " << brightnessLevelValue);
return UpnpService::processGetRequest(payload);
return UpnpService::processGetRequest(payload, resourceType);
}
OCEntityHandlerResult UpnpDimming::processPutRequest(OCEntityHandlerRequest *ehRequest,
......
......@@ -43,7 +43,7 @@ class UpnpDimming: public UpnpService
{
}
OCEntityHandlerResult processGetRequest(OCRepPayload *payload);
OCEntityHandlerResult processGetRequest(OCRepPayload *payload, string resourceType);
OCEntityHandlerResult processPutRequest(OCEntityHandlerRequest *ehRequest,
string uri, string resourceType, OCRepPayload *payload);
......
//******************************************************************
//
// Copyright 2017 Intel Corporation All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "UpnpGenericService.h"
static const string MODULE = "UpnpGenericService";
vector <UpnpAttributeInfo> UpnpGenericService::Attributes =
{
};
OCEntityHandlerResult UpnpGenericService::processGetRequest(OCRepPayload *payload, string resourceType)
{
if (payload == NULL)
{
throw "payload is null";
}
(void) resourceType;
//TODO use async version with callback
DEBUG_PRINT("TODO:");
return UpnpService::processGetRequest(payload, resourceType);
}
OCEntityHandlerResult UpnpGenericService::processPutRequest(OCEntityHandlerRequest *ehRequest,
string uri, string resourceType, OCRepPayload *payload)
{
(void) uri;
(void) resourceType;
(void) payload;
if (!ehRequest || !ehRequest->payload ||
ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
throw "Incoming payload is NULL or not a representation";
}
OCRepPayload *input = reinterpret_cast<OCRepPayload *>(ehRequest->payload);
if (!input)
{
throw "PUT payload is null";
}
//TODO use async version with callback
DEBUG_PRINT("TODO:");
return OC_EH_OK;
}
//******************************************************************
//
// Copyright 2017 Intel Corporation All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef UPNP_GENERIC_SERVICE_H_
#define UPNP_GENERIC_SERVICE_H_
#include <string>
#include <map>
#include <gupnp.h>
#include "UpnpResource.h"
#include "UpnpInternal.h"
#include "UpnpService.h"
using namespace std;
class UpnpGenericService: public UpnpService
{
friend class UpnpService;
public:
UpnpGenericService(GUPnPServiceInfo *serviceInfo, UpnpRequestState *requestState, string serviceType):
UpnpService(serviceInfo, serviceType, requestState, &Attributes)
{
}
OCEntityHandlerResult processGetRequest(OCRepPayload *payload, string resourceType);
OCEntityHandlerResult processPutRequest(OCEntityHandlerRequest *ehRequest,
string uri, string resourceType, OCRepPayload *payload);
private:
static vector <UpnpAttributeInfo> Attributes;
};
#endif
......@@ -82,8 +82,8 @@ static std::map<std::string, std::string > UpnpInterfaceMap =
{
// Lighting Control
{UPNP_OIC_TYPE_DEVICE_LIGHT, OC_RSRVD_INTERFACE_LL},
{UPNP_OIC_TYPE_POWER_SWITCH, "oic.if.a"},
{UPNP_OIC_TYPE_BRIGHTNESS, "oic.if.a"},
{UPNP_OIC_TYPE_POWER_SWITCH, OC_RSRVD_INTERFACE_ACTUATOR},
{UPNP_OIC_TYPE_BRIGHTNESS, OC_RSRVD_INTERFACE_ACTUATOR},
// Internet Gateway
{UPNP_OIC_TYPE_DEVICE_INET_GATEWAY, OC_RSRVD_INTERFACE_LL},
{UPNP_OIC_TYPE_DEVICE_WAN, OC_RSRVD_INTERFACE_LL},
......
......@@ -42,6 +42,7 @@
//#include "UpnpWanIpConnectionService.h"
//#include "UpnpWanPppConnectionService.h"
//#include "UpnpWanPotsLinkConfigService.h"
#include "UpnpGenericService.h"
using namespace std;
......@@ -478,9 +479,17 @@ std::shared_ptr<UpnpService> UpnpManager::generateService(GUPnPServiceInfo *ser
// }
else
{
//throw an exception
ERROR_PRINT("Service type " << serviceType << " not implemented!");
throw NotImplementedException("UpnpService::ctor: Service " + serviceType + " not implemented!");
return nullptr;
if (! resourceType.empty())
{
DEBUG_PRINT("Service type " << serviceType << " implemented as generic upnp service");
return (std::make_shared < UpnpGenericService > (serviceInfo, requestState, resourceType));
}
else
{
//throw an exception
ERROR_PRINT("Service type " << serviceType << " not implemented!");
throw NotImplementedException("UpnpService::ctor: Service " + serviceType + " not implemented!");
return nullptr;
}
}
}
......@@ -45,12 +45,13 @@ vector <UpnpAttributeInfo> UpnpPowerSwitch::Attributes =
static const char* powerSwitchStateName = "value";
OCEntityHandlerResult UpnpPowerSwitch::processGetRequest(OCRepPayload *payload)
OCEntityHandlerResult UpnpPowerSwitch::processGetRequest(OCRepPayload *payload, string resourceType)
{
if (payload == NULL)
{
throw "payload is null";
}
(void) resourceType;
//TODO use async version with callback
bool powerSwitchStateValue = false;
......@@ -77,7 +78,7 @@ OCEntityHandlerResult UpnpPowerSwitch::processGetRequest(OCRepPayload *payload)
}
DEBUG_PRINT(powerSwitchStateName << ": " << (powerSwitchStateValue ? "true" : "false"));
return UpnpService::processGetRequest(payload);
return UpnpService::processGetRequest(payload, resourceType);
}
OCEntityHandlerResult UpnpPowerSwitch::processPutRequest(OCEntityHandlerRequest *ehRequest,
......
......@@ -43,7 +43,7 @@ class UpnpPowerSwitch: public UpnpService
{
}
OCEntityHandlerResult processGetRequest(OCRepPayload *payload);
OCEntityHandlerResult processGetRequest(OCRepPayload *payload, string resourceType);
OCEntityHandlerResult processPutRequest(OCEntityHandlerRequest *ehRequest,
string uri, string resourceType, OCRepPayload *payload);
......
......@@ -51,8 +51,19 @@ void UpnpResource::addLink(UpnpResource::Ptr pResource)
_link singleLink;
singleLink.href = pResource->m_uri;
singleLink.rel = "contains";
singleLink.rel = LINK_REL_CONTAINS;
singleLink.rt = pResource->getResourceType();
// Embedded devices are all generic upnp devices for now
if (singleLink.rt.find(UPNP_OIC_TYPE_DEVICE_PREFIX) == 0) {
singleLink.rt = UPNP_DEVICE_RESOURCE;
}
// Non-light services are all generic upnp services for now
else if (singleLink.rt.find(UPNP_OIC_TYPE_SERVICE_PREFIX) == 0) {
if (!(singleLink.rt == UPNP_OIC_TYPE_BRIGHTNESS || singleLink.rt == UPNP_OIC_TYPE_POWER_SWITCH))
{
singleLink.rt = UPNP_SERVICE_RESOURCE;
}
}
m_links.push_back(singleLink);
}
......
......@@ -29,10 +29,13 @@
using namespace std;
static const string UPNP_DEVICE_RESOURCE = "oic.r.upnp.device";
static const string UPNP_SERVICE_RESOURCE = "oic.r.upnp.service";
struct _link {
string href;
string rel;
string rt;
string href;
string rel;
string rt;
};
class UpnpResource
......
......@@ -144,9 +144,10 @@ string UpnpService::getStringField(function< char *(GUPnPServiceInfo *serviceInf
return "";
}
OCEntityHandlerResult UpnpService::processGetRequest(OCRepPayload *payload)
OCEntityHandlerResult UpnpService::processGetRequest(OCRepPayload *payload, string resourceType)
{
(void) payload;
(void) payload;
(void) resourceType;
return OC_EH_OK;
}
......
......@@ -52,7 +52,7 @@ public:
string getId();
void stop();
virtual OCEntityHandlerResult processGetRequest(OCRepPayload *payload);
virtual OCEntityHandlerResult processGetRequest(OCRepPayload *payload, string resourceType);
virtual OCEntityHandlerResult processPutRequest(OCEntityHandlerRequest *ehRequest,
string uri, string resourceType, OCRepPayload *payload);
......@@ -68,8 +68,6 @@ protected:
UpnpRequestState *m_requestState;
// virtual void initAttributes();
private:
string m_serviceId;
......