Revert "Change build option - IP only"
[platform/upstream/iotivity.git] / service / simulator / src / common / request_model.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 "request_model.h"
22 #include "logger.h"
23
24 RequestModel::RequestModel(RequestType type) : m_type(type) {}
25
26 RequestType RequestModel::type() const
27 {
28     return m_type;
29 }
30
31 SupportedQueryParams RequestModel::getQueryParams()
32 {
33     return m_queryParams;
34 }
35
36 std::vector<std::string> RequestModel::getQueryParams(const std::string &key)
37 {
38     if (m_queryParams.end() != m_queryParams.find(key))
39     {
40         return m_queryParams[key];
41     }
42
43     return std::vector<std::string>();
44 }
45
46 void RequestModel::setQueryParams(
47     const SupportedQueryParams &queryParams)
48 {
49     m_queryParams = queryParams;
50 }
51
52 void RequestModel::addQueryParams(const std::string &key,
53                                   const std::vector<std::string> &values)
54 {
55     if (0 != values.size())
56         m_queryParams[key] = values;
57 }
58
59 void RequestModel::addQueryParam(const std::string &key, const std::string &value)
60 {
61     m_queryParams[key].push_back(value);
62 }
63
64 void RequestModel::addResponseModel(int code, ResponseModelSP &responseModel)
65 {
66     if (!responseModel)
67         m_responseList[code] = responseModel;
68 }
69
70 void RequestModel::setRepSchema(SimulatorResourceModelSP &repSchema)
71 {
72     m_repSchema = repSchema;
73 }
74
75 SimulatorResourceModelSP RequestModel::getRepSchema()
76 {
77     return m_repSchema;
78 }
79
80 SimulatorResult RequestModel::validateResponse(int responseCode, const OC::OCRepresentation &rep)
81 {
82     if (m_responseList.end() == m_responseList.find(responseCode))
83     {
84         return SIMULATOR_INVALID_RESPONSE_CODE;
85     }
86
87     return m_responseList[responseCode]->verifyResponse(rep);
88 }
89