Exemplo n.º 1
0
int main(int argc,
         char **argv)
{
    char *filename = NULL;
    gboolean init_ret;
    gboolean verbose = FALSE;
    GError *error = NULL;
    int ret;
    GOptionEntry options[] = {
        {
            "dev", 'd', 0,
            G_OPTION_ARG_FILENAME, &filename,
            "ZBC device file", NULL
        },
        {
            "interval", 'i', 0,
            G_OPTION_ARG_INT, &dz.interval,
            "Refresh interval (milliseconds)", NULL
        },
        {
            "verbose", 'v', 0,
            G_OPTION_ARG_NONE, &verbose,
            "Set libzbc verbose mode", NULL
        },
        { NULL }
    };

    /* Init */
    memset(&dz, 0, sizeof(dz));
    dz.interval = DZ_INTERVAL;
    gtk_set_locale();
    init_ret = gtk_init_with_args(&argc,
                                  &argv,
                                  "ZBC device zone state GUI",
                                  options,
                                  NULL,
                                  &error);
    if ( (init_ret == FALSE)
         || (error != NULL) ) {
        printf("Failed to parse command line arguments: %s\n",
               error->message);
        g_error_free(error);
        return( 1 );
    }

    if ( ! filename ) {
        fprintf(stderr, "No ZBC device file specified\n");
        return( 1 );
    }

    if ( verbose ) {
        zbc_set_log_level("debug");
    }

    dz_set_signal_handlers();

    /* Open device file */
    ret = zbc_open(filename, O_RDONLY, &dz.dev);
    if ( ret != 0 ) {
        fprintf(stderr, "Open device %s failed\n",
                filename);
        return( 1 );
    }

    ret = zbc_get_device_info(dz.dev, &dz.info);
    if ( ret < 0 ) {
        fprintf(stderr,
                "zbc_get_device_info failed\n");
        goto out;
    }

    dz.filename = filename;

    printf("Creating interface...\n");

    /* Create GUI */
    dz_if_create();

    /* Main event loop */
    gtk_main();
        
    /* Cleanup GUI */
    dz_if_destroy();

out:
    
    zbc_close(dz.dev);

    return( ret );

}
Exemplo n.º 2
0
int
main(int argc,
     char **argv)
{
    gboolean init_ret;
    gboolean verbose = FALSE;
    GError *error = NULL;
    int i;
    GOptionEntry options[] = {
        {
            "interval", 'i', 0,
            G_OPTION_ARG_INT, &dz.interval,
            "Refresh interval (milliseconds)", NULL
        },
	{
            "block", 'b', 0,
            G_OPTION_ARG_INT, &dz.block_size,
            "Use block bytes as the unit for displaying zone LBA, length and write pointer position", NULL
        },
        {
            "verbose", 'v', 0,
            G_OPTION_ARG_NONE, &verbose,
            "Set libzbc verbose mode", NULL
        },
        { NULL }
    };

    /* Init */
    memset(&dz, 0, sizeof(dz));
    init_ret = gtk_init_with_args(&argc,
                                  &argv,
                                  "ZBC device zone state GUI",
                                  options,
                                  NULL,
                                  &error);
    if ( (init_ret == FALSE)
         || (error != NULL) ) {
        printf("Failed to parse command line arguments: %s\n",
               error->message);
        g_error_free(error);
        return( 1 );
    }

    if ( dz.interval < 0 ) {
        fprintf(stderr, "Invalid update interval\n");
        return( 1 );
    }

    if ( dz.block_size < 0 ) {
	fprintf(stderr, "Invalid block size\n");
	return( 1 );
    }

    if ( verbose ) {
        zbc_set_log_level("debug");
    }

    dz_set_signal_handlers();

    /* Create GUI */
    dz_if_create();

    /* Add devices listed on command line */
    for(i = 1; i < argc; i++ ) {
	dz_if_add_device(argv[i]);
    }

    /* Main event loop */
    gtk_main();

    /* Cleanup GUI */
    dz_if_destroy();

    return( 0 );

}