Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208510
  • 博文数量: 82
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 18
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-28 13:26
个人简介

当做事的时候,也是在学习的时候!

文章分类

全部博文(82)

文章存档

2016年(9)

2015年(55)

2014年(7)

2013年(10)

2012年(1)

我的朋友

分类: 云计算

2015-09-21 18:06:26


  1. int main(int argc, char *argv[])
  2. {
  3.     GError *error = NULL;
  4.     GOptionContext *context;
  5.     spice_connection *conn;
  6.     gchar *conf_file, *conf;
  7.     char *host = NULL, *port = NULL, *tls_port = NULL;


  8. #if !GLIB_CHECK_VERSION(2,31,18)
  9.     g_thread_init(NULL);
  10. #endif
  11. /*国际化*/
  12.     bindtextdomain(GETTEXT_PACKAGE, SPICE_GTK_LOCALEDIR);
  13.     bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  14.     textdomain(GETTEXT_PACKAGE);


  15. /*信号处理函数*/
  16.     signal(SIGINT, signal_handler);
  17.     signal(SIGTERM, signal_handler);
  18.     segv_handler = signal(SIGSEGV, signal_handler);
  19.     abrt_handler = signal(SIGABRT, signal_handler);
  20.     fpe_handler = signal(SIGFPE, signal_handler);
  21.     ill_handler = signal(SIGILL, signal_handler);
  22.     
  23. #ifndef WIN32
  24.     signal(SIGHUP, signal_handler);
  25.     bus_handler = signal(SIGBUS, signal_handler);
  26. #endif


  27. /*读取配置文件*/
  28.     keyfile = g_key_file_new();


  29.     int mode = S_IRWXU;
  30.     conf_file = g_build_filename(g_get_user_config_dir(), "spicy", NULL);
  31.     if (g_mkdir_with_parents(conf_file, mode) == -1)
  32.         SPICE_DEBUG("failed to create config directory");
  33.     g_free(conf_file);


  34.     conf_file = g_build_filename(g_get_user_config_dir(), "spicy", "settings", NULL);
  35.     if (!g_key_file_load_from_file(keyfile, conf_file,
  36.                                    G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, &error)) {
  37.         SPICE_DEBUG("Couldn't load configuration: %s", error->message);
  38.         g_clear_error(&error);
  39.     }
  40.     
  41. /*解析命令行传入的参数*/
  42.     /* parse opts */
  43.     gtk_init(&argc, &argv);
  44.     context = g_option_context_new(_("- spice client test application"));
  45.     g_option_context_set_summary(context, _("Gtk+ test client to connect to Spice servers."));
  46.     g_option_context_set_description(context, _("Report bugs to " PACKAGE_BUGREPORT "."));
  47.     g_option_context_add_group(context, spice_get_option_group());
  48.     g_option_context_set_main_group(context, spice_cmdline_get_option_group());
  49.     g_option_context_add_main_entries(context, cmd_entries, NULL);
  50.     g_option_context_add_group(context, gtk_get_option_group(TRUE));
  51.     if (!g_option_context_parse (context, &argc, &argv, &error)) {
  52.         g_print(_("option parsing failed: %s\n"), error->message);
  53.         exit(1);
  54.     }
  55.     g_option_context_free(context);


  56.     if (version) {
  57.         g_print("spicy " PACKAGE_VERSION "\n");
  58.         exit(0);
  59.     }




  60.     g_type_init();
  61.     mainloop = g_main_loop_new(NULL, false);


  62. /*设置conn的通道默认回调函数,设置内部默认参数,读取命令行参数*/
  63.     conn = connection_new();
  64.     spice_set_session_option(conn->session);
  65.     spice_cmdline_session_setup(conn->session);


  66.     g_object_get(conn->session,
  67.                  "host", &host,
  68.                  "port", &port,
  69.                  "tls-port", &tls_port,
  70.                  NULL);
  71.     /* If user doesn't provide hostname and port, show the dialog window
  72.        instead of connecting to server automatically */
  73.     if (host == NULL || (port == NULL && tls_port == NULL)) {
  74.         int ret = connect_dialog(conn->session);
  75.         if (ret != 0) {
  76.             exit(0);
  77.         }
  78.     }
  79.     g_free(host);
  80.     g_free(port);
  81.     g_free(tls_port);


  82.     watch_stdin();


  83. /*创建主通道,激活channel_new()*/
  84.     connection_connect(conn);
  85.     if (connections > 0)
  86.         g_main_loop_run(mainloop);
  87.     g_main_loop_unref(mainloop);


  88.     if ((conf = g_key_file_to_data(keyfile, NULL, &error)) == NULL ||
  89.         !g_file_set_contents(conf_file, conf, -1, &error)) {
  90.         SPICE_DEBUG("Couldn't save configuration: %s", error->message);
  91.         g_error_free(error);
  92.         error = NULL;
  93.     }


  94.     g_free(conf_file);
  95.     g_free(conf);
  96.     g_key_file_free(keyfile);


  97.     g_free(spicy_title);


  98.     setup_terminal(true);
  99.     return 0;
  100. }


阅读(1485) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~