[Update] process of provisioning was split.
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / EnrolleeResource.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 ENROLLEE_RESOURCE_H_
22 #define ENROLLEE_RESOURCE_H_
23
24 #include <mutex>
25 #include <memory>
26
27 #include "ESRichCommon.h"
28
29 #include "OCApi.h"
30
31 using namespace OC;
32
33 namespace OIC
34 {
35     namespace Service
36     {
37         class OCResource;
38         class EnrolleeSecurity;
39
40         /**
41          * This class contains the resource discovery methods.
42          *
43          * @see EnrolleeResource
44          */
45         class EnrolleeResource
46         {
47             friend class EnrolleeSecurity;
48
49         public:
50
51             /**
52              * EnrolleeResource constructor
53              *
54              * @param enrolleeNWProvInfo Provisioning information for the Enrollee
55              *
56              * @throw ESBadRequestException is thrown if the parameters are invalid
57              */
58             EnrolleeResource(const WiFiOnboadingConnection &onboardingconn);
59             // EnrolleeResource(const ProvConfig &enrolleeNWProvInfo,
60             //                                    const WiFiOnboadingConnection &onboardingconn);
61
62             ~EnrolleeResource() = default;
63
64             /**
65              * Register provisioning status handler.
66              *
67              * @param callback Callback to get Provisioning status.
68              *
69              * @throws InvalidParameterException If callback is an empty function or null.
70              * @throws ESBadRequestException If registration is already completed.
71              *
72              * @see ProvisioningStatus
73              */
74             void registerInitRemoteEnrolleeStatusCallback (InitRemoteEnrolleeStatusCb callback);
75             void registerCapabilityStatusCallback (RequestCapabilityStatusCb callback);
76             void registerProvStatusCallback (DataProvStatusCb callback);
77
78             /**
79              * Construct Remote OIC resource using the enrollee host and connectivity information
80              * provided in the constructor of EnrolleeResource.
81              *
82              * @throws InvalidParameterException If the provided information is invalid.
83              * @throws ESBadRequestException If resource is already constructed.
84              *
85              * @see ProvisioningStatus
86              */
87             ESResult constructResourceObject();
88
89             void getCapabilityData();
90
91             /**
92              * Function for provisioning of Remote Enrollee resource using the information provided.
93              *
94              * @throws InvalidParameterException If cb is empty.
95              */
96             void provisionEnrollee();
97
98             /**
99              * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state
100              *
101              * @throws ESBadRequestException If device is not provisioned already.
102              */
103             void unprovisionEnrollee();
104
105
106
107         private:
108             std::shared_ptr< OC::OCResource > m_ocResource;
109             std::mutex m_mutex;
110             InitRemoteEnrolleeStatusCb m_initRemoteEnrolleeStatusCb;
111             RequestCapabilityStatusCb m_requestCapabilityStatusCb;
112             DataProvStatusCb m_dataProvStatusCb;
113             ProvConfig m_ProvConfig;
114             WiFiOnboadingConnection m_wifiOnboardingconn;
115             bool m_discoveryResponse;
116
117             void getCapabilityResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
118                     const int eCode);
119
120             void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
121                     const int eCode);
122
123             void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep,
124                     const int eCode);
125
126             ESResult ESDiscoveryTimeout(unsigned short waittime);
127
128             void onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource);
129
130             void triggerNetworkConnection();
131
132             void triggerNetworkConnectionCb(
133                     const HeaderOptions& headerOptions, const OCRepresentation& rep,
134                     const int eCode);
135         };
136     }
137 }
138 #endif