]> git.ozlabs.org Git - petitboot/blobdiff - ui/common/discover-client.c
Make client ops constant
[petitboot] / ui / common / discover-client.c
index 1901f6c5207e282cc8b754e79dcf67f4f4723d7f..d30498cdf48b4e8007d4e24a9515c326d4e2d902 100644 (file)
@@ -1,4 +1,5 @@
 
+#include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -9,6 +10,7 @@
 #include <asm/byteorder.h>
 
 #include <talloc/talloc.h>
+#include <log.h>
 
 #include "ui/common/discover-client.h"
 #include "pb-protocol/pb-protocol.h"
@@ -28,7 +30,8 @@ static int discover_client_destructor(void *arg)
        return 0;
 }
 
-struct discover_client* discover_client_init(struct discover_client_ops *ops)
+struct discover_client* discover_client_init(
+       const struct discover_client_ops *ops)
 {
        struct discover_client *client;
        struct sockaddr_un addr;
@@ -41,7 +44,7 @@ struct discover_client* discover_client_init(struct discover_client_ops *ops)
 
        client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (!client->fd < 0) {
-               perror("socket");
+               pb_log("%s: socket: %s\n", __func__, strerror(errno));
                goto out_err;
        }
 
@@ -51,7 +54,7 @@ struct discover_client* discover_client_init(struct discover_client_ops *ops)
        strcpy(addr.sun_path, PB_SOCKET_PATH);
 
        if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr))) {
-               perror("connect");
+               pb_log("%s: connect: %s\n", __func__, strerror(errno));
                goto out_err;
        }
 
@@ -62,7 +65,7 @@ out_err:
        return NULL;
 }
 
-int discover_client_get_fd(struct discover_client *client)
+int discover_client_get_fd(const struct discover_client *client)
 {
        return client->fd;
 }
@@ -81,28 +84,28 @@ int discover_client_process(struct discover_client *client)
        message = pb_protocol_read_message(client, client->fd);
 
        if (!message)
-               return 0;
+               return -1;
 
        switch (message->action) {
        case PB_PROTOCOL_ACTION_ADD:
                dev = pb_protocol_deserialise_device(client, message);
                if (!dev) {
-                       printf("no device?\n");
+                       pb_log("%s: no device?\n", __func__);
                        return 0;
                }
-               client->ops.add_device(dev);
+               client->ops.add_device(dev, client->ops.cb_arg);
                talloc_free(dev);
                break;
        case PB_PROTOCOL_ACTION_REMOVE:
                dev_id = pb_protocol_deserialise_string(client, message);
                if (!dev_id) {
-                       printf("no device id?\n");
+                       pb_log("%s: no device id?\n", __func__);
                        return 0;
                }
-               client->ops.remove_device(dev_id);
+               client->ops.remove_device(dev_id, client->ops.cb_arg);
                break;
        default:
-               printf("unknown action %d\n", message->action);
+               pb_log("%s: unknown action %d\n", __func__, message->action);
        }