Browse Source

Make --backup function use generic command types.

Georgi Chorbadzhiyski 9 years ago
parent
commit
bdf1c28b6f
3 changed files with 64 additions and 21 deletions
  1. 25
    7
      cmd.c
  2. 1
    0
      cmd.h
  3. 38
    14
      display.c

+ 25
- 7
cmd.c View File

39
 	[CMD_PROTOCOL_PREAMBLE]    = { .cmd = CMD_PROTOCOL_PREAMBLE   , .type = PARSE_CUSTOM },
39
 	[CMD_PROTOCOL_PREAMBLE]    = { .cmd = CMD_PROTOCOL_PREAMBLE   , .type = PARSE_CUSTOM },
40
 	[CMD_VIDEOHUB_DEVICE]      = { .cmd = CMD_VIDEOHUB_DEVICE     , .type = PARSE_CUSTOM },
40
 	[CMD_VIDEOHUB_DEVICE]      = { .cmd = CMD_VIDEOHUB_DEVICE     , .type = PARSE_CUSTOM },
41
 	[CMD_INPUT_LABELS]         = { .cmd = CMD_INPUT_LABELS        , .type = PARSE_LABEL,
41
 	[CMD_INPUT_LABELS]         = { .cmd = CMD_INPUT_LABELS        , .type = PARSE_LABEL,
42
-		.ports1 = OFS(inputs),  .port_id1 = "video input",  },
42
+		.ports1 = OFS(inputs),
43
+		.port_id1 = "video input",
44
+		.opt_prefix = "vi",
45
+	},
43
 	[CMD_OUTPUT_LABELS]        = { .cmd = CMD_OUTPUT_LABELS       , .type = PARSE_LABEL,
46
 	[CMD_OUTPUT_LABELS]        = { .cmd = CMD_OUTPUT_LABELS       , .type = PARSE_LABEL,
44
-		.ports1 = OFS(outputs), .port_id1 = "video output", },
47
+		.ports1 = OFS(outputs),
48
+		.port_id1 = "video output",
49
+		.opt_prefix = "vo",
50
+	},
45
 	[CMD_VIDEO_OUTPUT_LOCKS]   = { .cmd = CMD_VIDEO_OUTPUT_LOCKS  , .type = PARSE_LOCK,
51
 	[CMD_VIDEO_OUTPUT_LOCKS]   = { .cmd = CMD_VIDEO_OUTPUT_LOCKS  , .type = PARSE_LOCK,
46
-		.ports1 = OFS(outputs), .port_id1 = "video output",  },
52
+		.ports1 = OFS(outputs),
53
+		.port_id1 = "video output",
54
+		.opt_prefix = "vo",
55
+	},
47
 	[CMD_VIDEO_OUTPUT_ROUTING] = { .cmd = CMD_VIDEO_OUTPUT_ROUTING, .type = PARSE_ROUTE,
56
 	[CMD_VIDEO_OUTPUT_ROUTING] = { .cmd = CMD_VIDEO_OUTPUT_ROUTING, .type = PARSE_ROUTE,
48
-		.ports1   = OFS(outputs), .ports2 = OFS(inputs),
49
-		.port_id1 = "video output",     .port_id2 = "video input",
57
+		.ports1 = OFS(outputs),
58
+		.ports2 = OFS(inputs),
59
+		.port_id1 = "video output",
60
+		.port_id2 = "video input",
61
+		.opt_prefix = "vo",
50
 	},
62
 	},
51
 	[CMD_VIDEO_INPUT_STATUS]   = { .cmd = CMD_VIDEO_INPUT_STATUS  , .type = PARSE_STATUS,
63
 	[CMD_VIDEO_INPUT_STATUS]   = { .cmd = CMD_VIDEO_INPUT_STATUS  , .type = PARSE_STATUS,
52
-		.ports1 = OFS(inputs),  .port_id1 = "video input",   },
64
+		.ports1 = OFS(inputs),
65
+		.port_id1 = "video input",
66
+		.opt_prefix = "vi",
67
+	},
53
 	[CMD_VIDEO_OUTPUT_STATUS]  = { .cmd = CMD_VIDEO_OUTPUT_STATUS , .type = PARSE_STATUS,
68
 	[CMD_VIDEO_OUTPUT_STATUS]  = { .cmd = CMD_VIDEO_OUTPUT_STATUS , .type = PARSE_STATUS,
54
-		.ports1 = OFS(outputs), .port_id1 = "video output",  },
69
+		.ports1 = OFS(outputs),
70
+		.port_id1 = "video output",
71
+		.opt_prefix = "vo",
72
+	},
55
 	[CMD_PING]                 = { .cmd = CMD_PING                , .type = PARSE_NONE },
73
 	[CMD_PING]                 = { .cmd = CMD_PING                , .type = PARSE_NONE },
