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