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.h"
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;
60 m_csdkLock = OCPlatform_impl::Instance().csdkLock();
63 OCCloudProvisioning::~OCCloudProvisioning(void)
67 OCStackResult OCCloudProvisioning::requestCertificate(ResponseCallBack callback)
71 oclog() <<"Result callback can't be null";
72 return OC_STACK_INVALID_CALLBACK;
76 auto cLock = m_csdkLock.lock();
80 CloudProvisionContext *context = new CloudProvisionContext(callback);
82 std::lock_guard<std::recursive_mutex> lock(*cLock);
83 result = OCCloudCertificateIssueRequest(static_cast<void*>(context), &m_devAddr,
84 &OCCloudProvisioning::callbackWrapper);
88 oclog() <<"Mutex not found";
89 result = OC_STACK_ERROR;
94 OCStackResult OCCloudProvisioning::getIndividualAclInfo(const std::string& aclId,
95 ResponseCallBack callback)
99 oclog() <<"Result callback can't be null";
100 return OC_STACK_INVALID_CALLBACK;
103 OCStackResult result;
104 auto cLock = m_csdkLock.lock();
108 CloudProvisionContext *context = new CloudProvisionContext(callback);
110 std::lock_guard<std::recursive_mutex> lock(*cLock);
111 result = OCCloudAclIndividualGetInfo(static_cast<void*>(context), aclId.c_str(),
113 &OCCloudProvisioning::callbackWrapper);
117 oclog() <<"Mutex not found";
118 result = OC_STACK_ERROR;
123 OCStackResult OCCloudProvisioning::getAclIdByDevice(const std::string& deviceId,
124 AclIdResponseCallBack callback)
128 oclog() <<"Result callback can't be null";
129 return OC_STACK_INVALID_CALLBACK;
132 OCStackResult result;
133 auto cLock = m_csdkLock.lock();
137 AclIdContext *context = new AclIdContext(callback);
139 std::lock_guard<std::recursive_mutex> lock(*cLock);
140 result = OCCloudGetAclIdByDevice(static_cast<void*>(context), deviceId.c_str(),
142 &OCCloudProvisioning::aclIdResponseWrapper);
146 oclog() <<"Mutex not found";
147 result = OC_STACK_ERROR;
152 OCStackResult OCCloudProvisioning::getCRL(ResponseCallBack callback)
156 oclog() <<"Result callback can't be null";
157 return OC_STACK_INVALID_CALLBACK;
160 OCStackResult result;
161 auto cLock = m_csdkLock.lock();
165 CloudProvisionContext *context = new CloudProvisionContext(callback);
167 std::lock_guard<std::recursive_mutex> lock(*cLock);
168 result = OCCloudGetCRL(static_cast<void*>(context), &m_devAddr,
169 &OCCloudProvisioning::callbackWrapper);
173 oclog() <<"Mutex not found";
174 result = OC_STACK_ERROR;
179 OCStackResult OCCloudProvisioning::postCRL(const std::string& thisUpdate,
180 const std::string& nextUpdate,
181 const OCByteString *crl,
182 const stringArray_t *serialNumbers,
183 ResponseCallBack callback)
187 oclog() <<"Result callback can't be null";
188 return OC_STACK_INVALID_CALLBACK;
191 OCStackResult result;
192 auto cLock = m_csdkLock.lock();
196 CloudProvisionContext *context = new CloudProvisionContext(callback);
198 std::lock_guard<std::recursive_mutex> lock(*cLock);
199 result = OCCloudPostCRL(static_cast<void*>(context), thisUpdate.c_str(),
200 nextUpdate.c_str(), crl, serialNumbers, &m_devAddr,
201 &OCCloudProvisioning::callbackWrapper);
205 oclog() <<"Mutex not found";
206 result = OC_STACK_ERROR;