#include "device-handler.h"
#include "discover-server.h"
+#include "platform.h"
#include "sysinfo.h"
struct discover_server {
struct waitset *waitset;
struct waiter *waiter;
struct list clients;
+ struct list status;
struct device_handler *device_handler;
};
}
static int write_boot_status_message(struct discover_server *server,
- struct client *client, const struct boot_status *status)
+ struct client *client, const struct status *status)
{
struct pb_protocol_message *message;
int len;
struct boot_command *boot_command;
struct client *client = arg;
struct config *config;
+ char *url;
int rc;
message = pb_protocol_read_message(client, client->fd);
device_handler_cancel_default(client->server->device_handler);
break;
+ case PB_PROTOCOL_ACTION_REINIT:
+ device_handler_reinit(client->server->device_handler);
+ break;
+
case PB_PROTOCOL_ACTION_CONFIG:
config = talloc_zero(client, struct config);
config);
break;
+ case PB_PROTOCOL_ACTION_ADD_URL:
+ url = pb_protocol_deserialise_string((void *) client, message);
+
+ device_handler_process_url(client->server->device_handler,
+ url, NULL, NULL);
+ break;
+
default:
pb_log("%s: invalid action %d\n", __func__, message->action);
return 0;
static int discover_server_process_connection(void *arg)
{
struct discover_server *server = arg;
+ struct statuslog_entry *entry;
int fd, rc, i, n_devices;
struct client *client;
/* accept the incoming connection */
- fd = accept(server->socket, NULL, 0);
+ fd = accept(server->socket, NULL, NULL);
if (fd < 0) {
pb_log("accept: %s\n", strerror(errno));
return 0;
}
}
+ /* send status backlog to client */
+ list_for_each_entry(&server->status, entry, list)
+ write_boot_status_message(server, client, entry->status);
+
return 0;
}
}
void discover_server_notify_boot_status(struct discover_server *server,
- struct boot_status *status)
+ struct status *status)
{
+ struct statuslog_entry *entry;
struct client *client;
+ /* Duplicate the status struct to add to the backlog */
+ entry = talloc(server, struct statuslog_entry);
+ if (!entry) {
+ pb_log("Failed to allocated saved status!\n");
+ } else {
+ entry->status = talloc(entry, struct status);
+ if (entry->status) {
+ entry->status->type = status->type;
+ entry->status->message = talloc_strdup(entry->status,
+ status->message);
+ entry->status->backlog = true;
+ list_add_tail(&server->status, &entry->list);
+ } else {
+ talloc_free(entry);
+ }
+ }
+
list_for_each_entry(&server->clients, client, list)
write_boot_status_message(server, client, status);
}
server->waiter = NULL;
server->waitset = waitset;
list_init(&server->clients);
+ list_init(&server->status);
unlink(PB_SOCKET_PATH);