| libdbusmodel Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <dbusmodel/dbusmodel.h>
DbusPeerPrivate;
DbusPeer;
void dbus_peer_connect (DbusPeer *self);
DBusGConnection * dbus_peer_get_connection (DbusPeer *self);
const gchar * dbus_peer_get_peer_name (DbusPeer *self);
void dbus_peer_set_swarm_name (DbusPeer *self,
const gchar *swarm_name);
const gchar * dbus_peer_get_swarm_name (DbusPeer *self);
DbusPeer allows you to build objects that can 'find eachother' on D-Bus without the need for an central registration service. Think of it like peer-to-peer for your application.
Your object should sub-class DbusPeer and connect to it's signals to be notified when a matching object comes on, or falls off, the bus.
Peers find eachother through a well-known "swarm-name", which loosely translates to a DBus name, such as: org.myapp.MyPeers. Choose a name that would not normally be used outside of your program.
For example:
{
DbusPeer *peer;
peer = g_object_new (DBUS_TYPE_PEER,
"swarm-name", "org.myapp.MyPeers",
NULL);
g_signal_connect (peer, "peer-found",
G_CALLBACK (on_peer_found), NULL);
g_signal_connect (peer, "peer-lost",
G_CALLBACK (on_peer_lost), NULL);
/* Publish this peer and start monitoring for other peers *
dbus_peer_connect (peer);
}
The callbacks for these functions would use the usual DBusGlib bindings to access the remote objects at the name provided.
For example:
void
on_peer_found (DbusPeer *peer, const gchar *name)
{
DBusGProxy *proxy;
/* We have found a peer, so let's connect to it with a well-known
* interface.
*/
proxy = dbus_g_proxy_new_for_name_owner (connection,
name,
"/org/myapp/MyPeerIface",
"org.myapp.MyPeerIface",
NULL);
}
typedef struct {
} DbusPeer;
All fields in the DbusPeer structure are private and should never be accessed directly
void dbus_peer_connect (DbusPeer *self);
Will cause self to connect to the swarm and begin monitoring peers.
|
a DbusPeer |
DBusGConnection * dbus_peer_get_connection (DbusPeer *self);
Gets the DBusGConnection that self uses. Peer objects should export
themselves on the same connection
This function can only be used after #dbus_peer_connect() has been called.
|
a DbusPeer |
Returns : |
transfer full. transfer full. |
const gchar * dbus_peer_get_peer_name (DbusPeer *self);
Gets the unique name for this peer in the swarm. Peer objects should be published to this address.
|
a DbusPeer |
Returns : |
the unique name for this peer in the swarm |
void dbus_peer_set_swarm_name (DbusPeer *self,
const gchar *swarm_name);
Sets the swarm-name to swarm_name. This should be a well-known name that
peers can use to find each other on the bus.
The format should match standard DBus naming policy e.g. org.MyApp.Peers
|
a DbusPeer |
|
a well-known name for peers of the swarm to find eachother |