replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / src / EnrolleeResource.cpp
index a06eebb..a1e35e9 100755 (executable)
@@ -36,79 +36,194 @@ namespace OIC
         EnrolleeResource::EnrolleeResource(std::shared_ptr< OC::OCResource > resource)
         {
             m_ocResource = resource;
+            m_getStatusCb = nullptr;
+            m_getConfigurationStatusCb = nullptr;
+            m_devicePropProvStatusCb = nullptr;
+            m_connectRequestStatusCb = nullptr;
         }
 
-        void EnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
-                const OCRepresentation& rep, const int eCode)
+        void EnrolleeResource::onEnrolleeResourceSafetyCB(const HeaderOptions& headerOptions,
+                                                        const OCRepresentation& rep,
+                                                        const int eCode,
+                                                        ESEnrolleeResourceCb cb,
+                                                        std::weak_ptr<EnrolleeResource> this_ptr)
+        {
+            OIC_LOG(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)
         {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : %s, eCode = %d",
-                    rep.getUri().c_str(),
-                    eCode);
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onProvisioningResponse : eCode = %d",
+                        eCode);
 
-            if (eCode != 0)
+            if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
             {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "checkProvInformationCb : Provisioning is failed ");
-                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
-                        DataProvisioningStatus >(ESResult::ES_ERROR, ESDataProvState::ES_PROVISIONING_ERROR);
-                m_dataProvStatusCb(provStatus);
+                ESResult result = ESResult::ES_ERROR;
+
+                OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                            "onProvisioningResponse : Provisioning is failed ");
+
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
+                {
+                    OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
+                }
+
+                std::shared_ptr< DevicePropProvisioningStatus > provStatus = std::make_shared<
+                        DevicePropProvisioningStatus >(result);
+                m_devicePropProvStatusCb(provStatus);
                 return;
             }
 
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                    "checkProvInformationCb : Provisioning is success. ");
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                    "onProvisioningResponse : Provisioning is success. ");
 
-            std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
-                    DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONING_SUCCESS);
-            m_dataProvStatusCb(provStatus);
+            std::shared_ptr< DevicePropProvisioningStatus > provStatus = std::make_shared<
+                    DevicePropProvisioningStatus >(ESResult::ES_OK);
+            m_devicePropProvStatusCb(provStatus);
         }
 
-        void EnrolleeResource::onRequestPropertyDataResponse(const HeaderOptions& /*headerOptions*/,
+        void EnrolleeResource::onGetStatusResponse(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onRequestPropertyDataResponse : %s, eCode = %d",
-                    rep.getUri().c_str(), eCode);
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : eCode = %d",
+                        eCode);
 
-            if (eCode != 0)
+            if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
             {
-                ESResult result  = ESResult::ES_ERROR;
+                ESResult result = ESResult::ES_ERROR;
 
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,"onRequestPropertyDataResponse : onRequestPropertyDataResponse is failed ");
+                OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                            "onGetStatusResponse : onGetStatusResponse is failed ");
 
-                if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
                 {
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Mediator is unauthorized from Enrollee.");
-                    result = ESResult::ES_UNAUTHORIZED;
+                    OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
                 }
 
-                PropertyData propertyData;
-                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
-                        RequestPropertyDataStatus >(result, propertyData );
-                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
+                EnrolleeStatus enrolleeStatus(rep);
+                std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
+                        GetEnrolleeStatus >(result, enrolleeStatus);
+
+                m_getStatusCb(getEnrolleeStatus);
             }
             else
             {
-                PropertyData propertyData = parsePropertyDataFromRepresentation(rep);
+                EnrolleeStatus enrolleeStatus(rep);
+                std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
+                        GetEnrolleeStatus >(ESResult::ES_OK, enrolleeStatus);
 
-                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
-                        RequestPropertyDataStatus >(ESResult::ES_OK, propertyData);
-                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
+                m_getStatusCb(getEnrolleeStatus);
             }
         }
 
-        void EnrolleeResource::registerRequestPropertyDataStatusCallback(RequestPropertyDataStatusCb callback)
+        void EnrolleeResource::onGetConfigurationResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& rep, const int eCode)
         {
-            m_RequestPropertyDataStatusCb = callback;
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetConfigurationResponse : eCode = %d",
+                        eCode);
+
+            if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
+            {
+                ESResult result = ESResult::ES_ERROR;
+
+                OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                            "onGetConfigurationResponse : onGetConfigurationResponse is failed ");
+
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
+                {
+                    OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
+                }
+
+                EnrolleeConf enrolleeConf(rep);
+                std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
+                        GetConfigurationStatus >(result, enrolleeConf);
+                m_getConfigurationStatusCb(getConfigurationStatus);
+            }
+            else
+            {
+                EnrolleeConf enrolleeConf(rep);
+
+                std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
+                        GetConfigurationStatus >(ESResult::ES_OK, enrolleeConf);
+                m_getConfigurationStatusCb(getConfigurationStatus);
+            }
         }
 
