1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "RemoteEnrollee.h"
22 #include "EnrolleeResource.h"
23 #include "CloudResource.h"
24 #include "OCPlatform.h"
25 #include "ESException.h"
27 #include "OCResource.h"
28 #include "oic_string.h"
30 #include "EnrolleeSecurity.h"
32 #include "oic_malloc.h"
40 static const char ES_BASE_RES_URI[] = "/oic/res";
41 #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"
42 #define DISCOVERY_TIMEOUT 1
44 RemoteEnrollee::RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource)
46 m_ocResource = resource;
47 m_enrolleeResource = std::make_shared<EnrolleeResource>(m_ocResource);
48 m_securityProvStatusCb = nullptr;
49 m_getConfigurationStatusCb = nullptr;
50 m_securityPinCb = nullptr;
51 m_secProvisioningDbPathCb = nullptr;
52 m_devicePropProvStatusCb = nullptr;
53 m_cloudPropProvStatusCb = nullptr;
54 m_connectRequestStatusCb = nullptr;
56 m_deviceId = resource->sid();
59 void RemoteEnrollee::onSecurityStatusHandlerCallback(
60 const std::shared_ptr< SecProvisioningStatus > status,
61 std::weak_ptr<RemoteEnrollee> this_ptr)
63 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onSecurityStatusHandlerCallback");
64 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
67 Ptr->securityStatusHandler(status);
71 void RemoteEnrollee::securityStatusHandler(
72 const std::shared_ptr< SecProvisioningStatus > status) const
74 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusHandlr IN");
75 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "UUID = %s", status->getDeviceUUID().c_str());
76 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "ESResult = %d", status->getESResult());
78 if(status->getESResult() == ES_OK)
80 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Ownership transfer is successfully done.");
81 m_securityProvStatusCb(status);
85 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG, "Ownership transfer is failed.");
86 m_securityProvStatusCb(status);
88 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusHandlr OUT");
91 ESOwnershipTransferData RemoteEnrollee::onSecurityStatusWithOptionHandlerCallback(
92 const std::shared_ptr< SecProvisioningStatus > status,
93 std::weak_ptr<RemoteEnrollee> this_ptr)
95 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onSecurityStatusWithOptionHandlerCallback");
96 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
99 return Ptr->securityStatusWithOptionHandler(status);
101 return ESOwnershipTransferData();
104 ESOwnershipTransferData RemoteEnrollee::securityStatusWithOptionHandler(
105 const std::shared_ptr< SecProvisioningStatus > status) const
107 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusWithOptionHandler IN");
108 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "UUID = %s", status->getDeviceUUID().c_str());
109 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "ESResult = %d", status->getESResult());
111 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusWithOptionHandler OUT");
112 return m_securityProvStatusCbWithOption(status);
115 void RemoteEnrollee::onGetStatusHandlerCallback(
116 const std::shared_ptr< GetEnrolleeStatus > status,
117 std::weak_ptr<RemoteEnrollee> this_ptr)
119 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onGetStatusHandlerCallback");
120 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
123 Ptr->getStatusHandler(status);
127 void RemoteEnrollee::getStatusHandler(
128 const std::shared_ptr< GetEnrolleeStatus > status) const
130 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler IN");
132 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler = %d",
133 status->getESResult());
134 m_getStatusCb(status);
136 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler OUT");
139 void RemoteEnrollee::onGetConfigurationStatusHandlerCallback(
140 const std::shared_ptr< GetConfigurationStatus > status,
141 std::weak_ptr<RemoteEnrollee> this_ptr)
143 OIC_LOG(INFO,ES_REMOTE_ENROLLEE_TAG,"onGetConfigurationStatusHandlerCallback");
144 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
147 Ptr->getConfigurationStatusHandler(status);
151 void RemoteEnrollee::getConfigurationStatusHandler (
152 const std::shared_ptr< GetConfigurationStatus > status) const
154 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfigurationStatusHandler IN");
156 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG,"GetConfigurationStatus = %d",
157 status->getESResult());
158 m_getConfigurationStatusCb(status);
160 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfigurationStatusHandler OUT");
163 void RemoteEnrollee::onDevicePropProvisioningStatusHandlerCallback(
164 const std::shared_ptr< DevicePropProvisioningStatus > status,
165 std::weak_ptr<RemoteEnrollee> this_ptr)
167 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onDevicePropProvisioningStatusHandlerCallback");
168 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
171 Ptr->devicePropProvisioningStatusHandler(status);
175 void RemoteEnrollee::devicePropProvisioningStatusHandler(
176 const std::shared_ptr< DevicePropProvisioningStatus > status) const
178 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "devicePropProvisioningStatusHandler IN");
180 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "DeviceProvStatus = %d", status->getESResult());
181 m_devicePropProvStatusCb(status);
183 if( m_ocResource.get() != nullptr &&
184 !(m_ocResource->connectivityType() & CT_ADAPTER_GATT_BTLE) &&
185 ES_OK == status->getESResult() )
187 // NOTE: Temporary patch
188 CAEndpoint_t endpoint = {.adapter = CA_ADAPTER_IP};
190 OCDevAddr address = m_ocResource->getDevAddr();
191 OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE, address.addr);
192 endpoint.port = address.port;
194 OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "HOST = %s", endpoint.addr);
195 OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "PORT = %u", endpoint.port);
196 CAcloseSslSession(&endpoint);
199 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "devicePropProvisioningStatusHandler OUT");
202 void RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback(
203 const std::shared_ptr< CloudPropProvisioningStatus > status,
204 std::weak_ptr<RemoteEnrollee> this_ptr)
206 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onCloudPropProvisioningStatusHandlerCallback");
207 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
210 Ptr->cloudPropProvisioningStatusHandler(status);
214 void RemoteEnrollee::cloudPropProvisioningStatusHandler (
215 const std::shared_ptr< CloudPropProvisioningStatus > status) const
217 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "cloudPropProvisioningStatusHandler IN");
219 OIC_LOG_V(INFO,ES_REMOTE_ENROLLEE_TAG,"CloudProvStatus = %d",
220 status->getESResult());
221 m_cloudPropProvStatusCb(status);
223 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "cloudPropProvisioningStatusHandler OUT");
226 void RemoteEnrollee::onConnectRequestStatusHandlerCallback(
227 const std::shared_ptr< ConnectRequestStatus > status,
228 std::weak_ptr<RemoteEnrollee> this_ptr)
230 OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onConnectRequestStatusHandlerCallback");
231 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
234 Ptr->connectRequestStatusHandler(status);
238 void RemoteEnrollee::connectRequestStatusHandler(
239 const std::shared_ptr< ConnectRequestStatus > status) const
241 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connectRequestStatusHandler IN");
243 OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "RequestConnectStatus = %d", status->getESResult());
244 m_connectRequestStatusCb(status);
246 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connectRequestStatusHandler OUT");
249 void RemoteEnrollee::onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
250 std::weak_ptr<RemoteEnrollee> this_ptr)
252 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onDiscoveredCallback()");
253 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
256 Ptr->onDeviceDiscovered(resource);
260 void RemoteEnrollee::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
262 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered IN");
268 if(!(resource->connectivityType() & CT_ADAPTER_TCP))
270 std::string resourceURI;
271 std::string hostAddress;
272 std::string hostDeviceID;
274 // Get the resource URI
275 resourceURI = resource->uri();
276 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG,
277 "URI of the resource: %s", resourceURI.c_str());
279 // Get the resource host address
280 hostAddress = resource->host();
281 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG,
282 "Host address of the resource: %s", hostAddress.c_str());
284 hostDeviceID = resource->sid();
285 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG,
286 "Host DeviceID of the resource: %s", hostDeviceID.c_str());
288 if(!m_deviceId.empty() && m_deviceId == hostDeviceID)
290 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Find matched resource for cloud provisioning");
291 m_ocResource = resource;
292 m_discoveryResponse = true;
298 catch(std::exception& e)
300 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG,
301 "Exception in foundResource: %s", e.what());
304 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered OUT");
307 ESResult RemoteEnrollee::discoverResource()
309 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "discoverResource IN");
311 std::string query("");
312 query.append(ES_BASE_RES_URI);
313 query.append("?rt=");
314 query.append(OC_RSRVD_ES_RES_TYPE_EASYSETUP);
316 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "query = %s", query.c_str());
318 m_discoveryResponse = false;
320 onDeviceDiscoveredCb cb = std::bind(&RemoteEnrollee::onDiscoveredCallback,
321 std::placeholders::_1,
324 OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT, cb);
326 if (result != OCStackResult::OC_STACK_OK)
328 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
329 "Failed discoverResource");
333 std::unique_lock<std::mutex> lck(m_discoverymtx);
334 m_cond.wait_for(lck, std::chrono::seconds(DISCOVERY_TIMEOUT));
336 if (!m_discoveryResponse)
338 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
339 "Failed discoverResource because timeout");
346 void RemoteEnrollee::provisionSecurity(const SecurityProvStatusCb callback)
348 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity IN");
350 ESResult res = ESResult::ES_ERROR;
353 throw ESInvalidParameterException("Callback is empty");
355 m_securityProvStatusCb = callback;
357 SecurityProvStatusCb securityProvStatusCb = std::bind(
358 &RemoteEnrollee::onSecurityStatusHandlerCallback,
359 std::placeholders::_1,
361 //TODO : DBPath is passed empty as of now. Need to take dbpath from application.
362 if(!m_localEnrolleeSecurity.get())
364 m_localEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
367 res = m_localEnrolleeSecurity->provisionOwnership(NULL);
369 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
370 std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
371 securityProvStatusCb(securityProvisioningStatus);
373 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured built.");
377 throw ESInvalidParameterException("Callback is empty");
379 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
380 std::make_shared< SecProvisioningStatus >
381 ("", ESResult::ES_SEC_OPERATION_IS_NOT_SUPPORTED);
382 callback(securityProvisioningStatus);
384 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity OUT");
387 void RemoteEnrollee::provisionSecurity(const SecurityProvStatusCbWithOption callback)
389 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity IN");
391 ESResult res = ESResult::ES_ERROR;
394 throw ESInvalidParameterException("Callback is empty");
396 m_securityProvStatusCbWithOption = callback;
398 SecurityProvStatusCbWithOption securityProvStatusCbWithOption = std::bind(
399 &RemoteEnrollee::onSecurityStatusWithOptionHandlerCallback,
400 std::placeholders::_1,
403 if(!m_localEnrolleeSecurity.get())
405 m_localEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
408 res = m_localEnrolleeSecurity->provisionOwnership(securityProvStatusCbWithOption);
410 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
411 std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
412 securityProvStatusCbWithOption(securityProvisioningStatus);
414 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured built.");
418 throw ESInvalidParameterException("Callback is empty");
420 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
421 std::make_shared< SecProvisioningStatus >
422 ("", ESResult::ES_SEC_OPERATION_IS_NOT_SUPPORTED);
423 callback(securityProvisioningStatus);
425 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity OUT");
428 void RemoteEnrollee::getStatus(const GetStatusCb callback)
430 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatus IN");
434 throw ESInvalidParameterException("Callback is empty");
437 if (m_enrolleeResource == nullptr)
439 throw ESBadRequestException ("Device not created");
442 m_getStatusCb = callback;
444 GetStatusCb getStatusCb = std::bind(
445 &RemoteEnrollee::onGetStatusHandlerCallback,
446 std::placeholders::_1,
449 m_enrolleeResource->registerGetStatusCallback(getStatusCb);
450 m_enrolleeResource->getStatus();
452 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatus OUT");
455 void RemoteEnrollee::getConfiguration(const GetConfigurationStatusCb callback)
457 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfiguration IN");
461 throw ESInvalidParameterException("Callback is empty");
464 if (m_enrolleeResource == nullptr)
466 throw ESBadRequestException ("Device not created");
469 m_getConfigurationStatusCb = callback;
471 GetConfigurationStatusCb getConfigurationStatusCb = std::bind(
472 &RemoteEnrollee::onGetConfigurationStatusHandlerCallback,
473 std::placeholders::_1,
476 m_enrolleeResource->registerGetConfigurationStatusCallback(getConfigurationStatusCb);
477 m_enrolleeResource->getConfiguration();
479 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfiguration OUT");
482 void RemoteEnrollee::provisionDeviceProperties(const DeviceProp& deviceProp,
483 const DevicePropProvStatusCb callback)
485 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionDeviceProperties IN");
489 throw ESInvalidParameterException("Callback is empty");
492 m_devicePropProvStatusCb = callback;
494 if (m_enrolleeResource == nullptr)
496 throw ESBadRequestException ("Device not created");
499 DevicePropProvStatusCb devicePropProvStatusCb = std::bind(
500 &RemoteEnrollee::onDevicePropProvisioningStatusHandlerCallback,
501 std::placeholders::_1,
504 m_enrolleeResource->registerDevicePropProvStatusCallback(devicePropProvStatusCb);
505 m_enrolleeResource->provisionProperties(deviceProp);
507 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionDeviceProperties OUT");
510 void RemoteEnrollee::initCloudResource()
512 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "initCloudResource IN");
514 ESResult result = ES_ERROR;
516 result = discoverResource();
518 if (result == ES_ERROR)
520 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
521 "Failed to create resource object using discoverResource");
522 throw ESBadRequestException ("Resource object not created");
527 if(m_ocResource != nullptr)
529 m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
533 throw ESBadGetException ("Resource handle is invalid");
537 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "initCloudResource OUT");
540 void RemoteEnrollee::provisionCloudProperties(const CloudProp& cloudProp,
541 const CloudPropProvStatusCb callback)
543 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource IN");
545 provisionCloudProperties(NULL, cloudProp, callback);
547 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource OUT");
550 void RemoteEnrollee::provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
551 const CloudProp& cloudProp,
552 const CloudPropProvStatusCb callback)
554 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties IN");
558 throw ESInvalidParameterException("Callback is empty");
561 m_cloudPropProvStatusCb = callback;
563 if((cloudProp.getAuthCode().empty() && cloudProp.getAccessToken().empty()) ||
564 cloudProp.getAuthProvider().empty() ||
565 cloudProp.getCiServer().empty())
567 throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
572 if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_EASYSETUP ||
573 resource->connectivityType() & CT_ADAPTER_TCP)
575 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG, "Given resource is not valid due to wrong rt or conntype");
576 throw ESInvalidParameterException("A given OCResource is wrong");
579 auto interfaces = resource->getResourceInterfaces();
580 bool isFound = false;
581 for(auto interface : interfaces)
583 if(interface.compare(BATCH_INTERFACE) == 0)
585 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "RemoteEnrollee object is succeessfully created");
586 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "HOST: %s", resource->host().c_str());
587 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "URI: %s", resource->uri().c_str());
588 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "SID: %s", resource->sid().c_str());
589 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "CONNECTIVITY: %d", resource->connectivityType());
596 throw ESInvalidParameterException("A given OCResource has no batch interface");
608 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Skip to find a provisioning resource");
609 m_ocResource = resource;
610 m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
613 catch (const std::exception& e)
615 OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
616 "Exception caught in provisionCloudProperties = %s", e.what());
618 std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
619 CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE);
620 m_cloudPropProvStatusCb(provStatus);
623 #if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
624 if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0))
626 ESResult res = ESResult::ES_ERROR;
627 if(!m_cloudEnrolleeSecurity.get())
629 m_cloudEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
633 res = m_cloudEnrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(),
634 cloudProp.getCredID());
636 if(res != ESResult::ES_OK)
638 m_cloudResource = nullptr;
639 std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
640 CloudPropProvisioningStatus >(res);
641 m_cloudPropProvStatusCb(provStatus);
647 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped.");
649 #endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
651 if (m_cloudResource == nullptr)
653 throw ESBadRequestException ("Cloud Resource not created");
656 CloudPropProvStatusCb cloudPropProvStatusCb = std::bind(
657 &RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback,
658 std::placeholders::_1,
661 m_cloudResource->registerCloudPropProvisioningStatusCallback(cloudPropProvStatusCb);
662 m_cloudResource->provisionProperties(cloudProp);
664 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties OUT");
667 void RemoteEnrollee::requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes, const ConnectRequestStatusCb callback)
669 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connect IN");
673 throw ESInvalidParameterException("Callback is empty");
676 m_connectRequestStatusCb = callback;
678 ConnectRequestStatusCb connectRequestStatusCb = std::bind(
679 &RemoteEnrollee::onConnectRequestStatusHandlerCallback,
680 std::placeholders::_1,
683 m_enrolleeResource->registerConnectRequestStatusCallback(connectRequestStatusCb);
684 m_enrolleeResource->requestToConnect(connectTypes);
686 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connect OUT");