IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RemoteEnrollee.h
Go to the documentation of this file.
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 
21 #ifndef REMOTE_ENROLLEE_H_
22 #define REMOTE_ENROLLEE_H_
23 
24 #include <memory>
25 #include <iostream>
26 #include <condition_variable>
27 
28 #include "ESRichCommon.h"
29 #include "OCApi.h"
30 
31 using namespace OC;
32 
33 namespace OIC
34 {
35  namespace Service
36  {
37  class OCResource;
38  class EnrolleeResource;
39  class CloudResource;
40  class EnrolleeSecurity;
41 
42  typedef std::function<void(const std::shared_ptr<OC::OCResource> resource)> onDeviceDiscoveredCb;
43 
52  class RemoteEnrollee : public std::enable_shared_from_this<RemoteEnrollee>
53  {
54  public:
55  ~RemoteEnrollee() = default;
56 
67  void getStatus(const GetStatusCb callback);
68 
79  void getConfiguration(const GetConfigurationStatusCb callback);
80 
91  void provisionSecurity(const SecurityProvStatusCb callback);
92 
105  void provisionSecurity(const SecurityProvStatusCbWithOption callback);
106 
121  void provisionDeviceProperties(const DeviceProp& devProp,
122  const DevicePropProvStatusCb callback);
123 
141  void provisionCloudProperties(const CloudProp& cloudProp,
142  const CloudPropProvStatusCb callback);
143 
160  void provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
161  const CloudProp& cloudProp,
162  const CloudPropProvStatusCb callback);
163 
173  void requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes, const ConnectRequestStatusCb callback);
174 
175  private:
176  RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
177 
178  ESResult discoverResource();
179 
180  static void onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
181  std::weak_ptr<RemoteEnrollee> this_ptr);
182 
183  static void onGetStatusHandlerCallback(
184  const std::shared_ptr< GetEnrolleeStatus > status,
185  std::weak_ptr<RemoteEnrollee> this_ptr);
186 
187  static void onGetConfigurationStatusHandlerCallback(
188  const std::shared_ptr< GetConfigurationStatus > status,
189  std::weak_ptr<RemoteEnrollee> this_ptr);
190 
191  static void onDevicePropProvisioningStatusHandlerCallback(
192  const std::shared_ptr< DevicePropProvisioningStatus > status,
193  std::weak_ptr<RemoteEnrollee> this_ptr);
194 
195  static void onCloudPropProvisioningStatusHandlerCallback(
196  const std::shared_ptr< CloudPropProvisioningStatus > status,
197  std::weak_ptr<RemoteEnrollee> this_ptr);
198 
199  static void onConnectRequestStatusHandlerCallback(
200  const std::shared_ptr< ConnectRequestStatus > status,
201  std::weak_ptr<RemoteEnrollee> this_ptr);
202 
203  static void onSecurityStatusHandlerCallback(
204  const std::shared_ptr< SecProvisioningStatus > status,
205  std::weak_ptr<RemoteEnrollee> this_ptr);
206 
207  static ESOwnershipTransferData onSecurityStatusWithOptionHandlerCallback(
208  const std::shared_ptr< SecProvisioningStatus > status,
209  std::weak_ptr<RemoteEnrollee> this_ptr);
210 
211  void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
212  void initCloudResource();
213 
214  void getStatusHandler
215  (const std::shared_ptr< GetEnrolleeStatus > status) const;
216  void getConfigurationStatusHandler
217  (const std::shared_ptr< GetConfigurationStatus > status) const;
218  void devicePropProvisioningStatusHandler
219  (const std::shared_ptr< DevicePropProvisioningStatus > status) const;
220  void cloudPropProvisioningStatusHandler
221  (const std::shared_ptr< CloudPropProvisioningStatus > status) const;
222  void connectRequestStatusHandler(
223  const std::shared_ptr< ConnectRequestStatus > status) const;
224  void securityStatusHandler
225  (const std::shared_ptr< SecProvisioningStatus > status) const;
226  ESOwnershipTransferData securityStatusWithOptionHandler
227  (const std::shared_ptr< SecProvisioningStatus > status) const;
228 
229  private:
230  std::shared_ptr< OC::OCResource > m_ocResource;
231  std::shared_ptr< EnrolleeResource > m_enrolleeResource;
232  std::shared_ptr< EnrolleeSecurity > m_localEnrolleeSecurity;
233  std::shared_ptr< EnrolleeSecurity > m_cloudEnrolleeSecurity;
234  std::shared_ptr< CloudResource > m_cloudResource;
235 
236  std::string m_deviceId;
237  bool m_discoveryResponse;
238 
239  std::mutex m_discoverymtx;
240  std::condition_variable m_cond;
241 
242  SecurityProvStatusCb m_securityProvStatusCb;
243  SecurityProvStatusCbWithOption m_securityProvStatusCbWithOption;
244  GetStatusCb m_getStatusCb;
245  GetConfigurationStatusCb m_getConfigurationStatusCb;
246  SecurityPinCb m_securityPinCb;
247  SecProvisioningDbPathCb m_secProvisioningDbPathCb;
248  DevicePropProvStatusCb m_devicePropProvStatusCb;
249  CloudPropProvStatusCb m_cloudPropProvStatusCb;
250  ConnectRequestStatusCb m_connectRequestStatusCb;
251 
252  friend class EasySetup;
253  };
254  }
255 }
256 
257 #endif //REMOTE_ENROLLEE_H_
This provides an API to instanciate a new RemoteEnrollee object correspondent to Enrollee Device to b...
Definition: EasySetup.hpp:41
function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb
Callback function definition for providing Enrollee cloud property provisioning status.
Definition: ESRichCommon.h:1390
function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb
Callback function definition for providing Enrollee configuration status.
Definition: ESRichCommon.h:1380
function< void(string &) > SecProvisioningDbPathCb
Callback definition to be invoked when the stack expects a db path.
Definition: ESRichCommon.h:1419
function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb
Callback function definition for providing Enrollee device property provisioning status.
Definition: ESRichCommon.h:1385
This class represents Remote Enrollee device instance.
Definition: RemoteEnrollee.h:52
std::function< void(const std::shared_ptr< OC::OCResource > resource)> onDeviceDiscoveredCb
Definition: RemoteEnrollee.h:40
ESResult
A result of Easy Setup.
Definition: escommon.h:154
OCResource represents an OC resource.
Definition: OCResource.h:107
function< ESOwnershipTransferData(shared_ptr< SecProvisioningStatus >) > SecurityProvStatusCbWithOption
Callback function definition for providing Enrollee security provisioning status. ...
Definition: ESRichCommon.h:1409
function< void(string &) > SecurityPinCb
Callback definition to be invoked when the security stack expects a pin from application.
Definition: ESRichCommon.h:1414
Data class stored for provisioning of coap cloud server properties.
Definition: ESRichCommon.h:128
function< void(shared_ptr< ConnectRequestStatus >) > ConnectRequestStatusCb
Callback function definition for providing 'Connect' request status.
Definition: ESRichCommon.h:1395
Definition: ESRichCommon.h:1305
Data class stored for provisioning of Device properties which includes properties of WiFiConf resourc...
Definition: ESRichCommon.h:384
function< void(shared_ptr< SecProvisioningStatus >) > SecurityProvStatusCb
Callback function definition for providing Enrollee security provisioning status. ...
Definition: ESRichCommon.h:1401
function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb
Callback function definition for providing Enrollee status.
Definition: ESRichCommon.h:1375