Changed all of easysetup-callback-function to static member function.
authorParkhi <h_w.park@samsung.com>
Mon, 2 Jan 2017 04:48:39 +0000 (13:48 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 5 Jan 2017 06:46:03 +0000 (06:46 +0000)
This change can protect from crash when class instance is removed.

Change-Id: I0db76ee443a88ac15d11d62a44af0b92b754d697
Signed-off-by: Parkhi <h_w.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16037
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h
service/easy-setup/mediator/richsdk/src/CloudResource.cpp
service/easy-setup/mediator/richsdk/src/CloudResource.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeResource.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp

index 773ac62..69ea0ae 100755 (executable)
@@ -167,7 +167,31 @@ namespace OIC
             ESResult discoverResource();
 
             static void onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
-            std::weak_ptr<RemoteEnrollee> this_ptr);
+                std::weak_ptr<RemoteEnrollee> this_ptr);
+
+            static void onGetStatusHandlerCallback(
+                const std::shared_ptr< GetEnrolleeStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr);
+
+            static void onGetConfigurationStatusHandlerCallback(
+                const std::shared_ptr< GetConfigurationStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr);
+
+            static void onDevicePropProvisioningStatusHandlerCallback(
+                const std::shared_ptr< DevicePropProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr);
+
+            static void onCloudPropProvisioningStatusHandlerCallback(
+                const std::shared_ptr< CloudPropProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr);
+
+            static void onSecurityStatusHandlerCallback(
+                const std::shared_ptr< SecProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr);
+
+            static ESOwnershipTransferData onSecurityStatusWithOptionHandlerCallback(
+                const std::shared_ptr< SecProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr);
 
             void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
             void initCloudResource();
index ea760ee..dcbd207 100755 (executable)
@@ -40,20 +40,36 @@ namespace OIC
             m_ocResource = resource;
         }
 
+        void CloudResource::onCloudProvResponseSafetyCb(const HeaderOptions& headerOptions,
+                                                                const OCRepresentation& rep,
+                                                                const int eCode,
+                                                                ESCloudResourceCb cb,
+                                                                std::weak_ptr<CloudResource> this_ptr)
+        {
+            OIC_LOG_V(DEBUG, ES_CLOUD_RES_TAG, "onCloudProvResponseSafetyCb");
+            std::shared_ptr<CloudResource> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                cb(headerOptions, rep, eCode);
+            }
+        }
+
+
         void CloudResource::provisionProperties(const CloudProp& cloudProp)
         {
             OIC_LOG (DEBUG, ES_CLOUD_RES_TAG, "provisionProperties IN");
 
             OCRepresentation provisioningRepresentation = cloudProp.toOCRepresentation();
 
+            ESCloudResourceCb cb = std::bind(&CloudResource::onCloudProvResponseSafetyCb,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                            static_cast<ESCloudResourceCb>(
+                            std::bind(&CloudResource::onCloudProvResponse, this,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                            shared_from_this());
+
             m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE,
-                        provisioningRepresentation, QueryParamsMap(),
-                        std::function<
-                                void(const HeaderOptions& headerOptions,
-                                        const OCRepresentation& rep, const int eCode) >(
-                        std::bind(&CloudResource::onCloudProvResponse, this,
-                        std::placeholders::_1, std::placeholders::_2,
-                        std::placeholders::_3)), OC::QualityOfService::HighQos);
+                        provisioningRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos);
 
             OIC_LOG (DEBUG, ES_CLOUD_RES_TAG, "provisionProperties OUT");
         }
