69a4f6541f4ab136055832f14afca3de62677e97
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / src / RemoteEnrolleeResource.h
1 //******************************************************************\r
2 //\r
3 // Copyright 2015 Samsung Electronics All Rights Reserved.\r
4 //\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
6 //\r
7 // Licensed under the Apache License, Version 2.0 (the "License");\r
8 // you may not use this file except in compliance with the License.\r
9 // You may obtain a copy of the License at\r
10 //\r
11 //      http://www.apache.org/licenses/LICENSE-2.0\r
12 //\r
13 // Unless required by applicable law or agreed to in writing, software\r
14 // distributed under the License is distributed on an "AS IS" BASIS,\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16 // See the License for the specific language governing permissions and\r
17 // limitations under the License.\r
18 //\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
20 \r
21 #ifndef REMOTE_ENROLLEE_RESOURCE_H_\r
22 #define REMOTE_ENROLLEE_RESOURCE_H_\r
23 \r
24 #include <mutex>\r
25 #include <memory>\r
26 \r
27 #include "escommon.h"\r
28 \r
29 #include "OCApi.h"\r
30 \r
31 using namespace OC;\r
32 \r
33 namespace OIC\r
34 {\r
35     namespace Service\r
36     {\r
37         class OCResource;\r
38         class EnrolleeSecurity;\r
39 \r
40         /**\r
41          * This class contains the resource discovery methods.\r
42          *\r
43          * @see RemoteEnrolleeResource\r
44          */\r
45         class RemoteEnrolleeResource\r
46         {\r
47             friend class EnrolleeSecurity;\r
48 \r
49         public:\r
50             typedef std::shared_ptr< RemoteEnrolleeResource > Ptr;\r
51 \r
52             typedef std::function< void(std::shared_ptr< ProvisioningStatus >) > ProvStatusCb;\r
53 \r
54             /**\r
55              * RemoteEnrolleeResource constructor\r
56              *\r
57              * @param enrolleeNWProvInfo Provisioning information for the Enrollee\r
58              *\r
59              * @throw ESBadRequestException is thrown if the parameters are invalid\r
60              */\r
61             RemoteEnrolleeResource(EnrolleeNWProvInfo enrolleeNWProvInfo);\r
62 \r
63             ~RemoteEnrolleeResource() = default;\r
64 \r
65             /**\r
66              * Register provisioning status handler.\r
67              *\r
68              * @param callback Callback to get Provisioning status.\r
69              *\r
70              * @throws InvalidParameterException If callback is an empty function or null.\r
71              * @throws ESBadRequestException If registration is already completed.\r
72              *\r
73              * @see ProvisioningStatus\r
74              */\r
75             void registerProvStatusCallback (ProvStatusCb provStatusCb);\r
76 \r
77             /**\r
78              * Construct Remote OIC resource using the enrollee host and connectivity information\r
79              * provided in the constructor of RemoteEnrolleeResource.\r
80              *\r
81              * @throws InvalidParameterException If the provided information is invalid.\r
82              * @throws ESBadRequestException If resource is already constructed.\r
83              *\r
84              * @see ProvisioningStatus\r
85              */\r
86             ESResult constructResourceObject();\r
87 \r
88             /**\r
89              * Function for provisioning of Remote Enrollee resource using the information provided.\r
90              *\r
91              * @throws InvalidParameterException If cb is empty.\r
92              */\r
93             void provisionEnrollee();\r
94 \r
95             /**\r
96              * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state\r
97              *\r
98              * @throws ESBadRequestException If device is not provisioned already.\r
99              */\r
100             void unprovisionEnrollee();\r
101 \r
102 \r
103 \r
104         private:\r
105             std::shared_ptr< OC::OCResource > m_ocResource;\r
106             std::mutex m_mutex;\r
107             ProvStatusCb m_provStatusCb;\r
108             EnrolleeNWProvInfo m_enrolleeNWProvInfo;\r
109             bool m_discoveryResponse;\r
110 \r
111             void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
112                     const int eCode);\r
113 \r
114             void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
115                     const int eCode);\r
116 \r
117             ESResult ESDiscoveryTimeout(unsigned short waittime);\r
118 \r
119             void onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource);\r
120         };\r
121     }\r
122 }\r
123 #endif\r