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 getDeviceInfo(const std::string& host, const std::string& deviceURI,
84 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
86 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
87 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
88 QualityOfService QoS);
90 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
91 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
93 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
94 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
95 QualityOfService QoS);
98 * API for Device Discovery
100 * @param host Host IP Address. If null or empty, Multicast is performed.
101 * @param deviceURI Uri containing address to the virtual device in C Stack
103 * @param deviceInfoHandler device discovery callback
104 * @param QualityOfService the quality of communication
105 * @return Returns ::OC_STACK_OK if success.
106 * @note OCStackResult is defined in ocstack.h.
108 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
109 FindDeviceCallback deviceInfoHandler);
110 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
111 FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
114 * API for Platform Discovery
116 * @param host Host IP Address. If null or empty, Multicast is performed.
117 * @param platformURI Uri containing address to the virtual platform in C Stack
119 * @param platformInfoHandler platform discovery callback
120 * @param QualityOfService the quality of communication
121 * @return Returns ::OC_STACK_OK if success.
122 * @note OCStackResult is defined in ocstack.h.
124 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
125 FindPlatformCallback platformInfoHandler);
126 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
127 FindPlatformCallback platformInfoHandler, QualityOfService QoS);
130 * This API registers a resource with the server
131 * @note This API applies to server side only.
133 * @param resourceHandle Upon successful registration, resourceHandle will be filled
134 * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
135 * @param resourceTypeName The resource type. Example: "light"
136 * @param resourceInterface The resource interface (whether it is collection etc).
137 * @param entityHandler entity handler callback.
138 * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
139 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
140 * setting resourceProperty as OC_OBSERVABLE will allow observation
141 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
144 * @return Returns ::OC_STACK_OK if success.
145 * @note "a/light" is a relative URI.
146 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
147 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
148 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
149 * //192.168.1.1/oic/a/light"
150 * First parameter can take a relative URI and core will take care of preparing the fully
152 * first parameter can take fully qualified URI and core will take that as is for further
154 * @note OCStackResult is defined in ocstack.h.
156 OCStackResult registerResource(OCResourceHandle& resourceHandle,
157 std::string& resourceURI,
158 const std::string& resourceTypeName,
159 const std::string& resourceInterface,
160 EntityHandler entityHandler,
161 uint8_t resourceProperty);
163 OCStackResult registerResource(OCResourceHandle& resourceHandle,
164 const std::shared_ptr<OCResource> resource);
167 * This API registers all the device specific information
169 * @param deviceInfo Structure containing all the device related information
171 * @return Returns ::OC_STACK_OK if success
172 * @note OCDeviceInfo is defined in OCStack.h
174 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
177 * This API registers all the platform specific information
179 * @param platformInfo Structure containing all the platform related information
181 * @return Returns ::OC_STACK_OK if success
182 * @note OCPlatformInfo is defined in OCStack.h
184 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
186 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
188 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
190 OCStackResult bindResource(const OCResourceHandle collectionHandle,
191 const OCResourceHandle resourceHandle);
193 OCStackResult bindResources(const OCResourceHandle collectionHandle,
194 const std::vector<OCResourceHandle>& addedResourceHandleList);
196 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
197 const OCResourceHandle resourceHandle);
199 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
200 const std::vector<OCResourceHandle>& resourceHandleList);
202 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
203 const std::string& resourceTypeName) const;
205 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
206 const std::string& resourceInterfaceName) const;
208 OCStackResult startPresence(const unsigned int ttl);
210 OCStackResult stopPresence();
212 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
213 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
215 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
216 const std::string& resourceType, OCConnectivityType connectivityType,
217 SubscribeCallback presenceHandler);
218 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
220 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
221 OCConnectivityType connectivityType, bool isObservable,
222 const std::vector<std::string>& resourceTypes,
223 const std::vector<std::string>& interfaces);
224 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
226 std::weak_ptr<std::recursive_mutex> csdkLock();
228 OCStackResult findDirectPairingDevices(unsigned short waittime,
229 GetDirectPairedCallback callback);
231 OCStackResult getDirectPairedDevices(GetDirectPairedCallback callback);
233 OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
234 const std::string& pinNumber,
235 DirectPairingCallback resultCallback);
238 PlatformConfig m_cfg;
241 std::unique_ptr<WrapperFactory> m_WrapperInstance;
242 IServerWrapper::Ptr m_server;
243 IClientWrapper::Ptr m_client;
244 std::shared_ptr<std::recursive_mutex> m_csdkLock;
248 * Constructor for OCPlatform_impl. Constructs a new OCPlatform_impl from a given
249 * PlatformConfig with appropriate fields
250 * @param config PlatformConfig struct which has details such as modeType
251 * (server/client/both), in-proc/out-of-proc etc.
253 OCPlatform_impl(const PlatformConfig& config);
256 * Private function to initialize the platform
258 void init(const PlatformConfig& config);
261 * Private constructor/operators to prevent copying
264 OCPlatform_impl(const OCPlatform_impl& other)= delete;
265 OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
266 OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
270 #endif //__OCPLATFORM_IMPL_H