gedit r6807 - in trunk: . docs/reference gedit
- From: jessevdk svn gnome org
- To: svn-commits-list gnome org
- Subject: gedit r6807 - in trunk: . docs/reference gedit
- Date: Mon, 5 Jan 2009 10:04:05 +0000 (UTC)
Author: jessevdk
Date: Mon Jan 5 10:04:05 2009
New Revision: 6807
URL: http://svn.gnome.org/viewvc/gedit?rev=6807&view=rev
Log:
* gedit/gedit-message-bus.c:
* gedit/gedit-message-bus.h:
* gedit/gedit-message-type.c:
* gedit/gedit-message-type.h:
* docs/reference/gedit-sections.txt:
Added gedit_message_bus_foreach and
gedit_message_type_is_valid_object_path API. Added checks for valid
object paths.
Modified:
trunk/ChangeLog
trunk/docs/reference/gedit-sections.txt
trunk/gedit/gedit-message-bus.c
trunk/gedit/gedit-message-bus.h
trunk/gedit/gedit-message-type.c
trunk/gedit/gedit-message-type.h
Modified: trunk/docs/reference/gedit-sections.txt
==============================================================================
--- trunk/docs/reference/gedit-sections.txt (original)
+++ trunk/docs/reference/gedit-sections.txt Mon Jan 5 10:04:05 2009
@@ -142,6 +142,7 @@
gedit_message_bus_unregister
gedit_message_bus_unregister_all
gedit_message_bus_is_registered
+gedit_message_bus_foreach
gedit_message_bus_connect
gedit_message_bus_disconnect
gedit_message_bus_disconnect_by_func
@@ -170,6 +171,7 @@
gedit_message_type_get_type
gedit_message_type_is_supported
gedit_message_type_identifier
+gedit_message_type_is_valid_object_path
gedit_message_type_new
gedit_message_type_new_valist
gedit_message_type_ref
Modified: trunk/gedit/gedit-message-bus.c
==============================================================================
--- trunk/gedit/gedit-message-bus.c (original)
+++ trunk/gedit/gedit-message-bus.c Mon Jan 5 10:04:05 2009
@@ -624,6 +624,7 @@
GeditMessageType *message_type;
g_return_val_if_fail (GEDIT_IS_MESSAGE_BUS (bus), NULL);
+ g_return_val_if_fail (gedit_message_type_is_valid_object_path (object_path), NULL);
if (gedit_message_bus_is_registered (bus, object_path, method))
{
@@ -642,11 +643,15 @@
va_end (var_args);
if (message_type)
+ {
g_hash_table_insert (bus->priv->types, identifier, message_type);
+ g_signal_emit (bus, message_bus_signals[REGISTERED], 0, message_type);
+ }
else
+ {
g_free (identifier);
+ }
- g_signal_emit (bus, message_bus_signals[REGISTERED], 0, message_type);
return message_type;
}
@@ -758,6 +763,44 @@
return ret;
}
+typedef struct
+{
+ GeditMessageBusForeach func;
+ gpointer userdata;
+} ForeachInfo;
+
+static void
+foreach_type (const gchar *key,
+ GeditMessageType *message_type,
+ ForeachInfo *info)
+{
+ gedit_message_type_ref (message_type);
+ info->func (message_type, info->userdata);
+ gedit_message_type_unref (message_type);
+}
+
+/**
+ * gedit_message_bus_foreach:
+ * @bus: the #GeditMessagebus
+ * @func: the callback function
+ * @userdata: the user data to supply to the callback function
+ *
+ * Calls @func for each message type registered on the bus
+ *
+ */
+void
+gedit_message_bus_foreach (GeditMessageBus *bus,
+ GeditMessageBusForeach func,
+ gpointer userdata)
+{
+ ForeachInfo info = {func, userdata};
+
+ g_return_if_fail (GEDIT_IS_MESSAGE_BUS (bus));
+ g_return_if_fail (func != NULL);
+
+ g_hash_table_foreach (bus->priv->types, (GHFunc)foreach_type, &info);
+}
+
/**
* gedit_message_bus_connect:
* @bus: a #GeditMessageBus
Modified: trunk/gedit/gedit-message-bus.h
==============================================================================
--- trunk/gedit/gedit-message-bus.h (original)
+++ trunk/gedit/gedit-message-bus.h Mon Jan 5 10:04:05 2009
@@ -28,7 +28,7 @@
struct _GeditMessageBusClass {
GObjectClass parent_class;
- void (*dispatch) (GeditMessageBus *bus,
+ void (*dispatch) (GeditMessageBus *bus,
GeditMessage *message);
void (*registered) (GeditMessageBus *bus,
GeditMessageType *message_type);
@@ -36,10 +36,13 @@
GeditMessageType *message_type);
};
-typedef void (* GeditMessageCallback) (GeditMessageBus *bus,
+typedef void (* GeditMessageCallback) (GeditMessageBus *bus,
GeditMessage *message,
gpointer userdata);
+typedef void (* GeditMessageBusForeach) (GeditMessageType *message_type,
+ gpointer userdata);
+
GType gedit_message_bus_get_type (void) G_GNUC_CONST;
GeditMessageBus *gedit_message_bus_get_default (void);
@@ -61,10 +64,13 @@
void gedit_message_bus_unregister_all (GeditMessageBus *bus,
const gchar *object_path);
-gboolean gedit_message_bus_is_registered (GeditMessageBus *bus,
+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);
/* connecting to message events */
Modified: trunk/gedit/gedit-message-type.c
==============================================================================
--- trunk/gedit/gedit-message-type.c (original)
+++ trunk/gedit/gedit-message-type.c Mon Jan 5 10:04:05 2009
@@ -137,6 +137,45 @@
}
/**
+ * gedit_message_type_is_valid_object_path:
+ * @object_path: the object path
+ *
+ * Returns whether @object_path is a valid object path
+ *
+ * Return value: %TRUE if @object_path is a valid object path
+ *
+ */
+gboolean
+gedit_message_type_is_valid_object_path (const gchar *object_path)
+{
+ if (!object_path)
+ return FALSE;
+
+ /* needs to start with / */
+ if (*object_path != '/')
+ return FALSE;
+
+ while (*object_path)
+ {
+ if (*object_path == '/')
+ {
+ ++object_path;
+
+ if (!*object_path || !(g_ascii_isalpha (*object_path) || *object_path == '_'))
+ return FALSE;
+ }
+ else if (!(g_ascii_isalnum (*object_path) || *object_path == '_'))
+ {
+ return FALSE;
+ }
+
+ ++object_path;
+ }
+
+ return TRUE;
+}
+
+/**
* gedit_message_type_is_supported:
* @type: the #GType
*
@@ -209,6 +248,7 @@
g_return_val_if_fail (object_path != NULL, NULL);
g_return_val_if_fail (method != NULL, NULL);
+ g_return_val_if_fail (gedit_message_type_is_valid_object_path (object_path), NULL);
message_type = g_new0(GeditMessageType, 1);
Modified: trunk/gedit/gedit-message-type.h
==============================================================================
--- trunk/gedit/gedit-message-type.h (original)
+++ trunk/gedit/gedit-message-type.h Mon Jan 5 10:04:05 2009
@@ -18,46 +18,47 @@
typedef struct _GeditMessageType GeditMessageType;
-GType gedit_message_type_get_type (void) G_GNUC_CONST;
+GType gedit_message_type_get_type (void) G_GNUC_CONST;
-gboolean gedit_message_type_is_supported (GType type);
-gchar *gedit_message_type_identifier (const gchar *object_path,
- const gchar *method);
-
-GeditMessageType *gedit_message_type_new (const gchar *object_path,
- const gchar *method,
- guint num_optional,
- ...) G_GNUC_NULL_TERMINATED;
-GeditMessageType *gedit_message_type_new_valist (const gchar *object_path,
- const gchar *method,
- guint num_optional,
- va_list va_args);
-
-void gedit_message_type_set (GeditMessageType *message_type,
- guint num_optional,
- ...) G_GNUC_NULL_TERMINATED;
-void gedit_message_type_set_valist (GeditMessageType *message_type,
- guint num_optional,
- va_list va_args);
+gboolean gedit_message_type_is_supported (GType type);
+gchar *gedit_message_type_identifier (const gchar *object_path,
+ const gchar *method);
+gboolean gedit_message_type_is_valid_object_path (const gchar *object_path);
+
+GeditMessageType *gedit_message_type_new (const gchar *object_path,
+ const gchar *method,
+ guint num_optional,
+ ...) G_GNUC_NULL_TERMINATED;
+GeditMessageType *gedit_message_type_new_valist (const gchar *object_path,
+ const gchar *method,
+ guint num_optional,
+ va_list va_args);
+
+void gedit_message_type_set (GeditMessageType *message_type,
+ guint num_optional,
+ ...) G_GNUC_NULL_TERMINATED;
+void gedit_message_type_set_valist (GeditMessageType *message_type,
+ guint num_optional,
+ va_list va_args);
-GeditMessageType *gedit_message_type_ref (GeditMessageType *message_type);
-void gedit_message_type_unref (GeditMessageType *message_type);
+GeditMessageType *gedit_message_type_ref (GeditMessageType *message_type);
+void gedit_message_type_unref (GeditMessageType *message_type);
GeditMessage *gedit_message_type_instantiate_valist (GeditMessageType *message_type,
va_list va_args);
-GeditMessage *gedit_message_type_instantiate (GeditMessageType *message_type,
- ...) G_GNUC_NULL_TERMINATED;
+GeditMessage *gedit_message_type_instantiate (GeditMessageType *message_type,
+ ...) G_GNUC_NULL_TERMINATED;
-const gchar *gedit_message_type_get_object_path (GeditMessageType *message_type);
-const gchar *gedit_message_type_get_method (GeditMessageType *message_type);
+const gchar *gedit_message_type_get_object_path (GeditMessageType *message_type);
+const gchar *gedit_message_type_get_method (GeditMessageType *message_type);
-GType gedit_message_type_lookup (GeditMessageType *message_type,
- const gchar *key);
+GType gedit_message_type_lookup (GeditMessageType *message_type,
+ const gchar *key);
-void gedit_message_type_foreach (GeditMessageType *message_type,
- GeditMessageTypeForeach func,
- gpointer user_data);
+void gedit_message_type_foreach (GeditMessageType *message_type,
+ GeditMessageTypeForeach func,
+ gpointer user_data);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]