From d559302f15907c97f30d539cb608da567e92443f Mon Sep 17 00:00:00 2001 From: "seungha.son" Date: Mon, 10 Oct 2016 21:34:23 +0900 Subject: [PATCH] Separates files related shorcut error from shortcut internal Signed-off-by: seungha.son Change-Id: I82c5d2eae86d4821fdd35d685ecdfc06e3ad249b --- lib/CMakeLists.txt | 4 ++- lib/include/shortcut.h | 3 +- lib/include/shortcut_error.h | 62 +++++++++++++++++++++++++++++++++++++++++ lib/include/shortcut_internal.h | 1 + lib/include/shortcut_manager.h | 19 +------------ lib/src/shortcut_db.c | 2 +- lib/src/shortcut_error.c | 59 +++++++++++++++++++++++++++++++++++++++ lib/src/shortcut_internal.c | 44 ++--------------------------- lib/src/shortcut_manager.c | 1 - packaging/libshortcut.spec | 1 + 10 files changed, 132 insertions(+), 64 deletions(-) create mode 100755 lib/include/shortcut_error.h create mode 100755 lib/src/shortcut_error.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 43399c1..6b0e301 100755 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -33,10 +33,11 @@ ADD_DEFINITIONS("-DLOG_TAG=\"SHORTCUT\"") ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET") ADD_DEFINITIONS("-DDB_PATH=\"${DB_PATH}\"") -ADD_LIBRARY(${PROJECT_NAME} SHARED +ADD_LIBRARY(${PROJECT_NAME} SHARED src/shortcut_manager.c src/shortcut_db.c src/shortcut_internal.c + src/shortcut_error.c ) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${svc_pkgs_LDFLAGS}) @@ -50,6 +51,7 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_private.h DESTINATION inc INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_db.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_manager.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_internal.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_error.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}") diff --git a/lib/include/shortcut.h b/lib/include/shortcut.h index 538579b..5f66db1 100755 --- a/lib/include/shortcut.h +++ b/lib/include/shortcut.h @@ -19,8 +19,9 @@ #define __SHORTCUT_H__ #include -#include #include +#include "shortcut_manager.h" +#include "shortcut_error.h" #ifdef __cplusplus extern "C" { diff --git a/lib/include/shortcut_error.h b/lib/include/shortcut_error.h new file mode 100755 index 0000000..185078d --- /dev/null +++ b/lib/include/shortcut_error.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2011 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 + * + * 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 __SHORTCUT_ERROR_H__ +#define __SHORTCUT_ERROR_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file shortcut_error.h + */ + +/** + * @addtogroup SHORTCUT_MODULE + * @{ + */ + +/** + * @brief Enumeration for values of shortcut response types. + * @since_tizen 2.3 + */ +enum shortcut_error_e { + SHORTCUT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + SHORTCUT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */ + SHORTCUT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + SHORTCUT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O Error */ + SHORTCUT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + SHORTCUT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + SHORTCUT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ + SHORTCUT_ERROR_NO_SPACE = TIZEN_ERROR_SHORTCUT | 0x0001, /**< There is no space to add a new shortcut */ + SHORTCUT_ERROR_EXIST = TIZEN_ERROR_SHORTCUT | 0x0002, /**< Shortcut is already added */ + SHORTCUT_ERROR_FAULT = TIZEN_ERROR_SHORTCUT | 0x0004, /**< Unrecoverable error */ + SHORTCUT_ERROR_COMM = TIZEN_ERROR_SHORTCUT | 0x0040 /**< Connection not established or communication problem */ +}; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/shortcut_internal.h b/lib/include/shortcut_internal.h index e2c7796..923fe66 100755 --- a/lib/include/shortcut_internal.h +++ b/lib/include/shortcut_internal.h @@ -23,6 +23,7 @@ #include #include "shortcut.h" #include "shortcut_manager.h" +#include "shortcut_error.h" #ifndef EXPORT_API #define EXPORT_API __attribute__ ((visibility("default"))) diff --git a/lib/include/shortcut_manager.h b/lib/include/shortcut_manager.h index 0b8b153..fe44516 100755 --- a/lib/include/shortcut_manager.h +++ b/lib/include/shortcut_manager.h @@ -19,6 +19,7 @@ #define __SHORTCUT_MANAGER_H__ #include +#include "shortcut_error.h" #ifdef __cplusplus extern "C" { @@ -50,24 +51,6 @@ typedef enum _shortcut_type { } shortcut_type; /** - * @brief Enumeration for values of shortcut response types. - * @since_tizen 2.3 - */ -enum shortcut_error_e { - SHORTCUT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - SHORTCUT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */ - SHORTCUT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - SHORTCUT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O Error */ - SHORTCUT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ - SHORTCUT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ - SHORTCUT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ - SHORTCUT_ERROR_NO_SPACE = TIZEN_ERROR_SHORTCUT | 0x0001, /**< There is no space to add a new shortcut */ - SHORTCUT_ERROR_EXIST = TIZEN_ERROR_SHORTCUT | 0x0002, /**< Shortcut is already added */ - SHORTCUT_ERROR_FAULT = TIZEN_ERROR_SHORTCUT | 0x0004, /**< Unrecoverable error */ - SHORTCUT_ERROR_COMM = TIZEN_ERROR_SHORTCUT | 0x0040 /**< Connection not established or communication problem */ -}; - -/** * @brief Enumeration for sizes of shortcut widget. * @since_tizen 2.4 */ diff --git a/lib/src/shortcut_db.c b/lib/src/shortcut_db.c index a5bf617..aacfd97 100755 --- a/lib/src/shortcut_db.c +++ b/lib/src/shortcut_db.c @@ -6,7 +6,7 @@ #include #include - +#include "shortcut_error.h" static sqlite3 *_open_db(void) { diff --git a/lib/src/shortcut_error.c b/lib/src/shortcut_error.c new file mode 100755 index 0000000..00c2b17 --- /dev/null +++ b/lib/src/shortcut_error.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 + * + * 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 +#include +#include "shortcut_error.h" + +static const GDBusErrorEntry dbus_error_entries[] = { + {SHORTCUT_ERROR_INVALID_PARAMETER, "org.freedesktop.Shortcut.Error.INVALID_PARAMETER"}, + {SHORTCUT_ERROR_OUT_OF_MEMORY, "org.freedesktop.Shortcut.Error.OUT_OF_MEMORY"}, + {SHORTCUT_ERROR_IO_ERROR, "org.freedesktop.Shortcut.Error.IO_ERROR"}, + {SHORTCUT_ERROR_PERMISSION_DENIED, "org.freedesktop.Shortcut.Error.PERMISSION_DENIED"}, + {SHORTCUT_ERROR_NOT_SUPPORTED, "org.freedesktop.Shortcut.Error.NOT_SUPPORTED"}, + {SHORTCUT_ERROR_RESOURCE_BUSY, "org.freedesktop.Shortcut.Error.RESOURCE_BUSY"}, + {SHORTCUT_ERROR_NO_SPACE, "org.freedesktop.Shortcut.Error.NO_SPACE"}, + {SHORTCUT_ERROR_EXIST, "org.freedesktop.Shortcut.Error.EXIST"}, + {SHORTCUT_ERROR_FAULT, "org.freedesktop.Shortcut.Error.FAULT"}, + {SHORTCUT_ERROR_COMM, "org.freedesktop.Shortcut.Error.COMM"}, +}; + +#define SHORTCUT_ERROR_QUARK "shortcut-error-quark" + +EXPORT_API GQuark shortcut_error_quark(void) +{ + static volatile gsize quark_volatile = 0; + static char *domain_name = NULL; + + /* This is for preventing crash when notification api is used in ui-gadget */ + /* ui-gadget libraries can be unloaded when it is needed and the static string */ + /* parameter to g_dbus_error_register_error_domain may cause crash. */ + GQuark quark = g_quark_try_string(SHORTCUT_ERROR_QUARK); + + if (quark == 0) { + if (domain_name == NULL) + domain_name = strdup(SHORTCUT_ERROR_QUARK); + } else { + domain_name = SHORTCUT_ERROR_QUARK; + } + + g_dbus_error_register_error_domain(domain_name, + &quark_volatile, + dbus_error_entries, + G_N_ELEMENTS(dbus_error_entries)); + return (GQuark) quark_volatile; +} diff --git a/lib/src/shortcut_internal.c b/lib/src/shortcut_internal.c index 776d2f7..ece3e52 100755 --- a/lib/src/shortcut_internal.c +++ b/lib/src/shortcut_internal.c @@ -44,19 +44,6 @@ static GDBusConnection *_gdbus_conn = NULL; static int monitor_id = 0; static int provider_monitor_id = 0; -static const GDBusErrorEntry dbus_error_entries[] = { - {SHORTCUT_ERROR_INVALID_PARAMETER, "org.freedesktop.Shortcut.Error.INVALID_PARAMETER"}, - {SHORTCUT_ERROR_OUT_OF_MEMORY, "org.freedesktop.Shortcut.Error.OUT_OF_MEMORY"}, - {SHORTCUT_ERROR_IO_ERROR, "org.freedesktop.Shortcut.Error.IO_ERROR"}, - {SHORTCUT_ERROR_PERMISSION_DENIED, "org.freedesktop.Shortcut.Error.PERMISSION_DENIED"}, - {SHORTCUT_ERROR_NOT_SUPPORTED, "org.freedesktop.Shortcut.Error.NOT_SUPPORTED"}, - {SHORTCUT_ERROR_RESOURCE_BUSY, "org.freedesktop.Shortcut.Error.RESOURCE_BUSY"}, - {SHORTCUT_ERROR_NO_SPACE, "org.freedesktop.Shortcut.Error.NO_SPACE"}, - {SHORTCUT_ERROR_EXIST, "org.freedesktop.Shortcut.Error.EXIST"}, - {SHORTCUT_ERROR_FAULT, "org.freedesktop.Shortcut.Error.FAULT"}, - {SHORTCUT_ERROR_COMM, "org.freedesktop.Shortcut.Error.COMM"}, -}; - typedef struct _shortcut_request_cb_info { int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data); void *data; @@ -70,33 +57,6 @@ typedef struct _shortcut_remove_cb_info { static shortcut_request_cb_info _request_callback_info; static shortcut_remove_cb_info _remove_callback_info; - -#define SHORTCUT_ERROR_QUARK "shortcut-error-quark" - -EXPORT_API GQuark shortcut_error_quark(void) -{ - static volatile gsize quark_volatile = 0; - static char *domain_name = NULL; - - /* This is for preventing crash when notification api is used in ui-gadget */ - /* ui-gadget libraries can be unloaded when it is needed and the static string */ - /* parameter to g_dbus_error_register_error_domain may cause crash. */ - GQuark quark = g_quark_try_string(SHORTCUT_ERROR_QUARK); - - if (quark == 0) { - if (domain_name == NULL) - domain_name = strdup(SHORTCUT_ERROR_QUARK); - } else { - domain_name = SHORTCUT_ERROR_QUARK; - } - - g_dbus_error_register_error_domain(domain_name, - &quark_volatile, - dbus_error_entries, - G_N_ELEMENTS(dbus_error_entries)); - return (GQuark) quark_volatile; -} - /* LCOV_EXCL_START */ static void _add_shortcut_notify(GVariant *parameters) { @@ -504,7 +464,7 @@ EXPORT_API int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_d { int ret; - if(remove_cb == NULL) + if (remove_cb == NULL) return SHORTCUT_ERROR_INVALID_PARAMETER; ret = _dbus_init(); @@ -552,7 +512,7 @@ EXPORT_API int shortcut_remove_from_home(const char *name, result_cb_t result_cb int ret; GVariant *body; - if(name == NULL) { + if (name == NULL) { ErrPrint("name is NULL."); return SHORTCUT_ERROR_INVALID_PARAMETER; } diff --git a/lib/src/shortcut_manager.c b/lib/src/shortcut_manager.c index 21081be..214707b 100755 --- a/lib/src/shortcut_manager.c +++ b/lib/src/shortcut_manager.c @@ -32,7 +32,6 @@ #include "shortcut_manager.h" #include "shortcut_internal.h" - #define SHORTCUT_IS_WIDGET_SIZE(size) (!!((size) & WIDGET_SIZE_DEFAULT)) EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data) diff --git a/packaging/libshortcut.spec b/packaging/libshortcut.spec index 0d0e948..f8baec2 100755 --- a/packaging/libshortcut.spec +++ b/packaging/libshortcut.spec @@ -104,6 +104,7 @@ chsmack -a User::Home %{TZ_SYS_DB}/.shortcut_service.db-journal %{_includedir}/shortcut/shortcut_manager.h %{_includedir}/shortcut/shortcut_db.h %{_includedir}/shortcut/shortcut_internal.h +%{_includedir}/shortcut/shortcut_error.h %{_libdir}/pkgconfig/shortcut.pc -- 2.7.4