add the new APIS for alarm
authorJiwoong Im <jiwoong.im@samsung.com>
Wed, 27 May 2015 02:06:55 +0000 (11:06 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Fri, 29 May 2015 02:38:47 +0000 (11:38 +0900)
- alarm_schedule_once_after_delay
- alarm_schedule_once_at_date

Change-Id: Iab54567af28aa11a8b5cb88da80f98ab2fe97c42
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
alarm/alarm.c
include/app_alarm.h

index 374fd04..6ef1f17 100755 (executable)
@@ -281,6 +281,88 @@ int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int perio
        alarmmgr_free_alarm(alarm_info);
        return ALARM_ERROR_NONE;
 }
+int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id)
+{
+       bundle *bundle_data;
+       int result = 0;
+
+       if (app_control == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, delay, 0, bundle_data, alarm_id);
+
+       return  convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id)
+{
+       alarm_date_t internal_time;
+       alarm_entry_t* alarm_info;
+       bundle *bundle_data;
+       int result;
+
+       if (app_control == NULL || date == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       alarm_info = alarmmgr_create_alarm();
+       if (alarm_info == NULL) {
+               LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY);
+               return ALARM_ERROR_OUT_OF_MEMORY;
+       }
+
+       internal_time.year = date->tm_year + 1900;
+       internal_time.month = date->tm_mon + 1;
+       internal_time.day = date->tm_mday;
+
+       internal_time.hour = date->tm_hour;
+       internal_time.min = date->tm_min;
+       internal_time.sec = date->tm_sec;
+
+       result = alarmmgr_set_time(alarm_info, internal_time);
+
+       if (result < 0) {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
+
+       if (result < 0) {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
+
+       if (result < 0) {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
+
+       if (result < 0) {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       alarmmgr_free_alarm(alarm_info);
+       return ALARM_ERROR_NONE;
+}
 
 int alarm_cancel(int alarm_id)
 {
index 7b3ad0a..c61d2b1 100755 (executable)
@@ -129,6 +129,62 @@ int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int perio
 
 
 /**
+ * @brief Sets an alarm to be triggered after a specific time.
+ * @details The alarm will go off @a delay seconds later.
+ *          To cancel the alarm, call alarm_cancel() with @a alarm_id.
+ * @since_tizen 2.4
+ * @privlevel  public
+ * @privilege  %http://tizen.org/privilege/alarm.set
+ * @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically.
+ *
+ * @param[in] app_control The destination app_control to perform a specific task when the alarm is triggered
+ * @param[in] delay    The amount of time before the execution (in seconds)
+ * @param[out] alarm_id        The alarm ID that uniquely identifies an alarm
+ * @return     @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #ALARM_ERROR_NONE Successful
+ * @retval  #ALARM_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #ALARM_ERROR_INVALID_TIME Triggered time is invalid
+ * @retval  #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @retval  #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @see alarm_cancel()
+ * @see alarm_cancel_all()
+ * @see alarm_get_scheduled_date()
+ * @see alarm_get_scheduled_period()
+ */
+int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id);
+
+
+/**
+ * @brief Sets an alarm to be triggered at a specific time.
+ * @details The @a date describes the time of the first occurrence.
+ *          To cancel the alarm, call alarm_cancel() with @a alarm_id.
+ * @since_tizen 2.4
+ * @privlevel  public
+ * @privilege  %http://tizen.org/privilege/alarm.set
+ * @remarks If application is uninstalled after setting an alarm, the alarm is cancelled automatically.
+ *          If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request.
+ *          If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application.
+ *
+ * @param[in]  app_control The destination app_control to perform specific work when the alarm is triggered
+ * @param[in]  date    The first active alarm time
+ * @param[out] alarm_id        The alarm ID that uniquely identifies an alarm
+ * @return     @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #ALARM_ERROR_NONE   Successful
+ * @retval  #ALARM_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #ALARM_ERROR_INVALID_DATE Triggered date is invalid
+ * @retval  #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @retval  #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @see alarm_cancel()
+ * @see alarm_cancel_all()
+ * @see alarm_get_scheduled_date()
+ * @see alarm_get_scheduled_period()
+ */
+int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id);
+
+
+/**
  * @brief   Sets an alarm to be triggered at a specific time with recurrence repeat.
  * @details 
  * The @a date describes the time of first occurrence.