![]() |
![]() |
![]() |
gedit Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Signals |
#include <gedit/gedit-message-bus.h> struct GeditMessageBus; void (*GeditMessageCallback) (GeditMessageBus *bus
,GeditMessage *message
,gpointer user_data
); GeditMessageBus * gedit_message_bus_get_default (void
); GeditMessageBus * gedit_message_bus_new (void
); GType gedit_message_bus_lookup (GeditMessageBus *bus
,const gchar *object_path
,const gchar *method
); void gedit_message_bus_register (GeditMessageBus *bus
,GType message_type
,const gchar *object_path
,const gchar *method
); void gedit_message_bus_unregister (GeditMessageBus *bus
,const gchar *object_path
,const gchar *method
); 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 user_data
); guint gedit_message_bus_connect (GeditMessageBus *bus
,const gchar *object_path
,const gchar *method
,GeditMessageCallback callback
,gpointer user_data
,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 user_data
); 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 user_data
); 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 user_data
); 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
,const gchar *first_property
,...
); GeditMessage * gedit_message_bus_send_sync (GeditMessageBus *bus
,const gchar *object_path
,const gchar *method
,const gchar *first_property
,...
);
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
1 2 3 4 5 6 7 8 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
static void example_method_cb (GeditMessageBus *bus, GeditMessage *message, gpointer user_data) { 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
1 2 3 4 5 6 |
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 user_data
);
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. [transfer none] |
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 |
GType 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
|
void gedit_message_bus_register (GeditMessageBus *bus
,GType message_type
,const gchar *object_path
,const gchar *method
);
Register a message on the bus. A message must be registered on the bus before
it can be send. This function registers the type for method
at
object_path
.
This function emits a "registered" signal.
|
a GeditMessageBus |
|
the message type |
|
the object path |
|
the method to register |
void gedit_message_bus_unregister (GeditMessageBus *bus
,const gchar *object_path
,const gchar *method
);
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 object path |
|
the method |
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 user_data
);
Calls func
for each message type registered on the bus
|
the GeditMessagebus |
|
the callback function. [scope call] |
|
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 user_data
,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 |
|
user_data to use for the callback. [allow-none] |
|
function to evoke with user_data as argument when user_data
needs to be freed. [allow-none]
|
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 user_data
);
Disconnects a previously connected message callback by matching the
provided callback function and user_data. See also
gedit_message_bus_disconnect()
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
the connected callback. [scope call] |
|
the user_data 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 user_data
);
Blocks evoking the callback that matches provided callback
and user_data
.
Unblock the callback using gedit_message_unblock_by_func()
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
the callback to block. [scope call] |
|
the user_data 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 user_data
);
Unblocks the callback that matches provided callback
and user_data
.
|
a GeditMessageBus |
|
the object path |
|
the method |
|
the callback to block. [scope call] |
|
the user_data 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
,const gchar *first_property
,...
);
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
,const gchar *first_property
,...
);
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. [allow-none]
|
Returns : |
the constructed GeditMessage.
The caller owns a reference to the GeditMessage and should
call g_object_unref() when it is no longer needed. [allow-none][transfer full]
|
"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).
|
a GeditMessageBus |
|
the GeditMessage to dispatch |
|
user data set when the signal handler was connected. |
"registered"
signalvoid user_function (GeditMessageBus *bus,
gchar *message_type,
gchar *arg2,
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,
gchar *message_type,
gchar *arg2,
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. |