summaryrefslogtreecommitdiffstats
path: root/ui/common
diff options
context:
space:
mode:
Diffstat (limited to 'ui/common')
-rw-r--r--ui/common/discover-client.c89
-rw-r--r--ui/common/discover-client.h14
2 files changed, 46 insertions, 57 deletions
diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c
index 9374dc5..f75cfb7 100644
--- a/ui/common/discover-client.c
+++ b/ui/common/discover-client.c
@@ -32,50 +32,6 @@ static int discover_client_destructor(void *arg)
return 0;
}
-struct discover_client* discover_client_init(
- const struct discover_client_ops *ops, void *cb_arg)
-{
- struct discover_client *client;
- struct sockaddr_un addr;
-
- client = talloc(NULL, struct discover_client);
- if (!client)
- return NULL;
-
- memcpy(&client->ops, ops, sizeof(client->ops));
- client->ops.cb_arg = cb_arg;
-
- client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (client->fd < 0) {
- pb_log("%s: socket: %s\n", __func__, strerror(errno));
- goto out_err;
- }
-
- talloc_set_destructor(client, discover_client_destructor);
-
- client->n_devices = 0;
- client->devices = NULL;
-
- addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, PB_SOCKET_PATH);
-
- if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr))) {
- pb_log("%s: connect: %s\n", __func__, strerror(errno));
- goto out_err;
- }
-
- return client;
-
-out_err:
- talloc_free(client);
- return NULL;
-}
-
-int discover_client_get_fd(const struct discover_client *client)
-{
- return client->fd;
-}
-
void discover_client_destroy(struct discover_client *client)
{
talloc_free(client);
@@ -121,8 +77,9 @@ static void device_remove(struct discover_client *client, const char *id)
talloc_free(device);
}
-int discover_client_process(struct discover_client *client)
+static int discover_client_process(void *arg)
{
+ struct discover_client *client = arg;
struct pb_protocol_message *message;
struct device *dev;
char *dev_id;
@@ -158,6 +115,48 @@ int discover_client_process(struct discover_client *client)
return 0;
}
+struct discover_client* discover_client_init(struct waitset *waitset,
+ const struct discover_client_ops *ops, void *cb_arg)
+{
+ struct discover_client *client;
+ struct sockaddr_un addr;
+
+ client = talloc(NULL, struct discover_client);
+ if (!client)
+ return NULL;
+
+ memcpy(&client->ops, ops, sizeof(client->ops));
+ client->ops.cb_arg = cb_arg;
+
+ client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (client->fd < 0) {
+ pb_log("%s: socket: %s\n", __func__, strerror(errno));
+ goto out_err;
+ }
+
+ talloc_set_destructor(client, discover_client_destructor);
+
+ client->n_devices = 0;
+ client->devices = NULL;
+
+ addr.sun_family = AF_UNIX;
+ strcpy(addr.sun_path, PB_SOCKET_PATH);
+
+ if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr))) {
+ pb_log("%s: connect: %s\n", __func__, strerror(errno));
+ goto out_err;
+ }
+
+ waiter_register(waitset, client->fd, WAIT_IN, discover_client_process,
+ client);
+
+ return client;
+
+out_err:
+ talloc_free(client);
+ return NULL;
+}
+
/* accessors for discovered devices */
int discover_client_device_count(struct discover_client *client)
{
diff --git a/ui/common/discover-client.h b/ui/common/discover-client.h
index 6e768d9..6d5d1c4 100644
--- a/ui/common/discover-client.h
+++ b/ui/common/discover-client.h
@@ -2,6 +2,7 @@
#define _DISCOVER_CLIENT_H
#include <types/types.h>
+#include <waiter/waiter.h>
struct discover_client;
@@ -24,23 +25,12 @@ struct discover_client_ops {
void *cb_arg;
};
-struct discover_client *discover_client_init(
+struct discover_client *discover_client_init(struct waitset *waitset,
const struct discover_client_ops *ops, void *cb_arg);
-int discover_client_get_fd(const struct discover_client *client);
-
void discover_client_destroy(struct discover_client *client);
/**
- * Process data from the server.
- *
- * Will read from the client socket, and call device_add on any discovered
- * devices.
- *
- */
-int discover_client_process(struct discover_client *client);
-
-/**
* Get the number of devices that the discover client has stored. This
* is the set of devices that have been added and not removed
*
OpenPOWER on IntegriCloud