1 /* *****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * *****************************************************************/
22 #include "OCCloudProvisioning.hpp"
26 void OCCloudProvisioning::callbackWrapper(void *ctx,
30 CloudProvisionContext* context = static_cast<CloudProvisionContext*>(ctx);
32 std::thread exec(context->callback, result, data);
38 void OCCloudProvisioning::aclIdResponseWrapper(void *ctx,
42 std::string aclId = "";
43 AclIdContext* context = static_cast<AclIdContext*>(ctx);
45 if ((OC_STACK_OK == result) && data)
49 std::thread exec(context->callback, result, aclId);
55 OCCloudProvisioning::OCCloudProvisioning(std::string& ipAddr, uint16_t port)
57 memset(&m_devAddr, 0, sizeof(m_devAddr));
58 memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);
59 m_devAddr.port = port;
62 OCCloudProvisioning::~OCCloudProvisioning(void)
66 OCStackResult OCCloudProvisioning::requestCertificate(ResponseCallBack callback)
70 oclog() <<"Result callback can't be null";
71 return OC_STACK_INVALID_CALLBACK;
75 auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
79 CloudProvisionContext *context = new CloudProvisionContext(callback);
81 std::lock_guard<std::recursive_mutex> lock(*cLock);
82 result = OCCloudCertificateIssueRequest(static_cast<void*>(context), &m_devAddr,
83 &OCCloudProvisioning::callbackWrapper);
87 oclog() <<"Mutex not found";
88 result = OC_STACK_ERROR;
93 OCStackResult OCCloudProvisioning::getIndividualAclInfo(const std::string& aclId,
94 ResponseCallBack callback)
98 oclog() <<"Result callback can't be null";
99 return OC_STACK_INVALID_CALLBACK;
102 OCStackResult result;
103 auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
107 CloudProvisionContext *context = new CloudProvisionContext(callback);
109 std::lock_guard<std::recursive_mutex> lock(*cLock);
110 result = OCCloudAclIndividualGetInfo(static_cast<void*>(context), aclId.c_str(),
112 &OCCloudProvisioning::callbackWrapper);
116 oclog() <<"Mutex not found";
117 result = OC_STACK_ERROR;
122 OCStackResult OCCloudProvisioning::getAclIdByDevice(const std::string& deviceId,
123 AclIdResponseCallBack callback)
127 oclog() <<"Result callback can't be null";
128 return OC_STACK_INVALID_CALLBACK;
131 OCStackResult result;
132 auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
136 AclIdContext *context = new AclIdContext(callback);
138 std::lock_guard<std::recursive_mutex> lock(*cLock);
139 result = OCCloudGetAclIdByDevice(static_cast<void*>(context), deviceId.c_str(),
141 &OCCloudProvisioning::aclIdResponseWrapper);
145 oclog() <<"Mutex not found";
146 result = OC_STACK_ERROR;
151 OCStackResult OCCloudProvisioning::getCRL(ResponseCallBack callback)
155 oclog() <<"Result callback can't be null";
156 return OC_STACK_INVALID_CALLBACK;
159 OCStackResult result;
160 auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
164 CloudProvisionContext *context = new CloudProvisionContext(callback);
166 std::lock_guard<std::recursive_mutex> lock(*cLock);
167 result = OCCloudGetCRL(static_cast<void*>(context), &m_devAddr,
168 &OCCloudProvisioning::callbackWrapper);
172 oclog() <<"Mutex not found";
173 result = OC_STACK_ERROR;
178 OCStackResult OCCloudProvisioning::postCRL(const std::string& thisUpdate,
179 const std::string& nextUpdate,
180 const OCByteString *crl,
181 const stringArray_t *serialNumbers,
182 ResponseCallBack callback)
186 oclog() <<"Result callback can't be null";
187 return OC_STACK_INVALID_CALLBACK;
190 OCStackResult result;
191 auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
195 CloudProvisionContext *context = new CloudProvisionContext(callback);
197 std::lock_guard<std::recursive_mutex> lock(*cLock);
198 result = OCCloudPostCRL(static_cast<void*>(context), thisUpdate.c_str(),
199 nextUpdate.c_str(), crl, serialNumbers, &m_devAddr,
200 &OCCloudProvisioning::callbackWrapper);
204 oclog() <<"Mutex not found";
205 result = OC_STACK_ERROR;