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;
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);
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)
{
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
/**
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
{
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;