From 3213783bcfdd0331049d8d0a57b69d24e1122424 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 27 Apr 2016 15:29:06 +0900 Subject: [PATCH] library : add buxton_open_full api Change-Id: I878608e041cbcaf7c0d763619d02fda206991d9b Signed-off-by: Jiwoong Im --- lib/buxton2.c | 17 +++++++++++++---- lib/include/buxton2.h | 17 +++++++++++++++++ vconf-compat/vconf.c | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/buxton2.c b/lib/buxton2.c index 6f75279..fbfac62 100644 --- a/lib/buxton2.c +++ b/lib/buxton2.c @@ -2152,7 +2152,7 @@ EXPORT int buxton_close(struct buxton_client *client) return 0; } -EXPORT int buxton_open(struct buxton_client **client, +EXPORT int buxton_open_full(struct buxton_client **client, bool attach_fd, buxton_status_callback callback, void *user_data) { struct buxton_client *cli; @@ -2192,9 +2192,12 @@ EXPORT int buxton_open(struct buxton_client **client, return -1; } - cli->fd_id = g_unix_fd_add(cli->fd, - G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, - recv_cb, cli); + if (attach_fd) + cli->fd_id = g_unix_fd_add(cli->fd, + G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, + recv_cb, cli); + else + cli->fd_id = 0; pthread_mutex_lock(&clients_lock); clients = g_list_append(clients, cli); @@ -2207,6 +2210,12 @@ EXPORT int buxton_open(struct buxton_client **client, return 0; } +EXPORT int buxton_open(struct buxton_client **client, + buxton_status_callback callback, void *user_data) +{ + return buxton_open_full(client, true, callback, user_data); +} + __attribute__((destructor)) static void buxton_client_exit(void) { diff --git a/lib/include/buxton2.h b/lib/include/buxton2.h index ca2ff2b..512e9c1 100644 --- a/lib/include/buxton2.h +++ b/lib/include/buxton2.h @@ -29,6 +29,7 @@ extern "C" { #include #include +#include #include /** @@ -62,6 +63,22 @@ typedef void (*buxton_status_callback)(enum buxton_status status, void *user_data); /** + * Open a connection to the Buxton daemon like buxton_open with attach_fd flag + * + * @param[out] client A pointer #buxton_client is allocated to + * (this value should be released by #buxton_close) + * @param[in] callback status callback function. If this is NULL, no callback + * function is invoked + * @param[in] user_data User data to be used with status callback function + * @param[in] attach_fd The flag whether attach fd in main loop or not + * @return 0 on success, -1 on error(when an error occurred, errno is set) + * + * @see buxton_close + */ +int buxton_open_full(struct buxton_client **client, bool attach_fd, + buxton_status_callback callback, void *user_data); + +/** * Open a connection to the Buxton daemon * * @param[out] client A pointer #buxton_client is allocated to diff --git a/vconf-compat/vconf.c b/vconf-compat/vconf.c index ff2df8a..22e5620 100644 --- a/vconf-compat/vconf.c +++ b/vconf-compat/vconf.c @@ -248,7 +248,7 @@ static int _open(const char *key, struct buxton_client **client, { int r; - r = buxton_open(client, NULL, NULL); + r = buxton_open_full(client, false, NULL, NULL); if (r == -1) { LOGE("Can't connect to buxton: %d", errno); return -1; -- 2.7.4