安装 iPod 上的多个安装事件
我正在开发一个应用程序,它必须检测存储卷是否已安装或卸载。我正在使用 GIO 来实现这一点。我正在监听 mount-added
和 mount-removed
信号。当我安装/卸载笔式驱动器时,一切正常。但是,我在安装 iPod 时遇到问题。我在安装和卸载时分别收到两个回调。我假设 GMount
对象之一是 阴影但 g_mount_is_shadowed 两者都返回 false。我如何决定处理哪一个以及忽略哪一个?我无法同时处理两者。我必须检测与存储设备相对应的安装/卸载并仅对其进行处理。
int main()
{
g_type_init();
GVolumeMonitor* volume_monitor = g_volume_monitor_get();
g_signal_connect(G_OBJECT(volume_monitor), "mount-added", G_CALLBACK(mount_added), NULL);
g_signal_connect(G_OBJECT(volume_monitor), "mount-removed", G_CALLBACK(mount_removed), NULL);
GMainLoop* main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
...
}
I am working on an app which has to detect if a storage volume is mounted or unmounted. I am using GIO
for that. I listening for the mount-added
and mount-removed
signals. Everything works fine when I mount/unmount a pen drive. However, I am seeing an issue when mounting an iPod. I am getting two callbacks each on mount and unmount. I assumed one of the GMount
objects would be shadowed but g_mount_is_shadowed is returning false for both. How do I decide which one to process and which to ignore? I cannot process both. I have to detect the mount/unmount corresponding to the storage device and process only that.
int main()
{
g_type_init();
GVolumeMonitor* volume_monitor = g_volume_monitor_get();
g_signal_connect(G_OBJECT(volume_monitor), "mount-added", G_CALLBACK(mount_added), NULL);
g_signal_connect(G_OBJECT(volume_monitor), "mount-removed", G_CALLBACK(mount_removed), NULL);
GMainLoop* main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经想通了。
GIO
为每个添加的文件系统发出一个mount-added
信号。 iPod 有两种文件系统 - 一种用于操作系统,另一种用于存储音乐。因此反复回调。卸载时也会发生同样的情况。这与阴影坐骑无关。不幸的是,我仍然不知道如何区分这两个坐骑。GIO
显示的唯一区别是其中一个GMount
对象没有与其关联的GVolume
对象。我不知道如何解释这一点。I have figured it out.
GIO
emits amount-added
signal for each filesystem that is added. The iPod has two file systems - one for the OS and one for storing music. Hence the repeated callback. The same happens on unmount. This has nothing to do with shadowed mounts. Unfortunately, I still don't know how to distinguish between the two mounts. The only differenceGIO
shows is that one of theGMount
objects does not have aGVolume
object associated with it. I don't know how to interpret that.