+ if(!isFound)
+ {
+ throw ESInvalidParameterException("A given OCResource has no batch interface");
+ }
+
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Skip to find a provisioning resource");
+ m_ocResource = resource;
+ m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
+ if (m_cloudResource == nullptr)
+ {
+ throw ESBadRequestException ("Cloud Resource not created");
+ }
+ }
+
+ /* NOTE: Execute cloud resource discovery and secure resource discovery in
+ different thread to avoid blocking of main event loop of Tizen */
+ std::thread cloudProvThread = std::thread([this, cloudProp]()
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties - thread IN");
+ try
+ {
+ // Discover easy-setup resource only if it is not provided by API caller
+ if(!m_cloudResource)
+ {
+ initCloudResource();
+ if (m_cloudResource == nullptr)
+ {
+ OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG, "Cloud resource is not created");
+ std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
+ CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE);
+ m_cloudPropProvStatusCb(provStatus);
+ return;
+ }
+ }
+ }
+ catch (const std::exception& e)
+ {
+ OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
+ "Exception caught in provisionCloudProperties = %s", e.what());
+
+ std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
+ CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE);
+ m_cloudPropProvStatusCb(provStatus);
+ return;
+ }
+
+#if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
+ if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0))
+ {
+ ESResult res = ESResult::ES_ERROR;
+ if(!m_cloudEnrolleeSecurity.get())
+ {
+ m_cloudEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
+ }
+
+
+ res = m_cloudEnrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(),
+ cloudProp.getCredID());
+
+ if(res != ESResult::ES_OK)
+ {
+ m_cloudResource = nullptr;
+ std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
+ CloudPropProvisioningStatus >(res);
+ m_cloudPropProvStatusCb(provStatus);
+ return;
+ }
+ }
+ else
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped.");
+ }
+#endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
+
+ CloudPropProvStatusCb cloudPropProvStatusCb = std::bind(
+ &RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback,
+ std::placeholders::_1,
+ shared_from_this());
+
+ m_cloudResource->registerCloudPropProvisioningStatusCallback(cloudPropProvStatusCb);
+ m_cloudResource->provisionProperties(cloudProp);
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties - thread OUT");
+ });
+
+ // TODO: Join thread
+ cloudProvThread.detach();
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties OUT");
+ }
+#endif