7 #include <sys/socket.h>
9 #include <asm/byteorder.h>
11 #include <talloc/talloc.h>
13 #include "ui/common/discover-client.h"
14 #include "ui/common/device.h"
15 #include "pb-protocol/pb-protocol.h"
17 struct discover_client {
19 struct discover_client_ops ops;
22 static int discover_client_destructor(void *arg)
24 struct discover_client *client = arg;
32 struct discover_client* discover_client_init(struct discover_client_ops *ops)
34 struct discover_client *client;
35 struct sockaddr_un addr;
37 client = talloc(NULL, struct discover_client);
41 memcpy(&client->ops, ops, sizeof(client->ops));
43 client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
44 if (!client->fd < 0) {
49 talloc_set_destructor(client, discover_client_destructor);
51 addr.sun_family = AF_UNIX;
52 strcpy(addr.sun_path, PB_SOCKET_PATH);
54 if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr))) {
66 int discover_client_get_fd(struct discover_client *client)
71 void discover_client_destroy(struct discover_client *client)
76 int discover_client_process(struct discover_client *client)
78 struct pb_protocol_message *message;
82 message = pb_protocol_read_message(client, client->fd);
87 switch (message->action) {
88 case PB_PROTOCOL_ACTION_ADD:
89 dev = pb_protocol_deserialise_device(client, message);
91 printf("no device?\n");
94 client->ops.add_device(dev);
97 case PB_PROTOCOL_ACTION_REMOVE:
98 dev_id = pb_protocol_deserialise_string(client, message);
100 printf("no device id?\n");
103 client->ops.remove_device(dev_id);
106 printf("unknown action %d\n", message->action);