Skip to content
This repository was archived by the owner on Aug 14, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions oguri.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "animation.h"
#include "config.h"
#include "output.h"
#include "oguri_ipc.h"

//
// Signal handler
Expand Down Expand Up @@ -147,19 +148,41 @@ static void oguri_ipc_handle_command(
}

FILE * ipc_config = fdopen(config_fd, "r");
int loaded = load_config(oguri, ipc_config, "ipc");
if (loaded == -1) {
// TODO: Expose the error messages instead of writing them to oguri's
// stderr, where they will go nowhere.
if (write(client, "Invalid configuration\n", 23) < 0) {
fprintf(stderr, "Error replying to ipc command\n");
}
}

// TODO: If there was an error reading the config, we might have partially
// applied it. We're going to reconfig so that nothing gets out of sync
// internally, but this should be fixed in the config handlers.
oguri_reconfigure(oguri);
enum oguri_ipc_command cmd = OGURI_NOT_IPC_COMMAND;
cmd = fgetc(ipc_config);
if (cmd == OGURI_NOT_IPC_COMMAND)
{
fprintf(stderr, "Did not receive ipc command\n");
}
else
{
switch (cmd)
{
case OGURI_IPC_CONFIGURE:
int loaded = load_config(oguri, ipc_config, "ipc");
if (loaded == -1) {
// TODO: Expose the error messages instead of writing them to oguri's
// stderr, where they will go nowhere.
if (write(client, "Invalid configuration\n", 23) < 0) {
fprintf(stderr, "Error replying to ipc command\n");
}
}

// TODO: If there was an error reading the config, we might have partially
// applied it. We're going to reconfig so that nothing gets out of sync
// internally, but this should be fixed in the config handlers.
oguri_reconfigure(oguri, false);
break;
case OGURI_IPC_RELOAD_IMAGES:
oguri_reconfigure(oguri, true);
break;
default:
fprintf(stderr, "Unknown ipc command: %d\n", cmd);
break;
}
}
// close FILE, if we didn't do that before
if (fileno(ipc_config) >= 0) fclose(ipc_config);

close(client);
oguri->events[OGURI_IPC_CLIENT_EVENT].fd = -1;
Expand All @@ -179,7 +202,7 @@ static void oguri_ipc_handle_command(
//
// This is not particularly efficient, but it's extremely simple which makes it
// unlikely to introduce bugs. We also don't have that many outputs.
void oguri_reconfigure(struct oguri_state * oguri) {
void oguri_reconfigure(struct oguri_state * oguri, bool reload_cache) {
// Return all outputs to the idle list.
struct oguri_animation * anim;
wl_list_for_each(anim, &oguri->animations, link) {
Expand Down Expand Up @@ -220,7 +243,7 @@ void oguri_reconfigure(struct oguri_state * oguri) {
}
}

if (!found_anim) {
if (!found_anim || reload_cache) {
// No animation exists, so make one. Note that this may still
// fail, in which case this output will become idle.
// TODO: It would be better to get any possible failures out of
Expand Down Expand Up @@ -342,7 +365,7 @@ int main(int argc, char * argv[]) {
return 1;
}

oguri_reconfigure(&oguri);
oguri_reconfigure(&oguri, false);

oguri.run = true;
while (oguri.run) {
Expand Down
2 changes: 1 addition & 1 deletion oguri.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ struct oguri_state {
struct wl_list animations; // oguri_animation::link
};

void oguri_reconfigure(struct oguri_state * oguri);
void oguri_reconfigure(struct oguri_state * oguri, bool reload_cache);

#endif
10 changes: 10 additions & 0 deletions oguri_ipc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef OGURI_IPC_H
#define OGURI_IPC_H

enum oguri_ipc_command {
OGURI_NOT_IPC_COMMAND = 0,
OGURI_IPC_CONFIGURE,
OGURI_IPC_RELOAD_IMAGES,
};

#endif
47 changes: 33 additions & 14 deletions ogurictl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include "oguri_ipc.h"


static const char usage[] =
"Usage: ogurictl output NAME [<options>]\n"
"Usage: ogurictl COMMAND\n"
" ogurictl [--help] [--version]\n"
"\n"
"Output options:\n"
" --anchor Sides to which the image should be anchored\n"
" --filter Scaling filter to apply to the image\n"
" --image Path to the image to show on this output\n"
" --scaling-mode Method used to fit the image to the output\n"
"Available commands:\n"
" output NAME [<options>]\n"
" --anchor Sides to which the image should be anchored\n"
" --filter Scaling filter to apply to the image\n"
" --image Path to the image to show on this output\n"
" --scaling-mode Method used to fit the image to the output\n"
"\n"
" reload\n"
"\n"
"General options:\n"
" -V, --version Show the version of oguri\n"
Expand Down Expand Up @@ -91,6 +95,11 @@ int handle_output(int argc, char * argv[], char ** buffer, unsigned long * buffe
return 0;
}

static enum oguri_ipc_command parse_subcommand(char * subcommand) {
if (strcmp(subcommand, "output") == 0) return OGURI_IPC_CONFIGURE;
if (strcmp(subcommand, "reload") == 0) return OGURI_IPC_RELOAD_IMAGES;
return OGURI_NOT_IPC_COMMAND;
}

int main(int argc, char * argv[]) {
int opt_char, opt_index = -1;
Expand Down Expand Up @@ -118,13 +127,19 @@ int main(int argc, char * argv[]) {
// Since getopt state is global, we can just continue working in a
// command-specific function.
int subcommand_return = 0;
if (strcmp(subcommand, "output") == 0) {
subcommand_return = handle_output(argc, argv, &buffer, &buffer_size);
}
else {
fprintf(stderr, "Unknown command '%s'\n\n%s", subcommand, usage);
free(buffer);
return 1;
char * cmd = calloc(1, sizeof(char));
cmd [0] = parse_subcommand(subcommand);

switch (cmd[0]) {
case OGURI_IPC_CONFIGURE:
subcommand_return = handle_output(argc, argv, &buffer, &buffer_size);
break;
case OGURI_IPC_RELOAD_IMAGES:
break;
default:
fprintf(stderr, "Unknown command '%s'\n\n%s", subcommand, usage);
free(buffer);
return 1;
}

if (subcommand_return != 0) {
Expand Down Expand Up @@ -166,8 +181,12 @@ int main(int argc, char * argv[]) {
return 1;
}

if (send(sock_fd, cmd, 1, 0) == -1) {
perror("Unable to send command type to oguri");
goto close_err;
}
if (send(sock_fd, buffer, strnlen(buffer, buffer_size - 1), 0) == -1) {
perror("Unable to send command to oguri");
perror("Unable to send command data to oguri");
goto close_err;
}

Expand Down
2 changes: 1 addition & 1 deletion output.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ struct oguri_output * oguri_output_create(
wl_display_roundtrip(oguri->display);

wl_list_insert(oguri->idle_outputs.prev, &output->link);
oguri_reconfigure(oguri);
oguri_reconfigure(oguri, false);

return output;
}
Expand Down