1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 #include "WrapResource.h"
27 MiddleClient::MiddleClient()
29 m_findCB = bind(&MiddleClient::foundOCResource, this, placeholders::_1);
32 bool MiddleClient::init()
38 void MiddleClient::findResources()
40 m_resourceMap.clear();
42 OC::OCPlatform::findResource("", OC_RSRVD_WELL_KNOWN_URI, CT_DEFAULT, m_findCB);
45 void MiddleClient::foundOCResource(shared_ptr<OCResource> resource)
48 string resourceID = formatResourceID(resource);
50 m_mutexFoundCB.lock();
53 wres = m_resourceMap.at(resourceID);
54 } catch (const std::out_of_range) {
55 wres = new WrapResource(resourceID, resource);
56 m_resourceMap[resourceID] = wres;
59 m_mutexFoundCB.unlock();
65 * I need a unique ID, so I concatenate the host string and resource uri
66 * It's arbitrary and sufficient.
68 string MiddleClient::formatResourceID(std::shared_ptr<OCResource> resource)
72 throw invalid_argument("Invalid resource object in formatResourceID");
75 return resource->sid() + resource->uri();
78 void MiddleClient::addResource(WrapResource *wres)
82 throw invalid_argument("Invalid WrapResource object in addResource");
85 string resourceID = wres->getResourceID();
87 m_resourceMap[resourceID];
88 } catch (const std::out_of_range) {
89 m_resourceMap[resourceID] = wres;