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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include <StringConstants.h>
22 #include "ocpayload.h"
24 #include "oic_string.h"
28 class ListenOCContainer
31 static std::vector<std::string> StringLLToVector(OCStringLL* ll)
33 std::vector<std::string> strs;
36 strs.push_back(ll->value);
43 ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
44 OCDevAddr& devAddr, OCDiscoveryPayload* payload)
45 : m_clientWrapper(cw), m_devAddr(devAddr)
49 OCResourcePayload* res = payload->resources;
55 (OCTransportFlags)(OC_FLAG_SECURE | m_devAddr.flags);
60 m_devAddr.port = res->port;
65 OCDevAddr rdPubAddr = m_devAddr;
67 std::string baseURI = std::string(payload->baseURI);
68 size_t len = baseURI.length();
69 int addressLen = baseURI.find_first_of(":");
70 std::string ipaddress = baseURI.substr(0, addressLen);
71 int port = atoi(baseURI.substr(addressLen + 1, len).c_str());
72 OICStrcpy(rdPubAddr.addr, addressLen + 1, ipaddress.c_str());
73 rdPubAddr.port = port;
74 m_resources.push_back(std::shared_ptr<OC::OCResource>(
75 new OC::OCResource(m_clientWrapper, rdPubAddr,
76 std::string(res->uri),
77 std::string(payload->sid),
79 StringLLToVector(res->types),
80 StringLLToVector(res->interfaces)
85 m_resources.push_back(std::shared_ptr<OC::OCResource>(
86 new OC::OCResource(m_clientWrapper, m_devAddr,
87 std::string(res->uri),
88 std::string(payload->sid),
90 StringLLToVector(res->types),
91 StringLLToVector(res->interfaces)
95 if (res->tcpPort != 0)
97 OCDevAddr tcpDevAddr = m_devAddr;
98 tcpDevAddr.port = res->tcpPort;
99 tcpDevAddr.adapter = OC_ADAPTER_TCP;
100 m_resources.push_back(std::shared_ptr<OC::OCResource>(
101 new OC::OCResource(m_clientWrapper, tcpDevAddr,
102 std::string(res->uri),
103 std::string(payload->sid),
105 StringLLToVector(res->types),
106 StringLLToVector(res->interfaces)
113 payload = payload->next;
118 ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
119 OCDevAddr& devAddr, OCRepPayload* payload)
120 : m_clientWrapper(cw), m_devAddr(devAddr)
124 char**topicList = nullptr;
125 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0};
126 OCRepPayloadGetStringArray(payload, "topiclist", &topicList, dimensions);
128 for(size_t idx = 0; idx < dimensions[0]; idx++)
130 m_resources.push_back(std::shared_ptr<OC::OCResource>(
131 new OC::OCResource(m_clientWrapper, m_devAddr,
132 std::string(topicList[idx]),
135 {OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC},
136 {DEFAULT_INTERFACE})));
141 ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
142 OCDevAddr& devAddr, const std::string& topicUri)
143 : m_clientWrapper(cw), m_devAddr(devAddr)
145 m_resources.push_back(std::shared_ptr<OC::OCResource>(
146 new OC::OCResource(m_clientWrapper, m_devAddr,
150 {OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC},
151 {DEFAULT_INTERFACE})));
155 const std::vector<std::shared_ptr<OCResource>>& Resources() const
160 std::vector<std::shared_ptr<OC::OCResource>> m_resources;
161 std::weak_ptr<IClientWrapper> m_clientWrapper;
162 OCDevAddr& m_devAddr;