From: Jihun Ha Date: Tue, 27 Dec 2016 05:22:00 +0000 (+0900) Subject: Add an API to cloud provisioning with a given OCResource object X-Git-Tag: 1.3.0~949 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=202a2e3d6671c012bef6aab5136c3ac6d0ac2735;p=platform%2Fupstream%2Fiotivity.git Add an API to cloud provisioning with a given OCResource object When a user wants to do cloud provisioning with a specific OCResource object, the added API can be used and expected that a resource discovery in a current connectivity for cloud provisioning is skipped. Change-Id: Ic93da14b39e7576e413442b00db28ed3a6fc4890 Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/15947 Tested-by: jenkins-iotivity Reviewed-by: Heewon Park Reviewed-by: Senthil Kumar G S Reviewed-by: Uze Choi --- diff --git a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h index 5f1008f..450b151 100755 --- a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h @@ -59,6 +59,7 @@ namespace OIC * * @param callback will give the requested status * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * * @see GetStatusCb @@ -70,6 +71,7 @@ namespace OIC * * @param callback will give the requested configuration * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * * @see GetConfigurationStatusCb @@ -81,6 +83,7 @@ namespace OIC * * @param callback will give the result if the security provisioning succeeds or fails for some reasons * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * * @see SecurityProvStatusCb @@ -94,6 +97,7 @@ namespace OIC * * @param callback will give the result if the security provisioning succeeds or fails for some reasons. * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * * @see SecurityProvStatusCb @@ -108,6 +112,7 @@ namespace OIC * @param devProp a data structure storing the above information to be delivered * @param callback will give the result if the provisioning succeeds or fails * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * * @see DeviceProp @@ -127,6 +132,7 @@ namespace OIC * @param cloudProp a data structure storing the above information to be delivered * @param callback will give the result if the provisioning succeeds or fails * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * * @see CloudProp @@ -135,6 +141,26 @@ namespace OIC void provisionCloudProperties(const CloudProp& cloudProp, const CloudPropProvStatusCb callback); + /** + * Provision Cloud information to Enrollee, which includes Auth code, auth provider, + * Cloud interface server URL, and etc. + * Note that, this API is skipping finding Enrollee in a given network. Instead, an OCResource + * given as a first parameter will be considered to the Enrollee for cloud provisioning. + * + * @param resource an OCResource corresponding to a target Enrollee for cloud provisioning + * @param cloudProp a data structure storing the above information to be delivered + * @param callback will give the result if the provisioning succeeds or fails + * + * @throws ESInvalidParameterException If callback is null. + * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. + * + * @see CloudProp + * @see CloudPropProvStatusCb + */ + void provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource, + const CloudProp& cloudProp, + const CloudPropProvStatusCb callback); + private: RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource); diff --git a/service/easy-setup/mediator/richsdk/src/EasySetup.cpp b/service/easy-setup/mediator/richsdk/src/EasySetup.cpp index 73eab32..4fcc332 100755 --- a/service/easy-setup/mediator/richsdk/src/EasySetup.cpp +++ b/service/easy-setup/mediator/richsdk/src/EasySetup.cpp @@ -70,6 +70,7 @@ namespace OIC OIC_LOG_V (DEBUG, EASYSETUP_TAG, "HOST: %s", resource->host().c_str()); OIC_LOG_V (DEBUG, EASYSETUP_TAG, "URI: %s", resource->uri().c_str()); OIC_LOG_V (DEBUG, EASYSETUP_TAG, "SID: %s", resource->sid().c_str()); + OIC_LOG_V (DEBUG, EASYSETUP_TAG, "CONNECTIVITY: %d", resource->connectivityType()); return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee(resource)); } } diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp index f059aab..31ae394 100755 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp @@ -425,6 +425,17 @@ namespace OIC void RemoteEnrollee::provisionCloudProperties(const CloudProp& cloudProp, const CloudPropProvStatusCb callback) { + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource IN"); + + provisionCloudProperties(NULL, cloudProp, callback); + + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource OUT"); + } + + void RemoteEnrollee::provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource, + const CloudProp& cloudProp, + const CloudPropProvStatusCb callback) + { OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties IN"); if(!callback) @@ -441,11 +452,49 @@ namespace OIC throw ESBadRequestException ("Invalid Cloud Provisiong Info."); } - try + if(resource) { - initCloudResource(); + if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_PROV || + resource->connectivityType() & CT_ADAPTER_TCP) + { + OIC_LOG (ERROR, ES_REMOTE_ENROLLEE_TAG, "Given resource is not valid due to wrong rt or conntype"); + throw ESInvalidParameterException("A given OCResource is wrong"); + } + + auto interfaces = resource->getResourceInterfaces(); + bool isFound = false; + for(auto interface : interfaces) + { + if(interface.compare(BATCH_INTERFACE) == 0) + { + OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "RemoteEnrollee object is succeessfully created"); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "HOST: %s", resource->host().c_str()); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "URI: %s", resource->uri().c_str()); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "SID: %s", resource->sid().c_str()); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "CONNECTIVITY: %d", resource->connectivityType()); + isFound = true; + } + } + + if(!isFound) + { + throw ESInvalidParameterException("A given OCResource has no batch interface"); + } } + try + { + if(resource == NULL) + { + initCloudResource(); + } + else + { + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Skip to find a provisioning resource"); + m_ocResource = resource; + m_cloudResource = std::make_shared(m_ocResource); + } + } catch (const std::exception& e) { OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,