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();
28 return "Empty payload";
30 std::ostringstream payLoadString;
34 std::string payloadType;
35 payloadType = getPayloadTypeString(payload->base.type);
36 payLoadString << "Payload type: " << payloadType << std::endl;
39 if (NULL != payload->uri && strlen(payload->uri) > 0)
40 payLoadString << "URI: " << payload->uri << std::endl;
43 std::ostringstream typeString;
44 OCStringLL *ocTypes = payload->types;
47 if (NULL != ocTypes->value)
49 typeString << ocTypes->value;
54 ocTypes = ocTypes->next;
57 if (!typeString.str().empty())
59 payLoadString << "Types: " << typeString.str() << std::endl;
63 std::ostringstream interfaceString;
64 OCStringLL *ocInterfaces = payload->interfaces;
67 if (NULL != ocInterfaces->value)
69 interfaceString << ocInterfaces->value;
70 if (ocInterfaces->next)
71 interfaceString << ", ";
74 ocInterfaces = ocInterfaces->next;
77 if (!interfaceString.str().empty())
79 payLoadString << "Interfaces: " << interfaceString.str() << std::endl;
83 std::ostringstream valueString;
84 OCRepPayloadValue *ocValues = payload->values;
87 valueString << "\t" << ocValues->name << ":" << rep.getValueToString(ocValues->name) <<
89 ocValues = ocValues->next;
92 if (!valueString.str().empty())
94 payLoadString << "Values:" << std::endl;
95 payLoadString << valueString.str();
98 payload = payload->next;
100 payLoadString << "----------------" << std::endl;
103 return payLoadString.str();
106 std::string getPayloadTypeString(OCPayloadType type)
111 case PAYLOAD_TYPE_INVALID:
112 typeStr = "PAYLOAD_TYPE_INVALID";
114 case PAYLOAD_TYPE_DISCOVERY:
115 typeStr = "PAYLOAD_TYPE_DISCOVERY";
117 case PAYLOAD_TYPE_DEVICE:
118 typeStr = "PAYLOAD_TYPE_DEVICE";
120 case PAYLOAD_TYPE_PLATFORM:
121 typeStr = "PAYLOAD_TYPE_PLATFORM";
123 case PAYLOAD_TYPE_REPRESENTATION:
124 typeStr = "PAYLOAD_TYPE_REPRESENTATION";
126 case PAYLOAD_TYPE_SECURITY:
127 typeStr = "PAYLOAD_TYPE_SECURITY";
129 case PAYLOAD_TYPE_PRESENCE:
130 typeStr = "PAYLOAD_TYPE_PRESENCE";
132 case PAYLOAD_TYPE_RD:
133 typeStr = "PAYLOAD_TYPE_RD";
139 std::string getRequestString(const std::map<std::string, std::string> &queryParams,
140 const OC::OCRepresentation &rep)
142 std::ostringstream requestString;
143 if (queryParams.size() > 0)
145 requestString << "qp: ";
146 for (auto &qp : queryParams)
147 requestString << qp.first << "=" << qp.second << ";";
150 requestString << std::endl;
151 requestString << getPayloadString(rep);
152 return requestString.str();
155 std::string getRequestString(const std::map<std::string, std::string> &queryParams)
157 std::ostringstream requestString;
158 if (queryParams.size() > 0)
160 requestString << "qp: ";
161 for (auto &qp : queryParams)
162 requestString << qp.first << "=" << qp.second << ";";
165 requestString << std::endl;
166 return requestString.str();