old mode 100644 (file)
new mode 100755 (executable)
index 6a0c5bd..9f116fb
@@ -35,12 +35,15 @@ namespace OIC
     namespace Service
     {
         class OCResource;
+        typedef std::function<void(const HeaderOptions& headerOptions,
+                                   const OCRepresentation& rep,
+                                   const int eCode)> ESCloudResourceCb;
         /**
          * This class contains the resource discovery methods.
          *
          * @see CloudResource
          */
-        class CloudResource
+        class CloudResource : public std::enable_shared_from_this<CloudResource>
         {
         public:
             CloudResource(std::shared_ptr< OC::OCResource > resource);
@@ -51,6 +54,11 @@ namespace OIC
             void provisionProperties(const CloudProp& CloudProp);
 
         private:
+            static void onCloudProvResponseSafetyCb(const HeaderOptions& headerOptions,
+                                                    const OCRepresentation& rep,
+                                                    const int eCode,
+                                                    ESCloudResourceCb cb,
+                                                    std::weak_ptr<CloudResource> this_ptr);
             void onCloudProvResponse(const HeaderOptions& headerOptions,
                                                 const OCRepresentation& rep,
                                                 const int eCode);
index 17862a1..c642892 100755 (executable)
@@ -38,6 +38,20 @@ namespace OIC
             m_ocResource = resource;
         }
 
+        void EnrolleeResource::onEnrolleeResourceSafetyCB(const HeaderOptions& headerOptions,
+                                                        const OCRepresentation& rep,
+                                                        const int eCode,
+                                                        ESEnrolleeResourceCb cb,
+                                                        std::weak_ptr<EnrolleeResource> this_ptr)
+        {
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onEnrolleeResourceSafetyCB");
+            std::shared_ptr<EnrolleeResource> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                cb(headerOptions, rep, eCode);
+            }
+        }
+
         void EnrolleeResource::onProvisioningResponse(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& /*rep*/, const int eCode)
         {
@@ -175,12 +189,15 @@ namespace OIC
 
             std::function< OCStackResult(void) > getStatus = [&]
             {
-                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
-                        DEFAULT_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
-                        const OCRepresentation& rep, const int eCode) >(
+                ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                                static_cast<ESEnrolleeResourceCb>(
                                 std::bind(&EnrolleeResource::onGetStatusResponse, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3)), OC::QualityOfService::HighQos);
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                                shared_from_this());
+
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        DEFAULT_INTERFACE, query, cb, OC::QualityOfService::HighQos);
             };
 
             OCStackResult result = getStatus();
@@ -212,12 +229,15 @@ namespace OIC
 
             std::function< OCStackResult(void) > getConfigurationStatus = [&]
             {
-                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
-                        BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
-                        const OCRepresentation& rep, const int eCode) >(
+                ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                                static_cast<ESEnrolleeResourceCb>(
                                 std::bind(&EnrolleeResource::onGetConfigurationResponse, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3)), OC::QualityOfService::HighQos);
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                                shared_from_this());
+
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        BATCH_INTERFACE, query, cb, OC::QualityOfService::HighQos);
             };
 
             OCStackResult result = getConfigurationStatus();
@@ -245,14 +265,15 @@ namespace OIC
             OC::QueryParamsMap query;
             OC::OCRepresentation provisioningRepresentation = deviceProp.toOCRepresentation();
 
+            ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                            static_cast<ESEnrolleeResourceCb>(
+                            std::bind(&EnrolleeResource::onProvisioningResponse, this,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                            shared_from_this());
+
             m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE,
-                    provisioningRepresentation, QueryParamsMap(),
-                    std::function<
-                            void(const HeaderOptions& headerOptions,
-                                    const OCRepresentation& rep, const int eCode) >(
-                    std::bind(&EnrolleeResource::onProvisioningResponse, this,
-                    std::placeholders::_1, std::placeholders::_2,
-                    std::placeholders::_3)), OC::QualityOfService::HighQos);
+                    provisioningRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos);
 
             OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties OUT");
         }
old mode 100644 (file)
new mode 100755 (executable)
index f194b45..803e802
@@ -37,12 +37,15 @@ namespace OIC
         class OCResource;
         class EnrolleeSecurity;
 
