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)
46 OCDevAddr currentDevAddr = devAddr;
50 std::string deviceName;
53 deviceName = payload->name;
56 OCResourcePayload* res = payload->resources;
60 currentDevAddr.flags = res->secure ?
61 (OCTransportFlags)(OC_FLAG_SECURE | devAddr.flags) :
64 currentDevAddr.port = (res->port != 0) ? res->port : devAddr.port;
68 OCDevAddr rdPubAddr = currentDevAddr;
70 std::string baseURI = std::string(payload->baseURI);
71 size_t len = baseURI.length();
72 int addressLen = baseURI.find_first_of(":");
73 std::string ipaddress = baseURI.substr(0, addressLen);
74 int port = atoi(baseURI.substr(addressLen + 1, len).c_str());
75 OICStrcpy(rdPubAddr.addr, addressLen + 1, ipaddress.c_str());
76 rdPubAddr.port = port;
77 m_resources.push_back(std::shared_ptr<OC::OCResource>(
78 new OC::OCResource(cw, rdPubAddr,
79 std::string(res->uri),
80 std::string(payload->sid),
82 StringLLToVector(res->types),
83 StringLLToVector(res->interfaces),
89 m_resources.push_back(std::shared_ptr<OC::OCResource>(
90 new OC::OCResource(cw, currentDevAddr,
91 std::string(res->uri),
92 std::string(payload->sid),
94 StringLLToVector(res->types),
95 StringLLToVector(res->interfaces),
100 if (res->tcpPort != 0)
102 OCDevAddr tcpDevAddr = currentDevAddr;
103 tcpDevAddr.port = res->tcpPort;
104 tcpDevAddr.adapter = OC_ADAPTER_TCP;
105 m_resources.push_back(std::shared_ptr<OC::OCResource>(
106 new OC::OCResource(cw, tcpDevAddr,
107 std::string(res->uri),
108 std::string(payload->sid),
110 StringLLToVector(res->types),
111 StringLLToVector(res->interfaces),
119 payload = payload->next;
124 ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
125 OCDevAddr& devAddr, OCRepPayload* payload)
129 char**topicList = nullptr;
130 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0};
131 OCRepPayloadGetStringArray(payload, "topiclist", &topicList, dimensions);
133 for(size_t idx = 0; idx < dimensions[0]; idx++)
135 m_resources.push_back(std::shared_ptr<OC::OCResource>(
136 new OC::OCResource(cw, devAddr,
137 std::string(topicList[idx]),
140 {OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC},
148 ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
149 OCDevAddr& devAddr, const std::string& topicUri)
151 m_resources.push_back(std::shared_ptr<OC::OCResource>(
152 new OC::OCResource(cw, devAddr,
156 {OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC},
163 const std::vector<std::shared_ptr<OCResource>>& Resources() const
168 std::vector<std::shared_ptr<OC::OCResource>> m_resources;