56
 	[CMD_ACK]                  = { .cmd = CMD_ACK                 , .type = PARSE_NONE },
74
 	[CMD_ACK]                  = { .cmd = CMD_ACK                 , .type = PARSE_NONE },
57
 	[CMD_NAK]                  = { .cmd = CMD_NAK                 , .type = PARSE_NONE },
75
 	[CMD_NAK]                  = { .cmd = CMD_NAK                 , .type = PARSE_NONE },

+ 1
- 0
cmd.h View File

47
 	size_t			ports2;
47
 	size_t			ports2;
48
 	const char		*port_id1;
48
 	const char		*port_id1;
49
 	const char		*port_id2;
49
 	const char		*port_id2;
50
+	const char		*opt_prefix;
50
 };
51
 };
51
 
52
 
52
 extern struct videohub_commands videohub_commands[NUM_COMMANDS];
53
 extern struct videohub_commands videohub_commands[NUM_COMMANDS];

+ 38
- 14
display.c View File

14
 #include <string.h>
14
 #include <string.h>
15
 
15
 
16
 #include "data.h"
16
 #include "data.h"
17
+#include "cmd.h"
17
 #include "util.h"
18
 #include "util.h"
18
 #include "display.h"
19
 #include "display.h"
19
 
20
 
124
 	printf("\n");
125
 	printf("\n");
125
 }
126
 }
126
 
127
 
128
+static void __print_opt(struct videohub_data *d, enum vcmd vcmd) {
129
+	unsigned int i, last = 0;
130
+	struct videohub_commands *v = &videohub_commands[vcmd];
131
+	struct port_set *s_port = !v->ports1 ? NULL : (void *)d + v->ports1;
132
+	const char *p = v->opt_prefix;
133
+	for(i = 0; i < s_port->num; i++) {
134
+		switch (v->type) {
135
+		case PARSE_LABEL:
136
+			printf("  --%s-name %2d \"%s\" \\\n", p, i + 1, s_port->port[i].name);
137
+			break;
138
+		case PARSE_ROUTE:
139
+			printf("  --%s-route %2d %2d \\\n", p, i + 1, s_port->port[i].routed_to + 1);
140
+			break;
141
+		case PARSE_LOCK:
142
+			last = i + 1 < s_port->num;
143
+			if (s_port->port[i].lock != PORT_UNLOCKED) {
144
+				printf("  --%s-unlock %2d --%s-lock %2d%s\n",
145
+					p, i + 1, p, i + 1, last ? " \\" : "");
146
+			} else {
147
+				printf("  --%s-unlock %2d%s\n", p, i + 1, last ? " \\" : "");
148
+			}
149
+		default: break;
150
+		}
151
+	}
152
+}
153
+
127
 void print_device_backup(struct videohub_data *d) {
154
 void print_device_backup(struct videohub_data *d) {
128
 	unsigned int i;
155
 	unsigned int i;
129
 	printf("videohubctrl \\\n");
156
 	printf("videohubctrl \\\n");
130
-	for(i = 0; i < d->inputs.num; i++)
131
-		printf("  --vi-name %2d \"%s\" \\\n", i + 1, d->inputs.port[i].name);
132
-	for(i = 0; i < d->outputs.num; i++)
133
-		printf("  --vo-name %2d \"%s\" \\\n", i + 1, d->outputs.port[i].name);
134
-	for(i = 0; i < d->outputs.num; i++)
135
-		printf("  --vo-route %2d %2d \\\n", i + 1, d->outputs.port[i].routed_to + 1);
136
-	for(i = 0; i < d->outputs.num; i++) {
137
-		if (d->outputs.port[i].lock != PORT_UNLOCKED) {
138
-			printf("  --vo-unlock %2d --vo-lock %2d%s\n", i + 1, i + 1,
139
-				i + 1 < d->outputs.num ? " \\" : "");
140
-		} else {
141
-			printf("  --vo-unlock %2d%s\n", i + 1,
142
-				i + 1 < d->outputs.num ? " \\" : "");
143
-		}
157
+	for (i = 0; i < NUM_COMMANDS; i++) {
158
+		if (videohub_commands[i].type == PARSE_LABEL)
159
+			__print_opt(d, videohub_commands[i].cmd);
160
+	}
161
+	for (i = 0; i < NUM_COMMANDS; i++) {
162
+		if (videohub_commands[i].type == PARSE_ROUTE)
163
+			__print_opt(d, videohub_commands[i].cmd);
164
+	}
165
+	for (i = 0; i < NUM_COMMANDS; i++) {
166
+		if (videohub_commands[i].type == PARSE_LOCK)
167
+			__print_opt(d, videohub_commands[i].cmd);
144
 	}
168
 	}
145
 	printf("\n");
169
 	printf("\n");
146
 }
170
 }

Loading…
Cancel
Save