1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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.
29 #ifndef OC_PLATFORM_IMPL_H_
30 #define OC_PLATFORM_IMPL_H_
35 #include "OCResource.h"
36 #include "WrapperFactory.h"
37 #include "OCResourceRequest.h"
38 #include "OCResourceResponse.h"
39 #include "OCRepresentation.h"
40 #include "OCDirectPairing.h"
43 #include "OCAccountManager.h"
46 #include "oc_logger.hpp"
53 static PlatformConfig& globalConfig();
55 static void Configure(const PlatformConfig& config);
57 static OCPlatform_impl& Instance();
60 // typedef for handle to cancel presence info with
61 typedef OCDoHandle OCPresenceHandle;
63 virtual ~OCPlatform_impl(void);
65 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
67 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
69 OCStackResult notifyListOfObservers(
70 OCResourceHandle resourceHandle,
71 ObservationIds& observationIds,
72 const std::shared_ptr<OCResourceResponse> responsePtr);
74 OCStackResult notifyListOfObservers(
75 OCResourceHandle resourceHandle,
76 ObservationIds& observationIds,
77 const std::shared_ptr<OCResourceResponse> responsePtr,
78 QualityOfService QoS);
80 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
81 OCConnectivityType connectivityType, FindCallback resourceHandler);
83 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
84 OCConnectivityType connectivityType, FindCallback resourceHandler,
85 QualityOfService QoS);
87 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
88 OCConnectivityType connectivityType, FindCallback resourceHandler,
89 FindErrorCallback errorHandler);
91 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
92 OCConnectivityType connectivityType, FindCallback resourceHandler,
93 FindErrorCallback errorHandler, QualityOfService QoS);
95 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
96 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
98 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
99 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
100 QualityOfService QoS);
102 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
103 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
105 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
106 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
107 QualityOfService QoS);
110 * API for Device Discovery
112 * @param host Host IP Address. If null or empty, Multicast is performed.
113 * @param deviceURI Uri containing address to the virtual device in C Stack
115 * @param deviceInfoHandler device discovery callback
116 * @param QualityOfService the quality of communication
117 * @return Returns ::OC_STACK_OK if success.
118 * @note OCStackResult is defined in ocstack.h.
120 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
121 FindDeviceCallback deviceInfoHandler);
122 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
123 FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
126 * API for Platform Discovery
128 * @param host Host IP Address. If null or empty, Multicast is performed.
129 * @param platformURI Uri containing address to the virtual platform in C Stack
131 * @param platformInfoHandler platform discovery callback
132 * @param QualityOfService the quality of communication
133 * @return Returns ::OC_STACK_OK if success.
134 * @note OCStackResult is defined in ocstack.h.
136 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
137 FindPlatformCallback platformInfoHandler);
138 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
139 FindPlatformCallback platformInfoHandler, QualityOfService QoS);
142 * This API registers a resource with the server
143 * @note This API applies to server side only.
145 * @param resourceHandle Upon successful registration, resourceHandle will be filled
146 * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
147 * @param resourceTypeName The resource type. Example: "light"
148 * @param resourceInterface The resource interface (whether it is collection etc).
149 * @param entityHandler entity handler callback.
150 * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
151 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
152 * setting resourceProperty as OC_OBSERVABLE will allow observation
153 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
156 * @return Returns ::OC_STACK_OK if success.
157 * @note "a/light" is a relative URI.
158 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
159 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
160 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
161 * //192.168.1.1/oic/a/light"
162 * First parameter can take a relative URI and core will take care of preparing the fully
164 * first parameter can take fully qualified URI and core will take that as is for further
166 * @note OCStackResult is defined in ocstack.h.
168 OCStackResult registerResource(OCResourceHandle& resourceHandle,
169 std::string& resourceURI,
170 const std::string& resourceTypeName,
171 const std::string& resourceInterface,
172 EntityHandler entityHandler,
173 uint8_t resourceProperty);
175 OCStackResult registerResource(OCResourceHandle& resourceHandle,
176 const std::shared_ptr<OCResource> resource);
179 * This API registers all the device specific information
181 * @param deviceInfo Structure containing all the device related information
183 * @return Returns ::OC_STACK_OK if success
184 * @note OCDeviceInfo is defined in OCStack.h
186 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
189 * This API registers all the platform specific information
191 * @param platformInfo Structure containing all the platform related information
193 * @return Returns ::OC_STACK_OK if success
194 * @note OCPlatformInfo is defined in OCStack.h
196 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
198 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
200 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
202 OCStackResult bindResource(const OCResourceHandle collectionHandle,
203 const OCResourceHandle resourceHandle);
205 OCStackResult bindResources(const OCResourceHandle collectionHandle,
206 const std::vector<OCResourceHandle>& addedResourceHandleList);
208 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
209 const OCResourceHandle resourceHandle);
211 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
212 const std::vector<OCResourceHandle>& resourceHandleList);
214 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
215 const std::string& resourceTypeName) const;
217 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
218 const std::string& resourceInterfaceName) const;
220 OCStackResult startPresence(const unsigned int ttl);
222 OCStackResult stopPresence();
224 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
225 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
227 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
228 const std::string& resourceType, OCConnectivityType connectivityType,
229 SubscribeCallback presenceHandler);
230 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
233 OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
234 const std::string& host,
235 const QueryParamsList& queryParams,
236 OCConnectivityType connectivityType,
237 ObserveCallback callback);
240 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
241 OCConnectivityType connectivityType, bool isObservable,
242 const std::vector<std::string>& resourceTypes,
243 const std::vector<std::string>& interfaces);
244 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
246 OCStackResult publishResourceToRD(const std::string& host,
247 OCConnectivityType connectivityType,
248 ResourceHandles& resourceHandles,
249 PublishResourceCallback callback);
251 OCStackResult publishResourceToRD(const std::string& host,
252 OCConnectivityType connectivityType,
253 ResourceHandles& resourceHandles,
254 PublishResourceCallback callback, QualityOfService qos);
256 OCStackResult deleteResourceFromRD(const std::string& host,
257 OCConnectivityType connectivityType,
258 DeleteResourceCallback callback);
260 OCStackResult deleteResourceFromRD(const std::string& host,
261 OCConnectivityType connectivityType,
262 ResourceHandles& resourceHandles,
263 DeleteResourceCallback callback);
265 OCStackResult deleteResourceFromRD(const std::string& host,
266 OCConnectivityType connectivityType,
267 ResourceHandles& resourceHandles,
268 DeleteResourceCallback callback, QualityOfService qos);
270 std::weak_ptr<std::recursive_mutex> csdkLock();
272 OCStackResult findDirectPairingDevices(unsigned short waittime,
273 GetDirectPairedCallback callback);
275 OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
277 OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
278 const std::string& pinNumber,
279 DirectPairingCallback resultCallback);
281 OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
282 OCConnectivityType connectivityType);
285 PlatformConfig m_cfg;
288 std::unique_ptr<WrapperFactory> m_WrapperInstance;
289 IServerWrapper::Ptr m_server;
290 IClientWrapper::Ptr m_client;
291 std::shared_ptr<std::recursive_mutex> m_csdkLock;
295 * Constructor for OCPlatform_impl. Constructs a new OCPlatform_impl from a given
296 * PlatformConfig with appropriate fields
297 * @param config PlatformConfig struct which has details such as modeType
298 * (server/client/both), in-proc/out-of-proc etc.
300 OCPlatform_impl(const PlatformConfig& config);
303 * Private function to initialize the platform
305 void init(const PlatformConfig& config);
308 * Private constructor/operators to prevent copying
311 OCPlatform_impl(const OCPlatform_impl& other)= delete;
312 OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
313 OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
317 #endif //__OCPLATFORM_IMPL_H