X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Feasy-setup%2Fmediator%2Frichsdk%2Fsrc%2FEnrolleeResource.cpp;h=a1e35e9df2645785c93a71c7ebd295b0a3f220b1;hb=3c093548382bb2542c87a67e6e5fa32552c29cb3;hp=17862a12bee3d328f5bed1dd1fade9be6b9ab8da;hpb=edcfc3d2329da7b914771c0dcff5f42c9b74fd93;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp index 17862a1..a1e35e9 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp @@ -36,24 +36,42 @@ 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::onEnrolleeResourceSafetyCB(const HeaderOptions& headerOptions, + const OCRepresentation& rep, + const int eCode, + ESEnrolleeResourceCb cb, + std::weak_ptr this_ptr) + { + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onEnrolleeResourceSafetyCB"); + std::shared_ptr 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, "onProvisioningResponse : eCode = %d", + OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onProvisioningResponse : eCode = %d", eCode); if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED) { ESResult result = ESResult::ES_ERROR; - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "onProvisioningResponse : Provisioning is failed "); if(eCode == OCStackResult::OC_STACK_COMM_ERROR) { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "can't receive any response from Enrollee by a timeout threshold."); result = ESResult::ES_COMMUNICATION_ERROR; } @@ -64,7 +82,7 @@ namespace OIC return; } - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onProvisioningResponse : Provisioning is success. "); std::shared_ptr< DevicePropProvisioningStatus > provStatus = std::make_shared< @@ -75,19 +93,19 @@ namespace OIC void EnrolleeResource::onGetStatusResponse(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode) { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : eCode = %d", + OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : eCode = %d", eCode); if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED) { ESResult result = ESResult::ES_ERROR; - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : onGetStatusResponse is failed "); if(eCode == OCStackResult::OC_STACK_COMM_ERROR) { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "can't receive any response from Enrollee by a timeout threshold."); result = ESResult::ES_COMMUNICATION_ERROR; } @@ -111,19 +129,19 @@ namespace OIC void EnrolleeResource::onGetConfigurationResponse(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode) { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetConfigurationResponse : eCode = %d", + 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_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "onGetConfigurationResponse : onGetConfigurationResponse is failed "); if(eCode == OCStackResult::OC_STACK_COMM_ERROR) { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "can't receive any response from Enrollee by a timeout threshold."); result = ESResult::ES_COMMUNICATION_ERROR; } @@ -143,6 +161,41 @@ namespace OIC } } + void EnrolleeResource::onConnectRequestResponse(const HeaderOptions& /*headerOptions*/, + const OCRepresentation& /*rep*/, const int eCode) + { + 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::registerGetStatusCallback( const GetStatusCb callback) { @@ -161,9 +214,15 @@ namespace OIC 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"); + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus IN"); if (m_ocResource == nullptr) { @@ -175,12 +234,15 @@ namespace OIC std::function< OCStackResult(void) > getStatus = [&] { - return m_ocResource->get(m_ocResource->getResourceTypes().at(0), - DEFAULT_INTERFACE, query, std::function( + ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + static_cast( 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(); @@ -195,12 +257,12 @@ namespace OIC return; } - OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus OUT"); + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus OUT"); } void EnrolleeResource::getConfiguration() { - OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration IN"); + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration IN"); if (m_ocResource == nullptr) { @@ -212,12 +274,15 @@ namespace OIC std::function< OCStackResult(void) > getConfigurationStatus = [&] { - return m_ocResource->get(m_ocResource->getResourceTypes().at(0), - BATCH_INTERFACE, query, std::function( + ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + static_cast( 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(); @@ -231,12 +296,12 @@ namespace OIC return; } - OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration OUT"); + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration OUT"); } void EnrolleeResource::provisionProperties(const DeviceProp& deviceProp) { - OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties IN"); + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties IN"); if (m_ocResource == nullptr) { throw ESBadRequestException("Resource is not initialized"); @@ -245,16 +310,50 @@ namespace OIC OC::QueryParamsMap query; OC::OCRepresentation provisioningRepresentation = deviceProp.toOCRepresentation(); - 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); + ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + static_cast( + 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_EASYSETUP, BATCH_INTERFACE, + provisioningRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos); + + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties OUT"); + } + + void EnrolleeResource::requestToConnect(const std::vector &connectTypes) + { + OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "requestToConnect IN"); + if (m_ocResource == nullptr) + { + throw ESBadRequestException("Resource is not initialized"); + } + + OC::QueryParamsMap query; + OC::OCRepresentation requestRepresentation; + std::vector connectTypes_int; + connectTypes_int.clear(); + + for(auto it : connectTypes) + { + connectTypes_int.push_back(static_cast(it)); + } + + requestRepresentation.setValue>(OC_RSRVD_ES_CONNECT, connectTypes_int); + + ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + static_cast( + std::bind(&EnrolleeResource::onConnectRequestResponse, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)), + shared_from_this()); + + m_ocResource->post(OC_RSRVD_ES_RES_TYPE_EASYSETUP, OC_RSRVD_INTERFACE_DEFAULT, + requestRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos); - OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties OUT"); + OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "requestToConnect OUT"); } } }