+        typedef std::function<void(const HeaderOptions& headerOptions,
+                                   const OCRepresentation& rep,
+                                   const int eCode)> ESEnrolleeResourceCb;
         /**
          * This class contains the resource discovery methods.
          *
          * @see EnrolleeResource
          */
-        class EnrolleeResource
+        class EnrolleeResource : public std::enable_shared_from_this<EnrolleeResource>
         {
             friend class EnrolleeSecurity;
 
@@ -70,6 +73,13 @@ namespace OIC
             DevicePropProvStatusCb m_devicePropProvStatusCb;
 
         private:
+            static void onEnrolleeResourceSafetyCB(const HeaderOptions& headerOptions,
+                                    const OCRepresentation& rep,
+                                    const int eCode,
+                                    ESEnrolleeResourceCb cb,
+                                    std::weak_ptr<EnrolleeResource> this_ptr);
+
+
             void onGetStatusResponse(const HeaderOptions& headerOptions,
                                                 const OCRepresentation& rep,
                                                 const int eCode);
index 165939f..d78e542 100755 (executable)
@@ -69,6 +69,19 @@ namespace OIC
             m_ownershipTransferData = {};
         }
 
+        void EnrolleeSecurity::onEnrolleeSecuritySafetyCB(OC::PMResultList_t *result,
+                                                        int hasError,
+                                                        ESSecurityCb cb,
+                                                        std::weak_ptr<EnrolleeSecurity> this_ptr)
+        {
+            OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "onEnrolleeSecuritySafetyCB");
+            std::shared_ptr<EnrolleeSecurity> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                cb(result, hasError);
+            }
+        }
+
         void EnrolleeSecurity::convertUUIDToString(const uint8_t uuid[UUID_SIZE],
                                                               std::string& uuidString)
         {
@@ -362,8 +375,11 @@ namespace OIC
                             "Found Unowned device's DevID at DB of ownedDevices list");
 
                         OC::ResultCallBack removeDeviceWithUuidCB = std::bind(
-                                &EnrolleeSecurity::removeDeviceWithUuidCB,
-                                this, std::placeholders::_1, std::placeholders::_2);
+                                &EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                                std::placeholders::_1, std::placeholders::_2,
+                                static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::removeDeviceWithUuidCB,
+                                this, std::placeholders::_1, std::placeholders::_2)),
+                                shared_from_this());
 
                         result = OCSecure::removeDeviceWithUuid(ES_SEC_DISCOVERY_TIMEOUT,
                                                                 m_ocResource->sid(),
@@ -413,8 +429,11 @@ namespace OIC
                                 !m_ownershipTransferData.getPreConfiguredPin().empty())
                         {
                             OC::ResultCallBack preconfigPinProvCB = std::bind(
-                                    &EnrolleeSecurity::PreconfigPinProvCB, this, std::placeholders::_1,
-                                    std::placeholders::_2);
+                                    &EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::PreconfigPinProvCB,
+                                    this, std::placeholders::_1, std::placeholders::_2)),
+                                    shared_from_this());
 
                             std::string pin = m_ownershipTransferData.getPreConfiguredPin();
 
@@ -441,10 +460,12 @@ namespace OIC
                             OIC_PRECONFIG_PIN == m_ownershipTransferData.getMOTMethod() ||
                             OIC_RANDOM_DEVICE_PIN == m_ownershipTransferData.getMOTMethod())
                         {
-
                             OC::ResultCallBack selectMOTMethodCB = std::bind(
-                                &EnrolleeSecurity::SelectMOTMethodCB, this, std::placeholders::_1,
-                                std::placeholders::_2);
+                                    &EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::SelectMOTMethodCB,
+                                    this, std::placeholders::_1, std::placeholders::_2)),
+                                    shared_from_this());
 
                             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "selectMOTMethod is called.");
                             if(OC_STACK_OK != m_securedResource->selectMOTMethod(
@@ -515,9 +536,13 @@ namespace OIC
             OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Transfering ownership for : %s ",
                     m_securedResource->getDeviceID().c_str());
 
-            OC::ResultCallBack ownershipTransferCb = std::bind(
-                    &EnrolleeSecurity::ownershipTransferCb, this, std::placeholders::_1,
-                    std::placeholders::_2);
+            OC::ResultCallBack ownershipTransferCb =
+                std::bind(&EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                          std::placeholders::_1, std::placeholders::_2,
+                          static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::ownershipTransferCb,
+                          this, std::placeholders::_1, std::placeholders::_2)),
+                          shared_from_this());
+
 
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "doOwnershipTransfer is excuted");
             result = m_securedResource->doOwnershipTransfer(ownershipTransferCb);