-        void EnrolleeResource::registerProvStatusCallback(DataProvStatusCb callback)
+         void EnrolleeResource::onConnectRequestResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& /*rep*/, const int eCode)
         {
-            m_dataProvStatusCb = callback;
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onConnectRequestResponse : eCode = %d",
+                        eCode);
+
+            if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
+            {
+                ESResult result = ESResult::ES_ERROR;
+
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                            "onConnectRequestResponse : onConnectRequestResponse is failed ");
+
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
+                {
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
+                }
+
+                std::shared_ptr< ConnectRequestStatus > connectRequestStatus = std::make_shared<
+                        ConnectRequestStatus >(result);
+                m_connectRequestStatusCb(connectRequestStatus);
+                return;
+            }
+
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                    "onConnectRequestResponse : Provisioning is success. ");
+
+            std::shared_ptr< ConnectRequestStatus > connectRequestStatus = std::make_shared<
+                    ConnectRequestStatus >(ESResult::ES_OK);
+            m_connectRequestStatusCb(connectRequestStatus);
         }
 
-        void EnrolleeResource::RequestPropertyData()
+
+        void EnrolleeResource::registerGetStatusCallback(
+            const GetStatusCb callback)
         {
+            m_getStatusCb = callback;
+        }
+
+        void EnrolleeResource::registerGetConfigurationStatusCallback(
+            const GetConfigurationStatusCb callback)
+        {
+            m_getConfigurationStatusCb = callback;
+        }
+
+        void EnrolleeResource::registerDevicePropProvStatusCallback(
+            const DevicePropProvStatusCb callback)
+        {
+            m_devicePropProvStatusCb = callback;
+        }
+
+        void EnrolleeResource::registerConnectRequestStatusCallback(
+            const ConnectRequestStatusCb callback)
+        {
+            m_connectRequestStatusCb = callback;
+        }
+
+        void EnrolleeResource::getStatus()
+        {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus IN");
+
             if (m_ocResource == nullptr)
             {
                 throw ESBadRequestException("Resource is not initialized");
@@ -117,159 +232,128 @@ namespace OIC
             OC::QueryParamsMap query;
             OC::OCRepresentation rep;
 
-            std::function< OCStackResult(void) > requestPropertyDataStatus = [&]
-            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
-                        BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
-                        const OCRepresentation& rep, const int eCode) >(
-                                std::bind(&EnrolleeResource::onRequestPropertyDataResponse, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3)));
+            std::function< OCStackResult(void) > getStatus = [&]
+            {
+                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)),
+                                shared_from_this());
+
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        DEFAULT_INTERFACE, query, cb, OC::QualityOfService::HighQos);
             };
 
-            OCStackResult result = requestPropertyDataStatus();
+            OCStackResult result = getStatus();
 
             if (result != OCStackResult::OC_STACK_OK)
             {
-                PropertyData propertyData;
-                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
-                        RequestPropertyDataStatus >(ESResult::ES_ERROR, propertyData);
-                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
+                EnrolleeStatus enrolleeStatus(rep);// = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
+                std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
+                        GetEnrolleeStatus >(ESResult::ES_ERROR, enrolleeStatus);
+
+                m_getStatusCb(getEnrolleeStatus);
+
                 return;
             }
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus OUT");
         }
 
-        void EnrolleeResource::provisionEnrollee(const DataProvInfo& dataProvInfo)
-
+        void EnrolleeResource::getConfiguration()
         {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration IN");
+
             if (m_ocResource == nullptr)
             {
                 throw ESBadRequestException("Resource is not initialized");
             }
 
-            m_dataProvInfo = dataProvInfo;
-
             OC::QueryParamsMap query;
-            OC::OCRepresentation provisioningRepresentation;
-
-            provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, m_dataProvInfo.WIFI.ssid);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, m_dataProvInfo.WIFI.pwd);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHTYPE, m_dataProvInfo.WIFI.authtype);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE, m_dataProvInfo.WIFI.enctype);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_LANGUAGE, m_dataProvInfo.Device.language);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_COUNTRY, m_dataProvInfo.Device.country);
-
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s",
-                    (m_dataProvInfo.WIFI.ssid).c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
-                    (m_dataProvInfo.WIFI.pwd).c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d",
-                    m_dataProvInfo.WIFI.authtype);
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d",
-                    m_dataProvInfo.WIFI.enctype);
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : language - %s",
-                    (m_dataProvInfo.Device.language).c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : country - %s",
-                    (m_dataProvInfo.Device.country).c_str());
-
-            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::checkProvInformationCb, this,
-                    std::placeholders::_1, std::placeholders::_2,
-                    std::placeholders::_3)));
+            OC::OCRepresentation rep;
+
+            std::function< OCStackResult(void) > getConfigurationStatus = [&]
+            {
+                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)),
+                                shared_from_this());
+
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        BATCH_INTERFACE, query, cb, OC::QualityOfService::HighQos);
+            };
+
+            OCStackResult result = getConfigurationStatus();
+
+            if (result != OCStackResult::OC_STACK_OK)
+            {
+                EnrolleeConf enrolleeConf(rep);
+                std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
+                        GetConfigurationStatus >(ESResult::ES_ERROR, enrolleeConf);
+                m_getConfigurationStatusCb(getConfigurationStatus);
+                return;
+            }
+
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration OUT");
         }
 
