gedit Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Signals |
#include <gedit/gedit-message-bus.h> GeditMessageBus; void (*GeditMessageCallback) (GeditMessageBus *bus, GeditMessage *message, gpointer userdata); GeditMessageBus * gedit_message_bus_get_default (void); GeditMessageBus * gedit_message_bus_new (void); GeditMessageType * gedit_message_bus_lookup (GeditMessageBus *bus, const gchar *object_path, const gchar *method); GeditMessageType * gedit_message_bus_register (GeditMessageBus *bus, const gchar *object_path, const gchar *method, guint num_optional, ...); void gedit_message_bus_unregister (GeditMessageBus *bus, GeditMessageType *message_type); void gedit_message_bus_unregister_all (GeditMessageBus *bus, const gchar *object_path); gboolean gedit_message_bus_is_registered (GeditMessageBus *bus, const gchar *object_path, const gchar *method); void gedit_message_bus_foreach (GeditMessageBus *bus, GeditMessageBusForeach func, gpointer userdata); guint gedit_message_bus_connect (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata, GDestroyNotify destroy_data); void gedit_message_bus_disconnect (GeditMessageBus *bus, guint id); void gedit_message_bus_disconnect_by_func (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata); void gedit_message_bus_block (GeditMessageBus *bus, guint id); void gedit_message_bus_block_by_func (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata); void gedit_message_bus_unblock (GeditMessageBus *bus, guint id); void gedit_message_bus_unblock_by_func (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata); void gedit_message_bus_send_message (GeditMessageBus *bus, GeditMessage *message); void gedit_message_bus_send_message_sync (GeditMessageBus *bus, GeditMessage *message); void gedit_message_bus_send (GeditMessageBus *bus, const gchar *object_path, const gchar *method, ...); GeditMessage * gedit_message_bus_send_sync (GeditMessageBus *bus, const gchar *object_path, const gchar *method, ...);
gedit has a communication bus very similar to DBus. Its primary use is to allow easy communication between plugins, but it can also be used to expose gedit functionality to external applications by providing DBus bindings for the internal gedit message bus.
There are two different communication busses available. The default bus
(see gedit_message_bus_get_default()
) is an application wide communication
bus. In addition, each GeditWindow has a separate, private bus
(see gedit_window_get_message_bus()
). This makes it easier for plugins to
communicate to other plugins in the same window.
The concept of the message bus is very simple. You can register a message type on the bus, specified as a Method at a specific Object Path with a certain set of Method Arguments. You can then connect callback functions for this message type on the bus. Whenever a message with the Object Path and Method for which callbacks are connected is sent over the bus, the callbacks are called. There is no distinction between Methods and Signals (signals are simply messages where sender and receiver have switched places).
Example 1. Registering a message type
GeditMessageBus *bus = gedit_message_bus_get_default (); // Register 'method' at '/plugins/example' with one required // string argument 'arg1' GeditMessageType *message_type = gedit_message_bus_register ("/plugins/example", "method", 0, "arg1", G_TYPE_STRING, NULL);
Example 2. Connecting a callback
static void example_method_cb (GeditMessageBus *bus, GeditMessage *message, gpointer userdata) { gchar *arg1 = NULL; gedit_message_get (message, "arg1", &arg1, NULL); g_message ("Evoked /plugins/example.method with: %s", arg1); g_free (arg1); } GeditMessageBus *bus = gedit_message_bus_get_default (); guint id = gedit_message_bus_connect (bus, "/plugins/example", "method", example_method_cb, NULL, NULL);
Example 3. Sending a message
GeditMessageBus *bus = gedit_message_bus_get_default (); gedit_message_bus_send (bus, "/plugins/example", "method", "arg1", "Hello World", NULL);
void (*GeditMessageCallback) (GeditMessageBus *bus, GeditMessage *message, gpointer userdata);
Callback signature used for connecting callback functions to be called
when a message is received (see gedit_message_bus_connect()
).
|
the GeditMessageBus on which the message was sent |
|
the GeditMessage which was sent |
|
the supplied user data when connecting the callback |
GeditMessageBus * gedit_message_bus_get_default (void);
Get the default application GeditMessageBus.
Returns : |
the default GeditMessageBus |
GeditMessageBus * gedit_message_bus_new (void);
Create a new message bus. Use gedit_message_bus_get_default()
to get the
default, application wide, message bus. Creating a new bus is useful for
associating a specific bus with for instance a GeditWindow.
Returns : |
a new GeditMessageBus |
GeditMessageType * gedit_message_bus_lookup (GeditMessageBus *bus, const gchar *object_path, const gchar *method);
Get the registered GeditMessageType for method
at object_path
. The
returned GeditMessageType is owned by the bus and should not be unreffed.
|
a GeditMessageBus |
|
the object path |
|
the method |
Returns : |
the registered GeditMessageType or NULL if no message type
is registered for method at object_path
|
GeditMessageType * gedit_message_bus_register (GeditMessageBus *bus, const gchar *object_path, const gchar *method, guint num_optional, ...);
Register a message on the bus. A message must be registered on the bus before
it can be send. This function registers the type arguments for method
at
object_path
. The arguments are specified with the variable arguments which
should contain pairs of const gchar *key and GType terminated by NULL
. The
last num_optional
arguments are registered as optional (and are thus not
required when sending a message).
This function emits a "registered" signal.
|
a GeditMessageBus |
|
the object path |
|
the method to register |
|
the number of optional arguments |
|
NULL terminated list of key/gtype method argument pairs |
Returns : |
the registered GeditMessageType. The returned reference is
owned by the bus. If you want to keep it alive after
unregistering, use gedit_message_type_ref() .
|
void gedit_message_bus_unregister (GeditMessageBus *bus, GeditMessageType *message_type);
Unregisters a previously registered message type. This is especially useful for plugins which should unregister message types when they are deactivated.
This function emits the "unregistered" signal.
|
a GeditMessageBus |
|
the GeditMessageType to unregister |
void gedit_message_bus_unregister_all (GeditMessageBus *bus, const gchar *object_path);
Unregisters all message types for object_path
. This is especially useful for
plugins which should unregister message types when they are deactivated.
This function emits the "unregistered" signal for all unregistered message types.
|
a GeditMessageBus |
|
the object path |
gboolean gedit_message_bus_is_registered (GeditMessageBus *bus, const gchar *object_path, const gchar *method);
Check whether a message type method
at object_path
is registered on the
bus.
|
a GeditMessageBus |
|
the object path |
|
the method |
Returns : |
TRUE if the method at object_path is a registered message
type on the bus
|
void gedit_message_bus_foreach (GeditMessageBus *bus, GeditMessageBusForeach func, gpointer userdata);
Calls func
for each message type registered on the bus
|
the GeditMessagebus |
|
the callback function |
|
the user data to supply to the callback function |
guint gedit_message_bus_connect (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata, GDestroyNotify destroy_data);
Connect a callback handler to be evoked when message method
at object_path
is sent over the bus.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
function to be called when message method at object_path is sent
|
|
userdata to use for the callback |
|
function to evoke with userdata as argument when userdata
needs to be freed
|
Returns : |
the callback identifier |
void gedit_message_bus_disconnect (GeditMessageBus *bus, guint id);
Disconnects a previously connected message callback.
|
a GeditMessageBus |
|
the callback id as returned by gedit_message_bus_connect()
|
void gedit_message_bus_disconnect_by_func (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata);
Disconnects a previously connected message callback by matching the
provided callback function and userdata. See also
gedit_message_bus_disconnect()
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
the connected callback |
|
the userdata with which the callback was connected |
void gedit_message_bus_block (GeditMessageBus *bus, guint id);
Blocks evoking the callback specified by id
. Unblock the callback by
using gedit_message_bus_unblock()
.
|
a GeditMessageBus |
|
the callback id |
void gedit_message_bus_block_by_func (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata);
Blocks evoking the callback that matches provided callback
and userdata
.
Unblock the callback using gedit_message_unblock_by_func()
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
the callback to block |
|
the userdata with which the callback was connected |
void gedit_message_bus_unblock (GeditMessageBus *bus, guint id);
Unblocks the callback specified by id
.
|
a GeditMessageBus |
|
the callback id |
void gedit_message_bus_unblock_by_func (GeditMessageBus *bus, const gchar *object_path, const gchar *method, GeditMessageCallback callback, gpointer userdata);
Unblocks the callback that matches provided callback
and userdata
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
the callback to block |
|
the userdata with which the callback was connected |
void gedit_message_bus_send_message (GeditMessageBus *bus, GeditMessage *message);
This sends the provided message
asynchronously over the bus. To send
a message synchronously, use gedit_message_bus_send_message_sync()
. The
convenience function gedit_message_bus_send()
can be used to easily send
a message without constructing the message object explicitly first.
|
a GeditMessageBus |
|
the message to send |
void gedit_message_bus_send_message_sync (GeditMessageBus *bus, GeditMessage *message);
This sends the provided message
synchronously over the bus. To send
a message asynchronously, use gedit_message_bus_send_message()
. The
convenience function gedit_message_bus_send_sync()
can be used to easily send
a message without constructing the message object explicitly first.
|
a GeditMessageBus |
|
the message to send |
void gedit_message_bus_send (GeditMessageBus *bus, const gchar *object_path, const gchar *method, ...);
This provides a convenient way to quickly send a message method
at
object_path
asynchronously over the bus. The variable argument list
specifies key (string) value pairs used to construct the message arguments.
To send a message synchronously use gedit_message_bus_send_sync()
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
NULL terminated list of key/value pairs |
GeditMessage * gedit_message_bus_send_sync (GeditMessageBus *bus, const gchar *object_path, const gchar *method, ...);
This provides a convenient way to quickly send a message method
at
object_path
synchronously over the bus. The variable argument list
specifies key (string) value pairs used to construct the message
arguments. To send a message asynchronously use gedit_message_bus_send()
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
NULL terminated list of key/value pairs |
Returns : |
the constructed GeditMessage. The caller owns a reference
to the GeditMessage and should call g_object_unref() when
it is no longer needed
|
"dispatch"
signalvoid user_function (GeditMessageBus *bus, GeditMessage *message, gpointer user_data) : Run Last
The "dispatch" signal is emitted when a message is to be dispatched. The message is dispatched in the default handler of this signal. Primary use of this signal is to customize the dispatch of a message (for instance to automatically dispatch all messages over DBus). 2
|
a GeditMessageBus |
|
the GeditMessage to dispatch |
|
user data set when the signal handler was connected. |
"registered"
signalvoid user_function (GeditMessageBus *bus, GeditMessageType *message_type, gpointer user_data) : Run Last
The "registered" signal is emitted when a message has been registered on the bus.
|
a GeditMessageBus |
|
the registered GeditMessageType |
|
user data set when the signal handler was connected. |
"unregistered"
signalvoid user_function (GeditMessageBus *bus, GeditMessageType *message_type, gpointer user_data) : Run Last
The "unregistered" signal is emitted when a message has been unregistered from the bus.
|
a GeditMessageBus |
|
the unregistered GeditMessageType |
|
user data set when the signal handler was connected. |