summaryrefslogtreecommitdiff
path: root/monitor/main.c
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-03 19:05:10 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-03 19:05:10 +0100
commit1ff268ab13dd299c4cdc1e379df5397bd6a394e3 (patch)
tree014db93062f26cdfe2d2639fd833afd554e94a66 /monitor/main.c
parentc46fe12e47c405fbb03f0c93121402d873bc470e (diff)
downloadSystDigit-Projet-1ff268ab13dd299c4cdc1e379df5397bd6a394e3.tar.gz
SystDigit-Projet-1ff268ab13dd299c4cdc1e379df5397bd6a394e3.zip
Added simulator monitor tool.
Diffstat (limited to 'monitor/main.c')
-rw-r--r--monitor/main.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/monitor/main.c b/monitor/main.c
new file mode 100644
index 0000000..27fc1e0
--- /dev/null
+++ b/monitor/main.c
@@ -0,0 +1,61 @@
+#include <curses.h>
+#include <signal.h>
+
+#include "mon.h"
+
+#define MON2SIM "/tmp/mon2sim"
+#define SIM2MON "/tmp/sim2mon"
+
+void usage(char* p) {
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, " %s <simulator> [<simulator arguments>...]\n");
+ fprintf(stderr, "\n");
+}
+
+int main(int argc, char *argv[]) {
+ int err;
+
+ if (argc < 2) {
+ usage(argv[0]);
+ return 1;
+ }
+
+ // Launch simulator
+ mkfifo(MON2SIM, 0600);
+ mkfifo(SIM2MON, 0600);
+ int sim_pid = fork();
+ if (sim_pid == 0) {
+ // child : launch simulator
+ freopen(MON2SIM, "r", stdin);
+ freopen(SIM2MON, "w", stdout);
+ execv(argv[1], argv + 1);
+ }
+
+ t_mon mon;
+ mon.to_sim = fopen(MON2SIM, "w");
+ mon.from_sim = fopen(SIM2MON, "r");
+ if (err = mon_read_prologue(&mon)) {
+ fprintf(stderr, "\nError while launching simulator (%d).\n", err);
+ goto finish;
+ }
+
+ // Setup display
+ disp_init();
+
+ // RUN !!!
+ mon_loop(&mon);
+
+ // clean up
+ disp_finish();
+
+finish:
+ kill(sim_pid, SIGTERM);
+ waitpid(sim_pid);
+
+ fclose(mon.to_sim);
+ fclose(mon.from_sim);
+ unlink(MON2SIM);
+ unlink(SIM2MON);
+
+ return 0;
+}