From: Parkhi Date: Fri, 28 Oct 2016 07:51:28 +0000 (+0900) Subject: Change a timeout for resource discovery in cloud provisioning X-Git-Tag: 1.2.1~196 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=561c12914f83be035d38057e5f3e24579a1283af;p=platform%2Fupstream%2Fiotivity.git Change a timeout for resource discovery in cloud provisioning Change-Id: Id211ff2afab83cdeaaaf68162ca9d5cdbffeca8a Signed-off-by: Parkhi Reviewed-on: https://gerrit.iotivity.org/gerrit/13851 Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h index a58dacb..30ef55c 100755 --- a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h @@ -39,6 +39,8 @@ namespace OIC class CloudResource; class EnrolleeSecurity; + typedef std::function resource)> onDeviceDiscoveredCb; + /** * This class represents Remote Enrollee device instance. What operation the class provides: * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee @@ -47,7 +49,7 @@ namespace OIC * 3) Provision Device confiruation setting, i.e. language, country, and etc * 4) Provision Cloud information used for which Enrollee is going to register to the cloud */ - class RemoteEnrollee + class RemoteEnrollee : public std::enable_shared_from_this { public: ~RemoteEnrollee() = default; @@ -124,6 +126,10 @@ namespace OIC RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource); ESResult discoverResource(); + + static void onDiscoveredCallback(const std::shared_ptr resource, + std::weak_ptr this_ptr); + void onDeviceDiscovered(const std::shared_ptr resource); void initCloudResource(); diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp index 00c5df7..fc0b48a 100755 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp @@ -37,7 +37,7 @@ namespace OIC { static const char ES_BASE_RES_URI[] = "/oic/res"; #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE" - #define DISCOVERY_TIMEOUT 5 + #define DISCOVERY_TIMEOUT 1 RemoteEnrollee::RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource) { @@ -120,6 +120,17 @@ namespace OIC OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "cloudPropProvisioningStatusHandler OUT"); } + void RemoteEnrollee::onDiscoveredCallback(const std::shared_ptr resource, + std::weak_ptr this_ptr) + { + OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onDiscoveredCallback()"); + std::shared_ptr Ptr = this_ptr.lock(); + if(Ptr) + { + Ptr->onDeviceDiscovered(resource); + } + } + void RemoteEnrollee::onDeviceDiscovered(std::shared_ptr resource) { OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered IN"); @@ -180,11 +191,11 @@ namespace OIC m_discoveryResponse = false; - std::function< void (std::shared_ptr) > onDeviceDiscoveredCb = - std::bind(&RemoteEnrollee::onDeviceDiscovered, this, - std::placeholders::_1); - OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT, - onDeviceDiscoveredCb); + onDeviceDiscoveredCb cb = std::bind(&RemoteEnrollee::onDiscoveredCallback, + std::placeholders::_1, + shared_from_this()); + + OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT, cb); if (result != OCStackResult::OC_STACK_OK) {