int main(int argc, char *argv[]) { context_t c; mrp_clear(&c); if (!parse_cmdline(&c, argc, argv)) exit(1); mrp_log_set_mask(c.log_mask); mrp_log_set_target(c.log_target); if (c.server) mrp_log_info("Running as server, using D-BUS '%s'...", c.busaddr); else mrp_log_info("Running as client, using D-BUS '%s'...", c.busaddr); c.ml = mrp_mainloop_create(); mrp_add_sighandler(c.ml, SIGINT , signal_handler, &c); if (c.server) server_setup(&c); else client_setup(&c); mrp_mainloop_run(c.ml); if (c.server) server_cleanup(&c); else client_cleanup(&c); return 0; }
static void setup_dbus_tests(mrp_mainloop_t *ml) { mrp_sighandler_t *h; if (cfg.ndbus_method == 0 && cfg.ndbus_signal == 0) return; if ((h = mrp_add_sighandler(ml, SIGCHLD, sigchild_handler, NULL)) != NULL) { open_dbus_pipe(); fork_dbus_client(ml); } else fatal("failed create SIGCHLD handler"); }
static void setup_signals(mrp_mainloop_t *ml) { test_signal_t *t; int intervals[] = { SIG_INTERVALS, 0 }, *iv = intervals; int signums[] = SIGNUMS, *s = signums; int msecs, i; if ((signals = mrp_allocz_array(test_signal_t, cfg.nsignal)) != NULL) { for (i = 0, t = signals; i < cfg.nsignal; i++, t++) { t->id = i; t->signum = *s; msecs = *iv; while (cfg.runtime / msecs < 1 && msecs > 0) msecs /= 2; msecs *= 1000; if (!msecs) msecs = 500; t->target = 1000 * cfg.runtime / msecs; if (!t->target) continue; t->watch = mrp_add_sighandler(ml, *s, recv_signal, t); t->timer = mrp_add_timer(ml, msecs, send_signal, t); if (t->timer == NULL) fatal("MRPH signal #%d: could not create timer", t->id); if (t->watch == NULL) fatal("MRPH signal #%d: could not create watch", t->id); else info("MRPH signal #%d: interval=%d, target=%d", t->id, *iv, t->target); cfg.nrunning++; iv++; if (!*iv) iv = intervals; s++; if (!*s) s = signums; } } else if (cfg.nsignal > 0) fatal("could not allocate %d signal watches", cfg.nsignal); }
static int create_synth(srs_plugin_t *plugin) { srs_context_t *srs = plugin->srs; mrp_mainloop_t *ml = srs->ml; synth_t *synth; mrp_debug("creating simple voice plugin"); synth = mrp_allocz(sizeof(*synth)); if (synth != NULL) { synth->sigh = mrp_add_sighandler(ml, SIGCHLD, sighandler, synth); if (synth->sigh != NULL) { plugin->plugin_data = synth; return TRUE; } mrp_free(synth); } return FALSE; }
static void setup_signals(client_t *c) { mrp_add_sighandler(c->ml, SIGINT , sighandler, c); mrp_add_sighandler(c->ml, SIGTERM, sighandler, c); }
static void setup_signals(mrp_context_t *ctx) { mrp_add_sighandler(ctx->ml, SIGINT , signal_handler, ctx); mrp_add_sighandler(ctx->ml, SIGTERM, signal_handler, ctx); }