7 #include <sys/socket.h>
9 #include <asm/byteorder.h>
11 #include <talloc/talloc.h>
13 #include "ui/common/discover-client.h"
14 #include "pb-protocol/pb-protocol.h"
16 struct discover_client {
18 struct discover_client_ops ops;
21 static int discover_client_destructor(void *arg)
23 struct discover_client *client = arg;
31 struct discover_client* discover_client_init(struct discover_client_ops *ops)
33 struct discover_client *client;
34 struct sockaddr_un addr;
36 client = talloc(NULL, struct discover_client);
40 memcpy(&client->ops, ops, sizeof(client->ops));
42 client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
43 if (!client->fd < 0) {
48 talloc_set_destructor(client, discover_client_destructor);
50 addr.sun_family = AF_UNIX;
51 strcpy(addr.sun_path, PB_SOCKET_PATH);
53 if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr))) {
65 int discover_client_get_fd(struct discover_client *client)
70 void discover_client_destroy(struct discover_client *client)
75 int discover_client_process(struct discover_client *client)
77 struct pb_protocol_message *message;
81 message = pb_protocol_read_message(client, client->fd);
86 switch (message->action) {
87 case PB_PROTOCOL_ACTION_ADD:
88 dev = pb_protocol_deserialise_device(client, message);
90 printf("no device?\n");
93 client->ops.add_device(dev);
96 case PB_PROTOCOL_ACTION_REMOVE:
97 dev_id = pb_protocol_deserialise_string(client, message);
99 printf("no device id?\n");
102 client->ops.remove_device(dev_id);
105 printf("unknown action %d\n", message->action);