@@ -555,9 +580,12 @@ namespace OIC
                 OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Preconfig PIN : %s", pin.c_str());
             }
 
-            OC::ResultCallBack multipleOwnershipTransferCb = std::bind(
-                        &EnrolleeSecurity::MultipleOwnershipTransferCb, this, std::placeholders::_1,
-                        std::placeholders::_2);
+            OC::ResultCallBack multipleOwnershipTransferCb =
+                std::bind(&EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                          std::placeholders::_1, std::placeholders::_2,
+                          static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::MultipleOwnershipTransferCb,
+                          this, std::placeholders::_1, std::placeholders::_2)),
+                          shared_from_this());
 
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "doMultipleOwnershipTransfer is excuted");
 
@@ -769,9 +797,13 @@ namespace OIC
 
             OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Given CredId: %d", credId);
 
-            OC::ResultCallBack CertProvisioningCb = std::bind(
-                            &EnrolleeSecurity::CertProvisioningCb, this, std::placeholders::_1,
-                            std::placeholders::_2);
+            OC::ResultCallBack CertProvisioningCb =
+                std::bind(&EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                          std::placeholders::_1, std::placeholders::_2,
+                          static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::CertProvisioningCb,
+                          this, std::placeholders::_1, std::placeholders::_2)),
+                          shared_from_this());
+
             OCStackResult rst = ownedDevice->provisionTrustCertChain(SIGNED_ASYMMETRIC_KEY,
                                                                     static_cast<uint16_t>(credId),
                                                                     CertProvisioningCb);
@@ -823,9 +855,13 @@ namespace OIC
                 return res;
             }
 
-            OC::ResultCallBack aclProvisioningCb = std::bind(
-                            &EnrolleeSecurity::ACLProvisioningCb, this, std::placeholders::_1,
-                            std::placeholders::_2);
+            OC::ResultCallBack aclProvisioningCb =
+                std::bind(&EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+                          std::placeholders::_1, std::placeholders::_2,
+                          static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::ACLProvisioningCb,
+                          this, std::placeholders::_1, std::placeholders::_2)),
+                          shared_from_this());
+
             // ACL provisioning to Enrollee
             OCStackResult rst = ownedDevice->provisionACL(acl, aclProvisioningCb);
             if(OC_STACK_OK != rst)
index 76d0c8e..87d105a 100755 (executable)
@@ -25,6 +25,7 @@
 #include <atomic>
 #include <condition_variable>
 
+
 #include "ESRichCommon.h"
 #include "OCProvisioningManager.hpp"
 
@@ -41,13 +42,14 @@ namespace OIC
         class OCSecureResource;
 
         typedef std::vector<OCProvisionResult_t> PMResultList_t;
+        typedef std::function<void(OC::PMResultList_t *result, int hasError)> ESSecurityCb;
 
         /**
          * This class contains the methods needed for security  layer interaction.
          *
          * @see EnrolleeSecurity
          */
