491f68abd309549918d94d59728d4cec305a4218
[platform/upstream/iotivity.git] / resource / include / OCCloudProvisioning.hpp
1 //****************************************************************\r
2 //\r
3 // Copyright 2016 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 OC_CLOUD_PROVISIONING_CXX_H_\r
22 #define OC_CLOUD_PROVISIONING_CXX_H_\r
23 \r
24 #include <thread>\r
25 \r
26 #include "occloudprovisioning.h"\r
27 #include "OCApi.h"\r
28 #include "OCPlatform_impl.h"\r
29 #include "CAManager.h"\r
30 \r
31 namespace OC\r
32 {\r
33     typedef std::function<void(OCStackResult result, void *data)> ResponseCallBack;\r
34     typedef std::function<void(OCStackResult result, std::string aclId)> AclIdResponseCallBack;\r
35 \r
36     /**\r
37      * Context to be passed to the underlying stack. This is passed back as argument\r
38      * to the callback function\r
39      */\r
40     struct CloudProvisionContext\r
41     {\r
42         ResponseCallBack callback;\r
43         CloudProvisionContext(ResponseCallBack cb) : callback(cb){}\r
44     };\r
45 \r
46     struct AclIdContext\r
47     {\r
48         AclIdResponseCallBack callback;\r
49         AclIdContext(AclIdResponseCallBack cb) : callback(cb){}\r
50     };\r
51 \r
52     class OCCloudProvisioning\r
53     {\r
54 \r
55         private:\r
56             OCDevAddr  m_devAddr;\r
57         public:\r
58 \r
59             /**\r
60              * API to construct the CloudProvisioning\r
61              * @param ipAddr address of the cloud server\r
62              * @param port port of the cloud server\r
63              */\r
64             OCCloudProvisioning(std::string& ipAddr, uint16_t port);\r
65             ~OCCloudProvisioning();\r
66 \r
67             void setIpAddr(std::string& ipAddr)\r
68             {\r
69                 memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);\r
70             }\r
71 \r
72             void setPort(uint16_t port)\r
73             {\r
74                 m_devAddr.port = port;\r
75             }\r
76 \r
77             /**\r
78              * API to Request a certificate from the cloud\r
79              * @param callback function called by the stack on completion of request\r
80              * @return ::OC_STACK_OK on Success and other values otherwise\r
81              */\r
82             OCStackResult requestCertificate(ResponseCallBack callback);\r
83 \r
84             /**\r
85              * API to get ACL ID for the device\r
86              * @param deviceId device ID for which the Acl ID is requested\r
87              * @param callback function called by the stack on completion of request\r
88              * @return ::OC_STACK_OK on Success and other values otherwise\r
89              */\r
90             OCStackResult getAclIdByDevice(const std::string& deviceId, AclIdResponseCallBack callback);\r
91 \r
92             /**\r
93              * API to get ACL information about the given Acl ID\r
94              * @param aclId ACL ID for which the Acl information is requested\r
95              * @param callback function called by the stack on completion of request\r
96              * @return ::OC_STACK_OK on Success and other values otherwise\r
97              */\r
98             OCStackResult getIndividualAclInfo(const std::string& aclId, ResponseCallBack callback);\r
99 \r
100             /**\r
101              * API to get certificate revocation list\r
102              * @param callback function called by the stack on completion of request\r
103              * @return ::OC_STACK_OK on Success and other values otherwise\r
104              */\r
105             OCStackResult getCRL(ResponseCallBack callback);\r
106 \r
107             /**\r
108              * API to post the  certificate revocation list to cloud\r
109              * @param thisUpdate thisUpdate [mandatory param]\r
110              * @param nextUpdate nextUpdate [mandatory param]\r
111              * @param crl revocation list [optional]\r
112              * @param serialNumbers [optional]\r
113              * @param callback function called by the stack on completion of request\r
114              * @return ::OC_STACK_OK on Success and other values otherwise\r
115              */\r
116             OCStackResult postCRL(const std::string& thisUpdate,\r
117                     const std::string& nextUpdate,\r
118                     const OCByteString *crl,\r
119                     const stringArray_t *serialNumbers,\r
120                     ResponseCallBack callback);\r
121 \r
122             /**\r
123              * Common callback wrapper for all the callback functions.\r
124              * @param ctx user context passed to the request API\r
125              * @param result result of the request performed\r
126              * @param data response data\r
127              */\r
128             static void callbackWrapper(void* ctx, OCStackResult result, void* data);\r
129 \r
130             /**\r
131              * Callback wrapper for Acl ID get request\r
132              * @param ctx user context passed to the request API\r
133              * @param result result of the request performed\r
134              * @param data AclID for the device\r
135              */\r
136             static void aclIdResponseWrapper(void* ctx, OCStackResult result, void* data);\r
137     };\r
138 }\r
139 #endif //OC_CLOUD_PROVISIONING_CXX_H_\r