Change wait_for_mount APIs to callback-based APIs 06/121706/2 accepted/tizen_common accepted/tizen_ivi accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable accepted/tizen/common/20170330.151434 accepted/tizen/ivi/20170329.035632 accepted/tizen/mobile/20170329.035540 accepted/tizen/tv/20170329.035559 accepted/tizen/unified/20170329.035649 accepted/tizen/wearable/20170329.035614 submit/tizen/20170329.022805 submit/tizen/20170410.043335
authorSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 28 Mar 2017 12:23:22 +0000 (21:23 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Wed, 29 Mar 2017 01:42:42 +0000 (10:42 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I848c5a22690869c68b56a05f21585056351ec099

lib/ode/common.h
lib/ode/external-encryption.cpp
lib/ode/external-encryption.h
lib/ode/internal-encryption.cpp
lib/ode/internal-encryption.h
tools/cli/ode-admin-cli.cpp

index 3d07bcc..20ad83b 100644 (file)
@@ -75,6 +75,18 @@ typedef enum {
 } 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);
+
+
+/**
  * @}
  */
 
index eae3ecb..b22b50d 100644 (file)
@@ -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<ODEContext> 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;
 }
index 624832d..e56902e 100644 (file)
@@ -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();
 
 /**
  * @}
index 095a75a..d5ad13d 100644 (file)
@@ -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<ODEContext> 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;
 }
index 17ad253..e5f1cdb 100644 (file)
@@ -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();
+
 /*
  * @}
  */
index a128f15..b73de8a 100644 (file)
@@ -23,6 +23,7 @@
 #include <getopt.h>
 #include <termios.h>
 
+#include <mutex>
 #include <string>
 #include <vector>
 #include <iostream>
@@ -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 <<std::endl;
                return -1;
        }
+
+       mtx.lock();
        std::cout << "Mount is completed"<< std::endl;
 
        return ret;