-        void EnrolleeResource::unprovisionEnrollee()
+        void EnrolleeResource::provisionProperties(const DeviceProp& deviceProp)
         {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties IN");
             if (m_ocResource == nullptr)
             {
                 throw ESBadRequestException("Resource is not initialized");
             }
 
-            OCRepresentation provisioningRepresentation;
+            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());
 
-            provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, "");
-            provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, "");
+            m_ocResource->post(OC_RSRVD_ES_RES_TYPE_EASYSETUP, BATCH_INTERFACE,
+                    provisioningRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos);
 
-            m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
-                    std::function<
-                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                                    const int eCode) >(
-                    std::bind(&EnrolleeResource::checkProvInformationCb, this,
-                    std::placeholders::_1, std::placeholders::_2,
-                    std::placeholders::_3)));
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties OUT");
         }
 
-        PropertyData EnrolleeResource::parsePropertyDataFromRepresentation(const OCRepresentation& rep)
+        void EnrolleeResource::requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Enter parsePropertyDataFromRepresentation");
-
-            DeviceConfig devInfo;
-            NetworkInfo netInfo;
-            bool cloudable = false;
-
-            std::vector<OCRepresentation> children = rep.getChildren();
-
-            for(auto prop = children.begin(); prop != children.end(); ++prop)
+            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "requestToConnect IN");
+            if (m_ocResource == nullptr)
             {
-                if(prop->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
-                {
-                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find wifi resource");
-                    if(prop->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE)
-                                && prop->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
-                    {
-                        std::vector<int> types = prop->getValue<std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE);
-
-                        for(auto type = types.begin(); type != types.end(); ++type)
-                        {
-                            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIMODE = %d",
-                                *type);
-                            netInfo.types.push_back(static_cast<WIFI_MODE>(*type));
-                        }
+                throw ESBadRequestException("Resource is not initialized");
+            }
 
-                        netInfo.freq = static_cast<WIFI_FREQ>(prop->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+            OC::QueryParamsMap query;
+            OC::OCRepresentation requestRepresentation;
+            std::vector<int> connectTypes_int;
+            connectTypes_int.clear();
 
+            for(auto it : connectTypes)
+            {
+                connectTypes_int.push_back(static_cast<int>(it));
+            }
 
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIFREQ = %d",
-                                netInfo.freq);
-                    }
-                }
+            requestRepresentation.setValue<std::vector<int>>(OC_RSRVD_ES_CONNECT, connectTypes_int);
 
-                else if(prop->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                {
-                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find devconf");
-                    if(prop->hasAttribute(OC_RSRVD_ES_DEVNAME)
-                                && prop->hasAttribute(OC_RSRVD_ES_LANGUAGE)
-                                && prop->hasAttribute(OC_RSRVD_ES_COUNTRY))
-                    {
-                        //TODO:: setting DeviceID.
-                        //devInfo.id = devId;
-                        devInfo.name = prop->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
-                        devInfo.language = prop->getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
-                        devInfo.country = prop->getValue<std::string>(OC_RSRVD_ES_COUNTRY);
-
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_DEVNAME = %s",
-                                devInfo.name.c_str());
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_LANGUAGE = %s",
-                                devInfo.language.c_str());
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_COUNTRY = %s",
-                                devInfo.country.c_str());
-                    }
-                }
+            ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                            static_cast<ESEnrolleeResourceCb>(
+                            std::bind(&EnrolleeResource::onConnectRequestResponse, this,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                            shared_from_this());
 
-                else if(prop->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
-                {
-                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find cloudserver");
-                    cloudable = true;
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "cloudable = %d",
-                                cloudable);
-                }
-            }
+            m_ocResource->post(OC_RSRVD_ES_RES_TYPE_EASYSETUP, OC_RSRVD_INTERFACE_DEFAULT,
+                    requestRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos);
 
-            return PropertyData(devInfo, netInfo, cloudable);
+            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "requestToConnect OUT");
         }
-
     }
 }