summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pjctl.c25
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;