[gnome-builder/wip/chergert/debugger: 15/58] mi2: add event dispatch for Mi2EventMessage items
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/debugger: 15/58] mi2: add event dispatch for Mi2EventMessage items
- Date: Sun, 26 Mar 2017 07:22:36 +0000 (UTC)
commit 9656e0012910571487d5ebc6fefbabb6703e6564
Author: Christian Hergert <chergert redhat com>
Date: Thu Mar 23 16:37:41 2017 -0700
mi2: add event dispatch for Mi2EventMessage items
contrib/mi2/mi2-client.c | 14 ++++++++++-
contrib/mi2/mi2-client.h | 9 +++++-
contrib/mi2/mi2-event-message.c | 47 ++++++++++++++++++++++++++++++++++++--
contrib/mi2/mi2-event-message.h | 14 ++++++++---
contrib/mi2/test-client.c | 19 +++++++++++++++-
5 files changed, 92 insertions(+), 11 deletions(-)
---
diff --git a/contrib/mi2/mi2-client.c b/contrib/mi2/mi2-client.c
index d89f9aa..b6a69c5 100644
--- a/contrib/mi2/mi2-client.c
+++ b/contrib/mi2/mi2-client.c
@@ -42,6 +42,7 @@ enum {
};
enum {
+ EVENT,
LOG,
N_SIGNALS
};
@@ -158,6 +159,14 @@ mi2_client_class_init (Mi2ClientClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
+ signals [EVENT] =
+ g_signal_new ("event",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ G_STRUCT_OFFSET (Mi2ClientClass, event),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 1, MI2_TYPE_EVENT_MESSAGE);
+
signals [LOG] =
g_signal_new ("log",
G_TYPE_FROM_CLASS (klass),
@@ -261,7 +270,10 @@ mi2_client_dispatch (Mi2Client *self,
}
else if (MI2_IS_EVENT_MESSAGE (message))
{
- g_print ("Event: %s\n", mi2_event_message_get_name (MI2_EVENT_MESSAGE (message)));
+ const gchar *name = mi2_event_message_get_name (MI2_EVENT_MESSAGE (message));
+ GQuark detail = g_quark_try_string (name);
+
+ g_signal_emit (self, signals [EVENT], detail, message);
}
else
g_print ("Got message of type %s\n", G_OBJECT_TYPE_NAME (message));
diff --git a/contrib/mi2/mi2-client.h b/contrib/mi2/mi2-client.h
index 8231985..98d5445 100644
--- a/contrib/mi2/mi2-client.h
+++ b/contrib/mi2/mi2-client.h
@@ -23,6 +23,9 @@
G_BEGIN_DECLS
+#include "mi2-message.h"
+#include "mi2-event-message.h"
+
#define MI2_TYPE_CLIENT (mi2_client_get_type())
G_DECLARE_DERIVABLE_TYPE (Mi2Client, mi2_client, MI2, CLIENT, GObject)
@@ -31,8 +34,10 @@ struct _Mi2ClientClass
{
GObjectClass parent_instance;
- void (*log) (Mi2Client *self,
- const gchar *log);
+ void (*log) (Mi2Client *self,
+ const gchar *log);
+ void (*event) (Mi2Client *self,
+ Mi2EventMessage *message);
gpointer _reserved1;
gpointer _reserved2;
diff --git a/contrib/mi2/mi2-event-message.c b/contrib/mi2/mi2-event-message.c
index e1ab1b9..a074df1 100644
--- a/contrib/mi2/mi2-event-message.c
+++ b/contrib/mi2/mi2-event-message.c
@@ -23,9 +23,10 @@
struct _Mi2EventMessage
{
- Mi2Message parent_instance;
+ Mi2Message parent_instance;
- gchar *name;
+ gchar *name;
+ GHashTable *params;
};
enum {
@@ -44,6 +45,7 @@ mi2_event_mesage_finalize (GObject *object)
Mi2EventMessage *self = (Mi2EventMessage *)object;
g_clear_pointer (&self->name, g_free);
+ g_clear_pointer (&self->params, g_hash_table_unref);
G_OBJECT_CLASS (mi2_event_mesage_parent_class)->finalize (object);
}
@@ -108,6 +110,7 @@ mi2_event_mesage_class_init (Mi2EventMessageClass *klass)
static void
mi2_event_mesage_init (Mi2EventMessage *self)
{
+ self->params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
/**
@@ -136,7 +139,7 @@ mi2_event_message_new_from_string (const gchar *line)
!(value = mi2_util_parse_string (line, &line)))
break;
- g_print ("*%s* **%s**\n", key, value);
+ g_hash_table_insert (ret->params, g_steal_pointer (&key), g_steal_pointer (&value));
}
}
@@ -162,3 +165,41 @@ mi2_event_message_set_name (Mi2EventMessage *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_NAME]);
}
}
+
+const gchar *
+mi2_event_message_get_param_string (Mi2EventMessage *self,
+ const gchar *name)
+{
+ g_return_val_if_fail (MI2_IS_EVENT_MESSAGE (self), NULL);
+
+ return g_hash_table_lookup (self->params, name);
+}
+
+void
+mi2_event_message_set_param_string (Mi2EventMessage *self,
+ const gchar *name,
+ const gchar *value)
+{
+ g_return_if_fail (MI2_IS_EVENT_MESSAGE (self));
+ g_return_if_fail (name != NULL);
+
+ g_hash_table_insert (self->params, g_strdup (name), g_strdup (value));
+}
+
+/**
+ * mi2_event_message_get_params:
+ * @self: An #Mi2EventMessage
+ *
+ * Gets the keys for params that are stored in the message, free the
+ * result with g_free() as ownership of the fields is owned by the
+ * #Mi2EventMessage.
+ *
+ * Returns: (transfer container): A %NULL-terminated array of param names.
+ */
+const gchar **
+mi2_event_message_get_params (Mi2EventMessage *self)
+{
+ g_return_val_if_fail (MI2_IS_EVENT_MESSAGE (self), NULL);
+
+ return (const gchar **)g_hash_table_get_keys_as_array (self->params, NULL);
+}
diff --git a/contrib/mi2/mi2-event-message.h b/contrib/mi2/mi2-event-message.h
index 6150fad..8edd7e6 100644
--- a/contrib/mi2/mi2-event-message.h
+++ b/contrib/mi2/mi2-event-message.h
@@ -27,10 +27,16 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (Mi2EventMessage, mi2_event_mesage, MI2, EVENT_MESSAGE, Mi2Message)
-Mi2Message *mi2_event_message_new_from_string (const gchar *line);
-const gchar *mi2_event_message_get_name (Mi2EventMessage *self);
-void mi2_event_message_set_name (Mi2EventMessage *self,
- const gchar *name);
+Mi2Message *mi2_event_message_new_from_string (const gchar *line);
+const gchar *mi2_event_message_get_name (Mi2EventMessage *self);
+void mi2_event_message_set_name (Mi2EventMessage *self,
+ const gchar *name);
+const gchar **mi2_event_message_get_params (Mi2EventMessage *self);
+const gchar *mi2_event_message_get_param_string (Mi2EventMessage *self,
+ const gchar *name);
+void mi2_event_message_set_param_string (Mi2EventMessage *self,
+ const gchar *name,
+ const gchar *value);
G_END_DECLS
diff --git a/contrib/mi2/test-client.c b/contrib/mi2/test-client.c
index 9c4d9e1..04c933d 100644
--- a/contrib/mi2/test-client.c
+++ b/contrib/mi2/test-client.c
@@ -46,7 +46,22 @@ static void
log_handler (Mi2Client *client,
const gchar *log)
{
- g_print ("%s", log);
+ //g_print ("%s", log);
+}
+
+static void
+thread_group_added (Mi2Client *client,
+ Mi2EventMessage *message,
+ gpointer user_data)
+{
+}
+
+static void
+event (Mi2Client *client,
+ Mi2EventMessage *message,
+ gpointer user_data)
+{
+ g_print ("EVENT: %s\n", mi2_event_message_get_name (message));
}
gint
@@ -61,6 +76,8 @@ main (gint argc,
client = mi2_client_new (io_stream);
g_signal_connect (client, "log", G_CALLBACK (log_handler), NULL);
+ g_signal_connect (client, "event::thread-group-added", G_CALLBACK (thread_group_added), NULL);
+ g_signal_connect (client, "event", G_CALLBACK (event), NULL);
mi2_client_start_listening (client);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]