From 7f1978de2e1e3c264f8c68864b7c6f6c95e394e3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 23 Oct 2015 13:38:23 +0900 Subject: [PATCH] Merge tizen 2.4 into tizen - changes for migrating dbus-glib into gdbus Change-Id: I64ea42f2e07f79cb1d2e9d6477cca32754aa36e3 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 4 +- include/simple_util.h | 1 + include/syspopup.h | 25 ++--- include/syspopup_caller.h | 11 +- include/syspopup_core.h | 3 +- include/syspopup_db.h | 1 - packaging/syspopup.spec | 5 +- src/syspopup_core.c | 134 +++++++++++------------ src/syspopup_db.c | 224 ++++++++++---------------------------- syspopup-caller/CMakeLists.txt | 2 +- syspopup-caller/syspopup_caller.c | 64 +++++------ syspopup/CMakeLists.txt | 3 +- syspopup/syspopup.c | 115 +++++++++---------- syspopup/syspopup_efl.c | 7 +- 14 files changed, 236 insertions(+), 363 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac9e968..e21f258 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ IF (with_wayland) ADD_DEFINITIONS("-DWAYLAND") ENDIF(with_wayland) -pkg_check_modules(libpkgs REQUIRED aul dlog bundle sqlite3 glib-2.0 dbus-glib-1 libtzplatform-config) +pkg_check_modules(libpkgs REQUIRED aul dlog bundle sqlite3 glib-2.0 gio-2.0 libtzplatform-config) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -39,7 +39,7 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2") SET(CMAKE_SKIP_BUILD_RPATH true) -# Get uname value to set 'TARGET' definition +# Get uname value to set 'TARGET' definition # TODO: Is this needed? FIND_PROGRAM(UNAME NAMES uname) EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") diff --git a/include/simple_util.h b/include/simple_util.h index 684a56d..e95bc18 100755 --- a/include/simple_util.h +++ b/include/simple_util.h @@ -35,6 +35,7 @@ #define _E(fmt, arg...) LOGE(fmt,##arg) #define _D(fmt, arg...) LOGD(fmt,##arg) +#define _I(fmt, arg...) LOGI(fmt,##arg) #define SYSPOPUP_DBUS_PATH "/syspopup/dbus_handler" #define SYSPOPUP_DBUS_SIGNAL_INTERFACE "org.tizen.syspopup.signal" diff --git a/include/syspopup.h b/include/syspopup.h index 794ac7a..80a8f8d 100755 --- a/include/syspopup.h +++ b/include/syspopup.h @@ -33,8 +33,8 @@ /** * @mainpage - * - * This is System Popup Library + * + * This is System Popup Library * This library help to create system popup application & to launch/destroy system popup application * */ @@ -42,21 +42,21 @@ /** * @close * @ingroup APPLICATION_FRAMEWORK - * @defgroup syspopup System Popup Library + * @defgroup syspopup System Popup Library * @{ */ /** - * @file syspopup.h + * @file syspopup.h * @brief System Popup UI Library * * Patched by Knhoon Baik - * Patched by Noha Park + * Patched by Noha Park */ /** * @defgroup syspopup_ui Helper Library to create system popup application - * @ingroup syspopup + * @ingroup syspopup * @brief Helper Library to create system popup application */ @@ -65,8 +65,8 @@ * @{ */ -/** - *@brief action handler supplied by user +/** + * @brief action handler supplied by user * def_term_fn is called when event to destroy all system popup occur * def_timeout_fn is called when the system popup's timeout is expired */ @@ -82,7 +82,7 @@ typedef struct _syspopup_handler syspopup_handler; /** * @brief This API make elm system popup window * - * This API make elm system popup window. + * This API make elm system popup window. * and then, make given elm system popup window as system popup type * and set system popup properties based on system popup information DB.\n * system popup properties to be set : timeout, default action type, .... @@ -112,12 +112,12 @@ int syspopup_create(bundle *b, syspopup_handler *handler, int syspopup_reset(bundle *b); /** - * @brief This API ask that the system popup is created and is running + * @brief This API ask that the system popup is created and is running * - * This API ask that the the system popup with popup name is created and is running after extracting popup name from given bundle. + * This API ask that the the system popup with popup name is created and is running after extracting popup name from given bundle. * * @param[in] b bundle received by app_reset handler (included system popup name) - * @return true / false + * @return true / false * @retval 1 app already has the system popup * @retval 0 app has not the system popup */ @@ -139,4 +139,3 @@ int syspopup_reset_timeout(bundle *b, unsigned int time); /** @} */ #endif - diff --git a/include/syspopup_caller.h b/include/syspopup_caller.h index e00d5d2..7addaf4 100755 --- a/include/syspopup_caller.h +++ b/include/syspopup_caller.h @@ -31,16 +31,16 @@ extern "C" { #endif /** - * @file syspopup_caller.h + * @file syspopup_caller.h * @brief Library to launch/destroy System Popup Application * * Patched by Knhoon Baik - * Patched by Noha Park + * Patched by Noha Park */ /** * @defgroup syspopup_caller Helper Library to launch/destroy system popup application - * @ingroup syspopup + * @ingroup syspopup * @brief Helper Library to launch/destroy system popup application */ @@ -57,7 +57,7 @@ extern "C" { * And then, launch found application package * * @param[in] popup_name system popup application name to launch (not package name) - * @param[in] b extra bundle(arguement) to toss the popup application + * @param[in] b extra bundle(arguement) to toss the popup application * @return 0 if success, negative value(<0) if fail * @retval 0 - success * @retval -1 - generic error @@ -89,7 +89,7 @@ int syspopup_launch(char *popup_name, bundle *b); * @retval 0 - success * @retval -1 - generic error */ -int syspopup_destroy_all(); +int syspopup_destroy_all(void); /** @} */ @@ -98,4 +98,3 @@ int syspopup_destroy_all(); #endif #endif - diff --git a/include/syspopup_core.h b/include/syspopup_core.h index 463a60a..ea43742 100755 --- a/include/syspopup_core.h +++ b/include/syspopup_core.h @@ -29,7 +29,6 @@ #include "syspopup_db.h" #define SYSPOPUP_DEFAULT_TIMEOUT 20 /* sec */ -#define SYSPOPUP_TERM_NOTI_PATH "/usr/share/popup_noti_term" struct _syspopup { int id; @@ -49,7 +48,7 @@ struct _syspopup { typedef struct _syspopup syspopup; -syspopup *_syspopup_get_head(); +syspopup *_syspopup_get_head(void); int _syspopup_add_new(syspopup *pinfo); syspopup *_syspopup_find(const char *name); syspopup *_syspopup_find_by_id(int id); diff --git a/include/syspopup_db.h b/include/syspopup_db.h index f57e0dd..f4c07df 100755 --- a/include/syspopup_db.h +++ b/include/syspopup_db.h @@ -58,4 +58,3 @@ syspopup_info_t *_syspopup_info_get(const char *popup_name); void _syspopup_info_free(syspopup_info_t *pinfo); #endif - diff --git a/packaging/syspopup.spec b/packaging/syspopup.spec index b2cff21..d634db5 100644 --- a/packaging/syspopup.spec +++ b/packaging/syspopup.spec @@ -17,7 +17,8 @@ BuildRequires: cmake BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) %if %{with x} BuildRequires: pkgconfig(utilX) BuildRequires: pkgconfig(x11) @@ -31,7 +32,6 @@ BuildRequires: pkgconfig(libtzplatform-config) %description syspopup package for popup - %package devel Summary: Syspopup development package Group: System/Libraries @@ -58,7 +58,6 @@ Requires: %{name} = %{version}-%{release} %description caller-devel syspopup-caller development package for popup - %prep %setup -q sed -i %{SOURCE1001} -e "s|TZ_SYS_DB|%TZ_SYS_DB|g" diff --git a/src/syspopup_core.c b/src/syspopup_core.c index d8cced4..f4903a1 100755 --- a/src/syspopup_core.c +++ b/src/syspopup_core.c @@ -24,10 +24,10 @@ #include #include #include -#include -#include #include #include +#include +#include /* For multi-user support */ #include @@ -40,14 +40,12 @@ static syspopup *syspopup_head = NULL; static int initialized = 0; -static DBusConnection *bus; -static int noti_fd = -1; static int sp_id = 0; -static void (*_term_handler) (void *data); -static gboolean(*_timeout_handler) (void *data); +static void (*_term_handler)(void *data); +static gboolean (*_timeout_handler)(void *data); -syspopup *_syspopup_get_head() +syspopup *_syspopup_get_head(void) { return syspopup_head; } @@ -67,26 +65,32 @@ int _syspopup_add_new(syspopup *sp) syspopup *_syspopup_find(const char *name) { syspopup *tmp; + tmp = syspopup_head; while (tmp) { if (tmp->name) { if (strcmp(tmp->name, name) == 0) return tmp; } + tmp = tmp->next; } + return NULL; } syspopup *_syspopup_find_by_id(int id) { syspopup *tmp; + tmp = syspopup_head; while (tmp) { if (tmp->id == id) return tmp; + tmp = tmp->next; } + return NULL; } @@ -94,8 +98,10 @@ static void __syspopup_free(syspopup *sp) { if (sp->name != NULL) free(sp->name); + if (sp->dupped_bundle != NULL) bundle_free(sp->dupped_bundle); + free(sp); } @@ -122,80 +128,71 @@ void _syspopup_del(int id) __syspopup_free(target); return; } + tmp = tmp->next; } } - -static DBusHandlerResult -__sys_popup_dbus_signal_filter(DBusConnection *conn, DBusMessage *message, - void *user_data) +static void __syspopup_dbus_signal_filter(GDBusConnection *conn, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) { - const char *sender; - const char *interface; - int dead_pid; - - DBusError error; - dbus_error_init(&error); - - interface = dbus_message_get_interface(message); - if (interface == NULL) { - _E("reject by security issue - no interface\n"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (dbus_message_is_signal(message, interface, - SYSPOPUP_DBUS_SP_TERM_SIGNAL)) { + if (signal_name + && strcmp(signal_name, SYSPOPUP_DBUS_SP_TERM_SIGNAL) == 0) { if (_term_handler) _term_handler(NULL); _D("term handler has been called"); } - - return DBUS_HANDLER_RESULT_HANDLED; } - - -int _syspopup_init(void (*term_handler) (void *), - gboolean(*timeout_handler) (void *)) +int _syspopup_init(void (*term_handler)(void *), + gboolean (*timeout_handler)(void *)) { - DBusError error; - char rule[MAX_LOCAL_BUFSZ]; + GDBusConnection *conn = NULL; + GError *err = NULL; + guint conn_subsc_id; if (initialized) return 0; +#if !(GLIB_CHECK_VERSION(2, 36, 0)) + g_type_init(); +#endif + _term_handler = term_handler; _timeout_handler = timeout_handler; - dbus_error_init(&error); - bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); - if (!bus) { - _E("Failed to connect to the D-BUS daemon: %s", error.message); - dbus_error_free(&error); - return -1; - } - dbus_connection_setup_with_g_main(bus, NULL); - - snprintf(rule, MAX_LOCAL_BUFSZ, - "path='%s',type='signal',interface='%s'", SYSPOPUP_DBUS_PATH, - SYSPOPUP_DBUS_SIGNAL_INTERFACE); - /* listening to messages */ - dbus_bus_add_match(bus, rule, &error); - if (dbus_error_is_set(&error)) { - _E("Fail to rule set: %s", error.message); - dbus_error_free(&error); + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (err) { + _E("gdbus connection error (%s)", err->message); + g_error_free(err); return -1; } - if (dbus_connection_add_filter(bus, - __sys_popup_dbus_signal_filter, NULL, NULL) == FALSE) + /* Add a fileter for signal */ + conn_subsc_id = g_dbus_connection_signal_subscribe(conn, + NULL, + SYSPOPUP_DBUS_SIGNAL_INTERFACE, + NULL, + SYSPOPUP_DBUS_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __syspopup_dbus_signal_filter, + NULL, + NULL); + if (conn_subsc_id == 0) { + _E("Error in subscribing to the signal"); return -1; + } _D("syspopup signal initialized"); - initialized = 1; + return 0; } @@ -205,10 +202,12 @@ int _syspopup_reset_timeout(syspopup *sp, syspopup_info_t *info) _E("no initialized"); return -1; } + if (sp == NULL) { _E("syspopup is NULL"); return -1; } + if (info == NULL) { _E("syspopup info is NULL"); return -1; @@ -217,11 +216,11 @@ int _syspopup_reset_timeout(syspopup *sp, syspopup_info_t *info) if (sp->timeout_id != 0) g_source_remove(sp->timeout_id); - if(info->timeout > 0) { - sp->timeout_id = g_timeout_add_seconds(info->timeout, _timeout_handler, - (void *)sp->id); - _D("add timeout - timeout : id=%d,timeout=%d(sec)", sp->id, - info->timeout); + if (info->timeout > 0) { + sp->timeout_id = g_timeout_add_seconds(info->timeout, + _timeout_handler, (void *)sp->id); + _D("add timeout - timeout : id=%d,timeout=%d(sec)", + sp->id, info->timeout); } return 0; @@ -243,28 +242,29 @@ const char *_syspopup_get_name_from_bundle(bundle *b) { const char *name; - if (getuid() != 0 && getuid() != tzplatform_getuid(TZ_USER_NAME)) { - _E("syspopup permission error"); + if (b == NULL) { + _E("bundle is NULL"); return NULL; } - if (b == NULL) { - _E("bundle is NULL"); + if (getuid() != 0 && getuid() != tzplatform_getuid(TZ_USER_NAME)) { + _E("syspopup permission error"); return NULL; } name = bundle_get_val(b, SYSPOPUP_NAME); - if (name == NULL) { + if (name == NULL) _E("this is no bundle for syspopup"); - } + return name; } int _syspopup_set_name_to_bundle(bundle *b, char *popup_name) { - if ((b == NULL) || (popup_name == NULL)) + if (b == NULL || popup_name == NULL) return -1; + bundle_add(b, SYSPOPUP_NAME, popup_name); + return 0; } - diff --git a/src/syspopup_db.c b/src/syspopup_db.c index a53ffba..be797c9 100755 --- a/src/syspopup_db.c +++ b/src/syspopup_db.c @@ -33,43 +33,16 @@ #include "simple_util.h" #define SYSPOPUP_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".syspopup.db") -#define QUERY_MAXLEN 4096 +#define QUERY_MAXLEN 4096 -#define SP_INFO_TBL "syspopup_info" -#define SP_INFO_TBL_F_NAME "name" +#define SP_INFO_TBL "syspopup_info" +#define SP_INFO_TBL_F_NAME "name" static sqlite3 *db = NULL; /** - * exec - * param[in] db handler - * param[in] query query - * return This method returns 0 (SUCCESS) or -1 (FAIL) - */ -static int __exec(sqlite3 *db, char *query) -{ - int rc = 0; - char *errmsg = NULL; - - if (db == NULL) { - _E("DB handler is null"); - return -1; - } - rc = sqlite3_exec(db, query, NULL, 0, &errmsg); - - if (rc != SQLITE_OK) { - _D("Query: [%s]", query); - _E("SQL error: %s\n", errmsg); - sqlite3_free(errmsg); - return (-1); - } - - return 0; -} - -/** - * db initialize - */ + * * db initialize + * */ static int __init(void) { int rc; @@ -80,22 +53,15 @@ static int __init(void) } rc = sqlite3_open(SYSPOPUP_DB_PATH, &db); - if (rc) { - _E("Can't open database: %s", sqlite3_errmsg(db)); - goto err; - } - /* Enable persist journal mode*/ - rc = sqlite3_exec(db, "PRAGMA journal_mode = PERSIST", NULL, NULL, - NULL); - if (SQLITE_OK != rc) { - _D("Fail to change journal mode\n"); - goto err; + if (rc != SQLITE_OK) { + _E("Can't open database: %s / %d / %d", sqlite3_errmsg(db), + rc, sqlite3_extended_errcode(db)); + return -1; + } else { + _D("db open sucess"); } return 0; -err: - sqlite3_close(db); - return -1; } static int __fini(void) @@ -104,148 +70,69 @@ static int __fini(void) sqlite3_close(db); db = NULL; } - return 0; -} - -static int __delete_all(const char *tbl_name) -{ - char *_sqlbuf; - int rc; - _sqlbuf = sqlite3_mprintf("DELETE FROM %s;", tbl_name); - rc = __exec(db, _sqlbuf); - sqlite3_free(_sqlbuf); - - return rc; -} - -static int __delete_with_field(const char *tbl_name, const char *f_name, - const char *val) -{ - char *_sqlbuf; - int rc; - - _sqlbuf = sqlite3_mprintf("DELETE FROM %s WHERE %s = '%s';", - tbl_name, f_name, val); - rc = __exec(db, _sqlbuf); - sqlite3_free(_sqlbuf); - - return rc; + return 0; } -static int __count_with_field(const char *tbl_name, const char *f_name, - const char *val) +syspopup_info_t *_syspopup_info_get(const char *popup_name) { - char *_sqlbuf; int rc; - char **db_result = NULL; - char *db_err = NULL; - int nrows = 0; - int ncols = 0; - int cnt; - - _sqlbuf = sqlite3_mprintf("SELECT COUNT(*) FROM %s WHERE %s = '%s';", - tbl_name, f_name, val); - - rc = sqlite3_get_table(db, _sqlbuf, &db_result, &nrows, &ncols, - &db_err); - if (rc == -1 || nrows == 0) { - _E("get count = 0 or fail"); - sqlite3_free_table(db_result); - sqlite3_free(_sqlbuf); - return 0; - } else { - cnt = atoi(db_result[1]); - sqlite3_free_table(db_result); - sqlite3_free(_sqlbuf); - } - - return cnt; -} - -int _syspopup_info_add(syspopup_info_t *pinfo) -{ - int rc = -1; - int cnt = 0; - char *_sqlbuf; + char sqlbuf[256] = {0,}; + sqlite3_stmt *stmt = NULL; + syspopup_info_t *pinfo = NULL; - if (pinfo->name == NULL) { - _E("Name is null\n"); - return -1; + if (popup_name == NULL) { + _E("no popup name"); + return NULL; } if (__init() < 0) - return -1; + return NULL; - cnt = __count_with_field(SP_INFO_TBL, SP_INFO_TBL_F_NAME, pinfo->name); + snprintf(sqlbuf, sizeof(sqlbuf), + "SELECT name,prio,focus,timeout,term_act,endkey_act,pkgname FROM %s WHERE %s = ?;", + SP_INFO_TBL, SP_INFO_TBL_F_NAME); - if (cnt == 0) { - _sqlbuf = sqlite3_mprintf("INSERT INTO %s " - "(name,prio,focus,timeout,term_act,endkey_act,pkgname) values " - "(\"%s\", %d, %d, %d, \"%s\");", - SP_INFO_TBL, - pinfo->name, pinfo->prio, - pinfo->focus, pinfo->timeout, - pinfo->term_act, pinfo->endkey_act, - pinfo->pkgname); - rc = __exec(db, _sqlbuf); - sqlite3_free(_sqlbuf); - } else { - _E("already exist - %s", pinfo->name); - rc = -1; + rc = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL); + if (rc != SQLITE_OK) { + _E("popup info prepare error(%d)", rc); + goto out; } - if (rc < 0) - _E("Fail to insert\n"); - - __fini(); - return rc; -} - -syspopup_info_t *_syspopup_info_get(const char *popup_name) -{ - int rc = 0; - char *_sqlbuf; - sqlite3_stmt *stmt; - syspopup_info_t *pinfo = NULL; + rc = sqlite3_bind_text(stmt, 1, popup_name, strlen(popup_name), SQLITE_STATIC); + if (rc != SQLITE_OK) { + _E("popup name bind error(%d)", rc); + goto out; + } - if (popup_name == NULL) { - _E("no popup name"); - return NULL; + rc = sqlite3_step(stmt); + if (rc != SQLITE_ROW) { + _E("error(%d) in prepare", rc); + goto out; } - if (__init() < 0) - return NULL; + pinfo = (syspopup_info_t *)malloc(sizeof(syspopup_info_t)); + if (pinfo == NULL) { + _E("malloc error"); + goto out; + } - _sqlbuf = sqlite3_mprintf("SELECT name,prio,focus,timeout,term_act,endkey_act,pkgname " - "FROM %s WHERE %s='%s';", - SP_INFO_TBL, SP_INFO_TBL_F_NAME, popup_name); + pinfo->name = strdup((char *)sqlite3_column_text(stmt, 0)); + pinfo->prio = sqlite3_column_int(stmt, 1); + pinfo->focus = sqlite3_column_int(stmt, 2); + pinfo->timeout = sqlite3_column_int(stmt, 3); + pinfo->term_act = sqlite3_column_int(stmt, 4); + pinfo->endkey_act = sqlite3_column_int(stmt, 5); - rc = sqlite3_prepare_v2(db, _sqlbuf, -1, &stmt, NULL); - if (rc == SQLITE_OK) { - rc = sqlite3_step(stmt); - if (rc == SQLITE_ROW) { - pinfo = (syspopup_info_t *) malloc(sizeof(syspopup_info_t)); - if (pinfo == NULL) { - __fini(); - return NULL; - } - pinfo->name = strdup((char *) sqlite3_column_text(stmt, 0)); - pinfo->prio = sqlite3_column_int(stmt, 1); - pinfo->focus = sqlite3_column_int(stmt, 2); - pinfo->timeout = sqlite3_column_int(stmt, 3); - pinfo->term_act = sqlite3_column_int(stmt, 4); - pinfo->endkey_act = sqlite3_column_int(stmt, 5); - if (sqlite3_column_text(stmt, 6) != NULL) - pinfo->pkgname = strdup((char *) sqlite3_column_text(stmt, 6)); - else - pinfo->pkgname = NULL; - } - sqlite3_finalize(stmt); - } + if (sqlite3_column_text(stmt, 6) != NULL) + pinfo->pkgname = strdup((char *) sqlite3_column_text(stmt, 6)); + else + pinfo->pkgname = NULL; - sqlite3_free(_sqlbuf); +out: + sqlite3_finalize(stmt); __fini(); + return pinfo; } @@ -253,8 +140,9 @@ void _syspopup_info_free(syspopup_info_t *pinfo) { if (pinfo->name) free(pinfo->name); + if (pinfo->pkgname) free(pinfo->pkgname); + free(pinfo); } - diff --git a/syspopup-caller/CMakeLists.txt b/syspopup-caller/CMakeLists.txt index 143fbf3..d362f2e 100644 --- a/syspopup-caller/CMakeLists.txt +++ b/syspopup-caller/CMakeLists.txt @@ -20,7 +20,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") # Set required packages INCLUDE(FindPkgConfig) -pkg_check_modules(spcpkgs REQUIRED dlog bundle sqlite3 glib-2.0 aul dbus-glib-1 libtzplatform-config) +pkg_check_modules(spcpkgs REQUIRED dlog bundle sqlite3 glib-2.0 gio-2.0 aul libtzplatform-config) FOREACH(flag ${spcpkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/syspopup-caller/syspopup_caller.c b/syspopup-caller/syspopup_caller.c index c5eca62..3d4bde8 100755 --- a/syspopup-caller/syspopup_caller.c +++ b/syspopup-caller/syspopup_caller.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include "syspopup_core.h" @@ -68,49 +68,51 @@ API int syspopup_launch(char *popup_name, bundle *b) } ret = aul_launch_app(info->pkgname, b); - if (ret < 0) { - _E("aul launch error - %d", ret); - } + if (ret < 0) + _E("aul launch error: %d", ret); - if (is_bundle == 1) { + if (is_bundle == 1) bundle_free(b); - } _syspopup_info_free(info); return ret; } -API int syspopup_destroy_all() +API int syspopup_destroy_all(void) { - DBusMessage *message; - DBusError error; - DBusConnection *bus = NULL; - - dbus_error_init(&error); - bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); - if (bus == NULL) { - _E("Failed to connect to the D-BUS daemon: %s", error.message); - dbus_error_free(&error); + GDBusConnection *conn = NULL; + GError *err = NULL; + int ret = 0; + +#if !(GLIB_CHECK_VERSION(2, 36, 0)) + g_type_init(); +#endif + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (err) { + _E("gdbus connection error: %s", err->message); + g_error_free(err); return -1; } - message = dbus_message_new_signal(SYSPOPUP_DBUS_PATH, - SYSPOPUP_DBUS_SIGNAL_INTERFACE, - SYSPOPUP_DBUS_SP_TERM_SIGNAL); - - if (dbus_connection_send(bus, message, NULL) == FALSE) { - _E("dbus send error"); - return -1; + if (g_dbus_connection_emit_signal(conn, + NULL, + SYSPOPUP_DBUS_PATH, + SYSPOPUP_DBUS_SIGNAL_INTERFACE, + SYSPOPUP_DBUS_SP_TERM_SIGNAL, + NULL, + &err) == FALSE) { + _E("emitting the signal error: %s", err->message); + ret = -1; + } else { + _D("send signal done"); } - dbus_connection_flush(bus); - dbus_message_unref(message); + if (err) + g_error_free(err); + if (conn) + g_object_unref(conn); - dbus_connection_close(bus); - - _D("send signal done\n"); - - return 0; + return ret; } - diff --git a/syspopup/CMakeLists.txt b/syspopup/CMakeLists.txt index 0d7d4fc..5941566 100644 --- a/syspopup/CMakeLists.txt +++ b/syspopup/CMakeLists.txt @@ -19,7 +19,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") # Set required packages INCLUDE(FindPkgConfig) -SET(APPSVC_SPPPGS_CHECK_MODULES "dlog bundle sqlite3 glib-2.0 evas elementary ecore ecore-input dbus-glib-1 libtzplatform-config") +SET(APPSVC_SPPPGS_CHECK_MODULES "dlog bundle sqlite3 glib-2.0 gio-2.0 evas elementary ecore ecore-input libtzplatform-config") IF (with_wayland) pkg_check_modules(sppkgs REQUIRED ${APPSVC_SPPPGS_CHECK_MODULES}) @@ -74,4 +74,3 @@ ENDIF (with_wayland) INSTALL(TARGETS syspopup DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/syspopup.h DESTINATION include) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/syspopup.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - diff --git a/syspopup/syspopup.c b/syspopup/syspopup.c index 4e16c57..3e3e36f 100755 --- a/syspopup/syspopup.c +++ b/syspopup/syspopup.c @@ -29,6 +29,7 @@ #ifndef WAYLAND #include #include +#include #endif #define WIN_PROP_NAME "SYSTEM_POPUP" @@ -59,9 +60,11 @@ static int __utilx_ss_get_window_property(Display *dpy, Window win, Atom atom, else { if (num_ret < len) len = num_ret; + for (i = 0; i < len; i++) { val[i] = ((unsigned long *)prop_ret)[i]; } + num = len; } @@ -72,30 +75,9 @@ static int __utilx_ss_get_window_property(Display *dpy, Window win, Atom atom, } #endif -/* -static Window get_active_win(Display *dpy, Window win, Atom property) -{ - Window active_win = None; - Atom actual_type; - int actual_format; - unsigned long nitems, bytes_after; - unsigned char *prop_return = NULL; - - if(Success == XGetWindowProperty(dpy, win, property, 0L, sizeof(Window), - False, XA_WINDOW, &actual_type, - &actual_format, &nitems, &bytes_after, - &prop_return) && prop_return) { - active_win = *(Window *)prop_return; - XFree(prop_return); - } - - return active_win; -} -*/ - +#ifndef WAYLAND static void __X_syspopup_term_handler(void *data) { -#ifndef WAYLAND syspopup *tmp; syspopup *next; Display *d; @@ -104,25 +86,24 @@ static void __X_syspopup_term_handler(void *data) _D("enter syspopup term handler"); d = XOpenDisplay(NULL); + tmp = _syspopup_get_head(); while (tmp) { - _D("term action %d - %s", tmp->term_act, tmp->name); next = tmp->next; switch (tmp->term_act) { case SYSPOPUP_TERM: - win = (Window) tmp->internal_data; + win = (Window)tmp->internal_data; if (tmp->def_term_fn != NULL) tmp->def_term_fn(tmp->dupped_bundle, tmp->user_data); + XKillClient(d, win); - /*XDestroyWindow(d, win);*/ - /* TODO :modify for multi popup */ break; case SYSPOPUP_HIDE: - win = (Window) tmp->internal_data; + win = (Window)tmp->internal_data; if (tmp->def_term_fn != NULL) tmp->def_term_fn(tmp->dupped_bundle, @@ -130,19 +111,19 @@ static void __X_syspopup_term_handler(void *data) XUnmapWindow(d, win); break; default: - _D("term action IGNORED - %s", tmp->name); + _D("term action IGNORED: %s", tmp->name); } + tmp = next; } XCloseDisplay(d); - /*TODO : if there is no popup window, kill client*/ -#endif } +#endif +#ifndef WAYLAND static gboolean __X_syspopup_timeout_handler(void *user_data) { -#ifndef WAYLAND syspopup *sp = NULL; Display *d; int id; @@ -156,17 +137,18 @@ static gboolean __X_syspopup_timeout_handler(void *user_data) _D("find timeout - %s", sp->name); if (sp->def_timeout_fn != NULL) sp->def_timeout_fn(sp->dupped_bundle, sp->user_data); - win = (Window) sp->internal_data; + + win = (Window)sp->internal_data; XKillClient(d, win); } else { _E("no find timeout"); } XCloseDisplay(d); -#endif return 0; } +#endif #ifndef WAYLAND static int __X_syspopup_change_xwin_type(Display *dpy, Window win) @@ -190,7 +172,8 @@ static int __X_syspopup_disable_focus(Display *dpy, Window win) XWMHints *hints; hints = XAllocWMHints(); - if (!hints) return -1; + if (hints == NULL) + return -1; hints->flags = InputHint | StateHint; hints->input = 0; @@ -211,8 +194,6 @@ int X_syspopup_rotation_get(Display *dpy, Window win) int rotation = -1; int ret; - int angles[2]; - Atom atom_active_win; Atom atom_win_rotate_angle; @@ -222,21 +203,14 @@ int X_syspopup_rotation_get(Display *dpy, Window win) ret = __utilx_ss_get_window_property(dpy, root_win, atom_active_win, XA_WINDOW, (unsigned int *)&active_win, 1); - - /*printf("[SYSPOPUP] Active win : %x, Window %x\n", active_win, win);*/ - - /*active_win = get_active_win(dpy, root_win, atom_active_win);*/ if (ret < 0) return ret; - atom_win_rotate_angle = - XInternAtom(dpy, "_E_ILLUME_ROTATE_ROOT_ANGLE", False); + atom_win_rotate_angle = XInternAtom(dpy, + "_E_ILLUME_ROTATE_ROOT_ANGLE", False); ret = __utilx_ss_get_window_property(dpy, root_win, atom_win_rotate_angle, XA_CARDINAL, (unsigned int *)&rotation, 1); - - /*printf("[SYSPOPUP] Rotation %d\n", rotation);*/ - if (ret != -1) return rotation; @@ -253,24 +227,23 @@ int X_syspopup_process_keypress(int id, const char *keyname) _D("key press - %s", keyname); - if ((strcmp(keyname, KEY_END) == 0) || - (strcmp(keyname, "Escape") == 0)) - { + if (strcmp(keyname, KEY_END) == 0) { d = XOpenDisplay(NULL); sp = _syspopup_find_by_id(id); if (sp != NULL) { - _D("find - %s / endkey_act - %d", sp->name, sp->endkey_act); + _D("find key down: %s", sp->name); if (sp->endkey_act == SYSPOPUP_KEYEND_TERM) { if (sp->def_term_fn != NULL) sp->def_term_fn(sp->dupped_bundle, sp->user_data); + win = (Window) sp->internal_data; XKillClient(d, win); - } else if (sp->endkey_act == SYSPOPUP_KEYEND_HIDE) { if (sp->def_term_fn != NULL) sp->def_term_fn(sp->dupped_bundle, sp->user_data); + win = (Window) sp->internal_data; XUnmapWindow(d, win); } @@ -308,6 +281,7 @@ int X_syspopup_process_rotate(int id) return 0; } #else +#ifndef WAYLAND static void __efl_rotation_set(Evas_Object* win, Ecore_X_Window xwin) { ecore_x_icccm_name_class_set(xwin, WIN_PROP_NAME, WIN_PROP_NAME); @@ -319,6 +293,7 @@ static void __efl_rotation_set(Evas_Object* win, Ecore_X_Window xwin) } } #endif +#endif #ifndef WAYLAND int X_make_syspopup(bundle *b, Display *dpy, Window xwin, void *win, @@ -437,26 +412,33 @@ int X_syspopup_reset(bundle *b) if (sp->dupped_bundle) free(sp->dupped_bundle); + sp->dupped_bundle = bundle_dup(b); - d = XOpenDisplay(NULL); - win = (Window) sp->internal_data; - utilx_set_system_notification_level(d, win, info->prio); + do { + d = XOpenDisplay(NULL); + if (d == NULL) + break; - if (info->focus == 1) { - __X_syspopup_disable_focus (d, win); - } + win = (Window)sp->internal_data; + if (win == NULL) + break; + + utilx_set_system_notification_level(d, win, info->prio); + + if (info->focus == 1) + __X_syspopup_disable_focus (d, win); #ifdef ROTATE_USING_X_CLIENT - int (*rotate_func) (Display *, Window, syspopup *); - rotate_func = sp->rotate_cb; - rotate_func(d, win, sp); + int (*rotate_func) (Display *, Window, syspopup *); + rotate_func = sp->rotate_cb; + rotate_func(d, win, sp); #else - __efl_rotation_set((Evas_Object *)sp->win, (Ecore_X_Window)win); + __efl_rotation_set((Evas_Object *)sp->win, (Ecore_X_Window)win); #endif - XMapWindow(d, win); - /*XMapRaised(d,win);*/ - XCloseDisplay(d); + XMapWindow(d, win); + XCloseDisplay(d); + } while (0); _syspopup_info_free(info); } @@ -468,14 +450,15 @@ int X_syspopup_reset(bundle *b) API int syspopup_has_popup(bundle *b) { const char *popup_name; + popup_name = _syspopup_get_name_from_bundle(b); if (popup_name == NULL) return 0; if (_syspopup_find(popup_name) != NULL) return 1; - else - return 0; + + return 0; } API int syspopup_reset_timeout(bundle *b, unsigned int time) @@ -501,6 +484,7 @@ API int syspopup_reset_timeout(bundle *b, unsigned int time) _E("get syspopup info error"); return -1; } + info->timeout = time; ret = _syspopup_reset_timeout(sp, info); _syspopup_info_free(info); @@ -508,4 +492,3 @@ API int syspopup_reset_timeout(bundle *b, unsigned int time) return ret; } - diff --git a/syspopup/syspopup_efl.c b/syspopup/syspopup_efl.c index 5c33530..3e1b4f2 100755 --- a/syspopup/syspopup_efl.c +++ b/syspopup/syspopup_efl.c @@ -33,6 +33,7 @@ #include #endif +#ifndef WAYLAND static Eina_Bool __x_keypress_cb(void *data, int type, void *event) { int id = (int)data; @@ -45,6 +46,7 @@ static Eina_Bool __x_keypress_cb(void *data, int type, void *event) return ECORE_CALLBACK_RENEW; } +#endif #ifdef ROTATE_USING_X_CLIENT static Eina_Bool __x_rotate_cb(void *data, int type, void *event) @@ -145,6 +147,9 @@ API int syspopup_create(bundle *b, syspopup_handler *handler, API int syspopup_reset(bundle *b) { +#ifndef WAYLAND return X_syspopup_reset(b); +#else + return 0; +#endif } - -- 2.7.4