Remove unused old API.
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / RemoteEnrollee.h
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         /**
43          * This class represents Remote Enrollee device instance. What operation the class provides:
44          * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee
45          * devices.
46          * 2) Provision WiFi AP information used for which Enrollee is going to connect to the AP
47          * 3) Provision Device confiruation setting, i.e. language, country, and etc
48          * 4) Provision Cloud information used for which Enrollee is going to register to the cloud
49          */
50         class RemoteEnrollee
51         {
52         public:
53             ~RemoteEnrollee() = default;
54
55             /**
56              * Get an Enrollee's status which includes provisioning status and last error code
57              *
58              * @param callback will give the requested status
59              *
60              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
61              *
62              * @see GetStatusCb
63              */
64             void getStatus(const GetStatusCb callback);
65
66             /**
67              * Get an Enrollee's configuration which includes WiFi supported frequency and device name
68              *
69              * @param callback will give the requested configuration
70              *
71              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
72              *
73              * @see GetConfigurationStatusCb
74              */
75             void getConfiguration(const GetConfigurationStatusCb callback);
76
77              /**
78              * Do security provisioning such as ownership tranfer to Enrollee.
79              *
80              * @param callback will give the result if the security provisioning succeeds or fails for some reasons
81              *
82              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
83              *
84              * @see SecurityProvStatusCb
85              */
86             void provisionSecurity(const SecurityProvStatusCb callback);
87
88             /**
89              * Provision WiFi AP information and device configuration to Enrollee
90              * 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
91              * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
92              *
93              * @param devProp a data structure storing the above information to be delivered
94              * @param callback will give the result if the provisioning succeeds or fails
95              *
96              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
97              *
98              * @see DeviceProp
99              * @see DevicePropProvStatusCb
100              */
101             void provisionDeviceProperties(const DeviceProp& devProp,
102                                                const DevicePropProvStatusCb callback);
103
104             /**
105              * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
106              * Cloud interface server URL, and etc.
107              * In this function, Discovery for the Enrollee will happen again in a given network.
108              * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP
109              * and successfully connects to the certain WiFi AP. In that case, Mediator should discover
110              * the Enrollee with a certain Device ID in the network.
111              *
112              * @param cloudProp a data structure storing the above information to be delivered
113              * @param callback will give the result if the provisioning succeeds or fails
114              *
115              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
116              *
117              * @see CloudProp
118              * @see CloudPropProvStatusCb
119              */
120             void provisionCloudProperties(const CloudProp& cloudProp,
121                                               const CloudPropProvStatusCb callback);
122
123         private:
124             RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
125
126             ESResult discoverResource();
127             void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
128             void initCloudResource();
129
130             void getStatusHandler
131                 (const std::shared_ptr< GetEnrolleeStatus > status) const;
132             void getConfigurationStatusHandler
133                 (const std::shared_ptr< GetConfigurationStatus > status) const;
134             void devicePropProvisioningStatusHandler
135                 (const std::shared_ptr< DevicePropProvisioningStatus > status) const;
136             void cloudPropProvisioningStatusHandler
137                 (const std::shared_ptr< CloudPropProvisioningStatus > status) const;
138             void securityStatusHandler
139                 (const std::shared_ptr< SecProvisioningStatus > status) const;
140
141         private:
142             std::shared_ptr< OC::OCResource > m_ocResource;
143             std::shared_ptr< EnrolleeResource > m_enrolleeResource;
144             std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
145             std::shared_ptr< CloudResource > m_cloudResource;
146
147             std::string  m_deviceId;
148             bool m_discoveryResponse;
149
150             std::mutex m_discoverymtx;
151             std::condition_variable m_cond;
152
153             SecurityProvStatusCb m_securityProvStatusCb;
154             GetStatusCb m_getStatusCb;
155             GetConfigurationStatusCb m_getConfigurationStatusCb;
156             SecurityPinCb m_securityPinCb;
157             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
158             DevicePropProvStatusCb m_devicePropProvStatusCb;
159             CloudPropProvStatusCb m_cloudPropProvStatusCb;
160
161             friend class EasySetup;
162         };
163     }
164 }
165
166 #endif //REMOTE_ENROLLEE_H_