diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-11-05 10:42:32 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-11-05 10:44:10 +0100 |
commit | 2dd8a09f37ad898512fed366d312386dcf4f83cd (patch) | |
tree | c7519fa9123a09945001dfd28685fb42626441f3 /src | |
parent | fb8e8efb7072c2021c6c8cda2672d7eab1e3bbac (diff) | |
download | pjctl-2dd8a09f37ad898512fed366d312386dcf4f83cd.tar.gz pjctl-2dd8a09f37ad898512fed366d312386dcf4f83cd.tar.bz2 pjctl-2dd8a09f37ad898512fed366d312386dcf4f83cd.zip |
Use a function pointer as toggle indicator
This saves us from declaring query functions before the response
function for toggle functionality.
Diffstat (limited to 'src')
-rw-r--r-- | src/pjctl.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/pjctl.c b/src/pjctl.c index 7acc079..23d60f0 100644 --- a/src/pjctl.c +++ b/src/pjctl.c @@ -60,7 +60,7 @@ struct queue_command { void (*response_func)(struct pjctl *pjctl, struct queue_command *cmd, char *op, char *param); char *prefix; - int toggle; + int (*toggle)(struct pjctl *pjctl, char **argv, int argc); struct queue_command *prev, *next; }; @@ -319,18 +319,12 @@ read_cb(struct pjctl *pjctl) return 0; } -static int -power(struct pjctl *pjctl, char **argv, int argc); - static void power_response(struct pjctl *pjctl, struct queue_command *cmd, char *op, char *param) { int ret; - char *params[2][2] = { - { "power", "off" }, - { "power", "on" } - }; + char *p[2] = { "power", NULL }; fputs(cmd->prefix, stdout); free(cmd->prefix); @@ -342,8 +336,10 @@ power_response(struct pjctl *pjctl, struct queue_command *cmd, } else if (ret == 0) { printf("%s\n", param[0] == '1' ? "on" : "off" ); - if (cmd->toggle) - power(pjctl, param[0] == '1' ? params[0]:params[1], 2); + if (cmd->toggle) { + p[1] = param[0] == '1' ? "off" : "on"; + cmd->toggle(pjctl, p, ARRAY_SIZE(p)); + } } } @@ -366,7 +362,7 @@ power(struct pjctl *pjctl, char **argv, int argc) code = '0'; else if (strcmp(argv[1], "toggle") == 0) { code = '?'; - cmd->toggle = 1; + cmd->toggle = power; } else { fprintf(stderr, "invalid power parameter\n"); return -1; @@ -441,9 +437,6 @@ source(struct pjctl *pjctl, char **argv, int argc) return 0; } -static int -avmute(struct pjctl *pjctl, char **argv, int argc); - static void avmute_response(struct pjctl *pjctl, struct queue_command *cmd, char *op, char *param) @@ -484,7 +477,7 @@ avmute_response(struct pjctl *pjctl, struct queue_command *cmd, printf("%s\n", params[2]); if (cmd->toggle) - avmute(pjctl, params, 3); + cmd->toggle(pjctl, params, 3); } } @@ -525,7 +518,7 @@ avmute(struct pjctl *pjctl, char **argv, int argc) code = '0'; else if (strcmp(argv[2], "toggle") == 0) { code = '?'; - cmd->toggle = 1; + cmd->toggle = avmute; } else { fprintf(stderr, "invalid mute parameter\n"); return -1; |