Changeset for reviewing RI-CA integration changes.
[platform/upstream/iotivity.git] / resource / include / OCPlatform_impl.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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
23  *
24  * Implementation of the OCPlatform functionality. It contains a singleton
25  * interface that is used only by the OCPlatform namespace and is the
26  * central entrance to the stack.
27  */
28
29 #ifndef __OCPLATFORM_IMPL_H
30 #define __OCPLATFORM_IMPL_H
31
32 #include <map>
33
34 #include "OCApi.h"
35 #include "OCResource.h"
36 #include "WrapperFactory.h"
37 #include "OCResourceRequest.h"
38 #include "OCResourceResponse.h"
39 #include "OCRepresentation.h"
40
41 #include "oc_logger.hpp"
42
43 namespace OC
44 {
45     class OCPlatform_impl
46     {
47     private:
48         static PlatformConfig& globalConfig();
49     public:
50         static void Configure(const PlatformConfig& config);
51
52         static OCPlatform_impl& Instance();
53
54     public:
55         // typedef for handle to cancel presence info with
56         typedef OCDoHandle OCPresenceHandle;
57
58         virtual ~OCPlatform_impl(void);
59
60         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
61
62         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
63
64         OCStackResult notifyListOfObservers(
65                     OCResourceHandle resourceHandle,
66                     ObservationIds& observationIds,
67                     const std::shared_ptr<OCResourceResponse> responsePtr);
68
69         OCStackResult notifyListOfObservers(
70                     OCResourceHandle resourceHandle,
71                     ObservationIds& observationIds,
72                     const std::shared_ptr<OCResourceResponse> responsePtr,
73                     QualityOfService QoS);
74
75         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
76                     OCConnectivityType connectivityType, FindCallback resourceHandler);
77
78         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
79                     OCConnectivityType connectivityType, FindCallback resourceHandler,
80                     QualityOfService QoS);
81
82         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
83                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
84
85         OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
86                     OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
87                     QualityOfService QoS);
88
89         /**
90         * This API registers a resource with the server
91         * NOTE: This API applies to server side only.
92         *
93         * @param resourceHandle - Upon successful registration, resourceHandle will be filled
94         * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
95         * @param resourceTypeName - The resource type. Example: "light"
96         * @param resourceInterface - The resource interface (whether it is collection etc).
97         * @param entityHandler - entity handler callback.
98         * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
99         * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
100         * setting resourceProperty as OC_OBSERVABLE will allow observation
101         * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
102         * and observation
103         *
104         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
105         * NOTE: "a/light" is a relative URI.
106         * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
107         * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
108         * Example, a relative URI: 'a/light' will result in a fully qualified URI:
109         *   //192.168.1.1/oc/a/light"
110         * First parameter can take a relative URI and core will take care of preparing the fully
111         * qualified URI OR
112         * first parameter can take fully qualified URI and core will take that as is for further
113         * operations
114         * NOTE: OCStackResult is defined in ocstack.h.
115         */
116         OCStackResult registerResource(OCResourceHandle& resourceHandle,
117                         std::string& resourceURI,
118                         const std::string& resourceTypeName,
119                         const std::string& resourceInterface,
120                         EntityHandler entityHandler,
121                         uint8_t resourceProperty);
122
123         OCStackResult registerResource(OCResourceHandle& resourceHandle,
124                         const std::shared_ptr<OCResource> resource);
125
126         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
127
128         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
129
130         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
131
132         OCStackResult bindResource(const OCResourceHandle collectionHandle,
133                     const OCResourceHandle resourceHandle);
134
135         OCStackResult bindResources(const OCResourceHandle collectionHandle,
136                     const std::vector<OCResourceHandle>& addedResourceHandleList);
137
138         OCStackResult unbindResource(const OCResourceHandle collectionHandle,
139                     const OCResourceHandle resourceHandle);
140
141         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
142                         const std::vector<OCResourceHandle>& resourceHandleList);
143
144         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
145                         const std::string& resourceTypeName) const;
146
147         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
148                         const std::string& resourceInterfaceName) const;
149
150         OCStackResult startPresence(const unsigned int ttl);
151
152         OCStackResult stopPresence();
153
154         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
155                         OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
156
157         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
158                         const std::string& resourceType, OCConnectivityType connectivityType,
159                         SubscribeCallback presenceHandler);
160         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
161
162         OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
163                         OCConnectivityType connectivityType, bool isObservable,
164                         const std::vector<std::string>& resourceTypes,
165                         const std::vector<std::string>& interfaces);
166         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
167
168     private:
169         PlatformConfig m_cfg;
170
171     private:
172         std::unique_ptr<WrapperFactory> m_WrapperInstance;
173         IServerWrapper::Ptr m_server;
174         IClientWrapper::Ptr m_client;
175         std::shared_ptr<std::recursive_mutex> m_csdkLock;
176
177     private:
178         /**
179         * Constructor for OCPlatform_impl. Constructs a new OCPlatform_impl from a given
180         * PlatformConfig with appropriate fields
181         * @param config PlatformConfig struct which has details such as modeType
182         * (server/client/both), in-proc/out-of-proc etc.
183         */
184         OCPlatform_impl(const PlatformConfig& config);
185
186         /**
187         * Private function to initialize the platform
188         */
189         void init(const PlatformConfig& config);
190
191         /**
192         * Private constructor/operators to prevent copying
193         * of this object
194         */
195         OCPlatform_impl(const OCPlatform_impl& other)= delete;
196         OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
197         OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
198     };
199 }
200
201 #endif //__OCPLATFORM_IMPL_H
202
203
204