打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Spice 分析(3) – 编写 Spice Client

Spice 分析(3) – 编写 Spice Client

spice-gtk 的帮助下, spice client 的编写非常简单. 以致于我在做 Spice Server 的测试的时候, 顺手写了一个简单的 spice client.

把下面的一些核心部分做一个剖析:

static void channel_new(SpiceSession *s, SpiceChannel *c, gpointer *data); /* 创建一个 Spice session */spice_session = spice_session_new(); /* 设置 Spice 的地址和端口 */g_object_set(spice_session, "host", host, NULL);g_object_set(spice_session, "port", port, NULL); /* 设置当 Spice Channel 建立之后的 callback, 也就是说这个时候可以 * 获取 Spice Gtk 建立的 Spice Widget, 包括 Spice Window 等 */g_signal_connect(spice_session, "channel-new",                 G_CALLBACK(channel_new), NULL); /* 最后调用这个 API, 连接 Server 就可以了 */spice_session_connect(spice_session); static void channel_new(SpiceSession *s, SpiceChannel *c, gpointer *data){    int id = 0;     /* 获取通道 ID */    g_object_get(c, "channel-id", &id, NULL);     if (SPICE_IS_DISPLAY_CHANNEL(c)) {        /* 对 Display 通道, 获取 spice window, 然后把它加入我们的容器(主窗口,         * VBox 等), 这里的 main_window 是我用 gtk_window_new() 创建的主窗口 */        spice_display = spice_display_new(s, id);        gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(spice_display));        gtk_widget_show_all(main_window);    } }

事实上, 核心代码不超过 10 行, 如此的简单, 当然更多的鼠标, 键盘事件, USB 重定向 等, 只要自己写 signal 的 callback 就可以了.

完整的代码在 我的github 上:

$ git clone git://github.com/mathslinux/qemu-tools$ cd qemu-tools/spice-tools/$ make$ ./spice-client
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
DataSnap | Mat DeLong
GTK:对话框构件
GTK+ 3 基础知识学习
WebKit: Extending JavaScript
声网 Agora – 全球实时音视频云开创者
JAVA程序实现对SFTP服务器的操作,无密码
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服