Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / src / client / simulator_remote_resource_impl.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 /**
22  * @file simulator_remote_resource_impl.h
23  *
24  * @brief This file provides internal implementation of simulator remote resource functionalities.
25  *
26  */
27
28 #ifndef SIMULATOR_REMOTE_RESOURCE_IMPL_H_
29 #define SIMULATOR_REMOTE_RESOURCE_IMPL_H_
30
31 #include "simulator_remote_resource.h"
32 #include "request_automation_manager.h"
33 #include "RamlParser.h"
34 #include "request_model.h"
35 #include "request_sender.h"
36
37 #include <mutex>
38
39 class SimulatorRemoteResourceImpl : public SimulatorRemoteResource
40 {
41     public:
42         SimulatorRemoteResourceImpl(const std::shared_ptr<OC::OCResource> &ocResource);
43         std::string getURI() const;
44         std::string getHost() const;
45         std::string getID() const;
46         SimulatorConnectivityType getConnectivityType() const;
47         std::vector < std::string > getResourceTypes() const;
48         std::vector < std::string > getInterface() const;
49         bool isObservable() const;
50
51         void observe(ObserveType type, ObserveNotificationCallback callback);
52         void cancelObserve();
53
54         void get(const GetResponseCallback &callback);
55         void get(const std::map<std::string, std::string> &queryParams,
56                  const GetResponseCallback &callback);
57         void get(const std::string &interfaceType,
58                  const std::map<std::string, std::string> &queryParams,
59                  const GetResponseCallback &callback);
60
61         void put(const SimulatorResourceModel &representation,
62                  const PutResponseCallback &callback);
63         void put(const std::map<std::string, std::string> &queryParams,
64                  const SimulatorResourceModel &representation,
65                  const PutResponseCallback &callback);
66         void put(const std::string &interfaceType,
67                  const std::map<std::string, std::string> &queryParams,
68                  const SimulatorResourceModel &representation,
69                  const PutResponseCallback &callback);
70
71         void post(const SimulatorResourceModel &resourceModel,
72                   const PostResponseCallback &callback);
73         void post(const std::map<std::string, std::string> &queryParams,
74                   const SimulatorResourceModel &representation,
75                   const PostResponseCallback &callback);
76         void post(const std::string &interfaceType,
77                   const std::map<std::string, std::string> &queryParams,
78                   const SimulatorResourceModel &representation,
79                   const PostResponseCallback &callback);
80
81         std::map<RequestType, SimulatorRequestModel> configure(
82             const std::string &path);
83         int startAutoRequesting(RequestType type, AutoRequestGenerationCallback callback);
84         void stopAutoRequesting(int id);
85
86     private:
87         void configure(const std::shared_ptr<RAML::Raml> &raml);
88         void onResponseReceived(SimulatorResult result, const SimulatorResourceModel &resourceModel,
89                                 const RequestInfo &reqInfo, ResponseCallback callback);
90         void onAutoRequestingState(int sessionId, OperationState state,
91                                    AutoRequestGenerationCallback callback);
92         SimulatorConnectivityType convertConnectivityType(OCConnectivityType type) const;
93
94         std::string m_id;
95         std::mutex m_observeLock;
96         bool m_observeState;
97         GETRequestSender m_getRequestSender;
98         PUTRequestSender m_putRequestSender;
99         POSTRequestSender m_postRequestSender;
100
101         RequestAutomationMngr m_requestAutomationMngr;
102         std::unordered_map<std::string, std::shared_ptr<RequestModel>> m_requestModels;
103         std::shared_ptr<OC::OCResource> m_ocResource;
104 };
105
106 #endif