-        class EnrolleeSecurity
+        class EnrolleeSecurity : public std::enable_shared_from_this<EnrolleeSecurity>
         {
         public:
             EnrolleeSecurity(std::shared_ptr< OC::OCResource > resource,
@@ -74,6 +76,11 @@ namespace OIC
 
             ESOwnershipTransferData m_ownershipTransferData;
 
+            static void onEnrolleeSecuritySafetyCB(OC::PMResultList_t *result,
+                                    int hasError,
+                                    ESSecurityCb cb,
+                                    std::weak_ptr<EnrolleeSecurity> this_ptr);
+
             ESResult performOwnershipTransfer();
             bool isOwnedDeviceRegisteredInSVRDB();
             void removeDeviceWithUuidCB(OC::PMResultList_t *result, int hasError);
@@ -83,6 +90,9 @@ namespace OIC
             void PreconfigPinProvCB(PMResultList_t *result, int hasError);
             void MultipleOwnershipTransferCb(OC::PMResultList_t *result, int hasError);
 #endif
+            static void onOwnershipTransferCb(PMResultList_t *result,
+                                                        int hasError,
+                                                        std::weak_ptr<EnrolleeSecurity> this_ptr);
             void ownershipTransferCb(OC::PMResultList_t *result, int hasError);
             void convertUUIDToString(const uint8_t uuid[UUID_SIZE],
                                                 std::string& uuidString);
index 8b2b11b..ea963ff 100755 (executable)
@@ -53,6 +53,18 @@ namespace OIC
             m_deviceId = resource->sid();
         }
 
+        void RemoteEnrollee::onSecurityStatusHandlerCallback(
+                const std::shared_ptr< SecProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr)
+        {
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onSecurityStatusHandlerCallback");
+            std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                Ptr->securityStatusHandler(status);
+            }
+        }
+
         void RemoteEnrollee::securityStatusHandler(
                 const std::shared_ptr< SecProvisioningStatus > status) const
         {
@@ -73,6 +85,19 @@ namespace OIC
             OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "securityStatusHandlr OUT");
         }
 
+        ESOwnershipTransferData RemoteEnrollee::onSecurityStatusWithOptionHandlerCallback(
+                const std::shared_ptr< SecProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr)
+        {
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onSecurityStatusWithOptionHandlerCallback");
+            std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                return Ptr->securityStatusWithOptionHandler(status);
+            }
+            return ESOwnershipTransferData();
+        }
+
         ESOwnershipTransferData RemoteEnrollee::securityStatusWithOptionHandler(
                 const std::shared_ptr< SecProvisioningStatus > status) const
         {
@@ -84,6 +109,18 @@ namespace OIC
             return m_securityProvStatusCbWithOption(status);
         }
 
+        void RemoteEnrollee::onGetStatusHandlerCallback(
+                const std::shared_ptr< GetEnrolleeStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr)
+        {
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onGetStatusHandlerCallback");
+            std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                Ptr->getStatusHandler(status);
+            }
+        }
+
         void RemoteEnrollee::getStatusHandler(
                 const std::shared_ptr< GetEnrolleeStatus > status) const
         {
@@ -96,6 +133,18 @@ namespace OIC
             OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler OUT");
         }
 
+        void RemoteEnrollee::onGetConfigurationStatusHandlerCallback(
+                const std::shared_ptr< GetConfigurationStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr)
+        {
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onGetConfigurationStatusHandlerCallback");
+            std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                Ptr->getConfigurationStatusHandler(status);
+            }
+        }
+
         void RemoteEnrollee::getConfigurationStatusHandler (
                 const std::shared_ptr< GetConfigurationStatus > status) const
         {
@@ -108,6 +157,18 @@ namespace OIC
             OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "getConfigurationStatusHandler OUT");
         }
 
+        void RemoteEnrollee::onDevicePropProvisioningStatusHandlerCallback(
+                const std::shared_ptr< DevicePropProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr)
+        {
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onDevicePropProvisioningStatusHandlerCallback");
+            std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                Ptr->devicePropProvisioningStatusHandler(status);
+            }
+        }
+
         void RemoteEnrollee::devicePropProvisioningStatusHandler(
                 const std::shared_ptr< DevicePropProvisioningStatus > status) const
         {
@@ -119,6 +180,18 @@ namespace OIC
             OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "devicePropProvisioningStatusHandler OUT");
         }
 
