summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-11-09 18:04:25 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-11-09 18:07:03 +0100
commitc24da62c509928ffee2378709310f44f70ecdb1b (patch)
treee261cc8e0ba5f43e265b5509a2c1535fd81647ad /src
parent54074040bc9c8ff5d71ca11e07a5d936b537b2bf (diff)
downloadpjctl-c24da62c509928ffee2378709310f44f70ecdb1b.tar.gz
pjctl-c24da62c509928ffee2378709310f44f70ecdb1b.tar.bz2
pjctl-c24da62c509928ffee2378709310f44f70ecdb1b.zip
Store status commands in a table
Diffstat (limited to 'src')
-rw-r--r--src/pjctl.c69
1 files changed, 24 insertions, 45 deletions
diff --git a/src/pjctl.c b/src/pjctl.c
index 58e120e..10a538e 100644
--- a/src/pjctl.c
+++ b/src/pjctl.c
@@ -526,51 +526,30 @@ class_response(struct pjctl *pjctl, char *cmd, char *param)
static int
status(struct pjctl *pjctl, char **argv, int argc)
{
- struct queue_command cmd;
-
- cmd.command = g_strdup("%1NAME ?\r");
- cmd.response_func = name_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1INF1 ?\r");
- cmd.response_func = manufactor_name_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1INF2 ?\r");
- cmd.response_func = product_name_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1INFO ?\r");
- cmd.response_func = info_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1POWR ?\r");
- cmd.response_func = power_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1INPT ?\r");
- cmd.response_func = input_switch_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1INST ?\r");
- cmd.response_func = input_list_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1AVMT ?\r");
- cmd.response_func = avmute_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1LAMP ?\r");
- cmd.response_func = lamp_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1ERST ?\r");
- cmd.response_func = error_status_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
-
- cmd.command = g_strdup("%1CLSS ?\r");
- cmd.response_func = class_response;
- pjctl->queue = g_list_append(pjctl->queue, g_memdup(&cmd, sizeof cmd));
+ /* Note: incomplete commands stored here */
+ static const struct queue_command cmds[] = {
+ { "NAME", name_response },
+ { "INF1", manufactor_name_response },
+ { "INF2", product_name_response },
+ { "INFO", info_response },
+ { "POWR", power_response },
+ { "INPT", input_switch_response },
+ { "INST", input_list_response },
+ { "AVMT", avmute_response },
+ { "LAMP", lamp_response },
+ { "ERST", error_status_response },
+ { "CLSS", class_response }
+ };
+ struct queue_command *cmd;
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS(cmds); ++i) {
+ cmd = g_memdup(&cmds[i], sizeof *cmd);
+ if (!cmd)
+ return -1;
+ cmd->command = g_strdup_printf("%%1%s ?\r", cmd->command);
+ pjctl->queue = g_list_append(pjctl->queue, cmd);
+ }
return 0;
}