Commit 2b6c7c8d authored by George Nash's avatar George Nash Committed by Rick Bell

Enable code for teh pluginScan

Change-Id: Ib63bdeee924d0630a91f3d47b078cd8999c1fc24
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17941Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent 4f8e17ed
...@@ -54,7 +54,8 @@ upnp_env.PrependUnique(CPPPATH = [ os.path.join(src_dir, 'resource', 'c_common', ...@@ -54,7 +54,8 @@ upnp_env.PrependUnique(CPPPATH = [ os.path.join(src_dir, 'resource', 'c_common',
]) ])
upnp_env.AppendUnique(CPPPATH = [ os.path.join(bridging_path, 'include'), upnp_env.AppendUnique(CPPPATH = [ os.path.join(bridging_path, 'include'),
'#/include', '#/include',
'#/src']) #'#/src'
])
if target_os not in ['arduino', 'windows']: if target_os not in ['arduino', 'windows']:
upnp_env.AppendUnique(CPPDEFINES = ['WITH_POSIX']) upnp_env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
...@@ -96,9 +97,12 @@ upnp_env.PrependUnique(LIBS = ['m', ...@@ -96,9 +97,12 @@ upnp_env.PrependUnique(LIBS = ['m',
upnp_src = [ upnp_src = [
'upnp_plugin.cpp', 'upnp_plugin.cpp',
'UpnpConnector.cpp', 'UpnpConnector.cpp',
'UpnpDevice.cpp',
'UpnpException.cpp', 'UpnpException.cpp',
'UpnpManager.cpp', 'UpnpManager.cpp',
'UpnpResource.cpp' 'UpnpPowerSwitchService.cpp',
'UpnpResource.cpp',
'UpnpService.cpp'
] ]
upnplib = upnp_env.SharedLibrary('upnpplugin', upnp_src) upnplib = upnp_env.SharedLibrary('upnpplugin', upnp_src)
......
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// 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 "UpnpAttribute.h"
using namespace std;
static const string MODULE = "UpnpAttribute";
//UpnpAttributeInfo *UpnpAttribute::getAttributeInfo(std::vector <UpnpAttributeInfo>
// *serviceAttributes,
// std::string attrName)
//{
// vector<UpnpAttributeInfo>::iterator attrInfo;
// for (attrInfo = serviceAttributes->begin() ; attrInfo != serviceAttributes->end() ; ++attrInfo)
// {
// if (attrInfo->name == attrName)
// {
// return &(*attrInfo);
// }
// }
// return nullptr;
//}
//
//bool UpnpAttribute::isValidRequest(map <string, pair <UpnpAttributeInfo *, int>> *attrMap,
// string attrName,
// UpnpActionType actionType)
//
//{
// // Check if the attribute is present
// map <string, pair< UpnpAttributeInfo *, int>>::iterator attr = attrMap->find(attrName);
// if (attr == attrMap->end())
// {
// return false;
// }
//
// // Check that expected action for the attribute has been found
// if ((attr->second.second) & (int) actionType)
// {
// return true;
// }
//
// return false;
//}
void UpnpAttribute::getCb(GUPnPServiceProxy *proxy,
GUPnPServiceProxyAction *actionProxy,
gpointer userData)
{
GError *error = NULL;
UpnpVar value;
UpnpRequest *request = static_cast<UpnpRequest *> (userData);
UpnpAttributeInfo *attrInfo;
std::map< GUPnPServiceProxyAction *, UpnpAttributeInfo *>::iterator it = request->proxyMap.find(actionProxy);
assert(it != request->proxyMap.end());
attrInfo = it->second;
DEBUG_PRINT(attrInfo->actions[0].varName);
bool status = gupnp_service_proxy_end_action (proxy,
actionProxy,
&error,
attrInfo->actions[0].varName,
attrInfo->actions[0].varType,
&value.var_int64,
NULL);
if (error)
{
ERROR_PRINT("\"" << attrInfo->actions[0].name << "\" action failed: " << error->code << ", " <<
error->message);
g_error_free (error);
status = false;
}
if (status)
{
switch (attrInfo->actions[0].varType)
{
case G_TYPE_STRING:
{
DEBUG_PRINT("resource: " << request->resource->m_uri << ", " << attrInfo->name << ":(string) " <<
string(static_cast<const char *>(value.var_pchar)));
if (NULL != value.var_pchar)
{
request->resource->setAttribute(attrInfo->name, string(value.var_pchar), false);
g_free(value.var_pchar);
}
break;
}
case G_TYPE_BOOLEAN:
{
bool vbool = value.var_boolean;
DEBUG_PRINT("resource: " << request->resource->m_uri << ", " << attrInfo->name << ":(bool) " <<
vbool);
request->resource->setAttribute(attrInfo->name, vbool, false);
break;
}
case G_TYPE_INT:
case G_TYPE_UINT:
{
DEBUG_PRINT("resource: " << request->resource->m_uri << ", " << attrInfo->name << ":(int) " <<
value.var_int);
request->resource->setAttribute(attrInfo->name, value.var_int, false);
break;
}
case G_TYPE_INT64:
case G_TYPE_UINT64:
{
DEBUG_PRINT("resource: " << request->resource->m_uri << ", " << attrInfo->name << ":(int64) " <<
value.var_uint64);
request->resource->setAttribute(attrInfo->name, static_cast<double>(value.var_int64), false);
break;
}
default:
{
//TODO: handle additional types?
ERROR_PRINT("Type handling not implemented!");
assert(0);
}
}
}
else
{
ERROR_PRINT("Failed to retrieve " << attrInfo->actions[0].varName);
}
UpnpRequest::requestDone(request, status);
}
bool UpnpAttribute::get(GUPnPServiceProxy *serviceProxy,
UpnpRequest *request,
UpnpAttributeInfo *attrInfo)
{
DEBUG_PRINT("");
GUPnPServiceProxyAction *actionProxy = gupnp_service_proxy_begin_action (serviceProxy,
attrInfo->actions[0].name,
getCb,
(gpointer *) request,
NULL);
if (NULL == actionProxy)
{
return false;
}
// Hold on to the attribute info
request->proxyMap[actionProxy] = attrInfo;
return true;
}
void UpnpAttribute::setCb(GUPnPServiceProxy *proxy,
GUPnPServiceProxyAction *proxyAction,
gpointer userData)
{
GError *error = NULL;
UpnpRequest *request = static_cast<UpnpRequest *> (userData);
bool status = gupnp_service_proxy_end_action (proxy,
proxyAction,
&error,
NULL);
if (error)
{
ERROR_PRINT("Set action failed: " << error->code << ", " << error->message);
g_error_free (error);
status = false;
}
UpnpRequest::requestDone(request, status);
}
//bool UpnpAttribute::set(GUPnPServiceProxy *serviceProxy,
// UpnpRequest *request,
// UpnpAttributeInfo *attrInfo,
// RCSResourceAttributes::Value *attrValue)
//{
// GUPnPServiceProxyAction *actionProxy;
// UpnpVar value;
//
// if (attrValue != NULL)
// {
// // Type of the value to be stored can be derived either from
// // input variable type or from state variable type
// GType type = (attrInfo->actions[1].varType != G_TYPE_NONE) ?
// attrInfo->actions[1].varType : attrInfo->type;
//
// switch (type)
// {
// case G_TYPE_STRING:
// {
// const char *sValue = (attrValue->get< string >()).c_str();
// DEBUG_PRINT("resource: " << request->resource->m_uri << ", (string) " << sValue);
// value.var_pchar = (char *) sValue;
// break;
// }
// case G_TYPE_BOOLEAN:
// {
// value.var_boolean = attrValue->get< bool >();
// DEBUG_PRINT("resource: " << request->resource->m_uri << ", (bool) " << value.var_boolean);
// break;
// }
// case G_TYPE_INT:
// case G_TYPE_UINT:
// {
// value.var_int = attrValue->get< int >();
// DEBUG_PRINT("resource: " << request->resource->m_uri << ", (int) " << value.var_int);
// break;
// }
// case G_TYPE_INT64:
// case G_TYPE_UINT64:
// {
// value.var_int64 = attrValue->get< double >();
// DEBUG_PRINT("resource: " << request->resource->m_uri << ", (int64) " << value.var_int64);
// break;
// }
// default:
// {
// //TODO: handle additional types?
// ERROR_PRINT("Type handling not implemented!");
// assert(0);
// }
// }
// }
//
// if (string(attrInfo->actions[1].varName) == "")
// {
// DEBUG_PRINT("action (no args): " << attrInfo->actions[1].name);
// actionProxy = gupnp_service_proxy_begin_action (serviceProxy,
// attrInfo->actions[1].name,
// setCb,
// (gpointer *) request,
// NULL);
// }
// else
// {
// DEBUG_PRINT("action: " << attrInfo->actions[1].name << "( " << attrInfo->actions[1].varName <<
// " )");
// actionProxy = gupnp_service_proxy_begin_action (serviceProxy,
// attrInfo->actions[1].name,
// setCb,
// (gpointer *) request,
// attrInfo->actions[1].varName,
// attrInfo->actions[1].varType,
// value.var_int64,
// NULL);
// }
//
// if (NULL == actionProxy)
// {
// return false;
// }
//
// // Hold on to the attribute info
// request->proxyMap[actionProxy] = attrInfo;
//
// return true;
//}
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// 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_ATTRIBUTE_H_
#define UPNP_ATTRIBUTE_H_
#include "UpnpInternal.h"
#include "UpnpRequest.h"
class UpnpAttribute
{
public:
// static UpnpAttributeInfo *getAttributeInfo(std::vector <UpnpAttributeInfo> *serviceAttributes,
// std::string attrName);
//
// static bool isValidRequest(std::map <std::string, std::pair <UpnpAttributeInfo *, int>> *attrMap,
// std::string,
// UpnpActionType actionType);
static void getCb(GUPnPServiceProxy *proxy,
GUPnPServiceProxyAction *action,
gpointer userData);
static bool get(GUPnPServiceProxy *serviceProxy,
UpnpRequest *request,
UpnpAttributeInfo *attrInfo);
static void setCb(GUPnPServiceProxy *proxy,
GUPnPServiceProxyAction *action,
gpointer userData);
// static bool set(GUPnPServiceProxy *serviceProxy,
// UpnpRequest *request,
// UpnpAttributeInfo *attrInfo,
// RCSResourceAttributes::Value *attrValue);
};
#endif
...@@ -265,90 +265,90 @@ void UpnpConnector::onDeviceProxyAvailable(GUPnPControlPoint *controlPoint, ...@@ -265,90 +265,90 @@ void UpnpConnector::onDeviceProxyAvailable(GUPnPControlPoint *controlPoint,
GUPnPDeviceProxy *proxy, GUPnPDeviceProxy *proxy,
gpointer userData) gpointer userData)
{ {
GUPnPDeviceInfo *deviceInfo = GUPNP_DEVICE_INFO(proxy); // GUPnPDeviceInfo *deviceInfo = GUPNP_DEVICE_INFO(proxy);
UpnpResource::Ptr pUpnpResource; // UpnpResource::Ptr pUpnpResource;
const string udn = gupnp_device_info_get_udn(deviceInfo); // const string udn = gupnp_device_info_get_udn(deviceInfo);
bool isRoot = *(static_cast <bool *> (userData)); // bool isRoot = *(static_cast <bool *> (userData));
//
DEBUG_PRINT("Device type: " << gupnp_device_info_get_device_type(deviceInfo)); // DEBUG_PRINT("Device type: " << gupnp_device_info_get_device_type(deviceInfo));
#ifndef NDEBUG //#ifndef NDEBUG
char *devModel = gupnp_device_info_get_model_name(deviceInfo); // char *devModel = gupnp_device_info_get_model_name(deviceInfo);
if (devModel != NULL) // if (devModel != NULL)
{ // {
DEBUG_PRINT("\tDevice model: " << devModel); // DEBUG_PRINT("\tDevice model: " << devModel);
g_free(devModel); // g_free(devModel);
} // }
//
char *devName = gupnp_device_info_get_friendly_name(deviceInfo); // char *devName = gupnp_device_info_get_friendly_name(deviceInfo);
if (devName != NULL) // if (devName != NULL)
{ // {
DEBUG_PRINT("\tFriendly name: " << devName); // DEBUG_PRINT("\tFriendly name: " << devName);
g_free(devName); // g_free(devName);
} // }
#endif //#endif
DEBUG_PRINT("\tUdn: " << udn); // DEBUG_PRINT("\tUdn: " << udn);
//
if (isRoot) // if (isRoot)
{ // {
// Root device // // Root device
pUpnpResource = s_manager->processDevice(proxy, deviceInfo, true, &s_requestState); // pUpnpResource = s_manager->processDevice(proxy, deviceInfo, true, &s_requestState);
} // }
else // else
{ // {
pUpnpResource = s_manager->processDevice(proxy, deviceInfo, false, &s_requestState); // pUpnpResource = s_manager->processDevice(proxy, deviceInfo, false, &s_requestState);
} // }
//
if (pUpnpResource != nullptr && !pUpnpResource->isRegistered()) // if (pUpnpResource != nullptr && !pUpnpResource->isRegistered())
{ // {
DEBUG_PRINT("Register device resource: " << pUpnpResource->m_uri); // DEBUG_PRINT("Register device resource: " << pUpnpResource->m_uri);
if (s_discoveryCallback(pUpnpResource) == 0) // if (s_discoveryCallback(pUpnpResource) == 0)
{ // {
pUpnpResource->setRegistered(true); // pUpnpResource->setRegistered(true);
} // }
else // else
{ // {
pUpnpResource->setRegistered(false); // pUpnpResource->setRegistered(false);
unregisterDeviceResource(udn); // unregisterDeviceResource(udn);
return; // return;
} // }
//
// Traverse the service list and register all the services where isReady() returns true. // // Traverse the service list and register all the services where isReady() returns true.
// This is done in order to catch all the services that have been seen // // This is done in order to catch all the services that have been seen
// prior to discovering the hosting device. // // prior to discovering the hosting device.
GList *childService = gupnp_device_info_list_services (deviceInfo); // GList *childService = gupnp_device_info_list_services (deviceInfo);
//
while (childService) // while (childService)
{ // {
GUPnPServiceInfo *serviceInfo = GUPNP_SERVICE_INFO (childService->data); // GUPnPServiceInfo *serviceInfo = GUPNP_SERVICE_INFO (childService->data);
std::shared_ptr<UpnpResource> pUpnpResourceService = s_manager->findResource(serviceInfo); // std::shared_ptr<UpnpResource> pUpnpResourceService = s_manager->findResource(serviceInfo);
if (pUpnpResourceService == nullptr) // if (pUpnpResourceService == nullptr)
{ // {
DEBUG_PRINT("Registering device: Service link is empty!"); // DEBUG_PRINT("Registering device: Service link is empty!");
// This could happen if support for the service is not implemented // // This could happen if support for the service is not implemented
} // }
else // else
{ // {
DEBUG_PRINT(pUpnpResourceService->m_uri << "ready " << pUpnpResourceService->isReady() << // DEBUG_PRINT(pUpnpResourceService->m_uri << "ready " << pUpnpResourceService->isReady() <<
" and registered " << pUpnpResourceService->isRegistered()); // " and registered " << pUpnpResourceService->isRegistered());
if (pUpnpResourceService->isReady() && !pUpnpResourceService->isRegistered()) // if (pUpnpResourceService->isReady() && !pUpnpResourceService->isRegistered())
{ // {
DEBUG_PRINT("Register resource for previously discovered child service: " << // DEBUG_PRINT("Register resource for previously discovered child service: " <<
pUpnpResourceService->m_uri); // pUpnpResourceService->m_uri);
s_discoveryCallback(pUpnpResourceService); // s_discoveryCallback(pUpnpResourceService);
pUpnpResourceService->setRegistered(true); // pUpnpResourceService->setRegistered(true);
//
// Subscribe to notifications // // Subscribe to notifications
// Important!!! UpnpService object associated with this info/proxy // // Important!!! UpnpService object associated with this info/proxy
// must stay valid until we unsubscribe from notificatons. This // // must stay valid until we unsubscribe from notificatons. This
// means we have to keep a reference to the object inside the // // means we have to keep a reference to the object inside the
// UpnpManager as long as we are subscribed to notifications. // // UpnpManager as long as we are subscribed to notifications.
gupnp_service_proxy_set_subscribed(GUPNP_SERVICE_PROXY(serviceInfo), true); // gupnp_service_proxy_set_subscribed(GUPNP_SERVICE_PROXY(serviceInfo), true);
} // }
} // }
g_object_unref (childService->data); // g_object_unref (childService->data);
childService = g_list_delete_link (childService, childService); // childService = g_list_delete_link (childService, childService);
} // }
} // }
} }
void UpnpConnector::onServiceProxyAvailable(GUPnPControlPoint *controlPoint, void UpnpConnector::onServiceProxyAvailable(GUPnPControlPoint *controlPoint,
...@@ -494,3 +494,11 @@ void UpnpConnector::onServiceProxyUnavailable(GUPnPControlPoint *controlPoint, ...@@ -494,3 +494,11 @@ void UpnpConnector::onServiceProxyUnavailable(GUPnPControlPoint *controlPoint,
s_manager->removeService(info); s_manager->removeService(info);
} }
} }
void UpnpConnector::onScan()
{
DEBUG_PRINT("");
if (s_manager) {
s_manager->onScan();
}
}
...@@ -47,6 +47,7 @@ class UpnpConnector ...@@ -47,6 +47,7 @@ class UpnpConnector
void connect(); void connect();
void disconnect(); void disconnect();
void onScan();
private: private:
DiscoveryCallback m_discoveryCallback; DiscoveryCallback m_discoveryCallback;
......
//******************************************************************
//
// Copyright 2016 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 "UpnpConstants.h"
#include "UpnpException.h"
#include "UpnpInternal.h"
#include "UpnpDevice.h"
#include "UpnpHelper.h"
#include "UpnpService.h"
using namespace std;
static const string MODULE = "UpnpDevice";
UpnpDevice::UpnpDevice(GUPnPDeviceInfo *deviceInfo,
UpnpRequestState *requestState)
{
m_proxy = nullptr;
m_requestState = requestState;
m_udn = gupnp_device_info_get_udn(deviceInfo);
m_deviceType = gupnp_device_info_get_device_type(deviceInfo);
m_resourceType = findResourceType(m_deviceType);
if (m_resourceType == "")
{
throw logic_error(string("Device type ") + m_deviceType + string(" not implemented!"));
return;
}
m_name = getStringField(gupnp_device_info_get_friendly_name, deviceInfo);
m_uri = UpnpUriPrefixMap[m_resourceType] + gupnp_device_info_get_udn(deviceInfo);
if (m_uri.length() > MAX_URI_LENGTH)
{
ERROR_PRINT("URI too long " << m_uri << "( " << m_uri.length());
throw BadUriException("UpnpDevice::ctor: uri length too long");
return;
}
m_interface = UpnpInterfaceMap[m_resourceType];
m_registered = false;
m_deviceList.clear();
m_serviceList.clear();
initBasicAttributes(deviceInfo);
}
UpnpDevice::~UpnpDevice()
{
m_deviceList.clear();
m_serviceList.clear();
}
void UpnpDevice::insertDevice(string udn)
{
m_deviceList.push_back(udn);
}
void UpnpDevice::insertService(string id)
{
m_serviceList.push_back(id);
}
std::vector<string> &UpnpDevice::getDeviceList()
{
return<