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