int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; bindtextdomain(GETTEXT_PACKAGE, SPICE_GTK_LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); /* parse opts */ context = g_option_context_new(_(" - write screen shots in ppm format")); g_option_context_add_main_entries(context, app_entries, NULL); g_option_context_add_group(context, spice_cmdline_get_option_group()); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print (_("option parsing failed: %s\n"), error->message); exit (1); } g_type_init(); mainloop = g_main_loop_new(NULL, false); session = spice_session_new(); g_signal_connect(session, "channel-new", G_CALLBACK(channel_new), NULL); spice_cmdline_session_setup(session); if (!spice_session_connect(session)) { fprintf(stderr, _("spice_session_connect failed\n")); exit(1); } g_main_loop_run(mainloop); return 0; }
spice_connection *connection_new(void) { spice_connection *conn; SpiceUsbDeviceManager *manager; conn = g_new0(spice_connection, 1); conn->session = spice_session_new(); //conn->gtk_session = spice_gtk_session_get(conn->session); g_signal_connect(conn->session, "channel-new", G_CALLBACK(channel_new), conn); g_signal_connect(conn->session, "channel-destroy", G_CALLBACK(channel_destroy), conn); g_signal_connect(conn->session, "notify::migration-state", G_CALLBACK(migration_state), conn); manager = spice_usb_device_manager_get(conn->session, NULL); if (manager) { g_signal_connect(manager, "auto-connect-failed", G_CALLBACK(usb_auto_connect_failed), NULL); g_signal_connect(manager, "device-error", G_CALLBACK(usb_device_error), NULL); g_signal_connect(manager, "device-added", G_CALLBACK(usb_device_added), NULL); g_signal_connect(manager, "device-removed", G_CALLBACK(usb_device_removed), NULL); } connections++; SPICE_DEBUG("%s (%d)", __FUNCTION__, connections); return conn; }
int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; signal(SIGINT, signal_handler); /* parse opts */ context = g_option_context_new(NULL); g_option_context_set_summary(context, "A Spice client used for testing and measurements."); g_option_context_set_description(context, "Report bugs to " PACKAGE_BUGREPORT "."); g_option_context_set_main_group(context, spice_cmdline_get_option_group()); g_option_context_add_main_entries(context, app_entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print("option parsing failed: %s\n", error->message); exit(1); } if (version) { g_print("spicy-stats " PACKAGE_VERSION "\n"); exit(0); } mainloop = g_main_loop_new(NULL, false); session = spice_session_new(); g_signal_connect(session, "channel-new", G_CALLBACK(channel_new), NULL); spice_cmdline_session_setup(session); if (!spice_session_connect(session)) { fprintf(stderr, "spice_session_connect failed\n"); exit(1); } g_main_loop_run(mainloop); { GList *iter, *list = spice_session_get_channels(session); gulong total_read_bytes; gint channel_type; printf("total bytes read:\n"); for (iter = list ; iter ; iter = iter->next) { g_object_get(iter->data, "total-read-bytes", &total_read_bytes, "channel-type", &channel_type, NULL); printf("%s: %lu\n", spice_channel_type_to_string(channel_type), total_read_bytes); } g_list_free(list); } return 0; }
static gboolean do_connect(void *data) { struct connect_args *args = data; struct spice_context *ctx = args->ctx; ctx->session = spice_session_new(); if (args->password) g_object_set(ctx->session, "password", args->password, NULL); g_signal_connect(ctx->session, "channel-new", G_CALLBACK(channel_new), ctx); g_signal_connect(ctx->session, "channel-destroy", G_CALLBACK(channel_destroy), ctx); spice_session_open_fd(ctx->session, -1); g_free(args->password); g_slice_free(struct connect_args, args); return false; }
int main(int argc, char *argv[]) { parse_cmd(argc, argv); gtk_init(&argc, &argv); main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); spice_session = spice_session_new(); g_object_set(spice_session, "host", host, NULL); g_object_set(spice_session, "port", port, NULL); g_signal_connect(spice_session, "channel-new", G_CALLBACK(channel_new), NULL); if (!spice_session_connect(spice_session)) { fprintf(stderr, "spice_session_connect failed\n"); exit(1); } gtk_main(); return 0; }
static void test_session_uri(void) { SpiceSession *s; gint i; struct { gchar *port; gchar *tls_port; gchar *uri_input; gchar *uri_output; } tests[] = { /* Arguments with empty value */ { "5900", NULL, "spice://localhost?port=5900&tls-port=", "spice://localhost?port=5900&" }, { "5910", NULL, "spice://localhost?tls-port=&port=5910", "spice://localhost?port=5910&" }, { NULL, "5920", "spice://localhost?tls-port=5920&port=", "spice://localhost?tls-port=5920" }, { NULL, "5930", "spice://localhost?port=&tls-port=5930", "spice://localhost?tls-port=5930" }, }; /* Set URI and check URI, port and tls_port */ for (i = 0; i < G_N_ELEMENTS(tests); i++) { gchar *uri, *port, *tls_port; s = spice_session_new(); g_object_set(s, "uri", tests[i].uri_input, NULL); g_object_get(s, "uri", &uri, "port", &port, "tls-port", &tls_port, NULL); g_assert_cmpstr(tests[i].uri_output, ==, uri); g_assert_cmpstr(tests[i].port, ==, port); g_assert_cmpstr(tests[i].tls_port, ==, tls_port); g_clear_pointer(&uri, g_free); g_clear_pointer(&port, g_free); g_clear_pointer(&tls_port, g_free); g_object_unref(s); } /* Set port and tls_port, check URI */ for (i = 0; i < G_N_ELEMENTS(tests); i++) { gchar *uri; s = spice_session_new(); g_object_set(s, "port", tests[i].port, "tls-port", tests[i].tls_port, NULL); g_object_get(s, "uri", &uri, NULL); g_assert_cmpstr(tests[i].uri_output, ==, uri); g_clear_pointer(&uri, g_free); g_object_unref(s); } }