1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "ResourceManager.h"
23 ResourceManager *ResourceManager::s_instance = NULL;
24 std::list< VirtualRepresentation > ResourceManager::s_resourceList;
26 std::string ResourceManager::s_extraStr;
28 ResourceManager::ResourceManager()
32 ResourceManager::~ResourceManager()
36 ResourceManager *ResourceManager::getInstance()
40 s_instance = new ResourceManager();
45 VirtualRepresentation ResourceManager::findVirtualRepresentation(std::string uri)
48 VirtualRepresentation retObject;
50 for(auto it = s_resourceList.begin() ; it != s_resourceList.end() ; it++)
52 if(it->getUri().compare(uri) == 0)
62 OCStackResult ResourceManager::findNMResource(const std::string& host ,
63 const std::string& resourceName , bool ishosting)
65 return findResource(host , resourceName ,
66 std::function< void(std::shared_ptr< OCResource > resource) >(
67 std::bind(&ResourceManager::foundResourceforhosting , this ,
68 std::placeholders::_1)));
71 void ResourceManager::foundResourceforhosting(std::shared_ptr< OCResource > resource)
77 if(resource->uri().find("/a/NM") != std::string::npos)
79 NotificationManager::getInstance()->getOnFoundHostingCandidate()(resource);
87 catch(std::exception& e)
92 void ResourceManager::startHosting(std::shared_ptr< OCResource > resource)
94 VirtualRepresentation tmp = findVirtualRepresentation( resource->uri() );
96 if( !tmp.getUri().empty() )
101 VirtualRepresentation resourceObject;
102 resourceObject.setUri(resource->uri());
104 std::cout << "resourceObject uri: " << resourceObject.getUri() << std::endl;
106 std::string resourceHostIP;
107 std::string resourceType;
108 std::string resourceInterface;
109 uint8_t resourceProperty;
111 resourceHostIP = resource->host();
112 resourceType = *(resource->getResourceTypes().data());
113 resourceInterface = *(resource->getResourceInterfaces().data());
114 resourceProperty = (OC_DISCOVERABLE | resource->isObservable());
116 resourceObject.setHostIP(resourceHostIP);
117 resourceObject.setResourceTypeName(resourceType);
118 resourceObject.setResourceInterface(resourceInterface);
119 resourceObject.setResourceProperty(resourceProperty);
121 RegistrationManager::getInstance()->registerNMResource(resourceObject , resource);
123 s_resourceList.push_back(resourceObject);
127 AttributeMap ResourceManager::copyAttributeMap(AttributeMap &inputAttMap)
130 AttributeMap retAttMap;
132 retAttMap = inputAttMap;
137 bool ResourceManager::isEmptyAttributeMap(AttributeMap &inputAttMap)
139 for(auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it)
141 if(inputAttMap.find(it->first) == inputAttMap.end())
149 void ResourceManager::onFoundReport(std::shared_ptr< OCResource > resource)
151 NotificationManager::getInstance()->getStartHosting()(resource);
154 void ResourceManager::printAttributeMap(AttributeMap &inputAttMap)
156 for(auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it)
158 std::cout << "\tAttribute name: " << it->first << " value: ";
160 for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
162 std::cout << "\t" << *valueItr << " ";
165 std::cout << std::endl;
169 void ResourceManager::addExtraStr(std::string str)
174 std::string ResourceManager::getExtraStr()
179 void ResourceManager::checkResourceDBPolicy()
184 void ResourceManager::saveResourceDB()