1 //******************************************************************
3 // Copyright 2014 Intel Corporation.
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "WrapResource.h"
26 MiddleClient::MiddleClient()
28 m_findCB = bind(&MiddleClient::foundOCResource, this, placeholders::_1);
31 bool MiddleClient::init()
37 void MiddleClient::findResources()
39 m_resourceMap.clear();
41 OC::OCPlatform::findResource("", OC_WELL_KNOWN_QUERY, m_findCB);
44 void MiddleClient::foundOCResource(shared_ptr<OCResource> resource)
47 string resourceID = formatResourceID(resource);
49 m_mutexFoundCB.lock();
52 wres = m_resourceMap.at(resourceID);
53 } catch (const std::out_of_range) {
54 wres = new WrapResource(resourceID, resource);
55 m_resourceMap[resourceID] = wres;
58 m_mutexFoundCB.unlock();
64 * I need a unique ID, so I concatenate the host string and resource uri
65 * It's arbitrary and sufficient.
67 string MiddleClient::formatResourceID(std::shared_ptr<OCResource> resource)
69 string host = resource->host();
70 if (host.compare(0, 7, "coap://") == 0)
71 host = host.erase(0, 7);
72 return host + resource->uri();
75 void MiddleClient::addResource(WrapResource *wres)
77 string resourceID = wres->getResourceID();
79 m_resourceMap[resourceID];
80 } catch (const std::out_of_range) {
81 m_resourceMap[resourceID] = wres;