Imported Upstream version 1.1.0
[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 "ESRichCommon.h"
25
26 namespace OIC
27 {
28     namespace Service
29     {
30         class RemoteEnrolleeResource;
31         class EnrolleeSecurity;
32
33         /**
34          * This class represents Remote Enrollee device instance.
35          * It will provide APIs for Mediator to perform operations to enable the Enrollee device
36          * to connect to the Enroller.
37          */
38         class RemoteEnrollee
39         {
40         public:
41             /**
42              * RemoteEnrollee constructor
43              *
44              * @param enrolleeNWProvInfo Provisioning information for the Enrollee
45              *
46              * @throw ESBadRequestException is thrown if the parameters are invalid
47              */
48             RemoteEnrollee(const ProvConfig& enrolleeNWProvInfo, const WiFiOnboadingConnection& connection) ;
49
50             ~RemoteEnrollee() = default;
51
52             typedef std::shared_ptr< RemoteEnrollee > shared_ptr;
53
54             /**
55              * Callback definition to be invoked when EasySetup status is changed.
56              * The same callback will be invoked when there is an error in the
57              * EasySetup process.
58              *
59              * @see registerResourceHandler
60              * @see ResourceState
61              */
62             typedef std::function< void(std::shared_ptr< EasySetupStatus >) >
63                                                                         EasySetupStatusCB;
64
65 #ifdef __WITH_DTLS__
66             /**
67              * Register Security status and other information callback handlers.
68              *
69              * @param secProvisioningDbCb Callback to be invoked when the stack expects a
70              *        path for the provisioning db.
71              * @param securityPinCb Callback to get security pin during pin based ownership transfer.
72              *
73              * @throws InvalidParameterException If callback is an empty function or null.
74              * @throws ESBadRequestException If registration is already completed.
75              *
76              * @see SecProvisioningResult
77              */
78             ESResult registerSecurityCallbackHandler(SecurityPinCb securityPinCb,
79                     SecProvisioningDbPathCb secProvisioningDbPathCb);
80 #endif //__WITH_DTLS__
81
82             /**
83              * Register EasySetup status handler.
84              *
85              * @param callback Callback to get EasySetup status.
86              * @param secProvisioningDbCB Callback to be invoked when the stack expects a
87              *        path for the provisioning db.
88              *
89              * @throws InvalidParameterException If callback is an empty function or null.
90              * @throws ESBadRequestException If registration is already completed.
91              *
92              * @see EasySetupStatus
93              */
94             void registerEasySetupStatusHandler(EasySetupStatusCB callback);
95
96             /**
97              * Start provisioning of target Enrollers information to the Enrollee.
98              *
99              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
100              *
101              * @see RemoteEnrollee
102              */
103             void startProvisioning();
104
105             /**
106              * Stop provisioning process that is currently in progress.
107              *
108              * @throws BadRequestException If provisioning is not in progress.
109              */
110             void stopProvisioning();
111
112             /**
113              * Check if the Enrollee device provisioned.
114              */
115             bool isEnrolleeProvisioned();
116
117             /**
118              * Get the Provisioning information provided for the current Enrollee.
119              *
120              * @return ProvConfig Provisioning information provided for the current Enrollee.
121              */
122             ProvConfig getProvConfig ();
123
124             /**
125              * Get the Onboarding connection information between Mediator and Enrollee.
126              *
127              * @return WiFiOnboadingConnection information between Mediator and Enrollee.
128              */
129
130             WiFiOnboadingConnection getOnboardConn();
131
132         private:
133             std::shared_ptr< RemoteEnrolleeResource > m_remoteResource;
134             EasySetupStatusCB m_easySetupStatusCb;
135             EnrolleeSecStatusCb m_enrolleeSecStatusCb;
136             SecurityPinCb m_securityPinCb;
137             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
138             ProvConfig m_ProvConfig;
139             WiFiOnboadingConnection m_wifiOnboardingconn;
140
141             std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
142             CurrentESState m_currentESState;
143             bool m_isSecured;
144
145             void provisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus);
146             void easySetupSecurityStatusCallback(
147             std::shared_ptr< SecProvisioningResult > secProvisioningResult);
148         };
149     }
150 }
151
152 #endif //REMOTE_ENROLLEE_H_