From: Sungbae Yoo Date: Tue, 28 Mar 2017 12:23:22 +0000 (+0900) Subject: Change wait_for_mount APIs to callback-based APIs X-Git-Tag: submit/tizen/20170329.022805^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aee83a64d0a61d6f76052275fe53e6dcce2e7c51;p=platform%2Fcore%2Fsecurity%2Fode.git Change wait_for_mount APIs to callback-based APIs Signed-off-by: Sungbae Yoo Change-Id: I848c5a22690869c68b56a05f21585056351ec099 --- diff --git a/lib/ode/common.h b/lib/ode/common.h index 3d07bcc..20ad83b 100644 --- a/lib/ode/common.h +++ b/lib/ode/common.h @@ -74,6 +74,18 @@ typedef enum { ODE_STATE_CORRUPTED = 0x02 /**< Devoce is corrupted because of encryption error */ } ode_state_e; +/** + * @brief Called when internal storage is mounted with encryption + * @since_tizen 3.0 + * @param[in] user_data The user data passed from + * ode_internal_encryption_set_mount_event_cb() or + * ode_external_encryption_set_mount_event_cb(). + * @see ode_internal_encryption_set_mount_event_cb() + * @see ode_external_encryption_set_mount_event_cb() + */ +typedef void(*ode_mount_event_cb)(void* user_data); + + /** * @} */ diff --git a/lib/ode/external-encryption.cpp b/lib/ode/external-encryption.cpp index eae3ecb..b22b50d 100644 --- a/lib/ode/external-encryption.cpp +++ b/lib/ode/external-encryption.cpp @@ -174,23 +174,24 @@ int ode_external_encryption_get_supported_options(unsigned int* options) return ODE_ERROR_NONE; } -static void _ode_external_event_listener(void *user_data) { - std::mutex *pMtx = (std::mutex*)user_data; - pMtx->unlock(); -} +static std::unique_ptr mountEventCallbackContext; -int ode_external_encryption_wait_for_mount() +int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data) { - ODEContext client; - RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); + RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER); - std::mutex mtx; - mtx.lock(); + mountEventCallbackContext.reset(new ODEContext); + RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED); - int ret = client.subscribeSignal("ExternalEncryption::mount", _ode_external_event_listener, &mtx); + int ret = mountEventCallbackContext->subscribeSignal("ExternalEncryption::mount", callback, user_data); RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER); - mtx.lock(); + return ODE_ERROR_NONE; +} + +int ode_external_encryption_unset_mount_event_cb() +{ + mountEventCallbackContext.reset(); return ODE_ERROR_NONE; } diff --git a/lib/ode/external-encryption.h b/lib/ode/external-encryption.h index 624832d..e56902e 100644 --- a/lib/ode/external-encryption.h +++ b/lib/ode/external-encryption.h @@ -286,18 +286,37 @@ typedef enum { ODE_API int ode_external_encryption_get_supported_options(unsigned int* options); /** - * @brief Wait for mount of external storage - * @details Services can use this API to wait for mount of external storage. + * @brief Register a callback to get mount event of internal storage + * @details Services can use this API to attach a callback to be called + * by mount event of internal storage with encryption. * @since_tizen 3.0 + * @param[in] callback The mount event callback function + * @param[in] user_data The user data passed to the callback function * @return #ODE_ERROR_NONE on success, otherwise a negative value * @retval #ODE_ERROR_NONE Successful * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ODE_ERROR_TIMED_OUT Time out - * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API + * @post If the callback is not needed, + * ode_external_encryption_set_mount_event_cb() must be called. + * @see ode_external_encryption_mount() + * @see ode_external_encryption_unset_mount_event_cb() + */ +ODE_API int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data); + +/** + * @brief Unregister a callback to get mount event of internal storage + * @details Services can use this API to detach a callback to be called + * by mount event of internal storage with encryption. + * @since_tizen 3.0 + * @return #ODE_ERROR_NONE on success, otherwise a negative value + * @retval #ODE_ERROR_NONE Successful + * @retval #ODE_ERROR_TIMED_OUT Time out * the privilege to call this API * @see ode_external_encryption_mount() + * @see ode_external_encryption_set_mount_event_cb() */ -ODE_API int ode_external_encryption_wait_for_mount(); +ODE_API int ode_external_encryption_unset_mount_event_cb(); /** * @} diff --git a/lib/ode/internal-encryption.cpp b/lib/ode/internal-encryption.cpp index 095a75a..d5ad13d 100644 --- a/lib/ode/internal-encryption.cpp +++ b/lib/ode/internal-encryption.cpp @@ -174,23 +174,24 @@ int ode_internal_encryption_get_supported_options(unsigned int* options) return ODE_ERROR_NONE; } -static void _ode_internal_event_listener(void *user_data) { - std::mutex *pMtx = (std::mutex*)user_data; - pMtx->unlock(); -} +static std::unique_ptr mountEventCallbackContext; -int ode_internal_encryption_wait_for_mount() +int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data) { - ODEContext client; - RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); + RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER); - std::mutex mtx; - mtx.lock(); + mountEventCallbackContext.reset(new ODEContext); + RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED); - int ret = client.subscribeSignal("InternalEncryption::mount", _ode_internal_event_listener, &mtx); + int ret = mountEventCallbackContext->subscribeSignal("InternalEncryption::mount", callback, user_data); RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER); - mtx.lock(); + return ODE_ERROR_NONE; +} - return ODE_ERROR_NONE; +int ode_internal_encryption_unset_mount_event_cb() +{ + mountEventCallbackContext.reset(); + + return ODE_ERROR_NONE; } diff --git a/lib/ode/internal-encryption.h b/lib/ode/internal-encryption.h index 17ad253..e5f1cdb 100644 --- a/lib/ode/internal-encryption.h +++ b/lib/ode/internal-encryption.h @@ -287,18 +287,36 @@ typedef enum { ODE_API int ode_internal_encryption_get_supported_options(unsigned int* options); /** - * @brief Wait for mount of internal storage - * @details Services can use this API to wait for mount of internal storage. + * @brief Register a callback to get mount event of internal storage + * @details Services can use this API to attach a callback to be called + * by mount event of internal storage with encryption. * @since_tizen 3.0 + * @param[in] callback The mount event callback function + * @param[in] user_data The user data passed to the callback function * @return #ODE_ERROR_NONE on success, otherwise a negative value * @retval #ODE_ERROR_NONE Successful * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ODE_ERROR_TIMED_OUT Time out - * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have - * the privilege to call this API + * @post If the callback is not needed, + * ode_internal_encryption_set_mount_event_cb() must be called. * @see ode_internal_encryption_mount() + * @see ode_internal_encryption_unset_mount_event_cb() */ -ODE_API int ode_internal_encryption_wait_for_mount(); +ODE_API int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data); + +/** + * @brief Unregister a callback to get mount event of internal storage + * @details Services can use this API to detach a callback to be called + * by mount event of internal storage with encryption. + * @since_tizen 3.0 + * @return #ODE_ERROR_NONE on success, otherwise a negative value + * @retval #ODE_ERROR_NONE Successful + * @retval #ODE_ERROR_TIMED_OUT Time out + * the privilege to call this API + * @see ode_internal_encryption_set_mount_event_cb() + */ +ODE_API int ode_internal_encryption_unset_mount_event_cb(); + /* * @} */ diff --git a/tools/cli/ode-admin-cli.cpp b/tools/cli/ode-admin-cli.cpp index a128f15..b73de8a 100644 --- a/tools/cli/ode-admin-cli.cpp +++ b/tools/cli/ode-admin-cli.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -307,16 +308,23 @@ static inline int get_state(const std::string name) return ret; } +static void mount_event_cb(void *user_data) { + std::mutex *pMtx = (std::mutex*)user_data; + pMtx->unlock(); +} + static inline int wait_for_mount(const std::string name) { int ret; + std::mutex mtx; + mtx.lock(); if (name == "internal") { std::cout << "Wait for internal storage mount..." << std::endl; - ret = ode_internal_encryption_wait_for_mount(); + ret = ode_internal_encryption_set_mount_event_cb(mount_event_cb, &mtx); } else if (name == "external") { std::cout << "Wait for external storage mount..." << std::endl; - ret = ode_external_encryption_wait_for_mount(); + ret = ode_external_encryption_set_mount_event_cb(mount_event_cb, &mtx); } else { printSelectableStorage(); return -1; @@ -326,6 +334,8 @@ static inline int wait_for_mount(const std::string name) std::cerr << "Error : " << ret <