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"
42 #include "oc_logger.hpp"
49 static PlatformConfig& globalConfig();
51 static void Configure(const PlatformConfig& config);
53 static OCPlatform_impl& Instance();
56 // typedef for handle to cancel presence info with
57 typedef OCDoHandle OCPresenceHandle;
59 virtual ~OCPlatform_impl(void);
61 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
63 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
65 OCStackResult notifyListOfObservers(
66 OCResourceHandle resourceHandle,
67 ObservationIds& observationIds,
68 const std::shared_ptr<OCResourceResponse> responsePtr);
70 OCStackResult notifyListOfObservers(
71 OCResourceHandle resourceHandle,
72 ObservationIds& observationIds,
73 const std::shared_ptr<OCResourceResponse> responsePtr,
74 QualityOfService QoS);
76 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
77 OCConnectivityType connectivityType, FindCallback resourceHandler);
79 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
80 OCConnectivityType connectivityType, FindCallback resourceHandler,
81 QualityOfService QoS);
83 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
84 OCConnectivityType connectivityType, FindCallback resourceHandler,
85 FindErrorCallback errorHandler);
87 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
88 OCConnectivityType connectivityType, FindCallback resourceHandler,
89 FindErrorCallback errorHandler, QualityOfService QoS);
91 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
92 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
94 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
95 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
96 QualityOfService QoS);
98 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
99 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
101 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
102 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
103 QualityOfService QoS);
106 * API for Device Discovery
108 * @param host Host IP Address. If null or empty, Multicast is performed.
109 * @param deviceURI Uri containing address to the virtual device in C Stack
111 * @param deviceInfoHandler device discovery callback
112 * @param QualityOfService the quality of communication
113 * @return Returns ::OC_STACK_OK if success.
114 * @note OCStackResult is defined in ocstack.h.
116 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
117 FindDeviceCallback deviceInfoHandler);
118 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
119 FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
122 * API for Platform Discovery
124 * @param host Host IP Address. If null or empty, Multicast is performed.
125 * @param platformURI Uri containing address to the virtual platform in C Stack
127 * @param platformInfoHandler platform discovery callback
128 * @param QualityOfService the quality of communication
129 * @return Returns ::OC_STACK_OK if success.
130 * @note OCStackResult is defined in ocstack.h.
132 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
133 FindPlatformCallback platformInfoHandler);
134 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
135 FindPlatformCallback platformInfoHandler, QualityOfService QoS);
138 * This API registers a resource with the server
139 * @note This API applies to server side only.
141 * @param resourceHandle Upon successful registration, resourceHandle will be filled
142 * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
143 * @param resourceTypeName The resource type. Example: "light"
144 * @param resourceInterface The resource interface (whether it is collection etc).
145 * @param entityHandler entity handler callback.
146 * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
147 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
148 * setting resourceProperty as OC_OBSERVABLE will allow observation
149 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
152 * @return Returns ::OC_STACK_OK if success.
153 * @note "a/light" is a relative URI.
154 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
155 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
156 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
157 * //192.168.1.1/oic/a/light"
158 * First parameter can take a relative URI and core will take care of preparing the fully
160 * first parameter can take fully qualified URI and core will take that as is for further
162 * @note OCStackResult is defined in ocstack.h.
164 OCStackResult registerResource(OCResourceHandle& resourceHandle,
165 std::string& resourceURI,
166 const std::string& resourceTypeName,
167 const std::string& resourceInterface,
168 EntityHandler entityHandler,
169 uint8_t resourceProperty);
171 OCStackResult registerResource(OCResourceHandle& resourceHandle,
172 const std::shared_ptr<OCResource> resource);
175 * This API registers all the device specific information
177 * @param deviceInfo Structure containing all the device related information
179 * @return Returns ::OC_STACK_OK if success
180 * @note OCDeviceInfo is defined in OCStack.h
182 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
185 * This API registers all the platform specific information
187 * @param platformInfo Structure containing all the platform related information
189 * @return Returns ::OC_STACK_OK if success
190 * @note OCPlatformInfo is defined in OCStack.h
192 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
194 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
196 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
198 OCStackResult bindResource(const OCResourceHandle collectionHandle,
199 const OCResourceHandle resourceHandle);
201 OCStackResult bindResources(const OCResourceHandle collectionHandle,
202 const std::vector<OCResourceHandle>& addedResourceHandleList);
204 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
205 const OCResourceHandle resourceHandle);
207 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
208 const std::vector<OCResourceHandle>& resourceHandleList);
210 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
211 const std::string& resourceTypeName) const;
213 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
214 const std::string& resourceInterfaceName) const;
216 OCStackResult startPresence(const unsigned int ttl);
218 OCStackResult stopPresence();
220 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
221 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
223 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
224 const std::string& resourceType, OCConnectivityType connectivityType,
225 SubscribeCallback presenceHandler);
226 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
228 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
229 OCConnectivityType connectivityType, bool isObservable,
230 const std::vector<std::string>& resourceTypes,
231 const std::vector<std::string>& interfaces);
232 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
234 std::weak_ptr<std::recursive_mutex> csdkLock();
236 OCStackResult findDirectPairingDevices(unsigned short waittime,
237 GetDirectPairedCallback callback);
239 OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
241 OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
242 const std::string& pinNumber,
243 DirectPairingCallback resultCallback);
246 PlatformConfig m_cfg;
249 std::unique_ptr<WrapperFactory> m_WrapperInstance;
250 IServerWrapper::Ptr m_server;
251 IClientWrapper::Ptr m_client;
252 std::shared_ptr<std::recursive_mutex> m_csdkLock;
256 * Constructor for OCPlatform_impl. Constructs a new OCPlatform_impl from a given
257 * PlatformConfig with appropriate fields
258 * @param config PlatformConfig struct which has details such as modeType
259 * (server/client/both), in-proc/out-of-proc etc.
261 OCPlatform_impl(const PlatformConfig& config);
264 * Private function to initialize the platform
266 void init(const PlatformConfig& config);
269 * Private constructor/operators to prevent copying
272 OCPlatform_impl(const OCPlatform_impl& other)= delete;
273 OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
274 OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
278 #endif //__OCPLATFORM_IMPL_H