安装 iPod 上的多个安装事件

发布于 2024-10-10 23:06:56 字数 922 浏览 2 评论 0原文

我正在开发一个应用程序,它必须检测存储卷是否已安装或卸载。我正在使用 GIO 来实现这一点。我正在监听 mount-addedmount-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

‖放下 2024-10-17 23:06:56

我已经想通了。 GIO 为每个添加的文件系统发出一个 mount-added 信号。 iPod 有两种文件系统 - 一种用于操作系统,另一种用于存储音乐。因此反复回调。卸载时也会发生同样的情况。这与阴影坐骑无关。不幸的是,我仍然不知道如何区分这两个坐骑。 GIO 显示的唯一区别是其中一个 GMount 对象没有与其关联的 GVolume 对象。我不知道如何解释这一点。

I have figured it out. GIO emits a mount-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 difference GIOshows is that one of the GMount objects does not have a GVolume object associated with it. I don't know how to interpret that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文