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

Plugfest fixes so far

Change-Id: Iac27cae48fafa8d11151e17eb88d16f024d91d96
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19439Reviewed-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent 9a641d50
......@@ -40,11 +40,47 @@ static const string MODULE = "UpnpBridgeDevice";
static const string BRIDGE_RESOURCE_TYPE = "oic.d.bridge";
static string s_bridgeUri = "/upnp-bridge/0";
static string s_bridgeUri = "/oic/upnp-bridge/0";
static vector<_link> s_links;
OCStackResult 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);
}
else
{
DEBUG_PRINT("Failed to create resource " << uri);
}
}
else
{
DEBUG_PRINT("Not creating resource " << uri << " (already exists)");
result = OC_STACK_OK;
}
return result;
}
UpnpBridgeDevice::UpnpBridgeDevice()
{
OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
if (!handle)
{
DEBUG_PRINT("OCGetResourceHandleAtUri(" << OC_RSRVD_DEVICE_URI << ") failed");
}
DEBUG_PRINT("OCGetResourceHandleAtUri(" << OC_RSRVD_DEVICE_URI << ") " << handle);
uint8_t resourceProperties = (OC_OBSERVABLE | OC_DISCOVERABLE);
// Generate a UUID for the Protocol Independent ID
......@@ -60,11 +96,32 @@ UpnpBridgeDevice::UpnpBridgeDevice()
DEBUG_PRINT("Convert UUID to string for Upnp Bridge Device failed");
}
s_bridgeUri = "/upnp-bridge/" + string(uuidString);
OCStackResult result = ConcurrentIotivityUtils::queueCreateResource(s_bridgeUri,
BRIDGE_RESOURCE_TYPE, OC_RSRVD_INTERFACE_ACTUATOR, entityHandler,
(void *) 0, resourceProperties);
DEBUG_PRINT("Plugin start queueCreateResource() result = " << result);
s_bridgeUri = "/oic/upnp-bridge/" + string(uuidString);
OCStackResult result = OCBindResourceTypeToResource(handle, "oic.d.bridge");
if (result != OC_STACK_OK)
{
DEBUG_PRINT("OCBindResourceTypeToResource() = " << result);
}
handle = OCGetResourceHandleAtUri(OC_RSRVD_WELL_KNOWN_URI);
if (!handle)
{
DEBUG_PRINT("OCGetResourceHandleAtUri(" << OC_RSRVD_DEVICE_URI << ") failed");
}
result = OCSetResourceProperties(handle, OC_DISCOVERABLE | OC_OBSERVABLE);
if (result != OC_STACK_OK)
{
DEBUG_PRINT("OCSetResourceProperties() = " << result);
}
result = createResource("/securemode", "oic.r.securemode",
OC_RSRVD_INTERFACE_READ,
entityHandler, (void *) 0, resourceProperties);
if (result != OC_STACK_OK)
{
DEBUG_PRINT("CreateResource() = " << result);
}
DEBUG_PRINT("di=" << OCGetServerInstanceIDString());
}
UpnpBridgeDevice::~UpnpBridgeDevice()
......@@ -101,7 +158,7 @@ OCEntityHandlerResult UpnpBridgeDevice::entityHandler(OCEntityHandlerFlag flag,
{
uintptr_t callbackParamResourceType = (uintptr_t)callback;
(void)callbackParamResourceType;
return handleEntityHandlerRequests(flag, entityHandlerRequest, BRIDGE_RESOURCE_TYPE);
return handleEntityHandlerRequests(flag, entityHandlerRequest, "oic.r.securemode");
}
OCEntityHandlerResult UpnpBridgeDevice::handleEntityHandlerRequests(OCEntityHandlerFlag,
......@@ -164,7 +221,7 @@ OCEntityHandlerResult UpnpBridgeDevice::processGetRequest(string uri, string res
throw "payload is null";
}
if (BRIDGE_RESOURCE_TYPE == resType)
if ("oic.r.securemode" == resType)
{
bool secureMode = false;
if (!OCRepPayloadSetPropBool(payload, "secureMode", secureMode))
......@@ -172,25 +229,6 @@ OCEntityHandlerResult UpnpBridgeDevice::processGetRequest(string uri, string res
throw "Failed to set 'secureMode' in payload";
}
DEBUG_PRINT(uri << " -- secureMode: " << (secureMode ? "true" : "false"));
if (!s_links.empty())
{
DEBUG_PRINT("Setting links");
const OCRepPayload *links[s_links.size()];
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {s_links.size(), 0, 0};
for (unsigned int i = 0; i < s_links.size(); ++i) {
DEBUG_PRINT("link[" << i << "]");
DEBUG_PRINT("\thref=" << s_links[i].href);
DEBUG_PRINT("\trel=" << s_links[i].rel);
DEBUG_PRINT("\trt=" << s_links[i].rt);
OCRepPayload *linkPayload = OCRepPayloadCreate();
OCRepPayloadSetPropString(linkPayload, "href", s_links[i].href.c_str());
OCRepPayloadSetPropString(linkPayload, "rel", s_links[i].rel.c_str());
OCRepPayloadSetPropString(linkPayload, "rt", s_links[i].rt.c_str());
links[i] = linkPayload;
}
OCRepPayloadSetPropObjectArray(payload, "links", links, dimensions);
}
}
else
{
......@@ -218,9 +256,9 @@ OCRepPayload* UpnpBridgeDevice::getCommonPayload(const char *uri, char *interfac
// If the interface filter is explicitly oic.if.baseline, include all properties.
if (interfaceQuery && string(interfaceQuery) == string(OC_RSRVD_INTERFACE_DEFAULT))
{
if (!OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_ACTUATOR))
if (!OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_READ))
{
throw "Failed to set actuator interface";
throw "Failed to set read interface";
}
if (!OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT))
......
......@@ -739,7 +739,7 @@ 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");
createResource(uri, UPNP_OIC_TYPE_DEVICE_LIGHT, OC_RSRVD_INTERFACE_ACTUATOR,
createResource(uri, UPNP_OIC_TYPE_DEVICE_LIGHT, OC_RSRVD_INTERFACE_READ,
resourceEntityHandler, (void *) LIGHT_CALLBACK, resourceProperties);
}
else
......@@ -764,15 +764,16 @@ OCStackResult UpnpConnector::createResource(const string uri, const string resou
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);
}
// Commented-out for now... causes CTT failure
// 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
{
......
......@@ -201,18 +201,6 @@ OCEntityHandlerResult UpnpDevice::processGetRequest(OCRepPayload *payload)
g_free(iconUrl);
}
if (!OCRepPayloadSetPropString(payload, "name", m_name.c_str()))
{
throw "Failed to set name in payload";
}
DEBUG_PRINT("name: " << m_name);
if (!OCRepPayloadSetPropString(payload, "uri", m_uri.c_str()))
{
throw "Failed to set uri in payload";
}
DEBUG_PRINT("uri: " << m_uri);
if (!m_links.empty())
{
DEBUG_PRINT("Setting links");
......
......@@ -31,9 +31,6 @@ using namespace std;
static const string MODULE = "UpnpService";
static const char* nameAttribute = "name";
static const char* uriAttribute = "uri";
UpnpService::UpnpService(GUPnPServiceInfo *serviceInfo,
string type,
UpnpRequestState *requestState,
......@@ -149,18 +146,7 @@ string UpnpService::getStringField(function< char *(GUPnPServiceInfo *serviceInf
OCEntityHandlerResult UpnpService::processGetRequest(OCRepPayload *payload)
{
if (!OCRepPayloadSetPropString(payload, nameAttribute, m_name.c_str()))
{
throw "Failed to set name in payload";
}
DEBUG_PRINT(nameAttribute << ": " << m_name);
if (!OCRepPayloadSetPropString(payload, uriAttribute, m_uri.c_str()))
{
throw "Failed to set uri in payload";
}
DEBUG_PRINT(uriAttribute << ": " << m_uri);
(void) payload;
return OC_EH_OK;
}
......
......@@ -61,6 +61,8 @@ int connectorDiscoveryCb(UpnpResource::Ptr pUpnpResource)
ERROR_PRINT("Failed to add resource: " << pUpnpResource->m_uri);
}
s_upnpConnector->onAdd(pUpnpResource->m_uri); // add now, don't wait for scan
return 0;
}
......@@ -96,7 +98,7 @@ extern "C" DLL_PUBLIC MPMResult pluginCreate(MPMPluginCtx **plugin_specific_ctx)
*plugin_specific_ctx = ctx;
g_plugin_ctx = ctx;
ctx->device_name = "UPnP plugin";
ctx->resource_type = "oic.d.upnp";
ctx->resource_type = "oic.r.upnp.device";
ctx->open = sec_file;
return MPM_RESULT_OK;
}
......
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