Commit 9aac7c26 authored by Larry Sachs's avatar Larry Sachs Committed by Rick Bell

Handle resource removal on upnp device/service unavailable.

Change-Id: I3b60a832e78ada2622855cabdf78c17b80426592
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19017Tested-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 87545692
......@@ -84,6 +84,17 @@ void UpnpBridgeDevice::addResource(UpnpResource::Ptr pResource)
s_links.push_back(singleLink);
}
void UpnpBridgeDevice::removeResource(string uri)
{
for(vector<_link>::iterator itor = s_links.begin(); itor != s_links.end(); ++itor) {
if (itor->href == uri) {
DEBUG_PRINT("Removing link for " << uri);
s_links.erase(itor);
break;
}
}
}
// Entity handler
OCEntityHandlerResult UpnpBridgeDevice::entityHandler(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *entityHandlerRequest, void *callback)
......
......@@ -43,6 +43,7 @@ class UpnpBridgeDevice
std::string resourceType, OCRepPayload *payload);
void addResource(UpnpResource::Ptr resource);
void removeResource(std::string uri);
};
#endif
......@@ -787,3 +787,24 @@ OCStackResult UpnpConnector::createResource(const string uri, const string resou
return result;
}
void UpnpConnector::onRemove(std::string uri)
{
DEBUG_PRINT("Removing " << uri);
for (const auto& service : s_manager->m_services) {
if (service.second->m_uri == uri) {
OCStackResult result = OC::Bridging::ConcurrentIotivityUtils::queueDeleteResource(uri);
DEBUG_PRINT("queueDeleteResource() result = " << result);
ConcurrentIotivityUtils::queueNotifyObservers(uri);
}
}
for (const auto& device : s_manager->m_devices) {
if (device.second->m_uri == uri) {
OCStackResult result = OC::Bridging::ConcurrentIotivityUtils::queueDeleteResource(uri);
DEBUG_PRINT("queueDeleteResource() result = " << result);
ConcurrentIotivityUtils::queueNotifyObservers(uri);
}
}
}
......@@ -47,6 +47,7 @@ class UpnpConnector
void disconnect();
void onScan();
void onAdd(std::string uri);
void onRemove(std::string uri);
private:
DiscoveryCallback m_discoveryCallback;
......
......@@ -64,6 +64,24 @@ int connectorDiscoveryCb(UpnpResource::Ptr pUpnpResource)
return 0;
}
void connectorLostCb(UpnpResource::Ptr pUpnpResource)
{
DEBUG_PRINT("UpnpResource URI " << pUpnpResource->m_uri);
std::vector< UpnpResource::Ptr >::iterator itor;
itor = std::find(m_vecResources.begin(), m_vecResources.end(), pUpnpResource);
if (itor != m_vecResources.end())
{
m_vecResources.erase(itor);
}
if (s_bridge != nullptr)
{
s_bridge->removeResource(pUpnpResource->m_uri);
}
s_upnpConnector->onRemove(pUpnpResource->m_uri);
}
extern "C" DLL_PUBLIC MPMResult pluginCreate(MPMPluginCtx **plugin_specific_ctx)
{
printf("***********************************************\n");
......@@ -94,9 +112,9 @@ extern "C" DLL_PUBLIC MPMResult pluginStart(MPMPluginCtx *ctx)
s_bridge = new UpnpBridgeDevice();
UpnpConnector::DiscoveryCallback discoveryCb = std::bind(&connectorDiscoveryCb, std::placeholders::_1);
//UpnpConnector::LostCallback lostCb = std::bind(&UpnpBundleActivator::connectorLostCb, this, std::placeholders::_1);
UpnpConnector::LostCallback lostCb = std::bind(&connectorLostCb, std::placeholders::_1);
s_upnpConnector = new UpnpConnector(discoveryCb, nullptr /*lostCb*/);
s_upnpConnector = new UpnpConnector(discoveryCb, lostCb);
s_upnpConnector->connect();
return MPM_RESULT_OK;
......@@ -139,9 +157,19 @@ extern "C" DLL_PUBLIC MPMResult pluginRemove(MPMPluginCtx *, MPMPipeMessage *mes
printf("***********************************************\n");
printf("UPNP pluginRemove\n");
printf("***********************************************\n");
(void) message;
OIC_LOG(INFO, TAG, "Remove called! Remove iotivity resources here based on what the client says");
// Currently nothing needs to be done beyond what's already done in pluginStop
if (message->payloadSize <= 0 && message->payload == NULL)
{
OIC_LOG(ERROR, TAG, "No payload received, failed to remove device");
return MPM_RESULT_INTERNAL_ERROR;
}
std::string uri = reinterpret_cast<const char *>(message->payload);
s_upnpConnector->onRemove(uri);
s_bridge->removeResource(uri);
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