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 __OCPLATFORM_IMPL_H
30 #define __OCPLATFORM_IMPL_H
35 #include "OCResource.h"
36 #include "WrapperFactory.h"
37 #include "OCResourceRequest.h"
38 #include "OCResourceResponse.h"
39 #include "OCRepresentation.h"
41 #include "oc_logger.hpp"
48 static PlatformConfig& globalConfig();
50 static void Configure(const PlatformConfig& config);
52 static OCPlatform_impl& Instance();
55 // typedef for handle to cancel presence info with
56 typedef OCDoHandle OCPresenceHandle;
58 virtual ~OCPlatform_impl(void);
60 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
62 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
64 OCStackResult notifyListOfObservers(
65 OCResourceHandle resourceHandle,
66 ObservationIds& observationIds,
67 const std::shared_ptr<OCResourceResponse> responsePtr);
69 OCStackResult notifyListOfObservers(
70 OCResourceHandle resourceHandle,
71 ObservationIds& observationIds,
72 const std::shared_ptr<OCResourceResponse> responsePtr,
73 QualityOfService QoS);
75 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
76 OCConnectivityType connectivityType, FindCallback resourceHandler);
78 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
79 OCConnectivityType connectivityType, FindCallback resourceHandler,
80 QualityOfService QoS);
82 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
83 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
85 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
86 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
87 QualityOfService QoS);
90 * API for Device Discovery
92 * @param host - Host IP Address. If null or empty, Multicast is performed.
93 * @param resourceURI - Uri containing address to the virtual device in C Stack
96 * @param QualityOfService the quality of communication
99 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
100 FindDeviceCallback deviceInfoHandler);
101 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
102 FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
105 * This API registers a resource with the server
106 * NOTE: This API applies to server side only.
108 * @param resourceHandle - Upon successful registration, resourceHandle will be filled
109 * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
110 * @param resourceTypeName - The resource type. Example: "light"
111 * @param resourceInterface - The resource interface (whether it is collection etc).
112 * @param entityHandler - entity handler callback.
113 * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
114 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
115 * setting resourceProperty as OC_OBSERVABLE will allow observation
116 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
119 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
120 * NOTE: "a/light" is a relative URI.
121 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
122 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
123 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
124 * //192.168.1.1/oc/a/light"
125 * First parameter can take a relative URI and core will take care of preparing the fully
127 * first parameter can take fully qualified URI and core will take that as is for further
129 * NOTE: OCStackResult is defined in ocstack.h.
131 OCStackResult registerResource(OCResourceHandle& resourceHandle,
132 std::string& resourceURI,
133 const std::string& resourceTypeName,
134 const std::string& resourceInterface,
135 EntityHandler entityHandler,
136 uint8_t resourceProperty);
138 OCStackResult registerResource(OCResourceHandle& resourceHandle,
139 const std::shared_ptr<OCResource> resource);
142 * This API registers all the device specific information
144 * @param OCDeviceInfo - Structure containing all the device related information
146 * @return OCStackResult return value of the API. Returns OC_STACK_OK if success
148 * Note: OCDeviceInfo is defined in OCStack.h
150 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
152 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
154 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
156 OCStackResult bindResource(const OCResourceHandle collectionHandle,
157 const OCResourceHandle resourceHandle);
159 OCStackResult bindResources(const OCResourceHandle collectionHandle,
160 const std::vector<OCResourceHandle>& addedResourceHandleList);
162 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
163 const OCResourceHandle resourceHandle);
165 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
166 const std::vector<OCResourceHandle>& resourceHandleList);
168 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
169 const std::string& resourceTypeName) const;
171 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
172 const std::string& resourceInterfaceName) const;
174 OCStackResult startPresence(const unsigned int ttl);
176 OCStackResult stopPresence();
178 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
179 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
181 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
182 const std::string& resourceType, OCConnectivityType connectivityType,
183 SubscribeCallback presenceHandler);
184 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
186 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
187 OCConnectivityType connectivityType, bool isObservable,
188 const std::vector<std::string>& resourceTypes,
189 const std::vector<std::string>& interfaces);
190 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
193 PlatformConfig m_cfg;
196 std::unique_ptr<WrapperFactory> m_WrapperInstance;
197 IServerWrapper::Ptr m_server;
198 IClientWrapper::Ptr m_client;
199 std::shared_ptr<std::recursive_mutex> m_csdkLock;
203 * Constructor for OCPlatform_impl. Constructs a new OCPlatform_impl from a given
204 * PlatformConfig with appropriate fields
205 * @param config PlatformConfig struct which has details such as modeType
206 * (server/client/both), in-proc/out-of-proc etc.
208 OCPlatform_impl(const PlatformConfig& config);
211 * Private function to initialize the platform
213 void init(const PlatformConfig& config);
216 * Private constructor/operators to prevent copying
219 OCPlatform_impl(const OCPlatform_impl& other)= delete;
220 OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
221 OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
225 #endif //__OCPLATFORM_IMPL_H