Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    GIOChannel *pchan;
    gint events;
    const char *hci = "hci0";

    opt_sec_level = g_strdup("low");

    if (argc > 1)
        hci = argv[1];

    if (parse_dev_src(hci, &opt_src, &opt_src_idx)) {
        fprintf(stderr,"%s: expected optional argument 'hciX' valid and up\n", argv[0]);
        resp_error(err_BAD_HCI);
        return EXIT_FAILURE;
    }

    DBG("Using controller hci%d  addr:%s", opt_src_idx, opt_src);

    opt_dst = NULL;
    opt_dst_type = g_strdup("public");

    DBG(__FILE__ " built at " __TIME__ " on " __DATE__);

    mgmt_setup();

    event_loop = g_main_loop_new(NULL, FALSE);

    pchan = g_io_channel_unix_new(fileno(stdin));
    g_io_channel_set_close_on_unref(pchan, TRUE);
    events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
    g_io_add_watch(pchan, events, prompt_read, NULL);

    DBG("Starting loop");
    g_main_loop_run(event_loop);

    DBG("Exiting loop");
    cmd_disconnect(0, NULL);
    fflush(stdout);
    g_io_channel_unref(pchan);
    g_main_loop_unref(event_loop);

    g_free(opt_src);
    g_free(opt_dst);
    g_free(opt_dst_type);
    g_free(opt_sec_level);

    mgmt_unregister_index(mgmt_master, opt_src_idx);
    mgmt_cancel_index(mgmt_master, opt_src_idx);
    mgmt_unref(mgmt_master);
    mgmt_master = NULL;

    return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{

    GIOChannel *pchan;
    gint events;

    opt_sec_level = g_strdup("low");

    opt_src = NULL;
    //opt_dst = NULL;
    opt_dst_type = g_strdup("public");

    event_loop = g_main_loop_new(NULL, FALSE);

    pchan = g_io_channel_unix_new(fileno(stdin));
    g_io_channel_set_close_on_unref(pchan, TRUE);
    events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
    g_io_add_watch(pchan, events, prompt_read, NULL);
    GError *gerr = NULL;
    printf("Connecting to.. %s\n", argv[1]);
    iochannel = gatt_connect(opt_src, argv[1], opt_dst_type, opt_sec_level, opt_psm, opt_mtu, connect_cb, &gerr);
       if (iochannel == NULL)
    {
        g_error_free(gerr);
        }
    else
        g_io_add_watch(iochannel, G_IO_HUP, channel_watcher, NULL);
    g_main_loop_run(event_loop);

    fflush(stdout);
    g_io_channel_unref(pchan);
    g_main_loop_unref(event_loop);

    g_free(opt_src);
    //g_free(opt_dst);
    g_free(opt_sec_level);

    mgmt_unregister_index(mgmt_master, mgmt_ind);
    mgmt_cancel_index(mgmt_master, mgmt_ind);
    mgmt_unref(mgmt_master);
    mgmt_master = NULL;

    return EXIT_SUCCESS;
}