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 findResourceList(const std::string& host, const std::string& resourceURI,
96 OCConnectivityType connectivityType, FindResListCallback resourceHandler,
97 QualityOfService QoS);
99 OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
100 OCConnectivityType connectivityType, FindResListCallback resourceHandler,
101 FindErrorCallback errorHandler, QualityOfService Qos);
103 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
104 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
106 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
107 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
108 QualityOfService QoS);
110 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
111 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
113 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
114 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
115 QualityOfService QoS);
118 * API for Device Discovery
120 * @param host Host IP Address. If null or empty, Multicast is performed.
121 * @param deviceURI Uri containing address to the virtual device in C Stack
123 * @param deviceInfoHandler device discovery callback
124 * @param QualityOfService the quality of communication
125 * @return Returns ::OC_STACK_OK if success.
126 * @note OCStackResult is defined in ocstack.h.
128 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
129 FindDeviceCallback deviceInfoHandler);
130 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
131 FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
134 * API for Platform Discovery
136 * @param host Host IP Address. If null or empty, Multicast is performed.
137 * @param platformURI Uri containing address to the virtual platform in C Stack
139 * @param platformInfoHandler platform discovery callback
140 * @param QualityOfService the quality of communication
141 * @return Returns ::OC_STACK_OK if success.
142 * @note OCStackResult is defined in ocstack.h.
144 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
145 FindPlatformCallback platformInfoHandler);
146 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
147 FindPlatformCallback platformInfoHandler, QualityOfService QoS);
149 OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
150 const std::string& value);
151 OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
152 const std::vector<std::string>& value);
153 OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
155 OCStackResult getPropertyList(OCPayloadType type, const std::string& tag,
156 std::vector<std::string>& value);
159 * This API registers a resource with the server
160 * @note This API applies to server side only.
162 * @param resourceHandle Upon successful registration, resourceHandle will be filled
163 * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
164 * @param resourceTypeName The resource type. Example: "light"
165 * @param resourceInterface The resource interface (whether it is collection etc).
166 * @param entityHandler entity handler callback.
167 * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
168 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
169 * setting resourceProperty as OC_OBSERVABLE will allow observation
170 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
173 * @return Returns ::OC_STACK_OK if success.
174 * @note "a/light" is a relative URI.
175 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
176 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
177 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
178 * //192.168.1.1/oic/a/light"
179 * First parameter can take a relative URI and core will take care of preparing the fully
181 * first parameter can take fully qualified URI and core will take that as is for further
183 * @note OCStackResult is defined in ocstack.h.
185 OCStackResult registerResource(OCResourceHandle& resourceHandle,
186 std::string& resourceURI,
187 const std::string& resourceTypeName,
188 const std::string& resourceInterface,
189 EntityHandler entityHandler,
190 uint8_t resourceProperty);
192 OCStackResult registerResource(OCResourceHandle& resourceHandle,
193 const std::shared_ptr<OCResource> resource);
196 * This API registers all the device specific information
198 * @deprecated: Use setPropertyValue instead.
200 * @param deviceInfo Structure containing all the device related information
202 * @return Returns ::OC_STACK_OK if success
203 * @note OCDeviceInfo is defined in OCStack.h
205 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
208 * This API registers all the platform specific information
210 * @param platformInfo Structure containing all the platform related information
212 * @return Returns ::OC_STACK_OK if success
213 * @note OCPlatformInfo is defined in OCStack.h
215 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
217 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
219 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
221 OCStackResult bindResource(const OCResourceHandle collectionHandle,
222 const OCResourceHandle resourceHandle);
224 OCStackResult bindResources(const OCResourceHandle collectionHandle,
225 const std::vector<OCResourceHandle>& addedResourceHandleList);
227 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
228 const OCResourceHandle resourceHandle);
230 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
231 const std::vector<OCResourceHandle>& resourceHandleList);
233 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
234 const std::string& resourceTypeName) const;
236 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
237 const std::string& resourceInterfaceName) const;
239 OCStackResult startPresence(const unsigned int ttl);
241 OCStackResult stopPresence();
243 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
244 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
246 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
247 const std::string& resourceType, OCConnectivityType connectivityType,
248 SubscribeCallback presenceHandler);
249 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
252 OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
253 const std::string& host,
254 const std::vector<std::string>& di,
255 OCConnectivityType connectivityType,
256 ObserveCallback callback);
259 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
260 OCConnectivityType connectivityType, bool isObservable,
261 const std::vector<std::string>& resourceTypes,
262 const std::vector<std::string>& interfaces);
263 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
264 std::weak_ptr<std::recursive_mutex> csdkLock();
266 OCStackResult findDirectPairingDevices(unsigned short waittime,
267 GetDirectPairedCallback callback);
269 OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
271 OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
272 const std::string& pinNumber,
273 DirectPairingCallback resultCallback);
275 OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
276 OCConnectivityType connectivityType);
279 OCStackResult getDeviceId(OCUUIdentity *myUuid);
281 OCStackResult setDeviceId(const OCUUIdentity *myUuid);
283 OCStackResult stop();
284 OCStackResult start();
286 PlatformConfig m_cfg;
290 std::unique_ptr<WrapperFactory> m_WrapperInstance;
291 IServerWrapper::Ptr m_server;
292 IClientWrapper::Ptr m_client;
293 std::shared_ptr<std::recursive_mutex> m_csdkLock;
297 * Constructor for OCPlatform_impl. Constructs a new OCPlatform_impl from a given
298 * PlatformConfig with appropriate fields
299 * @param config PlatformConfig struct which has details such as modeType
300 * (server/client/both), in-proc/out-of-proc etc.
302 OCPlatform_impl(const PlatformConfig& config);
305 * Private function to initialize the platform
307 void init(const PlatformConfig& config);
310 * Private constructor/operators to prevent copying
313 OCPlatform_impl(const OCPlatform_impl& other)= delete;
314 OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
315 OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
319 #endif //__OCPLATFORM_IMPL_H