+        void RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback(
+                const std::shared_ptr< CloudPropProvisioningStatus > status,
+                std::weak_ptr<RemoteEnrollee> this_ptr)
+        {
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onCloudPropProvisioningStatusHandlerCallback");
+            std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                Ptr->cloudPropProvisioningStatusHandler(status);
+            }
+        }
+
         void RemoteEnrollee::cloudPropProvisioningStatusHandler (
                 const std::shared_ptr< CloudPropProvisioningStatus > status) const
         {
@@ -240,9 +313,9 @@ namespace OIC
             m_securityProvStatusCb = callback;
 
             SecurityProvStatusCb securityProvStatusCb = std::bind(
-                    &RemoteEnrollee::securityStatusHandler,
-                    this,
-                    std::placeholders::_1);
+                    &RemoteEnrollee::onSecurityStatusHandlerCallback,
+                    std::placeholders::_1,
+                    shared_from_this());
             //TODO : DBPath is passed empty as of now. Need to take dbpath from application.
             if(!m_localEnrolleeSecurity.get())
             {
@@ -281,9 +354,9 @@ namespace OIC
             m_securityProvStatusCbWithOption = callback;
 
             SecurityProvStatusCbWithOption securityProvStatusCbWithOption = std::bind(
-                                    &RemoteEnrollee::securityStatusWithOptionHandler,
-                                    this,
-                                    std::placeholders::_1);
+                                    &RemoteEnrollee::onSecurityStatusWithOptionHandlerCallback,
+                                    std::placeholders::_1,
+                                    shared_from_this());
 
             if(!m_localEnrolleeSecurity.get())
             {
@@ -327,7 +400,10 @@ namespace OIC
             m_getStatusCb = callback;
 
             GetStatusCb getStatusCb = std::bind(
-                &RemoteEnrollee::getStatusHandler, this, std::placeholders::_1);
+                &RemoteEnrollee::onGetStatusHandlerCallback,
+                std::placeholders::_1,
+                shared_from_this());
+
             m_enrolleeResource->registerGetStatusCallback(getStatusCb);
             m_enrolleeResource->getStatus();
 
@@ -351,7 +427,10 @@ namespace OIC
             m_getConfigurationStatusCb = callback;
 
             GetConfigurationStatusCb getConfigurationStatusCb = std::bind(
-                    &RemoteEnrollee::getConfigurationStatusHandler, this, std::placeholders::_1);
+                    &RemoteEnrollee::onGetConfigurationStatusHandlerCallback,
+                    std::placeholders::_1,
+                    shared_from_this());
+
             m_enrolleeResource->registerGetConfigurationStatusCallback(getConfigurationStatusCb);
             m_enrolleeResource->getConfiguration();
 
@@ -381,8 +460,9 @@ namespace OIC
             }
 
             DevicePropProvStatusCb devicePropProvStatusCb = std::bind(
-                    &RemoteEnrollee::devicePropProvisioningStatusHandler,
-                    this, std::placeholders::_1);
+                    &RemoteEnrollee::onDevicePropProvisioningStatusHandlerCallback,
+                    std::placeholders::_1,
+                    shared_from_this());
 
             m_enrolleeResource->registerDevicePropProvStatusCallback(devicePropProvStatusCb);
             m_enrolleeResource->provisionProperties(deviceProp);
@@ -537,8 +617,9 @@ namespace OIC
             }
 
             CloudPropProvStatusCb cloudPropProvStatusCb = std::bind(
-                    &RemoteEnrollee::cloudPropProvisioningStatusHandler,
-                                    this, std::placeholders::_1);
+                    &RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback,
+                    std::placeholders::_1,
+                    shared_from_this());
 
             m_cloudResource->registerCloudPropProvisioningStatusCallback(cloudPropProvStatusCb);
             m_cloudResource->provisionProperties(cloudProp);