Add wayvncctl wayvnc-exit command

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/195/head
Jim Ramsay 2022-11-25 20:56:07 -05:00 committed by Andri Yngvason
parent 467cfa1889
commit e958b06e44
4 changed files with 23 additions and 0 deletions

View File

@ -43,6 +43,7 @@ struct ctl_server_actions {
const char* output_name); const char* output_name);
struct cmd_response* (*on_disconnect_client)(struct ctl*, struct cmd_response* (*on_disconnect_client)(struct ctl*,
const char* id); const char* id);
struct cmd_response* (*on_wayvnc_exit)(struct ctl*);
// Return number of elements created // Return number of elements created
// Allocate 'clients' array or set ton ULL if none // Allocate 'clients' array or set ton ULL if none

View File

@ -49,6 +49,7 @@ enum cmd_type {
CMD_GET_CLIENTS, CMD_GET_CLIENTS,
CMD_GET_OUTPUTS, CMD_GET_OUTPUTS,
CMD_DISCONNECT_CLIENT, CMD_DISCONNECT_CLIENT,
CMD_WAYVNC_EXIT,
CMD_UNKNOWN, CMD_UNKNOWN,
}; };
#define CMD_LIST_LEN CMD_UNKNOWN #define CMD_LIST_LEN CMD_UNKNOWN
@ -113,6 +114,10 @@ static struct cmd_info cmd_list[] = {
{NULL, NULL}, {NULL, NULL},
} }
}, },
[CMD_WAYVNC_EXIT] = { "wayvnc-exit",
"Disconnect all clients and shut down wayvnc",
{{NULL,NULL}},
},
}; };
#define CLIENT_EVENT_PARAMS(including) \ #define CLIENT_EVENT_PARAMS(including) \
@ -333,6 +338,7 @@ static struct cmd* parse_command(struct jsonipc_request* ipc,
case CMD_EVENT_RECEIVE: case CMD_EVENT_RECEIVE:
case CMD_GET_CLIENTS: case CMD_GET_CLIENTS:
case CMD_GET_OUTPUTS: case CMD_GET_OUTPUTS:
case CMD_WAYVNC_EXIT:
cmd = calloc(1, sizeof(*cmd)); cmd = calloc(1, sizeof(*cmd));
break; break;
case CMD_UNKNOWN: case CMD_UNKNOWN:
@ -538,6 +544,9 @@ static struct cmd_response* ctl_server_dispatch_cmd(struct ctl* self,
response = self->actions.on_disconnect_client(self, c->id); response = self->actions.on_disconnect_client(self, c->id);
break; break;
} }
case CMD_WAYVNC_EXIT:
response = self->actions.on_wayvnc_exit(self);
break;
case CMD_VERSION: case CMD_VERSION:
response = generate_version_object(); response = generate_version_object();
break; break;

View File

@ -539,6 +539,14 @@ static struct cmd_response* on_disconnect_client(struct ctl* ctl,
return cmd_failed("No such client with ID \"%s\"", id_string); return cmd_failed("No such client with ID \"%s\"", id_string);
} }
static struct cmd_response* on_wayvnc_exit(struct ctl* ctl)
{
struct wayvnc* self = ctl_server_userdata(ctl);
nvnc_log(NVNC_LOG_WARNING, "Shutting down via control socket command");
wayvnc_exit(self);
return cmd_ok();
}
int init_main_loop(struct wayvnc* self) int init_main_loop(struct wayvnc* self)
{ {
struct aml* loop = aml_get_default(); struct aml* loop = aml_get_default();
@ -1385,6 +1393,7 @@ int main(int argc, char* argv[])
.get_client_list = get_client_list, .get_client_list = get_client_list,
.get_output_list = get_output_list, .get_output_list = get_output_list,
.on_disconnect_client = on_disconnect_client, .on_disconnect_client = on_disconnect_client,
.on_wayvnc_exit = on_wayvnc_exit,
}; };
self.ctl = ctl_server_new(socket_path, &ctl_actions); self.ctl = ctl_server_new(socket_path, &ctl_actions);
if (!self.ctl) if (!self.ctl)

View File

@ -213,6 +213,10 @@ Parameters:
Required: The ID of the client to disconnect. This ID can be found from the Required: The ID of the client to disconnect. This ID can be found from the
_GET-CLIENTS_ command or receipt of a _CLIENT-CONNECTED_ event. _GET-CLIENTS_ command or receipt of a _CLIENT-CONNECTED_ event.
_WAYVNC_EXIT_
The *wayvnc-exit* command disconnects all clients and shuts down wayvnc.
_GET-CLIENTS_ _GET-CLIENTS_
The *get-clients* command retrieves a list of all VNC clients currently The *get-clients* command retrieves a list of all VNC clients currently