Vala:D-BUS 对象实现接口,属性错误
Posted
技术标签:
【中文标题】Vala:D-BUS 对象实现接口,属性错误【英文标题】:Vala: D-BUS object implementing interface, error with properties 【发布时间】:2011-10-26 12:34:19 【问题描述】:是否可以让使用 [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
引用了,但是不存在
【问题讨论】:
【参考方案1】:这显然是一个错误。报告错误的正确位置是http://bugzilla.gnome.org。
【讨论】:
以上是关于Vala:D-BUS 对象实现接口,属性错误的主要内容,如果未能解决你的问题,请参考以下文章