From: Heewon Park Date: Fri, 12 Aug 2016 05:44:50 +0000 (+0900) Subject: Update Mediator code for more readable using const. X-Git-Tag: 1.2.0+RC1~128 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42c1137be9c152c83f808e7bd8ab51aa7e26c920;p=platform%2Fupstream%2Fiotivity.git Update Mediator code for more readable using const. Change-Id: I87f6222908c30e14f5c7963859a0310dd06ac03f Signed-off-by: Heewon Park Reviewed-on: https://gerrit.iotivity.org/gerrit/10323 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- diff --git a/service/easy-setup/mediator/richsdk/inc/CloudResource.h b/service/easy-setup/mediator/richsdk/inc/CloudResource.h index d9dc4a5..1d80c6c 100755 --- a/service/easy-setup/mediator/richsdk/inc/CloudResource.h +++ b/service/easy-setup/mediator/richsdk/inc/CloudResource.h @@ -46,12 +46,14 @@ namespace OIC CloudResource(std::shared_ptr< OC::OCResource > resource); ~CloudResource() = default; - void registerCloudPropProvisioningStatusCallback (CloudPropProvStatusCb callback); + void registerCloudPropProvisioningStatusCallback( + const CloudPropProvStatusCb callback); void provisionEnrollee(const CloudProp& CloudProp); private: - void onCloudProvResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); + void onCloudProvResponse(const HeaderOptions& headerOptions, + const OCRepresentation& rep, + const int eCode); private: std::shared_ptr< OC::OCResource > m_ocResource; diff --git a/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h b/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h index ed6f06c..9299400 100755 --- a/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h +++ b/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h @@ -51,9 +51,11 @@ namespace OIC ~EnrolleeResource() = default; - void registerGetStatusCallback (GetStatusCb callback); - void registerGetConfigurationStatusCallback (GetConfigurationStatusCb callback); - void registerDevicePropProvStatusCallback (DevicePropProvStatusCb callback); + void registerGetStatusCallback(const GetStatusCb callback); + void registerGetConfigurationStatusCallback( + const GetConfigurationStatusCb callback); + void registerDevicePropProvStatusCallback( + const DevicePropProvStatusCb callback); void getConfiguration(); void getStatus(); @@ -68,12 +70,15 @@ namespace OIC DevicePropProvStatusCb m_devicePropProvStatusCb; private: - void onGetStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); - void onGetConfigurationResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); - void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); + void onGetStatusResponse(const HeaderOptions& headerOptions, + const OCRepresentation& rep, + const int eCode); + void onGetConfigurationResponse(const HeaderOptions& headerOptions, + const OCRepresentation& rep, + const int eCode); + void checkProvInformationCb(const HeaderOptions& headerOptions, + const OCRepresentation& rep, + const int eCode); }; } } diff --git a/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h b/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h index 4375810..a55ccfb 100755 --- a/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h +++ b/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h @@ -47,11 +47,14 @@ namespace OIC { public: EnrolleeSecurity(std::shared_ptr< OC::OCResource > resource, - std::string secDbPath); - void registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb, - SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb); + const std::string secDbPath); + void registerCallbackHandler( + const SecurityProvStatusCb securityProvStatusCb, + const SecurityPinCb securityPinCb, + const SecProvisioningDbPathCb secProvisioningDbPathCb); void performOwnershipTransfer(); - ESResult performACLProvisioningForCloudServer(std::string cloudUuid); + ESResult performACLProvisioningForCloudServer( + const std::string cloudUuid); std::string getUUID() const; private: @@ -68,9 +71,9 @@ namespace OIC std::shared_ptr< OC::OCSecureResource > m_securedResource; std::shared_ptr< OC::OCSecureResource > getEnrollee(OC::DeviceList_t &list); void ownershipTransferCb(OC::PMResultList_t *result, int hasError); - void convertUUIDToString(OicUuid_t uuid, std::string& uuidString); - void convertStringToUUID(OicUuid_t& uuid, std::string uuidString); - OicSecAcl_t* createAcl(OicUuid_t cloudUuid); + void convertUUIDToString(const OicUuid_t uuid, std::string& uuidString); + void convertStringToUUID(OicUuid_t& uuid, const std::string uuidString); + OicSecAcl_t* createAcl(const OicUuid_t cloudUuid); void ACLProvisioningCb(PMResultList_t *result, int hasError); }; diff --git a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h index 6f5c6e4..e1ce4f3 100755 --- a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h @@ -65,8 +65,8 @@ namespace OIC * * @see SecProvisioningResult */ - ESResult registerSecurityCallbackHandler(SecurityPinCb securityPinCb, - SecProvisioningDbPathCb secProvisioningDbPathCb); + ESResult registerSecurityCallbackHandler(const SecurityPinCb securityPinCb, + const SecProvisioningDbPathCb secProvisioningDbPathCb); #endif //__WITH_DTLS__ /** @@ -78,7 +78,7 @@ namespace OIC * * @see GetStatusCb */ - void getStatus(GetStatusCb callback); + void getStatus(const GetStatusCb callback); /** * Get an Enrollee's configuration which includes WiFi supported frequency and device name @@ -89,7 +89,7 @@ namespace OIC * * @see GetConfigurationStatusCb */ - void getConfiguration(GetConfigurationStatusCb callback); + void getConfiguration(const GetConfigurationStatusCb callback); /** * Do security provisioning such as ownership tranfer to Enrollee. @@ -100,7 +100,7 @@ namespace OIC * * @see SecurityProvStatusCb */ - void provisionSecurity(SecurityProvStatusCb callback); + void provisionSecurity(const SecurityProvStatusCb callback); /** * Provision WiFi AP information and device configuration to Enrollee @@ -116,7 +116,7 @@ namespace OIC * @see DevicePropProvStatusCb */ void provisionDeviceProperties(const DeviceProp& devProp, - DevicePropProvStatusCb callback); + const DevicePropProvStatusCb callback); /** * Provision Cloud information to Enrollee, which includes Auth code, auth provider, @@ -135,20 +135,25 @@ namespace OIC * @see CloudPropProvStatusCb */ void provisionCloudProperties(const CloudProp& cloudProp, - CloudPropProvStatusCb callback); + const CloudPropProvStatusCb callback); private: - RemoteEnrollee(std::shared_ptr< OC::OCResource > resource); + RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource); ESResult discoverResource(); - void onDeviceDiscovered(std::shared_ptr resource); + void onDeviceDiscovered(const std::shared_ptr resource); void initCloudResource(); - void getStatusHandler (std::shared_ptr< GetEnrolleeStatus > status); - void getConfigurationStatusHandler (std::shared_ptr< GetConfigurationStatus > status); - void devicePropProvisioningStatusHandler (std::shared_ptr< DevicePropProvisioningStatus > status); - void cloudPropProvisioningStatusHandler (std::shared_ptr< CloudPropProvisioningStatus > status); - void securityStatusHandler(std::shared_ptr< SecProvisioningStatus > status); + void getStatusHandler + (const std::shared_ptr< GetEnrolleeStatus > status) const; + void getConfigurationStatusHandler + (const std::shared_ptr< GetConfigurationStatus > status) const; + void devicePropProvisioningStatusHandler + (const std::shared_ptr< DevicePropProvisioningStatus > status) const; + void cloudPropProvisioningStatusHandler + (const std::shared_ptr< CloudPropProvisioningStatus > status) const; + void securityStatusHandler + (const std::shared_ptr< SecProvisioningStatus > status) const; private: std::shared_ptr< OC::OCResource > m_ocResource; diff --git a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp index a0b327a..8d47b3c 100755 --- a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp @@ -75,19 +75,22 @@ namespace OIC } std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< - CloudPropProvisioningStatus >(result, ESCloudProvState::ES_CLOUD_PROVISIONING_ERROR); + CloudPropProvisioningStatus >( + result, ESCloudProvState::ES_CLOUD_PROVISIONING_ERROR); m_cloudPropProvStatusCb(provStatus); } else { OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is success "); - std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< - CloudPropProvisioningStatus >(ESResult::ES_OK, ESCloudProvState::ES_CLOUD_PROVISIONING_SUCCESS); + std::shared_ptr< CloudPropProvisioningStatus > provStatus = + std::make_shared( + ESResult::ES_OK, ESCloudProvState::ES_CLOUD_PROVISIONING_SUCCESS); m_cloudPropProvStatusCb(provStatus); } } - void CloudResource::registerCloudPropProvisioningStatusCallback(CloudPropProvStatusCb callback) + void CloudResource::registerCloudPropProvisioningStatusCallback( + const CloudPropProvStatusCb callback) { OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "Enter registerCloudPropProvisioningStatusCallback."); m_cloudPropProvStatusCb = callback; diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp index df9c15c..6ad843e 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp @@ -134,17 +134,20 @@ namespace OIC } } - void EnrolleeResource::registerGetStatusCallback(GetStatusCb callback) + void EnrolleeResource::registerGetStatusCallback( + const GetStatusCb callback) { m_getStatusCb = callback; } - void EnrolleeResource::registerGetConfigurationStatusCallback(GetConfigurationStatusCb callback) + void EnrolleeResource::registerGetConfigurationStatusCallback( + const GetConfigurationStatusCb callback) { m_getConfigurationStatusCb = callback; } - void EnrolleeResource::registerDevicePropProvStatusCallback(DevicePropProvStatusCb callback) + void EnrolleeResource::registerDevicePropProvStatusCallback( + const DevicePropProvStatusCb callback) { m_devicePropProvStatusCb = callback; } diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index 6e7bdf9..e351154 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -48,22 +48,25 @@ namespace OIC #define ES_SEC_DISCOVERY_TIMEOUT 5 EnrolleeSecurity::EnrolleeSecurity( - std::shared_ptr< OC::OCResource > resource, - std::string secDbPath) + std::shared_ptr< OC::OCResource > resource, + const std::string secDbPath) { (void) secDbPath; m_ocResource = resource; } - void EnrolleeSecurity::registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb, - SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb) + void EnrolleeSecurity::registerCallbackHandler( + const SecurityProvStatusCb securityProvStatusCb, + const SecurityPinCb securityPinCb, + const SecProvisioningDbPathCb secProvisioningDbPathCb) { m_securityProvStatusCb = securityProvStatusCb; m_securityPinCb = securityPinCb; m_secProvisioningDbPathCb = secProvisioningDbPathCb; } - std::shared_ptr< OC::OCSecureResource > EnrolleeSecurity::getEnrollee(DeviceList_t &list) + std::shared_ptr< OC::OCSecureResource > EnrolleeSecurity::getEnrollee( + DeviceList_t &list) { for (unsigned int i = 0; i < list.size(); i++) { @@ -71,7 +74,8 @@ namespace OIC { OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Device %d ID %s ", i + 1, list[i]->getDeviceID().c_str()); - OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "From IP :%s", list[i]->getDevAddr().c_str()); + OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "From IP :%s", + list[i]->getDevAddr().c_str()); return list[i]; } } @@ -79,7 +83,8 @@ namespace OIC return NULL; } - void EnrolleeSecurity::convertUUIDToString(OicUuid_t uuid, std::string& uuidString) + void EnrolleeSecurity::convertUUIDToString(const OicUuid_t uuid, + std::string& uuidString) { char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*) 0)->id)) + 1] = { 0, }; @@ -97,7 +102,8 @@ namespace OIC uuidString = deviceId.str(); } - void EnrolleeSecurity::convertStringToUUID(OicUuid_t& uuid, std::string uuidString) + void EnrolleeSecurity::convertStringToUUID(OicUuid_t& uuid, + const std::string uuidString) { size_t outBufSize = B64DECODE_OUT_SAFESIZE((uuidString.length() + 1)); uint8_t* outKey = (uint8_t*)OICCalloc(1, outBufSize); @@ -316,7 +322,7 @@ namespace OIC return m_ocResource->sid(); }; - OicSecAcl_t* EnrolleeSecurity::createAcl(OicUuid_t cloudUuid) + OicSecAcl_t* EnrolleeSecurity::createAcl(const OicUuid_t cloudUuid) { // allocate memory for |acl| struct OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t)); diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp index 3760875..40d0d7e 100755 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp @@ -39,7 +39,7 @@ namespace OIC #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE" #define DISCOVERY_TIMEOUT 5 - RemoteEnrollee::RemoteEnrollee(std::shared_ptr< OC::OCResource > resource) + RemoteEnrollee::RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource) { m_ocResource = resource; m_enrolleeResource = std::make_shared(m_ocResource); @@ -54,8 +54,9 @@ namespace OIC } #ifdef __WITH_DTLS__ - ESResult RemoteEnrollee::registerSecurityCallbackHandler(SecurityPinCb securityPinCb, - SecProvisioningDbPathCb secProvisioningDbPathCb) + ESResult RemoteEnrollee::registerSecurityCallbackHandler( + const SecurityPinCb securityPinCb, + const SecProvisioningDbPathCb secProvisioningDbPathCb) { // No need to check NULL for m_secProvisioningDbPathCB as this is not a mandatory // callback function. If m_secProvisioningDbPathCB is NULL, provisioning manager @@ -69,7 +70,7 @@ namespace OIC #endif //__WITH_DTLS__ void RemoteEnrollee::securityStatusHandler( - std::shared_ptr< SecProvisioningStatus > status) + const std::shared_ptr< SecProvisioningStatus > status) const { OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "easySetupStatusCallback status is, UUID = %s," "Status = %d", status->getDeviceUUID().c_str(), @@ -92,7 +93,8 @@ namespace OIC } } - void RemoteEnrollee::getStatusHandler(std::shared_ptr< GetEnrolleeStatus > status) + void RemoteEnrollee::getStatusHandler( + const std::shared_ptr< GetEnrolleeStatus > status) const { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering getStatusHandler"); @@ -102,7 +104,7 @@ namespace OIC } void RemoteEnrollee::getConfigurationStatusHandler ( - std::shared_ptr< GetConfigurationStatus > status) + const std::shared_ptr< GetConfigurationStatus > status) const { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering getConfigurationStatusHandler"); @@ -113,7 +115,7 @@ namespace OIC } void RemoteEnrollee::devicePropProvisioningStatusHandler( - std::shared_ptr< DevicePropProvisioningStatus > status) + const std::shared_ptr< DevicePropProvisioningStatus > status) const { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering DevicePropProvisioningStatusHandler"); @@ -125,7 +127,7 @@ namespace OIC } void RemoteEnrollee::cloudPropProvisioningStatusHandler ( - std::shared_ptr< CloudPropProvisioningStatus > status) + const std::shared_ptr< CloudPropProvisioningStatus > status) const { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering cloudPropProvisioningStatusHandler"); @@ -219,9 +221,13 @@ namespace OIC return ES_OK; } - void RemoteEnrollee::provisionSecurity(SecurityProvStatusCb callback) + void RemoteEnrollee::provisionSecurity(const SecurityProvStatusCb callback) { #ifdef __WITH_DTLS__ + if(!callback) + { + throw ESInvalidParameterException("Callback is empty"); + } m_securityProvStatusCb = callback; SecurityProvStatusCb securityProvStatusCb = std::bind( @@ -260,7 +266,7 @@ namespace OIC #endif } - void RemoteEnrollee::getStatus(GetStatusCb callback) + void RemoteEnrollee::getStatus(const GetStatusCb callback) { if(!callback) { @@ -281,7 +287,7 @@ namespace OIC } - void RemoteEnrollee::getConfiguration(GetConfigurationStatusCb callback) + void RemoteEnrollee::getConfiguration(const GetConfigurationStatusCb callback) { if(!callback) { @@ -302,7 +308,7 @@ namespace OIC } void RemoteEnrollee::provisionDeviceProperties(const DeviceProp& deviceProp, - DevicePropProvStatusCb callback) + const DevicePropProvStatusCb callback) { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter provisionDeviceProperties"); @@ -369,7 +375,7 @@ namespace OIC } void RemoteEnrollee::provisionCloudProperties(const CloudProp& cloudProp, - CloudPropProvStatusCb callback) + const CloudPropProvStatusCb callback) { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter provisionCloudProperties"); ESResult res = ES_OK;