Example #1
0
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;
}
Example #2
0
int main(int argc, char **argv)
{
    mrp_mainloop_t *ml;
    int mask;
    mrp_io_watch_t *watch;

    my_app_data app_data;

    MRP_UNUSED(argc);
    MRP_UNUSED(argv);

    if ((ml = mrp_mainloop_create()) == NULL)
        exit(1);

    app_data.rs = NULL;
    app_data.cx = mrp_res_create(ml, state_callback, &app_data);

    mask = MRP_IO_EVENT_IN | MRP_IO_EVENT_HUP | MRP_IO_EVENT_ERR;
    watch = mrp_add_io_watch(ml, fileno(stdin), (mrp_io_event_t) mask,
            handle_input, &app_data);

    if (!watch)
        exit(1);

    /* start looping */
    mrp_mainloop_run(ml);

    mrp_res_destroy(app_data.cx);
    mrp_mainloop_destroy(ml);

    app_data.cx = NULL;
    app_data.rs = NULL;

    return 0;
}
Example #3
0
static void setup_dbus_client(mrp_mainloop_t *ml)
{
    DBusConnection *conn;
    int             i, nmethod, nsignal;
    size_t          size;
    ssize_t         amount_read;

    nmethod = cfg.ndbus_method;
    nsignal = cfg.ndbus_signal;
    mrp_clear(&cfg);
    cfg.ndbus_method = nmethod;
    cfg.ndbus_signal = nsignal;

    mrp_mainloop_quit(ml, 0);
#ifdef GLIB_ENABLED
    glib_pump_cleanup();
#endif
    mrp_mainloop_destroy(ml);

    for (i = 3; i < 1024; i++)
        if (i != dbus_test.pipe[0])
            close(i);

    size = sizeof(dbus_test.address) - 1;
    amount_read = read(dbus_test.pipe[0], dbus_test.address, size);
    if (amount_read > 0) {
        dbus_test.address[amount_read] = '\0';
        info("DBUS test: got address '%s'", dbus_test.address);
    }

    /*sleep(5);*/

    if ((ml = dbus_test.ml = mrp_mainloop_create()) == NULL)
        fatal("failed to create mainloop");

    cfg.ml = ml;

    if ((conn = dbus_test.conn = connect_to_dbus(NULL)) == NULL)
        fatal("failed to connect to DBUS");

    if (!mrp_setup_dbus_connection(ml, conn))
        fatal("failed to setup DBUS connection with mainloop");

    if (mrp_add_timer(ml, 1000, client_send_msg, NULL) == NULL)
        fatal("failed to create DBUS message sending timer");

    if (mrp_add_timer(ml, 1000, check_quit, NULL) == NULL)
        fatal("failed to create quit-check timer");

    cfg.nrunning++;
}
Example #4
0
int main(int argc, char **argv) {
    mrp_mainloop_t *ml = mrp_mainloop_create();

    if (argc == 2 && strcmp(argv[1], "pid") == 0) {
        test_pid_watch(ml);
    }
    else if (argc == 2 && strcmp(argv[1], "process") == 0) {
        test_process_watch(ml);
    }
    else {
        printf("Usage: process-watch-test <process|pid>\n");
    }

    mrp_mainloop_destroy(ml);
}
Example #5
0
static mrp_mainloop_t *mainloop_create(test_config_t *cfg)
{
    switch (cfg->mainloop_type) {
    case MAINLOOP_NATIVE:
        cfg->ml = mrp_mainloop_create();
        break;

    case MAINLOOP_PULSE:
        pulse_mainloop_create(cfg);
        break;

    case MAINLOOP_ECORE:
        ecore_mainloop_create(cfg);
        break;

    case MAINLOOP_GLIB:
        glib_mainloop_create(cfg);
        break;

#ifdef QT_ENABLED
    case MAINLOOP_QT:
        cfg->ml = qt_mainloop_create();
        break;
#endif

    default:
        mrp_log_error("Invalid mainloop type 0x%x.", cfg->mainloop_type);
        exit(1);
    }

    if (cfg->ml == NULL) {
        mrp_log_error("Failed to create mainloop.");
        exit(1);
    }

    return cfg->ml;
}