summaryrefslogtreecommitdiff
path: root/kies_alarm
diff options
context:
space:
mode:
Diffstat (limited to 'kies_alarm')
-rw-r--r--kies_alarm/CMakeLists.txt61
-rw-r--r--kies_alarm/include/kies_alarm.h83
-rw-r--r--kies_alarm/include/kies_define.h55
-rw-r--r--kies_alarm/include/kies_dlog.h131
-rw-r--r--kies_alarm/include/kies_fwk_alarmmgr.h28
-rwxr-xr-xkies_alarm/kies_alarm.pc.in13
-rw-r--r--kies_alarm/src/kies_alarm.c290
-rw-r--r--kies_alarm/src/kies_fwk_alarmmgr.c129
8 files changed, 790 insertions, 0 deletions
diff --git a/kies_alarm/CMakeLists.txt b/kies_alarm/CMakeLists.txt
new file mode 100644
index 0000000..5cdea8c
--- /dev/null
+++ b/kies_alarm/CMakeLists.txt
@@ -0,0 +1,61 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(LIBRARY_NAME ${LIB_NAME_KIES_ALM})
+SET(PKGNAME "kies_alarm")
+SET(PKGNAME_RING "org.tizen.ring")
+
+
+SET(VERSION_MAJOR_KIES_ALARM 0)
+#SET(VERSION_KIES_ALARM "${VERSION_MAJOR_KIES_ALARM}.0.0")
+SET(VERSION_KIES_ALARM 0.1)
+
+#lib
+SET(LIB_SRCS
+ src/kies_alarm.c
+ src/kies_fwk_alarmmgr.c
+)
+
+#include file
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+#dependency
+INCLUDE(FindPkgConfig)
+pkg_check_modules(kies_alm_pkgs REQUIRED
+ gobject-2.0 glib-2.0 gmodule-2.0 dlog
+ alarm-service
+ vconf
+)
+
+#CFlags
+FOREACH(flag ${kies_alm_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -ldl")
+#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+#definitions
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"")
+ADD_DEFINITIONS("-DPKGNAME=\"${PKGNAME}\"")
+ADD_DEFINITIONS("-DALARMRING_PKGNAME=\"${PKGNAME_RING}\"")
+
+#add lib
+SET(LIB_SO -L${CMAKE_BINARY_DIR} -lalarm-engine)
+ADD_LIBRARY(${LIBRARY_NAME} SHARED ${LIB_SRCS})
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${kies_alm_pkgs_LDFLAGS} -lpthread -ldl)
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${LIB_SO})
+SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR_KIES_ALARM})
+SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES VERSION ${VERSION_KIES_ALARM})
+
+ADD_DEPENDENCIES(${LIBRARY_NAME} alarm-engine)
+
+#pc file
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${LIBRARY_NAME}.pc.in ${CMAKE_BINARY_DIR}/${LIBRARY_NAME}.pc @ONLY)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/${LIBRARY_NAME}.pc DESTINATION ${PKGCONFIGDIR})
+
+#install lib
+INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
+
+#install head file
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/kies_alarm.h DESTINATION ${INCLUDEDIR})
diff --git a/kies_alarm/include/kies_alarm.h b/kies_alarm/include/kies_alarm.h
new file mode 100644
index 0000000..978f9c9
--- /dev/null
+++ b/kies_alarm/include/kies_alarm.h
@@ -0,0 +1,83 @@
+/*
+*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+#ifndef __KIES_ALARM_H__
+#define __KIES_ALARM_H__
+
+#define KIES_ALM_SUCCESS 0
+#define KIES_ALM_FAILED -1
+
+/*return value*/
+enum {
+ RESULT_FAILED = KIES_ALM_FAILED,
+ RESULT_SUCCESS = KIES_ALM_SUCCESS,
+ RESULT_ERR_NULL_ALARM, /*don't alarm in phone, not save */
+};
+/**
+ * @def A_DBAPI
+ * prefix
+ */
+#ifndef A_DBAPI
+#define A_DBAPI __attribute__ ((visibility("default")))
+#endif
+/**
+ * @def VCONFKEY_ALARM_RESTORE
+ * when restore alarm, send the message to notify the alarm data changed.
+ * It could be get by use vconf_ignore_key_changed
+ */
+#define VCONFKEY_ALARM_RESTORE "memory/alarm/restore"
+
+/**
+ * This function backup alarm data, the data will be saved to @param
+ * If the file path is NULL, return FAILED
+ *
+ * @brief backup alarm data
+ *
+ * @param [in] file_path the path of user want to save data
+ *
+ * @return On success, SUCCESS is returned. On error, FAILED is returned
+ * if phone don't save any alarm, RESULT_ERR_NULL_ALARM is returned.
+ *
+ * @remarks
+ *
+ * @exception
+ *
+ * @see alarm_restore
+ *
+ */
+A_DBAPI int alarm_backup(const char *file_path);
+
+/**
+ * This function restore alarm data, the data is from @param
+ * If the file path is NULL, return FAILED
+ *
+ * @brief backup alarm data
+ *
+ * @param [in] file_path the path of user want to get data
+ *
+ * @return On success, SUCCESS is returned. On error, FAILED is returned
+ *
+ * @remarks
+ *
+ * @exception
+ *
+ * @see alarm_backup
+ *
+ */
+A_DBAPI int alarm_restore(const char *file_path);
+
+#endif/*__KIES_ALARM_H__*/
diff --git a/kies_alarm/include/kies_define.h b/kies_alarm/include/kies_define.h
new file mode 100644
index 0000000..c15b9bf
--- /dev/null
+++ b/kies_alarm/include/kies_define.h
@@ -0,0 +1,55 @@
+/*
+*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+#ifndef __KIES_DEFINE_H__
+#define __KIES_DEFINE_H__
+
+#include "kies_dlog.h"
+
+//tag
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "KIES_ALARM"
+//value
+#define MAX_FILE_LENGTH 256
+//equal
+#define IS_EQUAL(a, b) ((a) == (b))
+#define IS_STR_EQUAL(a, b) (!strcmp(a, b))
+#define FCLOSE_IF(p) if (p) {fclose(p); p = NULL; }
+#define FREE_ADLIST(p) if (p) {alarmdb_free_data_list(p); p = NULL; }
+//
+#ifndef SUCCESS
+#define SUCCESS 0
+#endif
+#ifndef FAILED
+#define FAILED -1
+#endif
+//
+#define SET_TIME_DATA_T(pTime_data, YEAR, MONTH, DAY, HOUR, MIN, SEC) \
+do {\
+ (pTime_data)->year = (YEAR);\
+ (pTime_data)->month = (MONTH);\
+ (pTime_data)->day = (DAY);\
+ (pTime_data)->hour = (HOUR);\
+ (pTime_data)->min = (MIN);\
+ (pTime_data)->sec = (SEC);\
+} while (0);
+
+//#define PKGNAME "kies_alarm"
+//#define ALARMRING_PKGNAME "org.tizen.alarmring"
+#endif //__KIES_DEFINE_H__
diff --git a/kies_alarm/include/kies_dlog.h b/kies_alarm/include/kies_dlog.h
new file mode 100644
index 0000000..24fa5fb
--- /dev/null
+++ b/kies_alarm/include/kies_dlog.h
@@ -0,0 +1,131 @@
+/*
+*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+#ifndef __KIES_DLOG_H__
+#define __KIES_DLOG_H__
+
+#include <stdio.h>
+#include <assert.h>
+#include <dlog.h>
+/**********************************************************************
+******************define, struct ,typedef, union, enum, global val *************************************
+***********************************************************************/
+#define KIES_FUN_BEG() KIES_INFO("====>>>>fun=%s, BEGIN====>>>>", __FUNCTION__);
+#define KIES_FUN_END() KIES_INFO("====>>>>fun=%s, END====>>>>", __FUNCTION__);
+#define KIES_INFO(fmt, arg...) LOGD("[%s:%d] "fmt, __FILE__, __LINE__, ##arg);
+#define KIES_ERR(fmt, arg...) LOGE(FONT_COLOR_RED"[%s:%d] "fmt FONT_COLOR_RESET, __FILE__, __LINE__, ##arg);
+
+#define KIES_FUN_DEBUG_BEG() //KIES_INFO("====>>>>fun=%s, BEGIN====>>>>", __FUNCTION__);
+#define KIES_FUN_DEBUG_END() //KIES_INFO("====>>>>fun=%s, END====>>>>", __FUNCTION__);
+#define KIES_DEBUG_INFO(fmt, arg...) //KIES_INFO(fmt, ##arg)
+#define KIES_DEBUG_INFO(fmt, arg...) //KIES_ERR(fmt, ##arg)
+
+#define KIES_RET_IF(expr) \
+ do { \
+ if (expr) { \
+ nErr = FAILED;\
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } \
+ } while (0);
+#define KIES_RETV_IF(expr, val) \
+ do { \
+ if (expr) { \
+ nErr = FAILED;\
+ ret = val;\
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+#define KIES_RETE_IF(expr, errorId) \
+ do { \
+ if (expr) { \
+ nErr = errorId;\
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+#define KIES_RETEM_IF(expr, errorId, fmt, arg...) \
+ do { \
+ if (expr) { \
+ nErr = errorId;\
+ KIES_INFO_RED(fmt, ##arg); \
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+#define KIES_RETVE_IF(expr, val, errorId) \
+ do { \
+ if (expr) { \
+ nErr = errorId;\
+ ret = val;\
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+#define KIES_RETM_IF(expr, fmt, arg...) \
+ do { \
+ if (expr) { \
+ nErr = FAILED;\
+ KIES_INFO_RED(fmt, ##arg); \
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+#define KIES_RETVM_IF(expr, val, fmt, arg...) \
+ do { \
+ if (expr) { \
+ nErr = FAILED;\
+ ret = val;\
+ KIES_INFO_RED(fmt, ##arg); \
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+#define KIES_RETVME_IF(expr, val, errorId, fmt, arg...) \
+ do { \
+ if (expr) { \
+ nErr = errorId;\
+ ret = val;\
+ KIES_INFO_RED(fmt, ##arg); \
+ KIES_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
+ goto End; \
+ } \
+ } while (0);
+/* anci c color type */
+#define FONT_COLOR_RESET "\033[0m"
+#define FONT_COLOR_RED "\033[31m"
+#define FONT_COLOR_GREEN "\033[32m"
+#define FONT_COLOR_YELLOW "\033[33m"
+#define FONT_COLOR_BLUE "\033[34m"
+#define FONT_COLOR_PURPLE "\033[35m"
+#define FONT_COLOR_CYAN "\033[36m"
+#define FONT_COLOR_GRAY "\033[37m"
+
+#define KIES_INFO_RED(fmt, arg...) KIES_INFO(FONT_COLOR_RED fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_GREEN(fmt, arg...) KIES_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_YELLOW(fmt, arg...) KIES_INFO(FONT_COLOR_YELLOW fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_BLUE(fmt, arg...) KIES_INFO(FONT_COLOR_BLUE fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_PURPLE(fmt, arg...) KIES_INFO(FONT_COLOR_PURPLE fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_GREEN(fmt, arg...) KIES_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_CYAN(fmt, arg...) KIES_INFO(FONT_COLOR_CYAN fmt FONT_COLOR_RESET, ##arg)
+#define KIES_INFO_GRAY(fmt, arg...) KIES_INFO(FONT_COLOR_GRAY fmt FONT_COLOR_RESET, ##arg)
+
+#define KIES_INFO_WITH_COLOR(color, fmt, arg...) KIES_INFO(color fmt FONT_COLOR_RESET, ##arg)
+
+#endif //__KIES_DLOG_H__
diff --git a/kies_alarm/include/kies_fwk_alarmmgr.h b/kies_alarm/include/kies_fwk_alarmmgr.h
new file mode 100644
index 0000000..5966ce1
--- /dev/null
+++ b/kies_alarm/include/kies_fwk_alarmmgr.h
@@ -0,0 +1,28 @@
+/*
+*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+#ifndef __KIES_FWK_ALARMMGR_H__
+#define __KIES_FWK_ALARMMGR_H__
+
+#include <alarm-engine.h>
+#include "kies_define.h"
+
+int kies_fwk_alarmmgr_remove(struct alarm_data *alarm);
+int kies_fwk_alarmmgr_create(struct alarm_data *alarm);
+int kies_fwk_alarmmgr_update(struct alarm_data *alarm);
+
+#endif //__KIES_FWK_ALARMMGR_H__
diff --git a/kies_alarm/kies_alarm.pc.in b/kies_alarm/kies_alarm.pc.in
new file mode 100755
index 0000000..2347a8b
--- /dev/null
+++ b/kies_alarm/kies_alarm.pc.in
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: Alarm for kies library
+Description: It is used by kies team, for save/restore alarm.
+Version: @VERSION@
+Requires: db-util
+Libs: -L${libdir} -lkies_alarm
+Cflags: -I${includedir}
diff --git a/kies_alarm/src/kies_alarm.c b/kies_alarm/src/kies_alarm.c
new file mode 100644
index 0000000..4e7e6b6
--- /dev/null
+++ b/kies_alarm/src/kies_alarm.c
@@ -0,0 +1,290 @@
+/*
+*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+#include "kies_alarm.h"
+#include <alarm.h>
+#include "alarm-engine.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include "kies_fwk_alarmmgr.h"
+#include "kies_define.h"
+/**********************************************************************
+******************define *************************************
+***********************************************************************/
+typedef enum {
+ TYPE_SAVE_ALARM_MODE_BINARY,
+ TYPE_SAVE_ALARM_MODE_TEXT,
+ TYPE_SAVE_ALARM_MODE_MAX,
+} TYPE_SAVE_ALARM_MODE;
+/**********************************************************************
+******************common *************************************
+***********************************************************************/
+
+//
+static bool is_file_exist(char *file_path)
+{
+ if (!file_path) {
+ return false;
+ }
+ FILE *pFile = NULL;
+ pFile = fopen(file_path, "r");
+ if (!pFile) {
+ return false;
+ }
+ fclose(pFile);
+ return true;
+}
+
+/**********************************************************************
+******************save *************************************
+***********************************************************************/
+
+//
+static int _write_alarm_to_file_binary(ADList * list, char * file_path)
+{
+ int ret = SUCCESS;
+ int nErr = SUCCESS;
+ FILE *pFile = NULL;
+ ADList *cur_data = NULL;
+ struct alarm_data *pAlarm = NULL;
+ size_t cur_size = 0;
+ KIES_FUN_BEG();
+ KIES_RETVM_IF(!list, FAILED, "alarm list null");
+ KIES_RETVM_IF(!file_path, FAILED, "file_path null");
+ //KIES_RETVM_IF(is_file_exist(file_path),FAILED,"file path error");
+ pFile = fopen(file_path, "w");
+ KIES_RETVM_IF(!pFile, FAILED, "fopen error");
+ for (cur_data = list; cur_data; cur_data = cur_data->next) {
+ pAlarm = &cur_data->ad;
+ cur_size = fwrite(pAlarm, sizeof(struct alarm_data), 1, pFile);
+ KIES_RETVM_IF(cur_size != 1, FAILED, "fwrite size error");
+ }
+ End:
+ FCLOSE_IF(pFile);
+ KIES_FUN_END();
+ return ret;
+}
+
+//
+static int _write_alarm_to_file_text(ADList *list, char *file_path)
+{
+ int ret = SUCCESS;
+ return ret;
+}
+
+//
+static int _write_alarm_to_file(ADList *list,
+ char *file_path, TYPE_SAVE_ALARM_MODE save_mode)
+{
+ int ret = FAILED;
+ KIES_FUN_BEG();
+ switch (save_mode) {
+ case TYPE_SAVE_ALARM_MODE_BINARY:
+ ret = _write_alarm_to_file_binary(list, file_path);
+ break;
+ case TYPE_SAVE_ALARM_MODE_TEXT:
+ ret = _write_alarm_to_file_text(list, file_path);
+ break;
+ case TYPE_SAVE_ALARM_MODE_MAX:
+ KIES_INFO_RED("type is error, save_mode=%d", save_mode);
+ break;
+ }
+ KIES_FUN_END();
+ return ret;
+}
+
+//when backup, firstly, we need to get alarm data from libslp-alarm
+//then, save the data to file_path
+A_DBAPI int alarm_backup(const char *file_path)
+{
+ int nErr = SUCCESS;
+ int ret = SUCCESS;
+ int db_success = FAILED;
+ ADList *list = NULL;
+ KIES_FUN_BEG();
+ //init alarmdb
+ KIES_RETVM_IF(!file_path, FAILED, "file_path null");
+ nErr = alarmdb_init(NULL);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmdb_init");
+ db_success = SUCCESS;
+ //get alarm data, because alarmdb is used by many APs
+ list = alarmdb_get_data_list_by_author(ALARM_DB_AUTHOR_ALARM);
+ KIES_RETVM_IF(!list, RESULT_ERR_NULL_ALARM, "alarm data is NULL");
+ nErr =
+ _write_alarm_to_file(list, (char *)file_path,
+ TYPE_SAVE_ALARM_MODE_BINARY);
+ KIES_RETVM_IF(nErr != SUCCESS, nErr, "_write_alarm_to_file NULL");
+ End:
+ FREE_ADLIST(list);
+ if (IS_EQUAL(db_success, SUCCESS)) {
+ alarmdb_fini();
+ }
+ KIES_FUN_END();
+ return ret;
+}
+
+/**********************************************************************
+******************restore *************************************
+ ***********************************************************************/
+
+//clear alarm data in db;
+//if alarm is enable, remove from alarm-manger
+static int _reset_alarm(ADList *list)
+{
+ int nErr = SUCCESS;
+ int ret = SUCCESS;
+ ADList *cur_data = NULL;
+ struct alarm_data *pAlarm = NULL;
+ KIES_FUN_BEG();
+ KIES_RETVM_IF(!list, SUCCESS, "null list, nothing to do");
+ //
+ for (cur_data = list; cur_data; cur_data = cur_data->next) {
+ pAlarm = &cur_data->ad;
+ if (pAlarm->enable) {
+ nErr = kies_fwk_alarmmgr_remove(pAlarm);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED,
+ "alarmmgr_remove_alarm error");
+ }
+ nErr = alarmdb_del_data(pAlarm->id);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED,
+ "alarmdb_del_data error");
+ }
+ End:
+ KIES_FUN_END();
+ return ret;
+}
+
+//if enable alarm, register alarm
+//then, add to alarm db
+static int _save_alarm(struct alarm_data *pAlarm)
+{
+ int ret = SUCCESS;
+ int nErr = SUCCESS;
+ KIES_FUN_BEG();
+ KIES_RETVM_IF(!pAlarm, FAILED, "null alarm");
+ if (pAlarm->enable) {
+ nErr = kies_fwk_alarmmgr_create(pAlarm);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "_register_alarm error");
+ }
+ nErr = alarmdb_add_data(pAlarm);
+ KIES_RETVM_IF(IS_EQUAL(nErr, -1), FAILED, "alarmdb_add_data error");
+ End:
+ KIES_FUN_END();
+ return ret;
+}
+
+//
+static int _read_alarm_from_file_binary(char *file_path)
+{
+ int ret = SUCCESS;
+ int nErr = SUCCESS;
+ FILE *pFile = NULL;
+ size_t cur_size = 0;
+ struct alarm_data alarm;
+ KIES_FUN_BEG();
+ KIES_RETVM_IF(!file_path, FAILED, "file_path null");
+ KIES_RETVM_IF(!is_file_exist(file_path), FAILED, "file path error");
+ pFile = fopen(file_path, "r");
+ KIES_RETVM_IF(!pFile, FAILED, "fopen error");
+ //
+ while (1) {
+ cur_size = fread(&alarm, sizeof(alarm), 1, pFile);
+ if (IS_EQUAL(0, cur_size)) {
+ //file is null, success
+ goto End;
+ }
+ KIES_RETVM_IF(cur_size != 1, FAILED, "fread size error");
+ //
+ nErr = _save_alarm(&alarm);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "_save_alarm error");
+ }
+ End:
+ FCLOSE_IF(pFile);
+ KIES_FUN_END();
+ return ret;
+}
+
+//
+static int _read_alarm_from_file_text(char *file_path)
+{
+ int ret = SUCCESS;
+ return ret;
+}
+
+//
+static int _read_alarm_from_file(char *file_path,
+ TYPE_SAVE_ALARM_MODE save_mode)
+{
+ int ret = FAILED;
+ KIES_FUN_BEG();
+ switch (save_mode) {
+ case TYPE_SAVE_ALARM_MODE_BINARY:
+ ret = _read_alarm_from_file_binary(file_path);
+ break;
+ case TYPE_SAVE_ALARM_MODE_TEXT:
+ ret = _read_alarm_from_file_text(file_path);
+ break;
+ case TYPE_SAVE_ALARM_MODE_MAX:
+ KIES_INFO_RED("type is error, save_mode=%d", save_mode);
+ break;
+ }
+ KIES_FUN_END();
+ return ret;
+}
+
+//
+A_DBAPI int alarm_restore(const char *file_path)
+{
+ int nErr = SUCCESS;
+ int ret = SUCCESS;
+ int db_success = FAILED;
+ int mgr_success = FAILED;
+ ADList *list = NULL;
+ KIES_FUN_BEG();
+ //init alarmdb
+ KIES_RETVM_IF(!file_path, FAILED, "file_path null");
+ nErr = alarmdb_init(NULL);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmdb_init");
+ db_success = SUCCESS;
+ nErr = alarmmgr_init(PKGNAME);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_init error");
+ mgr_success = SUCCESS;
+ //get alarm data, because alarmdb is used by many APs
+ list = alarmdb_get_data_list_by_author(ALARM_DB_AUTHOR_ALARM);
+ //delete all alarm data
+ nErr = _reset_alarm(list);
+ KIES_RETVM_IF(nErr != SUCCESS, nErr, "_reset_alarm error");
+ //
+ nErr =
+ _read_alarm_from_file((char *)file_path,
+ TYPE_SAVE_ALARM_MODE_BINARY);
+ KIES_RETVM_IF(nErr != SUCCESS, nErr, "_write_alarm_to_file NULL");
+ //notify
+ vconf_set_bool(VCONFKEY_ALARM_RESTORE, true);
+ End:
+ FREE_ADLIST(list);
+ if (IS_EQUAL(db_success, SUCCESS)) {
+ alarmdb_fini();
+ }
+ if (IS_EQUAL(mgr_success, SUCCESS)) {
+ alarmmgr_fini();
+ }
+ KIES_FUN_END();
+ return ret;
+}
diff --git a/kies_alarm/src/kies_fwk_alarmmgr.c b/kies_alarm/src/kies_fwk_alarmmgr.c
new file mode 100644
index 0000000..1d681f4
--- /dev/null
+++ b/kies_alarm/src/kies_fwk_alarmmgr.c
@@ -0,0 +1,129 @@
+/*
+*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+#define __KIES_FWK_ALARMMGR_C__
+
+#include "kies_fwk_alarmmgr.h"
+#include <alarm.h>
+
+/**********************************************************************
+******************define, struct ,typedef, union, enum, global val *************************************
+***********************************************************************/
+
+/**********************************************************************
+******************Local function declear, extern function declear*************************************
+***********************************************************************/
+
+/**********************************************************************
+******************Local function ref*************************************
+***********************************************************************/
+/**********************************************************************
+******************Global function ref*************************************
+***********************************************************************/
+
+/**
+* send
+* This function is used to create mgr
+* @param data[in] pointer to struct alarm_data
+* @return when success, return true or false if error
+* @exception
+*/
+int kies_fwk_alarmmgr_create(struct alarm_data *alarm)
+{
+ int ret = SUCCESS;
+ int nErr = SUCCESS;
+ alarm_entry_t *alarm_entry = NULL;
+ alarm_date_t alarm_data;
+ KIES_FUN_BEG();
+ KIES_RETVM_IF(!alarm, FAILED, "para error");
+ /*create alarm */
+ alarm_entry = alarmmgr_create_alarm();
+ KIES_RETVM_IF(!alarm_entry, FAILED, "alarmmgr_create_alarm error");
+ /*set time_data */
+ struct tm pt;
+ localtime_r((__const time_t *) &alarm->atime, &pt);
+ SET_TIME_DATA_T(&alarm_data, pt.tm_year + 1900, pt.tm_mon + 1,
+ pt.tm_mday, pt.tm_hour, pt.tm_min, pt.tm_sec);
+ nErr = alarmmgr_set_time(alarm_entry, alarm_data);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_time error");
+ /*set repeat */
+ int repeat_value = 0;
+ alarm_repeat_mode_t repeat_mode = 0;
+ if (alarm->repeat_once) {
+ repeat_mode = ALARM_REPEAT_MODE_ONCE;
+ } else if (alarm->repeat_weekly) {
+ repeat_mode = ALARM_REPEAT_MODE_WEEKLY;
+ }
+ repeat_value = alarm->repeat_weekly;
+ nErr = alarmmgr_set_repeat_mode(alarm_entry, repeat_mode, repeat_value);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED,
+ "alarmmgr_set_repeat_mode error");
+ /**set type */
+ nErr = alarmmgr_set_type(alarm_entry, ALARM_TYPE_DEFAULT);
+ KIES_RETVM_IF(nErr != SUCCESS, FAILED, "alarmmgr_set_type error");
+ /**create new */
+ int alarm_mgr_id = 0;
+ KIES_INFO_PURPLE("%s", ALARMRING_PKGNAME);
+ nErr =
+ alarmmgr_add_alarm_with_localtime(alarm_entry, ALARMRING_PKGNAME,
+ &alarm_mgr_id);
+ KIES_RETVM_IF(SUCCESS != nErr, FAILED,
+ "alarmmgr_add_alarm_with_localtime error,nErr=%d", nErr);
+
+ alarm->alarm_mgr_id = alarm_mgr_id;
+ KIES_INFO_CYAN("alarm_mgr_id = %d", alarm->alarm_mgr_id);
+ End:
+ if (alarm_entry) {
+ alarmmgr_free_alarm(alarm_entry);
+ }
+ KIES_FUN_END();
+ return ret;
+}
+
+/**
+* send
+* This function is used to remove mgr
+* @param data[in] pointer to struct alarm_data
+* @return when success, return true or false if error
+* @exception
+*/
+int kies_fwk_alarmmgr_remove(struct alarm_data *alarm)
+{
+ int ret = SUCCESS;
+ ret = alarmmgr_remove_alarm(alarm->alarm_mgr_id);
+ if (ret != SUCCESS) {
+ KIES_INFO_RED("Failed to remove alarm[%d], error code: %d\n",
+ alarm->alarm_mgr_id, ret);
+ }
+ alarm->alarm_mgr_id = -1;
+ return ret;
+}
+
+/**
+* send
+* This function is used to update mgr
+* @param data[in] pointer to struct alarm_data
+* @return when success, return true or false if error
+* @exception
+*/
+int kies_fwk_alarmmgr_update(struct alarm_data *alarm)
+{
+ int ret = SUCCESS;
+ ret = kies_fwk_alarmmgr_remove(alarm);
+ ret |= kies_fwk_alarmmgr_create(alarm);
+ return ret;
+}