grim/guifications3

the start of GfClient
org.guifications.gf3
2009-10-10, Gary Kramlich
eaa9ebda9e94
Parents 1d226f8d0018
Children 2942100ebb6f
the start of GfClient
--- a/gflib/gflib/Makefile.am Sat Oct 10 12:53:12 2009 -0500
+++ b/gflib/gflib/Makefile.am Sat Oct 10 13:48:59 2009 -0500
@@ -24,6 +24,7 @@
lib_LTLIBRARIES = libgflib.la
gfinc_HEADERS = \
+ gf_client.h \
gf_client_connection.h \
gf_connection.h \
gf_connection_manager.h \
@@ -61,6 +62,7 @@
gfinc_DATA = gf_lib.h gf_intl.h
libgflib_la_SOURCES = \
+ gf_client.c \
gf_client_connection.c \
gf_connection.c \
gf_connection_manager.c \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib/gflib/gf_client.c Sat Oct 10 13:48:59 2009 -0500
@@ -0,0 +1,219 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <gflib/gf_client.h>
+#include <gflib/gf_intl.h>
+
+#define GF_CLIENT_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GF_TYPE_CLIENT, GfClientPrivate))
+
+/******************************************************************************
+ * Structs
+ *****************************************************************************/
+typedef struct {
+ GfClientConnection *connection;
+} GfClientPrivate;
+
+/******************************************************************************
+ * Enums
+ *****************************************************************************/
+enum {
+ PROP_ZERO = 0,
+ PROP_CONNECTION,
+ PROP_LAST
+};
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+GObjectClass *parent_class = NULL;
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+gf_client_connecting(GfClientConnection *connection, gpointer data) {
+ GfClient *client = GF_CLIENT(data);
+ GfClientClass *klass = GF_CLIENT_GET_CLASS(client);
+
+ if(klass->connecting)
+ klass->connecting(client, connection);
+}
+
+static void
+gf_client_connected(GfClientConnection *connection, gpointer data) {
+ GfClient *client = GF_CLIENT(data);
+ GfClientClass *klass = GF_CLIENT_GET_CLASS(client);
+
+ if(klass->connected)
+ klass->connected(client, connection);
+}
+
+static void
+gf_client_disconnecting(GfConnection *connection, gpointer data) {
+ GfClientConnection *client_connection = GF_CLIENT_CONNECTION(connection);
+ GfClient *client = GF_CLIENT(data);
+ GfClientClass *klass = GF_CLIENT_GET_CLASS(client);
+
+ if(klass->disconnecting)
+ klass->disconnecting(client, client_connection);
+}
+
+static void
+gf_client_disconnected(GfConnection *connection, gpointer data) {
+ GfClientConnection *client_connection = GF_CLIENT_CONNECTION(connection);
+ GfClient *client = GF_CLIENT(data);
+ GfClientClass *klass = GF_CLIENT_GET_CLASS(client);
+
+ if(klass->disconnected)
+ klass->disconnected(client, client_connection);
+}
+
+/******************************************************************************
+ * Object Stuff
+ *****************************************************************************/
+static void
+gf_client_get_property(GObject *obj, guint param_id, GValue *value,
+ GParamSpec *pspec)
+{
+ GfClient *client = GF_CLIENT(obj);
+
+ switch(param_id) {
+ case PROP_CONNECTION:
+ g_value_set_object(value, gf_client_get_connection(client));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_client_set_property(GObject *obj, guint param_id, const GValue *value,
+ GParamSpec *pspec)
+{
+ GfClient *client = GF_CLIENT(obj);
+
+ switch(param_id) {
+ case PROP_CONNECTION:
+ gf_client_set_connection(client, g_value_get_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_client_finalize(GObject *obj) {
+ gf_client_set_connection(GF_CLIENT(obj), NULL);
+
+ G_OBJECT_CLASS(parent_class)->finalize(obj);
+}
+
+static void
+gf_client_class_init(GfClientClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+ parent_class = g_type_class_peek_parent(klass);
+
+ g_type_class_add_private(klass, sizeof(GfClientPrivate));
+
+ obj_class->get_property = gf_client_get_property;
+ obj_class->set_property = gf_client_set_property;
+ obj_class->finalize = gf_client_finalize;
+
+ g_object_class_install_property(obj_class, PROP_CONNECTION,
+ g_param_spec_object("connection", P_("Connection"),
+ P_("The connection this client is using."),
+ GF_TYPE_CLIENT_CONNECTION,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+GType
+gf_client_get_gtype(void) {
+ static GType type = 0;
+
+ if(type == 0) {
+ static const GTypeInfo info = {
+ sizeof(GfClientClass),
+ NULL,
+ NULL,
+ (GClassInitFunc)gf_client_class_init,
+ NULL,
+ NULL,
+ sizeof(GfClient),
+ 0,
+ NULL,
+ NULL
+ };
+
+ type = g_type_register_static(GF_TYPE_OBJECT,
+ "GfClient",
+ &info, G_TYPE_FLAG_ABSTRACT);
+ }
+
+ return type;
+}
+
+void
+gf_client_set_connection(GfClient *client, GfClientConnection *connection) {
+ GfClientPrivate *priv = NULL;
+
+ g_return_if_fail(GF_IS_CLIENT(client));
+
+ priv = GF_CLIENT_GET_PRIVATE(client);
+
+ if(GF_IS_CLIENT_CONNECTION(priv->connection))
+ g_object_unref(G_OBJECT(priv->connection));
+
+ if(GF_IS_CLIENT_CONNECTION(connection)) {
+ priv->connection = g_object_ref(G_OBJECT(connection));
+
+ g_signal_connect(G_OBJECT(priv->connection), "connecting",
+ G_CALLBACK(gf_client_connecting), client);
+ g_signal_connect(G_OBJECT(priv->connection), "connected",
+ G_CALLBACK(gf_client_connected), client);
+ g_signal_connect(G_OBJECT(priv->connection), "disconnecting",
+ G_CALLBACK(gf_client_disconnecting), client);
+ g_signal_connect(G_OBJECT(priv->connection), "disconnected",
+ G_CALLBACK(gf_client_disconnected), client);
+ } else {
+ priv->connection = NULL;
+ }
+
+ g_object_notify(G_OBJECT(client), "connection");
+}
+
+GfClientConnection *
+gf_client_get_connection(const GfClient *client) {
+ GfClientPrivate *priv = NULL;
+
+ g_return_val_if_fail(GF_IS_CLIENT(client), NULL);
+
+ priv = GF_CLIENT_GET_PRIVATE(client);
+
+ return priv->connection;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib/gflib/gf_client.h Sat Oct 10 13:48:59 2009 -0500
@@ -0,0 +1,66 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef GF_CLIENT_H
+#define GF_CLIENT_H
+
+#define GF_TYPE_CLIENT (gf_client_get_gtype())
+#define GF_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GF_TYPE_CLIENT, GfClient))
+#define GF_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GF_TYPE_CLIENT, GfClientClass))
+#define GF_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GF_TYPE_CLIENT))
+#define GF_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GF_TYPE_CLIENT))
+#define GF_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GF_TYPE_CLIENT, GfClientClass))
+
+typedef struct _GfClient GfClient;
+typedef struct _GfClientClass GfClientClass;
+
+#include <gflib/gf_object.h>
+#include <gflib/gf_client_connection.h>
+
+struct _GfClient {
+ GfObject parent;
+
+ void (*_gf_reserved1)(void);
+ void (*_gf_reserved2)(void);
+ void (*_gf_reserved3)(void);
+ void (*_gf_reserved4)(void);
+};
+
+struct _GfClientClass {
+ GfObjectClass parent;
+
+ void (*connecting)(GfClient *client, GfClientConnection *connection);
+ void (*connected)(GfClient *client, GfClientConnection *connection);
+ void (*disconnecting)(GfClient *client, GfClientConnection *connection);
+ void (*disconnected)(GfClient *client, GfClientConnection *connection);
+
+ void (*_gf_reserved1)(void);
+ void (*_gf_reserved2)(void);
+ void (*_gf_reserved3)(void);
+ void (*_gf_reserved4)(void);
+};
+
+G_BEGIN_DECLS
+
+GType gf_client_get_gtype(void);
+
+void gf_client_set_connection(GfClient *client, GfClientConnection *connection);
+GfClientConnection *gf_client_get_connection(const GfClient *client);
+
+G_END_DECLS
+
+#endif /* GF_CLIENT_H */