Browse Source

Add support for -b / --backup parameter.

This prints the device configuration as videohubctrl parameters thus
allowing the configuration to be restored later.
Georgi Chorbadzhiyski 9 years ago
parent
commit
258dd4f0ea
5 changed files with 37 additions and 1 deletions
  1. 2
    0
      ChangeLog
  2. 2
    0
      README
  3. 21
    0
      display.c
  4. 2
    0
      display.h
  5. 10
    1
      videohubctrl.c

+ 2
- 0
ChangeLog View File

@@ -9,6 +9,8 @@ xxxx-xx-xx : Version next
9 9
  * Add --list-device, --list-vinputs and --list-voutputs parameters.
10 10
  * Display last update time in --monitor.
11 11
  * Add support for VIDEOHUB_HOST and VIDEOHUB_PORT env variables.
12
+ * Add support for generating command line that restores the device
13
+   to it's current configuration using -b / --backup parameter.
12 14
 
13 15
 2014-11-27 : Version 0.2
14 16
  * Fix port routing. Previously it was reversed and incorrect.

+ 2
- 0
README View File

@@ -54,6 +54,8 @@ Misc options:
54 54
 Commands:
55 55
  -i --info                  | Show device info (default command).
56 56
  -m --monitor               | Show real time monitor for config changes.
57
+ -b --backup                | Show the command line that will restore
58
+                            . the device to the current configuration.
57 59
 
58 60
 Video input/output configuration:
59 61
  --vi-name <in_X> <name>    | Set video input port X name.

+ 21
- 0
display.c View File

@@ -77,3 +77,24 @@ void print_device_video_outputs(struct videohub_data *d) {
77 77
 	printf_line(len);
78 78
 	printf("\n");
79 79
 }
80
+
81
+void print_device_backup(struct videohub_data *d) {
82
+	unsigned int i;
83
+	printf("videohubctrl \\\n");
84
+	for(i = 0; i < d->device.num_video_inputs; i++)
85
+		printf("  --vi-name %2d \"%s\" \\\n", i + 1, d->inputs[i].name);
86
+	for(i = 0; i < d->device.num_video_outputs; i++)
87
+		printf("  --vo-name %2d \"%s\" \\\n", i + 1, d->outputs[i].name);
88
+	for(i = 0; i < d->device.num_video_outputs; i++)
89
+		printf("  --vo-route %2d %2d \\\n", i + 1, d->outputs[i].routed_to + 1);
90
+	for(i = 0; i < d->device.num_video_outputs; i++) {
91
+		if (d->outputs[i].locked) {
92
+			printf("  --vo-unlock %2d --vo-lock %2d%s\n", i + 1, i + 1,
93
+				i + 1 < d->device.num_video_outputs ? " \\" : "");
94
+		} else {
95
+			printf("  --vo-unlock %2d%s\n", i + 1,
96
+				i + 1 < d->device.num_video_outputs ? " \\" : "");
97
+		}
98
+	}
99
+	printf("\n");
100
+}

+ 2
- 0
display.h View File

@@ -17,4 +17,6 @@ void print_device_info(struct videohub_data *d);
17 17
 void print_device_video_inputs(struct videohub_data *d);
18 18
 void print_device_video_outputs(struct videohub_data *d);
19 19
 
20
+void print_device_backup(struct videohub_data *d);
21
+
20 22
 #endif

+ 10
- 1
videohubctrl.c View File

@@ -29,6 +29,7 @@ int quiet;
29 29
 static struct videohub_data maindata;
30 30
 static int show_info = 1;
31 31
 static int show_monitor = 0;
32
+static int show_backup = 0;
32 33
 static int show_list = 0;
33 34
 
34 35
 enum list_actions {
@@ -39,7 +40,7 @@ enum list_actions {
39 40
 
40 41
 static const char *program_id = PROGRAM_NAME " Version: " VERSION " Git: " GIT_VER;
41 42
 
42
-static const char short_options[] = "h:p:qdHVim";
43
+static const char short_options[] = "h:p:qdHVimb";
43 44
 
44 45
 static const struct option long_options[] = {
45 46
 	{ "host",				required_argument, NULL, 'h' },
@@ -50,6 +51,7 @@ static const struct option long_options[] = {
50 51
 	{ "version",			no_argument,       NULL, 'V' },
51 52
 	{ "info",				no_argument,       NULL, 'i' },
52 53
 	{ "monitor",			no_argument,       NULL, 'm' },
54
+	{ "backup",				no_argument,       NULL, 'b' },
53 55
 	{ "list-device",		no_argument,       NULL, 901 },
54 56
 	{ "list-vinputs",		no_argument,       NULL, 902 },
55 57
 	{ "list-voutputs",		no_argument,       NULL, 903 },
@@ -81,6 +83,8 @@ static void show_help(struct videohub_data *data) {
81 83
 	printf("                            . This command is shows the equivallent of\n");
82 84
 	printf("                            .  running all --list-XXX commands.\n");
83 85
 	printf(" -m --monitor               | Display real-time config changes monitor.\n");
86
+	printf(" -b --backup                | Show the command line that will restore\n");
87
+	printf("                            . the device to the current configuration.\n");
84 88
 	printf("\n");
85 89
 	printf(" --list-device              | Display device info.\n");
86 90
 	printf(" --list-vinputs             | List device video inputs.\n");
@@ -137,6 +141,9 @@ static void parse_options(struct videohub_data *data, int argc, char **argv) {
137 141
 			case 'm': // --monitor
138 142
 				show_monitor = 1;
139 143
 				break;
144
+			case 'b': // --backup
145
+				show_backup = 1;
146
+				break;
140 147
 			case 901: show_list |= action_list_device; break; // --list-device
141 148
 			case 902: show_list |= action_list_vinputs; break; // --list-vinputs
142 149
 			case 903: show_list |= action_list_voutputs; break; // --list-voutputs
@@ -285,6 +292,8 @@ int main(int argc, char **argv) {
285 292
 		if (show_list & action_list_vinputs)	print_device_video_inputs(data);
286 293
 		if (show_list & action_list_voutputs)	print_device_video_outputs(data);
287 294
 		fflush(stdout);
295
+	} else if (show_backup) {
296
+		print_device_backup(data);
288 297
 	} else if (show_info) {
289 298
 		print_device_info(data);
290 299
 		print_device_video_inputs(data);

Loading…
Cancel
Save