Esempio n. 1
0
static void mainloop_run(test_config_t *cfg)
{
    switch (cfg->mainloop_type) {
    case MAINLOOP_NATIVE:
        mrp_mainloop_run(cfg->ml);
        break;

    case MAINLOOP_PULSE:
        pulse_mainloop_run(cfg);
        break;

    case MAINLOOP_ECORE:
        ecore_mainloop_run(cfg);
        break;

    case MAINLOOP_GLIB:
        glib_mainloop_run(cfg);
        break;

#ifdef QT_ENABLED
    case MAINLOOP_QT:
        qt_mainloop_run();
        break;
#endif

    default:
        mrp_log_error("Invalid mainloop type 0x%x.", cfg->mainloop_type);
        exit(1);
    }
}
Esempio n. 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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
static void test_pid_watch(mrp_mainloop_t *ml)
{
    pid_t pid = fork();

    if (pid < 0) {
        printf("error forking\n");
    }
    else if (pid > 0) {
        mrp_pid_watch_t *w;

        if (mrp_pid_query_state(pid) != MRP_PROCESS_STATE_READY) {
            printf("failed to query the process READY state\n");
        }

        printf("setting pid watch\n");
        w = mrp_pid_set_watch(pid, ml, pid_watch, ml);

        printf("killing the process '%d'\n", pid);
        kill(pid, 15);
        waitpid(pid, NULL, 0);

        printf("running main loop\n");
        mrp_mainloop_run(ml);

        if (mrp_pid_query_state(pid) != MRP_PROCESS_STATE_NOT_READY) {
            printf("failed to query the process NOT READY state\n");
        }
        printf("removing the watch\n");
        mrp_pid_remove_watch(w);
    }
}
Esempio n. 5
0
static void test_process_watch(mrp_mainloop_t *ml)
{
    mrp_process_state_t s = mrp_process_query_state("foobar");

    printf("initial state %s\n",
            s == MRP_PROCESS_STATE_READY ? "ready" : "not ready");

    if (mrp_process_set_state("foobar", MRP_PROCESS_STATE_READY) < 0) {
        printf("error setting the state 1\n");
    }

    s = mrp_process_query_state("foobar");

    printf("second state %s\n",
            s == MRP_PROCESS_STATE_READY ? "ready" : "not ready");

    if (mrp_process_set_state("foobar", MRP_PROCESS_STATE_NOT_READY) < 0) {
        printf("error setting the state 2\n");
    }

    s = mrp_process_query_state("foobar");

    printf("third state %s\n",
            s == MRP_PROCESS_STATE_READY ? "ready" : "not ready");

    if (mrp_process_set_watch("foobar", ml, process_watch, ml) < 0) {
        printf("failed to register watch\n");
    }

    printf("setting state to ready\n");

    if (mrp_process_set_state("foobar", MRP_PROCESS_STATE_READY) < 0) {
        printf("error setting the state 3\n");
    }

    mrp_mainloop_run(ml);

    printf("removing the watch\n");

    if(mrp_process_remove_watch("foobar") < 0) {
        printf("failed to remove watch\n");
    }
}
Esempio n. 6
0
static void run_mainloop(mrp_context_t *ctx)
{
    mrp_context_setstate(ctx, MRP_STATE_RUNNING);
    emit_daemon_event(DAEMON_EVENT_RUNNING);
    mrp_mainloop_run(ctx->ml);
}