019a51494f00f3d7c39029c82c4f7d7dc41a6980
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / RemoteEnrolleeResource.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_RESOURCE_H_
22 #define REMOTE_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 RemoteEnrolleeResource
44          */
45         class RemoteEnrolleeResource
46         {
47             friend class EnrolleeSecurity;
48
49         public:
50             typedef std::shared_ptr< RemoteEnrolleeResource > Ptr;
51
52             typedef std::function< void(std::shared_ptr< ProvisioningStatus >) > ProvStatusCb;
53
54             /**
55              * RemoteEnrolleeResource constructor
56              *
57              * @param enrolleeNWProvInfo Provisioning information for the Enrollee
58              *
59              * @throw ESBadRequestException is thrown if the parameters are invalid
60              */
61             RemoteEnrolleeResource(ProvConfig enrolleeNWProvInfo, WiFiOnboadingConnection onboardingconn);
62
63             ~RemoteEnrolleeResource() = default;
64
65             /**
66              * Register provisioning status handler.
67              *
68              * @param callback Callback to get Provisioning status.
69              *
70              * @throws InvalidParameterException If callback is an empty function or null.
71              * @throws ESBadRequestException If registration is already completed.
72              *
73              * @see ProvisioningStatus
74              */
75             void registerProvStatusCallback (ProvStatusCb provStatusCb);
76
77             /**
78              * Construct Remote OIC resource using the enrollee host and connectivity information
79              * provided in the constructor of RemoteEnrolleeResource.
80              *
81              * @throws InvalidParameterException If the provided information is invalid.
82              * @throws ESBadRequestException If resource is already constructed.
83              *
84              * @see ProvisioningStatus
85              */
86             ESResult constructResourceObject();
87
88             /**
89              * Function for provisioning of Remote Enrollee resource using the information provided.
90              *
91              * @throws InvalidParameterException If cb is empty.
92              */
93             void provisionEnrollee();
94
95             /**
96              * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state
97              *
98              * @throws ESBadRequestException If device is not provisioned already.
99              */
100             void unprovisionEnrollee();
101
102
103
104         private:
105             std::shared_ptr< OC::OCResource > m_ocResource;
106             std::mutex m_mutex;
107             ProvStatusCb m_provStatusCb;
108             ProvConfig m_ProvConfig;
109             WiFiOnboadingConnection m_wifiOnboardingconn;
110             bool m_discoveryResponse;
111
112             void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
113                     const int eCode);
114
115             void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep,
116                     const int eCode);
117
118             ESResult ESDiscoveryTimeout(unsigned short waittime);
119
120             void onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource);
121
122             void triggerNetworkConnection();
123
124             void triggerNetworkConnectionCb(
125                     const HeaderOptions& headerOptions, const OCRepresentation& rep,
126                     const int eCode);
127         };
128     }
129 }
130 #endif