replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / common / primitiveResource / include / PrimitiveResource.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 COMMON_PRIMITIVERESOURCE_H
22 #define COMMON_PRIMITIVERESOURCE_H
23
24 #include <functional>
25 #include <string>
26 #include <vector>
27
28 #include "OCResource.h"
29
30 #include "ResponseStatement.h"
31 #include "RCSAddress.h"
32
33 namespace OIC
34 {
35     namespace Service
36     {
37
38         typedef OC::HeaderOption::OCHeaderOption HeaderOption;
39         typedef std::vector<HeaderOption> HeaderOptions;
40
41         class RCSResourceAttributes;
42         class RCSRepresentation;
43
44         class PrimitiveResource: public std::enable_shared_from_this< PrimitiveResource >
45         {
46         public:
47             typedef std::shared_ptr< PrimitiveResource > Ptr;
48             typedef std::shared_ptr< const PrimitiveResource > ConstPtr;
49
50             typedef std::function<void(const HeaderOptions&, const RCSRepresentation&, int)>
51                     GetCallback;
52
53             typedef std::function<void(const HeaderOptions&, const RCSRepresentation&, int)>
54                     SetCallback;
55
56             typedef std::function<void(const HeaderOptions&, const RCSRepresentation&, int)>
57                     PutCallback;
58
59             typedef std::function<void(const HeaderOptions&, const RCSRepresentation&, int, int)>
60                     ObserveCallback;
61
62         public:
63             static PrimitiveResource::Ptr create(const std::shared_ptr<OC::OCResource>&);
64
65             virtual ~PrimitiveResource() { }
66
67             virtual void requestGet(GetCallback) = 0;
68
69             virtual void requestGetWith(const std::string& resourceType,
70                     const std::string& resourceInterface,
71                     const OC::QueryParamsMap& queryParametersMap, GetCallback) = 0;
72
73             virtual void requestSet(const RCSResourceAttributes&, SetCallback) = 0;
74
75             virtual void requestSetWith(const std::string& resourceType,
76                     const std::string& resourceInterface,
77                     const OC::QueryParamsMap& queryParametersMap,
78                     const RCSResourceAttributes&, GetCallback) = 0;
79
80             virtual void requestSetWith(const std::string& resourceType,
81                     const std::string& resourceInterface,
82                     const OC::QueryParamsMap& queryParametersMap,
83                     const RCSRepresentation&, SetCallback) = 0;
84
85             virtual void requestPut(const RCSResourceAttributes&, PutCallback) = 0;
86             virtual void requestObserve(ObserveCallback) = 0;
87             virtual void cancelObserve() = 0;
88
89             virtual std::string getSid() const = 0;
90             virtual std::string getUri() const = 0;
91             virtual std::string getHost() const = 0;
92             virtual std::vector< std::string > getTypes() const = 0;
93             virtual std::vector< std::string > getInterfaces() const = 0;
94             virtual OCConnectivityType getConnectivityType() const = 0;
95
96             virtual bool isObservable() const = 0;
97
98         protected:
99             PrimitiveResource() = default;
100
101             PrimitiveResource(const PrimitiveResource&) = delete;
102             PrimitiveResource(PrimitiveResource&&) = delete;
103
104             PrimitiveResource& operator=(const PrimitiveResource&) = delete;
105             PrimitiveResource& operator=(PrimitiveResource&&) = delete;
106         };
107
108         typedef std::function<void(std::shared_ptr<PrimitiveResource>)> DiscoverCallback;
109
110         void discoverResource(const std::string& host, const std::string& resourceURI,
111                 OCConnectivityType, DiscoverCallback);
112
113         void discoverResource(const RCSAddress& address, const std::string& resourceURI,
114                 DiscoverCallback);
115
116     }
117 }
118
119 #endif // COMMON_PRIMITIVERESOURCE_H