0

是否可以让一个用 [DBus (name = ...)] 注释的类实现一个接口?

按照https://live.gnome.org/Vala/DBusServerSample的示例,我正在实现一个 D-BUS 客户端/服务器应用程序。

我发现该示例的特别之处在于没有单独的接口定义。我想将客户端使用的接口放在一个单独的文件中,并让服务器类实现该接口。这样我就可以让编译器在我错过某些东西时告诉我。

不过,这似乎不适用于属性。以下定义与我所拥有的兼容:

/* interface.vala */
namespace org.test {
    [DBus (name = "org.test.Items")]
    public interface IItems : Object {
        /**
         * The object paths to the item instances.
         *
         * These objects are of type org.test.items.Item.
         */
        public abstract ObjectPath[] items {
            owned get;
        }

        /**
         * The signal that is emitted when a new item is added.
         *
         * When this signal is emitted, the item will be available.
         *
         * @param id
         *     The object path to the item instance.
         */
        public signal void item_added(ObjectPath id);

        /**
         * The signal that is emitted when an item is removed.
         *
         * When this signal is emitted, the item will be unavailable.
         *
         * @param id
         *     The object path to the item instance.
         */
        public signal void item_removed(ObjectPath id);

        /**
         * Adds a new item.
         *
         * The URL will be parsed, and if it contains a valid item, it will be
         * added.
         *
         * @param url
         *     The URL to the item. This should typically be the URL of the
         *     RSS feed.
         * @return the ID of the item added, which can be used to query D-BUS
         *     for it
         * @throws IOError if a D-BUS error occurs
         */
        public abstract ObjectPath add_item(string url) throws IOError;

        /**
         * Removes an item.
         *
         * @param id
         *     The ID of the item to remove.
         * @throws IOError if a D-BUS error occurs
         */
        public abstract void remove_item(ObjectPath id) throws IOError;
    }
}

/* server.vala */
using Gee;

namespace org.test {
    [DBus (name = "org.test.Items")]
    public class Items : DBUSObject, IItems {
        private ArrayList<Item> _items;

        [DBus (visible = false)]
        protected override void dbus_register(DBusConnection conn,
                ObjectPath path) throws IOError {
            conn.register_object(path, this);
        }

        [DBus (visible = false)]
        public Items() {
            base("org.test.Items", "/org/test", "Items", true);
            _items = new ArrayList<Item>();
        }

        [DBus (visible = false)]
        ~Items() {
            unregister();
        }

        /**
         * @see interface.vala::org.test.IItems.comics
         */
        public ObjectPath[] items {
            owned get {
                ObjectPath[] result = {};
                foreach (var item in _items) {
                    result += new ObjectPath(item.path);
                }
                return result;
            }
        }

        /**
         * @see interface.vala::org.test.IItems.add_comic
         */
        public ObjectPath add_item(string url) throws IOError {
            /* . . . */
        }

        /**
         * @see interface.vala::org.test.IItems.remove_item
         */
        public void remove_item(ObjectPath id) throws IOError {
            /* . . . */
        }
    }
}

当我编译它时,我没有从 valac 得到错误,但是当编译生成的 C 代码时,链接器会抱怨:undefined reference to 'org_test_items_get_items'.

此函数被 引用_dbus_org_test_items_get_items,但不存在

4

1 回答 1

0

这显然是一个错误。报告错误的正确位置是http://bugzilla.gnome.org

于 2011-08-14T08:42:10.080 回答