[ENROLLEE] Tizen enrollee sample application build using scons command
[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 "escommon.h"
28 #include "Utility.h"
29
30 #include "OCApi.h"
31
32 using namespace OC;
33
34 namespace OIC
35 {
36     namespace Service
37     {
38         class OCResource;
39         class EnrolleeSecurity;
40
41         /**
42          * This class contains the resource discovery methods.
43          *
44          * @see RemoteEnrolleeResource
45          */
46         class RemoteEnrolleeResource
47         {
48             friend class EnrolleeSecurity;
49
50         public:
51             typedef std::shared_ptr< RemoteEnrolleeResource > Ptr;
52
53             typedef std::function< void(std::shared_ptr< ProvisioningStatus >) > ProvStatusCb;
54
55             /**
56              * RemoteEnrolleeResource constructor
57              *
58              * @param enrolleeNWProvInfo Provisioning information for the Enrollee
59              *
60              * @throw ESBadRequestException is thrown if the parameters are invalid
61              */
62             RemoteEnrolleeResource(EnrolleeNWProvInfo enrolleeNWProvInfo);
63
64             ~RemoteEnrolleeResource() = default;
65
66             /**
67              * Register provisioning status handler.
68              *
69              * @param callback Callback to get Provisioning status.
70              *
71              * @throws InvalidParameterException If callback is an empty function or null.
72              * @throws ESBadRequestException If registration is already completed.
73              *
74              * @see ProvisioningStatus
75              */
76             void registerProvStatusCallback (ProvStatusCb provStatusCb);
77
78             /**
79              * Construct Remote OIC resource using the enrollee host and connectivity information
80              * provided in the constructor of RemoteEnrolleeResource.
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             /**
90              * Function for provisioning of Remote Enrollee resource using the information provided.
91              *
92              * @throws InvalidParameterException If cb is empty.
93              */
94             void provisionEnrollee();
95
96             /**
97              * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state
98              *
99              * @throws ESBadRequestException If device is not provisioned already.
100              */
101             void unprovisionEnrollee();
102
103
104
105         private:
106             std::shared_ptr< OC::OCResource > m_ocResource;
107             std::mutex m_mutex;
108             ProvStatusCb m_provStatusCb;
109             EnrolleeNWProvInfo m_enrolleeNWProvInfo;
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     }
123 }
124 #endif