alarm_repeat_mode_t repeat; /**< repeat mode */
} alarm_mode_t;
+typedef struct {
+ alarm_set_time_cb_t callback;
+ void *user_data;
+ GDBusProxy *proxy;
+} alarm_set_time_data_t;
+
+enum async_param_type {
+ SET_SYSTIME = 0,
+ SET_SYSTIME_WITH_PROPAGATION_DELAY,
+};
+
/**
* This enumeration has alarm type
bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code);
+bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, alarm_set_time_cb_t result_cb, void *user_data);
bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, int method, alarm_id_t *alarm_id, int *error_code);
bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code);
+bool _send_alarm_set_time_async(alarm_context_t context, int new_time, alarm_set_time_cb_t result_cb, void *user_data);
bool _send_alarm_set_global(alarm_context_t context, int alarm_id, bool global, int *error_code);
bool _send_alarm_get_global(alarm_context_t context, int alarm_id, bool *global, int *error_code);
* The prototype of alarm handler.
* param [in] alarm_id the id of expired alarm
*/
+typedef int (*alarm_set_time_cb_t) (int result, void *user_param);
+
typedef int (*alarm_cb_t) (alarm_id_t alarm_id, void *user_param);
typedef int (*alarm_enum_fn_t) (alarm_id_t alarm_id, void *user_param);
int alarmmgr_set_systime(int new_time);
/**
+ * This function asynchronously changes the system time which tranferred by other module
+ * @param [in] new_time epoch time to be set
+ * @param [in] result_cb The asynchronous callback function to get the result
+ * @param [in] user_param User parameter to be passed to the callback function
+ *
+ * @return @c ALARMMGR_RESULT_SUCCESS on success,
+ * otherwise a negative error value
+ * @retval #ALARMMGR_RESULT_SUCCESS Successful
+ * @retval #ERR_ALARM_SYSTEM_FAIL System failure
+ */
+int alarmmgr_set_systime_async(int new_time, alarm_set_time_cb_t result_cb, void *user_param);
+
+/**
* This function changes the system time and compensates the time using propagation delay.
* @param [in] new_time system time to be set (seconds, nanoseconds)
* @param [in] req_time time to request to change the system time (seconds, nanoseconds)
int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct timespec req_time);
/**
+ * This function asynchronously changes the system time and compensates the time using propagation delay.
+ * @param [in] new_time system time to be set (seconds, nanoseconds)
+ * @param [in] req_time time to request to change the system time (seconds, nanoseconds)
+ * @param [in] result_cb The asynchronous callback function to get the result
+ * @param [in] user_param User parameter to be passed to the callback function
+ *
+ * @return @c ALARMMGR_RESULT_SUCCESS on success,
+ * otherwise a negative error value
+ * @retval #ALARMMGR_RESULT_SUCCESS Successful
+ * @retval #ERR_ALARM_SYSTEM_FAIL System failure
+ * @retval #ERR_ALARM_INVALID_PARAM invalid parameter
+ */
+int alarmmgr_set_systime_with_propagation_delay_async(struct timespec new_time, struct timespec req_time, alarm_set_time_cb_t result_cb, void *user_param);
+
+/**
* This function changes the timezone which tranferred by other module
* @param [in] tzpath_str the path to timezone definition file
*
return true;
}
+static void _alarm_set_time_cb(GObject *source_object, GAsyncResult *res,
+ gpointer user_data)
+{
+ int return_code = 0;
+ GError *error = NULL;
+ alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data;
+
+ if (!alarm_manager_call_alarm_set_time_finish((AlarmManager *)func_data->proxy,
+ (gint *)&return_code,
+ res, &error)) {
+ ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+ g_error_free(error);
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ if (func_data->callback != NULL)
+ func_data->callback(return_code, func_data->user_data);
+}
+
+bool _send_alarm_set_time_async(alarm_context_t context, int new_time, alarm_set_time_cb_t result_cb, void *user_data)
+{
+ alarm_set_time_data_t *func_data;
+
+ func_data = g_try_new0(alarm_set_time_data_t, 1);
+
+ if (func_data == NULL)
+ return false;
+
+ func_data->callback = result_cb;
+ func_data->user_data = user_data;
+ func_data->proxy = context.proxy;
+
+ alarm_manager_call_alarm_set_time((AlarmManager *)context.proxy, new_time,
+ NULL, _alarm_set_time_cb, func_data);
+
+ return true;
+}
+
bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code)
{
GError *error = NULL;
return true;
}
+static void _alarm_set_time_with_delay_cb(GObject *source_object, GAsyncResult *res,
+ gpointer user_data)
+{
+ int return_code = 0;
+ GError *error = NULL;
+ alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data;
+
+ if (!alarm_manager_call_alarm_set_time_with_propagation_delay_finish((AlarmManager *)func_data->proxy,
+ (gint *)&return_code,
+ res, &error)) {
+ ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+ g_error_free(error);
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ if (func_data->callback != NULL)
+ func_data->callback(return_code, func_data->user_data);
+}
+
+bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, alarm_set_time_cb_t result_cb, void *user_data)
+{
+ alarm_set_time_data_t *func_data;
+
+ func_data = g_try_new0(alarm_set_time_data_t, 1);
+
+ if (func_data == NULL)
+ return false;
+
+ func_data->callback = result_cb;
+ func_data->user_data = user_data;
+ func_data->proxy = context.proxy;
+
+ alarm_manager_call_alarm_set_time_with_propagation_delay((AlarmManager *)context.proxy,
+ new_sec, new_nsec, req_sec, req_nsec,
+ NULL, _alarm_set_time_with_delay_cb, func_data);
+
+ return true;
+}
+
bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code)
{
GError *error = NULL;
static bool b_initialized = false;
static bool sub_initialized = false;
-pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
static void __handle_expired_signal(GDBusConnection *conn,
const gchar *name, const gchar *path, const gchar *interface,
struct _alarm_cb_info_t *next;
} alarm_cb_info_t;
+struct alarm_async_param_t {
+ enum async_param_type type;
+ GVariant *v;
+ alarm_set_time_cb_t result_cb;
+ void *user_param;
+};
+
static alarm_cb_info_t *alarmcb_head = NULL;
static void __add_resultcb(alarm_id_t alarm_id, alarm_cb_t cb_func, void *data)
return _return;
}
+static int __alarm_context_init()
+{
+ int fd = 0;
+ int ret = 0;
+
+ if (sub_initialized)
+ return ALARMMGR_RESULT_SUCCESS;
+
+ alarm_context.proxy = g_dbus_proxy_new_sync(alarm_context.connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
+ NULL,
+ "org.tizen.alarm.manager",
+ "/org/tizen/alarm/manager",
+ "org.tizen.alarm.manager",
+ NULL,
+ NULL);
+
+ if (alarm_context.proxy == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("Creating a proxy is failed.");
+ g_object_unref(alarm_context.connection);
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ sub_initialized = true;
+
+ return ALARMMGR_RESULT_SUCCESS;
+}
+
+static void __bus_get_for_async_api(GObject *source_object, GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ struct alarm_async_param_t *param = (struct alarm_async_param_t *)user_data;
+
+ pthread_mutex_lock(&init_lock);
+
+ alarm_context.connection = g_bus_get_finish(res, &error);
+ if (!alarm_context.connection) {
+ ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+ g_error_free(error);
+ g_variant_unref(param->v);
+ g_free(param);
+ pthread_mutex_unlock(&init_lock);
+ return;
+ }
+
+ if (__alarm_context_init() != ALARMMGR_RESULT_SUCCESS) {
+ g_variant_unref(param->v);
+ g_free(param);
+ pthread_mutex_unlock(&init_lock);
+ return;
+ }
+
+ if (param->type == SET_SYSTIME_WITH_PROPAGATION_DELAY) {
+ struct timespec new_time;
+ struct timespec req_time;
+ g_variant_get(param->v, "(uuuu)", &new_time.tv_sec, &new_time.tv_nsec,
+ &req_time.tv_sec, &req_time.tv_nsec);
+ _send_alarm_set_time_with_propagation_delay_async(alarm_context,
+ new_time.tv_sec, new_time.tv_nsec,
+ req_time.tv_sec, req_time.tv_nsec,
+ param->result_cb, param->user_param);
+ } else if (param->type == SET_SYSTIME) {
+ int new_time;
+ g_variant_get(param->v, "i", &new_time);
+ _send_alarm_set_time_async(alarm_context, new_time,
+ param->result_cb, param->user_param);
+ }
+
+ g_variant_unref(param->v);
+ g_free(param);
+ pthread_mutex_unlock(&init_lock);
+}
+
static int __sub_init()
{
GError *error = NULL;
return ERR_ALARM_SYSTEM_FAIL;
}
- alarm_context.proxy = g_dbus_proxy_new_sync(alarm_context.connection,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.tizen.alarm.manager",
- "/org/tizen/alarm/manager",
- "org.tizen.alarm.manager",
- NULL,
- NULL);
-
- if (alarm_context.proxy == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("Creating a proxy is failed.");
- g_object_unref(alarm_context.connection);
- pthread_mutex_unlock(&init_lock);
- return ERR_ALARM_SYSTEM_FAIL;
- }
-
- sub_initialized = true;
-
+ ret = __alarm_context_init();
pthread_mutex_unlock(&init_lock);
return ALARMMGR_RESULT_SUCCESS;
return ALARMMGR_RESULT_SUCCESS;
}
+EXPORT_API int alarmmgr_set_systime_async(int new_time, alarm_set_time_cb_t result_cb, void *user_param)
+{
+ int error_code;
+ struct alarm_async_param_t *param;
+
+ ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_systime(%d) is called.", new_time);
+
+ if (sub_initialized) {
+ if (!_send_alarm_set_time_async(alarm_context, new_time,
+ result_cb, user_param))
+ return ERR_ALARM_SYSTEM_FAIL;
+ } else {
+#if !(GLIB_CHECK_VERSION(2, 32, 0))
+ g_thread_init(NULL);
+#endif
+#if !(GLIB_CHECK_VERSION(2, 36, 0))
+ g_type_init();
+#endif
+ param = g_try_new0(struct alarm_async_param_t, 1);
+ param->type = SET_SYSTIME;
+ param->v = g_variant_new("i", new_time);
+ param->result_cb = result_cb;
+ param->user_param = user_param;
+ g_bus_get(G_BUS_TYPE_SYSTEM, NULL, __bus_get_for_async_api, param);
+ }
+
+ return ALARMMGR_RESULT_SUCCESS;
+}
+
EXPORT_API int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct timespec req_time)
{
int error_code;
return ALARMMGR_RESULT_SUCCESS;
}
+EXPORT_API int alarmmgr_set_systime_with_propagation_delay_async(struct timespec new_time, struct timespec req_time, alarm_set_time_cb_t result_cb, void *user_param)
+{
+ int error_code;
+ struct alarm_async_param_t *param;
+
+ ALARM_MGR_LOG_PRINT("[alarm-lib] New: %d(sec) %09d(nsec), Requested: %d(sec) %09d(nsec)",
+ new_time.tv_sec, new_time.tv_nsec, req_time.tv_sec, req_time.tv_nsec);
+
+ if (sub_initialized) {
+ if (!_send_alarm_set_time_with_propagation_delay_async(alarm_context,
+ new_time.tv_sec, new_time.tv_nsec, req_time.tv_sec,
+ req_time.tv_nsec, result_cb, user_param))
+ return ERR_ALARM_SYSTEM_FAIL;
+ } else {
+#if !(GLIB_CHECK_VERSION(2, 32, 0))
+ g_thread_init(NULL);
+#endif
+#if !(GLIB_CHECK_VERSION(2, 36, 0))
+ g_type_init();
+#endif
+ param = g_try_new0(struct alarm_async_param_t, 1);
+ param->type = SET_SYSTIME_WITH_PROPAGATION_DELAY;
+ param->v = g_variant_new("(uuuu)", new_time.tv_sec, new_time.tv_nsec,
+ req_time.tv_sec, req_time.tv_nsec);
+ param->result_cb = result_cb;
+ param->user_param = user_param;
+ g_bus_get(G_BUS_TYPE_SYSTEM, NULL, __bus_get_for_async_api, param);
+ }
+
+ return ALARMMGR_RESULT_SUCCESS;
+}
+
EXPORT_API int alarmmgr_set_timezone(char *tzpath_str)
{
int error_code;