Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / src / client / request_sender.h
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 #ifndef SIMULATOR_REQUEST_SENDER_H_
22 #define SIMULATOR_REQUEST_SENDER_H_
23
24 #include "simulator_client_types.h"
25 #include "simulator_resource_model.h"
26 #include "simulator_error_codes.h"
27
28 struct RequestInfo
29 {
30     RequestType type;
31     std::map<std::string, std::string> queryParams;
32     SimulatorResourceModel payLoad;
33 };
34
35 class GETRequestSender
36 {
37     public:
38         typedef std::function<void (SimulatorResult result, const SimulatorResourceModel &resModel,
39                                     const RequestInfo &reqInfo)> ResponseCallback;
40
41         GETRequestSender(const std::shared_ptr<OC::OCResource> &ocResource);
42
43         SimulatorResult send(const ResponseCallback &callback);
44
45         SimulatorResult send(const std::map<std::string, std::string> &queryParams,
46                              const ResponseCallback &callback);
47
48         void onResponseReceived(const OC::HeaderOptions &headerOptions,
49                                 const OC::OCRepresentation &rep, const int errorCode, RequestInfo &requestInfo,
50                                 ResponseCallback callback);
51
52     private:
53         std::shared_ptr<OC::OCResource> m_ocResource;
54 };
55
56 class PUTRequestSender
57 {
58     public:
59         typedef std::function<void (SimulatorResult result, const SimulatorResourceModel &resModel,
60                                     const RequestInfo &reqInfo)> ResponseCallback;
61
62         PUTRequestSender(const std::shared_ptr<OC::OCResource> &ocResource);
63
64         SimulatorResult send(const SimulatorResourceModel &representation,
65                              const ResponseCallback &callback);
66
67         SimulatorResult send(const std::map<std::string, std::string> &queryParams,
68                              const SimulatorResourceModel &representation,
69                              const ResponseCallback &callback);
70
71         void onResponseReceived(const OC::HeaderOptions &headerOptions,
72                                 const OC::OCRepresentation &rep, const int errorCode, RequestInfo &requestInfo,
73                                 ResponseCallback callback);
74
75     private:
76         std::shared_ptr<OC::OCResource> m_ocResource;
77 };
78
79 class POSTRequestSender
80 {
81     public:
82         typedef std::function<void (SimulatorResult result, const SimulatorResourceModel &resModel,
83                                     const RequestInfo &reqInfo)> ResponseCallback;
84
85         POSTRequestSender(const std::shared_ptr<OC::OCResource> &ocResource);
86
87         SimulatorResult send(const SimulatorResourceModel &representation,
88                              const ResponseCallback &callback);
89
90         SimulatorResult send(const std::map<std::string, std::string> &queryParams,
91                              const SimulatorResourceModel &representation,
92                              const ResponseCallback &callback);
93
94         void onResponseReceived(const OC::HeaderOptions &headerOptions,
95                                 const OC::OCRepresentation &rep, const int errorCode, RequestInfo &requestInfo,
96                                 ResponseCallback callback);
97
98     private:
99         std::shared_ptr<OC::OCResource> m_ocResource;
100 };
101
102 #endif