summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-10-30 22:56:14 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-10-30 22:56:14 +0800
commiteb06a962426f7e9cc14a1fda17dc9a2adc7236a1 (patch)
tree0f451a7c2545a436bee56c2c718f937f93c1f127
parentfb7474f636294163cdd23c41926b7b2e7e4c3f07 (diff)
downloadibus-eb06a962426f7e9cc14a1fda17dc9a2adc7236a1.tar.gz
ibus-eb06a962426f7e9cc14a1fda17dc9a2adc7236a1.tar.xz
ibus-eb06a962426f7e9cc14a1fda17dc9a2adc7236a1.zip
WIP.
-rw-r--r--bus/connection.c4
-rw-r--r--bus/matchrule.c168
-rw-r--r--bus/matchrule.h63
-rw-r--r--bus/test-matchrule.c9
4 files changed, 169 insertions, 75 deletions
diff --git a/bus/connection.c b/bus/connection.c
index 41019b3..263c7c6 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -242,8 +242,7 @@ bus_connection_add_match (BusConnection *connection,
for (link = priv->rules; link != NULL; link = link->next) {
if (bus_match_rule_is_equal (p, (BusMatchRule *)link->data)) {
- bus_match_rule_ref ((BusMatchRule *)link->data);
- bus_match_rule_unref (p);
+ g_object_unref (p);
return TRUE;
}
}
@@ -257,5 +256,6 @@ gboolean
bus_connection_remove_match (BusConnection *connection,
const gchar *rule)
{
+ return FALSE;
}
diff --git a/bus/matchrule.c b/bus/matchrule.c
index 7bbdb6f..ffc238d 100644
--- a/bus/matchrule.c
+++ b/bus/matchrule.c
@@ -18,22 +18,100 @@
* Boston, MA 02111-1307, USA.
*/
#include <string.h>
-#include <glib.h>
#include <dbus/dbus.h>
#include "matchrule.h"
-typedef struct _BusArg BusArg;
-struct _BusArg {
- guint len;
- gchar *value;
-};
+#define BUS_CONFIG_PROXY_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), BUS_TYPE_CONFIG_PROXY, BusMatchRulePrivate))
+
+
+static void bus_match_rule_class_init (BusMatchRuleClass *klass);
+static void bus_match_rule_init (BusMatchRule *rule);
+static void bus_match_rule_destroy (BusMatchRule *rule);
+
+static IBusObjectClass *parent_class = NULL;
+
+GType
+bus_match_rule_get_type (void)
+{
+ static GType type = 0;
+
+ static const GTypeInfo type_info = {
+ sizeof (BusMatchRuleClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) bus_match_rule_class_init,
+ NULL, /* class finalize */
+ NULL, /* class data */
+ sizeof (BusMatchRule),
+ 0,
+ (GInstanceInitFunc) bus_match_rule_init,
+ };
+
+ if (type == 0) {
+ type = g_type_register_static (IBUS_TYPE_OBJECT,
+ "BusMatchRule",
+ &type_info,
+ (GTypeFlags)0);
+ }
+ return type;
+}
+
+static void
+bus_match_rule_class_init (BusMatchRuleClass *klass)
+{
+ IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass);
+
+ parent_class = (IBusObjectClass *) g_type_class_peek_parent (klass);
+
+ ibus_object_class->destroy = (IBusObjectDestroyFunc) bus_match_rule_destroy;
+}
+
+static void
+bus_match_rule_init (BusMatchRule *rule)
+{
+ rule->flags = 0;
+ rule->message_type = DBUS_MESSAGE_TYPE_INVALID;
+ rule->interface = NULL;
+ rule->member = NULL;
+ rule->sender = NULL;
+ rule->destination = NULL;
+ rule->path = NULL;
+ rule->args = g_array_new (TRUE, TRUE, sizeof (gchar *));
+}
+
+static void
+bus_match_rule_destroy (BusMatchRule *rule)
+{
+ g_free (rule->interface);
+ g_free (rule->member);
+ g_free (rule->sender);
+ g_free (rule->destination);
+ g_free (rule->path);
+
+ gint i;
+ GList *link;
+
+ for (i = 0; i < rule->args->len; i++) {
+ g_free (g_array_index (rule->args, gchar *, i));
+ }
+ g_array_free (rule->args, TRUE);
-typedef struct _Token Token;
-struct _Token {
+ for (link = rule->recipients; link != NULL; link = link->next) {
+ Recipient *recipient = (Recipient *) link->data;
+ g_object_unref (recipient->connection);
+ g_slice_free (Recipient, recipient);
+ }
+ g_list_free (rule->recipients);
+
+ IBUS_OBJECT_CLASS(parent_class)->destroy (IBUS_OBJECT (rule));
+}
+
+
+typedef struct _Token {
gchar *key;
gchar *value;
-};
-
+} Token;
#define SKIP_WHITE(a) \
while (*(a) == ' ' || *(a) == '\t') { (a)++; }
@@ -193,12 +271,7 @@ bus_match_rule_new (const gchar *text)
Token *tokens, *p;
BusMatchRule *rule;
- rule = g_slice_new0 (BusMatchRule);
-
- rule->refcount = 1;
- rule->message_type = DBUS_MESSAGE_TYPE_INVALID;
-
- rule->args = g_array_new (TRUE, TRUE, sizeof (gchar *));
+ rule = BUS_MATCH_RULE (g_object_new (BUS_TYPE_MATCH_RULE, NULL));
/* parse rule */
tokens = tokenize_rule (text);
@@ -250,51 +323,10 @@ bus_match_rule_new (const gchar *text)
failed:
tokens_free (tokens);
- bus_match_rule_unref (rule);
+ g_object_unref (rule);
return NULL;
}
-BusMatchRule *
-bus_match_rule_ref (BusMatchRule *rule)
-{
- g_assert (rule != NULL);
-
- rule->refcount ++;
-
- return rule;
-}
-
-void
-bus_match_rule_unref (BusMatchRule *rule)
-{
- g_assert (rule != NULL);
-
- gint i;
-
- rule->refcount --;
-
- if (rule->refcount > 0)
- return;
-
- bus_match_rule_free (rule);
-}
-
-
-void
-bus_match_rule_free (BusMatchRule *rule)
-{
- g_free (rule->interface);
- g_free (rule->member);
- g_free (rule->sender);
- g_free (rule->destination);
- g_free (rule->path);
-
- for (i = 0; i < rule->args->len; i++) {
- g_free (g_array_index (rule->args, gchar *, i));
- }
- g_array_free (rule->args, TRUE);
-}
-
gboolean
bus_match_rule_set_message_type (BusMatchRule *rule,
gint type)
@@ -523,3 +555,23 @@ bus_match_rule_is_equal (BusMatchRule *a,
return TRUE;
}
+
+void
+bus_match_rule_add_recipient (BusMatchRule *rule,
+ BusConnection *connection)
+{
+}
+
+void
+bus_match_rule_remove_recipient (BusMatchRule *rule,
+ BusConnection *connection)
+{
+}
+
+gboolean
+bus_match_rule_get_recipients (BusMatchRule *rule,
+ GList **recipients)
+{
+ return TRUE;
+}
+
diff --git a/bus/matchrule.h b/bus/matchrule.h
index 8922168..e679078 100644
--- a/bus/matchrule.h
+++ b/bus/matchrule.h
@@ -20,20 +20,51 @@
#ifndef __MATCH_RULE_H_
#define __MATCH_RULE_H_
-#include <glib-object.h>
+#include <ibus.h>
+#include "connection.h"
+
+/*
+ * Type macros.
+ */
+
+/* define GOBJECT macros */
+#define BUS_TYPE_MATCH_RULE \
+ (bus_match_rule_get_type ())
+#define BUS_MATCH_RULE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUS_TYPE_MATCH_RULE, BusMatchRule))
+#define BUS_MATCH_RULE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), BUS_TYPE_MATCH_RULE, BusMatchRuleClass))
+#define BUS_IS_MATCH_RULE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUS_TYPE_MATCH_RULE))
+#define BUS_IS_MATCH_RULE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), BUS_TYPE_MATCH_RULE))
+#define BUS_MATCH_RULE_GET_CLASS(obj) \
+ (G_TYPE_CHECK_GET_CLASS ((obj), BUS_TYPE_MATCH_RULE, BusMatchRuleClass))
+
+G_BEGIN_DECLS
+
typedef struct _BusMatchRule BusMatchRule;
+typedef struct _BusMatchRuleClass BusMatchRuleClass;
+
typedef enum {
- MATCH_TYPE = 1 << 0,
- MATCH_INTERFACE = 1 << 1,
- MATCH_MEMBER = 1 << 2,
- MATCH_SENDER = 1 << 3,
- MATCH_DESTINATION = 1 << 4,
- MATCH_PATH = 1 << 5,
- MATCH_ARGS = 1 << 6,
+ MATCH_TYPE = 1 << 0,
+ MATCH_INTERFACE = 1 << 1,
+ MATCH_MEMBER = 1 << 2,
+ MATCH_SENDER = 1 << 3,
+ MATCH_DESTINATION = 1 << 4,
+ MATCH_PATH = 1 << 5,
+ MATCH_ARGS = 1 << 6,
} BusMatchFlags;
+typedef struct _Recipient Recipient;
+struct _Recipient {
+ BusConnection *connection;
+ gint refcount;
+};
+
struct _BusMatchRule {
- gint refcount;
+ IBusProxy parent;
+ /* instance members */
gint flags;
gint message_type;
gchar *interface;
@@ -41,12 +72,16 @@ struct _BusMatchRule {
gchar *sender;
gchar *destination;
gchar *path;
-
GArray *args;
+ GList *recipients;
};
-G_BEGIN_DECLS
+struct _BusMatchRuleClass {
+ IBusProxyClass parent;
+ /* class members */
+};
+GType bus_match_rule_get_type (void);
BusMatchRule *bus_match_rule_new (const gchar *text);
BusMatchRule *bus_match_rule_ref (BusMatchRule *rule);
void bus_match_rule_unref (BusMatchRule *rule);
@@ -73,6 +108,12 @@ gboolean bus_match_rule_match (BusMatchRule *rule,
DBusMessage *message);
gboolean bus_match_rule_is_equal (BusMatchRule *a,
BusMatchRule *b);
+void bus_match_rule_add_recipient
+ (BusMatchRule *rule,
+ BusConnection *connection);
+gboolean bus_match_rule_get_recipients
+ (BusMatchRule *rule,
+ GList **recipients);
G_END_DECLS
#endif
diff --git a/bus/test-matchrule.c b/bus/test-matchrule.c
index c8c5dd0..5e506ab 100644
--- a/bus/test-matchrule.c
+++ b/bus/test-matchrule.c
@@ -3,16 +3,17 @@
int main()
{
BusMatchRule *rule, *rule1;
+ g_type_init ();
rule = bus_match_rule_new (" type='signal' , interface = 'org.freedesktop.IBus' ");
g_assert (rule->message_type == DBUS_MESSAGE_TYPE_SIGNAL);
g_assert (g_strcmp0 (rule->interface, "org.freedesktop.IBus") == 0 );
- bus_match_rule_unref (rule);
+ g_object_unref (rule);
rule = bus_match_rule_new ("type='method_call', interface='org.freedesktop.IBus' ");
g_assert (rule->message_type == DBUS_MESSAGE_TYPE_METHOD_CALL);
g_assert (g_strcmp0 (rule->interface, "org.freedesktop.IBus") == 0 );
- bus_match_rule_unref (rule);
+ g_object_unref (rule);
rule = bus_match_rule_new ("type='signal',"
"interface='org.freedesktop.DBus',"
@@ -31,8 +32,8 @@ int main()
g_assert (bus_match_rule_is_equal (rule, rule1));
- bus_match_rule_unref (rule);
- bus_match_rule_unref (rule1);
+ g_object_unref (rule);
+ g_object_unref (rule1);
return 0;
}