} 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);
+
+
+/**
* @}
*/
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;
}
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();
/**
* @}
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;
}
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();
+
/*
* @}
*/
#include <getopt.h>
#include <termios.h>
+#include <mutex>
#include <string>
#include <vector>
#include <iostream>
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;
std::cerr << "Error : " << ret <<std::endl;
return -1;
}
+
+ mtx.lock();
std::cout << "Mount is completed"<< std::endl;
return ret;