Merge branch 'simulator'
[platform/upstream/iotivity.git] / service / simulator / src / common / simulator_utils.cpp
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #include "simulator_utils.h"
22 #include "OCRepresentation.h"
23
24 std::string getPayloadString(const OC::OCRepresentation &rep)
25 {
26     std::ostringstream data;
27     OCRepPayload *payload = rep.getPayload();
28     if (!payload)
29     {
30         return "Payload: No payload";
31     }
32
33     // URI
34     data << "URI: " << payload->uri << std::endl;
35
36     // Attributes
37     data << "Attributes:" << std::endl;
38     OCRepPayloadValue *values = payload->values;
39     while (NULL != values)
40     {
41         data << values->name << ":" << rep.getValueToString(values->name) << std::endl;
42         values = values->next;
43     }
44
45     return data.str();
46 }
47
48 std::string getRequestString(const std::map<std::string, std::string> &queryParams,
49                              const OC::OCRepresentation &rep)
50 {
51     std::ostringstream data;
52     data << "qp: ";
53     if (queryParams.size() > 0)
54     {
55         for (auto & qp : queryParams)
56             data << qp.second << ",";
57     }
58
59     data << getPayloadString(rep);
60     return data.str();
61 }
62
63 std::string getRequestString(const std::map<std::string, std::string> &queryParams)
64 {
65     std::ostringstream data;
66     data << "qp: ";
67     if (queryParams.size() > 0)
68     {
69         for (auto & qp : queryParams)
70             data << qp.second << ",";
71     }
72
73     data << "Payload:  No payload";
74     return data.str();
75 }