summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2015-08-03 09:54:51 +0100
committerFrediano Ziglio <fziglio@redhat.com>2015-08-03 09:54:51 +0100
commit1f45a3fb666a3ff3b34b096ddaa9965937cb48b8 (patch)
treefe7eaff389a9f50e130236c287b22077a59ff84f
parentbd3ab1726969aac792fc1bcdfaf18fb3637b069d (diff)
Start to write main program
-rw-r--r--global.h5
-rw-r--r--spice-replay.c130
2 files changed, 135 insertions, 0 deletions
diff --git a/global.h b/global.h
new file mode 100644
index 0000000..0ea6f7b
--- /dev/null
+++ b/global.h
@@ -0,0 +1,5 @@
+
+extern Display *dpy;
+
+void xev_init(Window w);
+void xev_dump(XEvent *event);
diff --git a/spice-replay.c b/spice-replay.c
new file mode 100644
index 0000000..59ca8f5
--- /dev/null
+++ b/spice-replay.c
@@ -0,0 +1,130 @@
+/**
+ * Program to record/reproduce key/mouse events
+ *
+ * The intention is to be able to record a Spice
+ * session and reproduce it
+ */
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <X11/Xlib.h>
+
+#include "global.h"
+
+Display *dpy = NULL;
+
+enum {
+ MODE_UNKNOWN,
+ MODE_RECORD,
+ MODE_PLAY
+};
+
+static int mode = MODE_UNKNOWN;
+static int verbose = 0;
+
+static const char short_options[] = "hVvi:";
+static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h' },
+ {"version", no_argument, 0, 'V' },
+ {"record", no_argument, &mode, MODE_RECORD },
+ {"play", no_argument, &mode, MODE_PLAY },
+ {"verbose", no_argument, &verbose, 1 },
+ {"id", required_argument, 0, 'i'},
+ {"display", required_argument, 0, 'D'},
+ {NULL, 0, 0, 0 }
+};
+
+static void
+usage(FILE *f)
+{
+ fprintf(f, "Usage: spice-replay [--record|--play] [OPTION].. [FILE]\n"
+ "--display=<X>|-D <X> X server to contact\n"
+ "--record record events\n"
+ "--play play registered events\n"
+ "--verbose print more verbose information\n"
+ "--help|-h this help\n"
+ "--version|-V print program version\n"
+ "--id=<ID>|-i <ID> specify a window id\n"
+ );
+ exit(f == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+static void
+version(void)
+{
+ printf("spice-replay version " VERSION "\n");
+ exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+ Window w;
+ const char *fn_out = NULL;
+ const char *display = NULL;
+
+ while (1) {
+ int option_index = 0, c;
+
+ c = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 0:
+ break;
+
+ case 'h':
+ usage(stdout);
+ break;
+
+ case 'V':
+ version();
+ break;
+
+ case 'v':
+ verbose = 1;
+ break;
+
+ case 'i':
+ w = strtoul(optarg, NULL, 0);
+ break;
+
+ case 'd':
+ display = optarg;
+ break;
+
+ default:
+ usage(stderr);
+ break;
+ }
+ }
+
+ if (optind >= argc || mode == MODE_UNKNOWN)
+ usage(stderr);
+
+ fn_out = argv[optind];
+
+ dpy = XOpenDisplay (display);
+ if (!dpy) {
+ fprintf (stderr, "unable to open display '%s'\n", XDisplayName (display));
+ return EXIT_FAILURE;
+ }
+
+ xev_init(w);
+
+ while(1) {
+ XEvent event;
+
+ XNextEvent (dpy, &event);
+
+ if (verbose)
+ xev_dump(&event);
+ }
+
+ XCloseDisplay (dpy);
+
+ return EXIT_SUCCESS;
+}