1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 "simulator_utils.h"
22 #include "OCRepresentation.h"
24 std::string getPayloadString(const OC::OCRepresentation &rep)
26 OCRepPayload *payload = rep.getPayload();
29 return "Empty payload";
31 std::ostringstream data;
32 std::ostringstream dummy;
34 std::string payloadType;
36 OCStringLL *interfaces;
37 OCRepPayloadValue *values;
39 // Iterate the payload list
43 payloadType = getPayloadTypeString(payload->base.type);
44 if (!payloadType.empty())
45 data << "Payload type: " << payloadType << std::endl;
48 if (NULL != payload->uri && strlen(payload->uri) > 0)
49 data << "URI: " << payload->uri << std::endl;
52 types = payload->types;
55 if (NULL != types->value && strlen(types->value) > 0)
57 dummy << types->value;
63 if (!dummy.str().empty())
65 data << "Types: " << dummy.str() << std::endl;
70 interfaces = payload->interfaces;
73 if (NULL != interfaces->value && strlen(interfaces->value) > 0)
75 dummy << interfaces->value;
79 interfaces = interfaces->next;
81 if (!dummy.str().empty())
83 data << "Interfaces: " << dummy.str() << std::endl;
88 values = payload->values;
91 dummy << "\t" << values->name << ":" << rep.getValueToString(values->name) << std::endl;
92 values = values->next;
94 if (!dummy.str().empty())
96 data << "Values:-" << std::endl;
100 payload = payload->next;
102 data << "----------------" << std::endl;
108 std::string getPayloadTypeString(OCPayloadType type)
113 case PAYLOAD_TYPE_INVALID:
114 typeStr = "PAYLOAD_TYPE_INVALID";
116 case PAYLOAD_TYPE_DISCOVERY:
117 typeStr = "PAYLOAD_TYPE_DISCOVERY";
119 case PAYLOAD_TYPE_DEVICE:
120 typeStr = "PAYLOAD_TYPE_DEVICE";
122 case PAYLOAD_TYPE_PLATFORM:
123 typeStr = "PAYLOAD_TYPE_PLATFORM";
125 case PAYLOAD_TYPE_REPRESENTATION:
126 typeStr = "PAYLOAD_TYPE_REPRESENTATION";
128 case PAYLOAD_TYPE_SECURITY:
129 typeStr = "PAYLOAD_TYPE_SECURITY";
131 case PAYLOAD_TYPE_PRESENCE:
132 typeStr = "PAYLOAD_TYPE_PRESENCE";
138 std::string getRequestString(const std::map<std::string, std::string> &queryParams,
139 const OC::OCRepresentation &rep)
141 std::ostringstream data;
142 std::ostringstream dummy;
143 if (queryParams.size() > 0)
145 for (auto &qp : queryParams)
146 dummy << qp.second << ",";
148 if (!dummy.str().empty())
150 data << "qp: " << dummy.str() << std::endl;
152 data << getPayloadString(rep);
156 std::string getRequestString(const std::map<std::string, std::string> &queryParams)
158 std::ostringstream data;
159 std::ostringstream dummy;
160 if (queryParams.size() > 0)
162 for (auto &qp : queryParams)
163 dummy << qp.second << ",";
165 if (!dummy.str().empty())
167 data << "qp: " << dummy.str() << std::endl;
169 data << "Payload: No payload";