gnome-mud r798 - in trunk: . src/handlers src/zmp



Author: lharris
Date: Tue Mar 17 20:39:59 2009
New Revision: 798
URL: http://svn.gnome.org/viewvc/gnome-mud?rev=798&view=rev

Log:
ZMP Rearchitecturing

Added:
   trunk/src/zmp/zmp-core.c
   trunk/src/zmp/zmp-core.h
   trunk/src/zmp/zmp-main.c
   trunk/src/zmp/zmp-main.h
   trunk/src/zmp/zmp-package-interface.c
   trunk/src/zmp/zmp-package-interface.h
Modified:
   trunk/ChangeLog
   trunk/src/handlers/mud-telnet-zmp.c
   trunk/src/handlers/mud-telnet-zmp.h
   trunk/src/zmp/Makefile.am
   trunk/src/zmp/zmp-subwindow.c
   trunk/src/zmp/zmp-subwindow.h

Modified: trunk/src/handlers/mud-telnet-zmp.c
==============================================================================
--- trunk/src/handlers/mud-telnet-zmp.c	(original)
+++ trunk/src/handlers/mud-telnet-zmp.c	Tue Mar 17 20:39:59 2009
@@ -33,6 +33,8 @@
 #include "mud-telnet-handler-interface.h"
 #include "mud-telnet-zmp.h"
 
+#include "zmp/zmp-main.h"
+
 struct _MudTelnetZmpPrivate
 {
     /* Interface Properties */
@@ -42,6 +44,7 @@
 
     /* Private Instance Members */
     GHashTable *commands;
+    ZmpMain *main_zmp;
 };
 
 /* Property Identifiers */
@@ -83,18 +86,10 @@
                                                mud_telnet_zmp_interface_init));
 
 /* Private Methods */
-static void mud_zmp_register_core_functions(MudTelnetZmp *self);
-static void mud_zmp_send_command(MudTelnetZmp *self, guint32 count, ...);
 static void mud_zmp_destroy_key(gpointer k);
 static void mud_zmp_destroy_command(gpointer c);
-static gboolean mud_zmp_has_command(MudTelnetZmp *self, gchar *name);
-static gboolean mud_zmp_has_package(MudTelnetZmp *self, gchar *package);
 static MudZMPFunction mud_zmp_get_function(MudTelnetZmp *self, gchar *name);
 
-/* Core ZMP Functions */
-static void ZMP_ident(MudTelnetZmp *self, gint argc, gchar **argv);
-static void ZMP_ping_and_time(MudTelnetZmp *self, gint argc, gchar **argv);
-static void ZMP_check(MudTelnetZmp *self, gint argc, gchar **argv);
 
 /* MudTelnetZmp class functions */
 static void
@@ -177,7 +172,11 @@
                                                  mud_zmp_destroy_key,
                                                  mud_zmp_destroy_command);
 
-    mud_zmp_register_core_functions(self);
+    self->priv->main_zmp = g_object_new(ZMP_TYPE_MAIN,
+                                        "parent-zmp", self,
+                                        NULL);
+
+    zmp_main_register_commands(self->priv->main_zmp);
 
     return obj;
 }
@@ -193,6 +192,8 @@
     if(self->priv->commands)
         g_hash_table_destroy(self->priv->commands);
 
+    g_object_unref(self->priv->main_zmp);
+
     parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
     parent_class->finalize(object);
 }
@@ -339,6 +340,52 @@
 
 /* Private Methods */
 static void
+mud_zmp_destroy_key(gpointer k)
+{
+    gchar *key = (gchar *)k;
+
+    if(key)
+        g_free(key);
+}
+
+static void
+mud_zmp_destroy_command(gpointer c)
+{
+    MudZMPCommand *command = (MudZMPCommand *)c;
+
+    if(command)
+    {
+        if(command->name)
+            g_free(command->name);
+
+        if(command->package)
+            g_free(command->package);
+
+        g_free(command);
+    }
+}
+
+static MudZMPFunction
+mud_zmp_get_function(MudTelnetZmp *self, gchar *name)
+{
+    MudZMPFunction ret = NULL;
+    MudZMPCommand *val;
+
+    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
+
+    if(!mud_zmp_has_command(self, name))
+        return NULL;
+
+    val = (MudZMPCommand *)g_hash_table_lookup(self->priv->commands, name);
+
+    if(val)
+        ret = (MudZMPFunction)val->execute;
+
+    return ret;
+}
+
+/* Public Methods */
+void
 mud_zmp_send_command(MudTelnetZmp *self, guint32 count, ...)
 {
     guchar byte;
@@ -391,52 +438,7 @@
     gnet_conn_write(conn, (gchar *)&byte, 1);
 }
 
-static void
-mud_zmp_register_core_functions(MudTelnetZmp *self)
-{
-    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
-
-    mud_zmp_register(self, mud_zmp_new_command("zmp.",
-                                               "zmp.ident",
-                                               ZMP_ident));
-    mud_zmp_register(self, mud_zmp_new_command("zmp.",
-                                               "zmp.ping",
-                                               ZMP_ping_and_time));
-    mud_zmp_register(self, mud_zmp_new_command("zmp.",
-                                               "zmp.time",
-                                               ZMP_ping_and_time));
-    mud_zmp_register(self, mud_zmp_new_command("zmp.",
-                                               "zmp.check",
-                                               ZMP_check));
-}
-
-static void
-mud_zmp_destroy_key(gpointer k)
-{
-    gchar *key = (gchar *)k;
-
-    if(key)
-        g_free(key);
-}
-
-static void
-mud_zmp_destroy_command(gpointer c)
-{
-    MudZMPCommand *command = (MudZMPCommand *)c;
-
-    if(command)
-    {
-        if(command->name)
-            g_free(command->name);
-
-        if(command->package)
-            g_free(command->package);
-
-        g_free(command);
-    }
-}
-
-static gboolean
+gboolean
 mud_zmp_has_command(MudTelnetZmp *self, gchar *name)
 {
     if(!MUD_IS_TELNET_ZMP(self))
@@ -445,7 +447,7 @@
     return !(g_hash_table_lookup(self->priv->commands, name) == NULL);
 }
 
-static gboolean
+gboolean
 mud_zmp_has_package(MudTelnetZmp *self, gchar *package)
 {
     GList *keys;
@@ -473,82 +475,6 @@
     return FALSE;
 }
 
-static MudZMPFunction
-mud_zmp_get_function(MudTelnetZmp *self, gchar *name)
-{
-    MudZMPFunction ret = NULL;
-    MudZMPCommand *val;
-
-    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
-
-    if(!mud_zmp_has_command(self, name))
-        return NULL;
-
-    val = (MudZMPCommand *)g_hash_table_lookup(self->priv->commands, name);
-
-    if(val)
-        ret = (MudZMPFunction)val->execute;
-
-    return ret;
-}
-
-
-/* Core ZMP Functions */
-static void
-ZMP_ident(MudTelnetZmp *self, gint argc, gchar **argv)
-{
-    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
-
-    mud_zmp_send_command(self, 4,
-            "zmp.ident", "gnome-mud", VERSION,
-            "A mud client written for the GNOME environment.");
-}
-
-static void
-ZMP_ping_and_time(MudTelnetZmp *self, gint argc, gchar **argv)
-{
-    time_t t;
-    gchar time_buffer[128];
-
-    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
-
-    time(&t);
-
-    strftime(time_buffer, sizeof(time_buffer),
-            "%Y-%m-%d %H:%M:%S", gmtime(&t));
-
-    mud_zmp_send_command(self, 2, "zmp.time", time_buffer);
-}
-
-static void
-ZMP_check(MudTelnetZmp *self, gint argc, gchar **argv)
-{
-    gchar *item;
-
-    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
-
-    if(argc < 2)
-        return; // Malformed ZMP_Check
-
-    item = argv[1];
-
-    if(item[strlen(item) - 1] == '.') // Check for package.
-    {
-        if(mud_zmp_has_package(self, item))
-            mud_zmp_send_command(self, 2, "zmp.support", item);
-        else
-            mud_zmp_send_command(self, 2, "zmp.no-support", item);
-    }
-    else // otherwise command
-    {
-        if(mud_zmp_has_command(self, item))
-            mud_zmp_send_command(self, 2, "zmp.support", item);
-        else
-            mud_zmp_send_command(self, 2, "zmp.no-support", item);
-    }
-}
-
-/* Public Methods */
 void
 mud_zmp_register(MudTelnetZmp *self, MudZMPCommand *command)
 {

Modified: trunk/src/handlers/mud-telnet-zmp.h
==============================================================================
--- trunk/src/handlers/mud-telnet-zmp.h	(original)
+++ trunk/src/handlers/mud-telnet-zmp.h	Tue Mar 17 20:39:59 2009
@@ -66,5 +66,9 @@
 
 void mud_zmp_register(MudTelnetZmp *self, MudZMPCommand *command);
 
+gboolean mud_zmp_has_command(MudTelnetZmp *self, gchar *name);
+gboolean mud_zmp_has_package(MudTelnetZmp *self, gchar *package);
+void mud_zmp_send_command(MudTelnetZmp *self, guint32 count, ...);
+
 #endif // MUD_TELNET_ZMP_H
 

Modified: trunk/src/zmp/Makefile.am
==============================================================================
--- trunk/src/zmp/Makefile.am	(original)
+++ trunk/src/zmp/Makefile.am	Tue Mar 17 20:39:59 2009
@@ -3,6 +3,12 @@
 noinst_LTLIBRARIES = libzmpcommands.la
 
 libzmpcommands_la_SOURCES = \
+	zmp-package-interface.c \
+	zmp-package-interface.h \
+	zmp-core.c \
+	zmp-core.h \
+	zmp-main.c \
+	zmp-main.h \
 	zmp-subwindow.c \
 	zmp-subwindow.h \
 	$(NULL)

Added: trunk/src/zmp/zmp-core.c
==============================================================================
--- (empty file)
+++ trunk/src/zmp/zmp-core.c	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,270 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-core.c
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <string.h>
+
+#include "gnome-mud.h"
+#include "mud-telnet.h"
+#include "handlers/mud-telnet-handlers.h"
+#include "zmp-package-interface.h"
+#include "zmp-core.h"
+
+struct _ZmpCorePrivate
+{
+    /* Interface Properties */
+    gchar *package;
+
+    /* Private Instance Members */
+};
+
+/* Property Identifiers */
+enum
+{
+    PROP_ZMP_CORE_0,
+    PROP_PACKAGE,
+};
+
+/* Class Functions */
+static void zmp_core_init (ZmpCore *self);
+static void zmp_core_class_init (ZmpCoreClass *klass);
+static void zmp_core_interface_init(ZmpPackageInterface *iface);
+static void zmp_core_finalize (GObject *object);
+static GObject *zmp_core_constructor (GType gtype,
+                                      guint n_properties,
+                                      GObjectConstructParam *properties);
+static void zmp_core_set_property(GObject *object,
+                                  guint prop_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec);
+static void zmp_core_get_property(GObject *object,
+                                  guint prop_id,
+                                  GValue *value,
+                                  GParamSpec *pspec);
+
+/*Interface Implementation */
+static void zmp_core_register_commands(MudTelnetZmp *zmp);
+
+/* ZmpCore zmp_core Commands */
+static void zmp_core_ident(MudTelnetZmp *self, gint argc, gchar **argv);
+static void zmp_core_ping_and_time(MudTelnetZmp *self, gint argc, gchar **argv);
+static void zmp_core_check(MudTelnetZmp *self, gint argc, gchar **argv);
+
+/* Create the Type. We implement ZmpPackageInterface */
+G_DEFINE_TYPE_WITH_CODE(ZmpCore, zmp_core, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (ZMP_PACKAGE_TYPE,
+                                               zmp_core_interface_init));
+/* ZmpCore class functions */
+static void
+zmp_core_class_init (ZmpCoreClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    /* Override base object constructor */
+    object_class->constructor = zmp_core_constructor;
+
+    /* Override base object's finalize */
+    object_class->finalize = zmp_core_finalize;
+
+    /* Override base object property methods */
+    object_class->set_property = zmp_core_set_property;
+    object_class->get_property = zmp_core_get_property;
+
+    /* Add private data to class */
+    g_type_class_add_private(klass, sizeof(ZmpCorePrivate));
+
+    /* Override Implementation Properties */
+    g_object_class_override_property(object_class,
+                                     PROP_PACKAGE,
+                                     "package");
+}
+
+static void
+zmp_core_interface_init(ZmpPackageInterface *iface)
+{
+    iface->register_commands = zmp_core_register_commands;
+}
+
+static void
+zmp_core_init (ZmpCore *self)
+{
+    /* Get our private data */
+    self->priv = ZMP_CORE_GET_PRIVATE(self);
+
+    /* Set the defaults */
+    self->priv->package = NULL;
+}
+
+static GObject *
+zmp_core_constructor (GType gtype,
+                      guint n_properties,
+                      GObjectConstructParam *properties)
+{
+    ZmpCore *self;
+    GObject *obj;
+    ZmpCoreClass *klass;
+    GObjectClass *parent_class;
+
+    /* Chain up to parent constructor */
+    klass = ZMP_CORE_CLASS( g_type_class_peek(ZMP_TYPE_CORE) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
+
+    self = ZMP_CORE(obj);
+
+    self->priv->package = g_strdup("zmp.");
+
+    return obj;
+}
+
+static void
+zmp_core_finalize (GObject *object)
+{
+    ZmpCore *self;
+    GObjectClass *parent_class;
+
+    self = ZMP_CORE(object);
+
+    g_free(self->priv->package);
+
+    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
+    parent_class->finalize(object);
+}
+
+static void
+zmp_core_set_property(GObject *object,
+                      guint prop_id,
+                      const GValue *value,
+                      GParamSpec *pspec)
+{
+    ZmpCore *self;
+
+    self = ZMP_CORE(object);
+
+    switch(prop_id)
+    {
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void
+zmp_core_get_property(GObject *object,
+                      guint prop_id,
+                      GValue *value,
+                      GParamSpec *pspec)
+{
+    ZmpCore *self;
+
+    self = ZMP_CORE(object);
+
+    switch(prop_id)
+    {
+        case PROP_PACKAGE:
+            g_value_set_string(value, self->priv->package);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+/* Interface Implementation */
+static void
+zmp_core_register_commands(MudTelnetZmp *zmp)
+{
+    g_return_if_fail(MUD_IS_TELNET_ZMP(zmp));
+
+    mud_zmp_register(zmp, mud_zmp_new_command("zmp.",
+                                              "zmp.ident",
+                                              zmp_core_ident));
+    mud_zmp_register(zmp, mud_zmp_new_command("zmp.",
+                                              "zmp.ping",
+                                              zmp_core_ping_and_time));
+    mud_zmp_register(zmp, mud_zmp_new_command("zmp.",
+                                              "zmp.time",
+                                              zmp_core_ping_and_time));
+    mud_zmp_register(zmp, mud_zmp_new_command("zmp.",
+                                              "zmp.check",
+                                              zmp_core_check));
+}
+
+/* zmp.core Commands */
+static void
+zmp_core_ident(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
+
+    mud_zmp_send_command(self, 4,
+            "zmp.ident", "gnome-mud", VERSION,
+            "A mud client written for the GNOME environment.");
+}
+
+static void
+zmp_core_ping_and_time(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+    time_t t;
+    gchar time_buffer[128];
+
+    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
+
+    time(&t);
+
+    strftime(time_buffer, sizeof(time_buffer),
+            "%Y-%m-%d %H:%M:%S", gmtime(&t));
+
+    mud_zmp_send_command(self, 2, "zmp.time", time_buffer);
+}
+
+static void
+zmp_core_check(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+    gchar *item;
+
+    g_return_if_fail(MUD_IS_TELNET_ZMP(self));
+
+    if(argc < 2)
+        return; // Malformed zmp_core_Check
+
+    item = argv[1];
+
+    if(item[strlen(item) - 1] == '.') // Check for package.
+    {
+        if(mud_zmp_has_package(self, item))
+            mud_zmp_send_command(self, 2, "zmp.support", item);
+        else
+            mud_zmp_send_command(self, 2, "zmp.no-support", item);
+    }
+    else // otherwise command
+    {
+        if(mud_zmp_has_command(self, item))
+            mud_zmp_send_command(self, 2, "zmp.support", item);
+        else
+            mud_zmp_send_command(self, 2, "zmp.no-support", item);
+    }
+}
+

Added: trunk/src/zmp/zmp-core.h
==============================================================================
--- (empty file)
+++ trunk/src/zmp/zmp-core.h	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,57 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-core.h
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef ZMP_CORE_H
+#define ZMP_CORE_H
+
+G_BEGIN_DECLS
+
+#include <glib.h>
+
+#define ZMP_TYPE_CORE              (zmp_core_get_type ())
+#define ZMP_CORE(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), ZMP_TYPE_CORE, ZmpCore))
+#define ZMP_CORE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), ZMP_TYPE_CORE, ZmpCoreClass))
+#define ZMP_IS_CORE(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), ZMP_TYPE_CORE))
+#define ZMP_IS_CORE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), ZMP_TYPE_CORE))
+#define ZMP_CORE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), ZMP_TYPE_CORE, ZmpCoreClass))
+#define ZMP_CORE_GET_PRIVATE(obj)  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZMP_TYPE_CORE, ZmpCorePrivate))
+
+typedef struct _ZmpCore            ZmpCore;
+typedef struct _ZmpCoreClass       ZmpCoreClass;
+typedef struct _ZmpCorePrivate     ZmpCorePrivate;
+
+struct _ZmpCoreClass
+{
+    GObjectClass parent_class;
+};
+
+struct _ZmpCore
+{
+    GObject parent_instance;
+
+    /*< private >*/
+    ZmpCorePrivate *priv;
+};
+
+GType zmp_core_get_type (void);
+
+G_END_DECLS
+
+#endif // ZMP_CORE_H
+

Added: trunk/src/zmp/zmp-main.c
==============================================================================
--- (empty file)
+++ trunk/src/zmp/zmp-main.c	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,233 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-main.c
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "gnome-mud.h"
+#include "mud-telnet.h"
+#include "handlers/mud-telnet-handlers.h"
+
+#include "zmp-main.h"
+
+#include "zmp-package-interface.h"
+#include "zmp-core.h"
+#include "zmp-subwindow.h"
+
+struct _ZmpMainPrivate
+{
+    MudTelnetZmp *parent;
+    GList *packages;
+};
+
+/* Property Identifiers */
+enum
+{
+    PROP_ZMP_MAIN_0,
+    PROP_PARENT
+};
+
+/* Create the Type */
+G_DEFINE_TYPE(ZmpMain, zmp_main, G_TYPE_OBJECT);
+
+/* Class Functions */
+static void zmp_main_init (ZmpMain *self);
+static void zmp_main_class_init (ZmpMainClass *klass);
+static void zmp_main_finalize (GObject *object);
+static GObject *zmp_main_constructor (GType gtype,
+                                      guint n_properties,
+                                      GObjectConstructParam *properties);
+static void zmp_main_set_property(GObject *object,
+                                  guint prop_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec);
+static void zmp_main_get_property(GObject *object,
+                                  guint prop_id,
+                                  GValue *value,
+                                  GParamSpec *pspec);
+
+/* Private Methods */
+static void zmp_main_unref_package(gpointer value,
+                                   gpointer user_data);
+
+/* ZmpMain class functions */
+static void
+zmp_main_class_init (ZmpMainClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    /* Override base object constructor */
+    object_class->constructor = zmp_main_constructor;
+
+    /* Override base object's finalize */
+    object_class->finalize = zmp_main_finalize;
+
+    /* Override base object property methods */
+    object_class->set_property = zmp_main_set_property;
+    object_class->get_property = zmp_main_get_property;
+
+    /* Add private data to class */
+    g_type_class_add_private(klass, sizeof(ZmpMainPrivate));
+
+    /* Install Properties */
+    g_object_class_install_property(object_class,
+            PROP_PARENT,
+            g_param_spec_object("parent-zmp",
+                "Parent ZMP",
+                "The Parent MudTelnetZMP Object",
+                MUD_TYPE_TELNET_ZMP,
+                G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+zmp_main_init (ZmpMain *self)
+{
+    /* Get our private data */
+    self->priv = ZMP_MAIN_GET_PRIVATE(self);
+
+    /* set defaults */
+    self->priv->parent = NULL;
+    self->priv->packages = NULL;
+}
+
+static GObject *
+zmp_main_constructor (GType gtype,
+                      guint n_properties,
+                      GObjectConstructParam *properties)
+{
+    ZmpMain *self;
+    GObject *obj;
+    ZmpMainClass *klass;
+    GObjectClass *parent_class;
+
+    /* Chain up to parent constructor */
+    klass = ZMP_MAIN_CLASS( g_type_class_peek(ZMP_TYPE_MAIN) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
+
+    self = ZMP_MAIN(obj);
+
+    if(!self->priv->parent)
+    {
+        g_printf("ERROR: Tried to instantiate ZmpMain without passing parent MudTelnetZmp\n");
+        g_error("Tried to instantiate ZmpMain without passing parent MudTelnetZmp");
+    }
+
+    /* zmp.core */
+    self->priv->packages = g_list_append(self->priv->packages,
+                                         g_object_new(ZMP_TYPE_CORE, NULL));
+
+    /* subwindow */
+    self->priv->packages = g_list_append(self->priv->packages,
+                                         g_object_new(ZMP_TYPE_SUBWINDOW, NULL));
+
+    return obj;
+}
+
+static void
+zmp_main_finalize (GObject *object)
+{
+    ZmpMain *self;
+    GObjectClass *parent_class;
+
+    self = ZMP_MAIN(object);
+
+    g_list_foreach(self->priv->packages, zmp_main_unref_package, NULL);
+    g_list_free(self->priv->packages);
+
+    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
+    parent_class->finalize(object);
+}
+
+static void
+zmp_main_set_property(GObject *object,
+                      guint prop_id,
+                      const GValue *value,
+                      GParamSpec *pspec)
+{
+    ZmpMain *self;
+
+    self = ZMP_MAIN(object);
+
+    switch(prop_id)
+    {
+        /* Parent is Construct Only */
+        case PROP_PARENT:
+            self->priv->parent = MUD_TELNET_ZMP(g_value_get_object(value));
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void
+zmp_main_get_property(GObject *object,
+                      guint prop_id,
+                      GValue *value,
+                      GParamSpec *pspec)
+{
+    ZmpMain *self;
+
+    self = ZMP_MAIN(object);
+
+    switch(prop_id)
+    {
+        case PROP_PARENT:
+            g_value_take_object(value, self->priv->parent);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+/* Private Methods */
+static void
+zmp_main_unref_package(gpointer value,
+                       gpointer user_data)
+{
+    ZmpPackage *package = ZMP_PACKAGE(value);
+
+    if(package)
+        g_object_unref(package);
+}
+
+/* Public Methods */
+void
+zmp_main_register_commands(ZmpMain *self)
+{
+    GList *entry;
+
+    g_return_if_fail(ZMP_IS_MAIN(self));
+
+    entry = g_list_first(self->priv->packages);
+
+    while(entry)
+    {
+        ZmpPackage *package = ZMP_PACKAGE(entry->data);
+
+        zmp_package_register_commands(package, self->priv->parent);
+
+        entry = g_list_next(entry);
+    }
+}
+

Added: trunk/src/zmp/zmp-main.h
==============================================================================
--- (empty file)
+++ trunk/src/zmp/zmp-main.h	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,59 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-main.h
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef ZMP_MAIN_H
+#define ZMP_MAIN_H
+
+G_BEGIN_DECLS
+
+#include <glib.h>
+
+#define ZMP_TYPE_MAIN              (zmp_main_get_type ())
+#define ZMP_MAIN(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), ZMP_TYPE_MAIN, ZmpMain))
+#define ZMP_MAIN_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), ZMP_TYPE_MAIN, ZmpMainClass))
+#define ZMP_IS_MAIN(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), ZMP_TYPE_MAIN))
+#define ZMP_IS_MAIN_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), ZMP_TYPE_MAIN))
+#define ZMP_MAIN_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), ZMP_TYPE_MAIN, ZmpMainClass))
+#define ZMP_MAIN_GET_PRIVATE(obj)  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZMP_TYPE_MAIN, ZmpMainPrivate))
+
+typedef struct _ZmpMain            ZmpMain;
+typedef struct _ZmpMainClass       ZmpMainClass;
+typedef struct _ZmpMainPrivate     ZmpMainPrivate;
+
+struct _ZmpMainClass
+{
+    GObjectClass parent_class;
+};
+
+struct _ZmpMain
+{
+    GObject parent_instance;
+
+    /*< private >*/
+    ZmpMainPrivate *priv;
+};
+
+GType zmp_main_get_type (void);
+
+void zmp_main_register_commands(ZmpMain *self);
+
+G_END_DECLS
+
+#endif // ZMP_MAIN_H
+

Added: trunk/src/zmp/zmp-package-interface.c
==============================================================================
--- (empty file)
+++ trunk/src/zmp/zmp-package-interface.c	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,87 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-package-interface.c
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "zmp-package-interface.h"
+#include "handlers/mud-telnet-handlers.h"
+#include "mud-telnet.h"
+
+/* Interface Prototypes */
+static void zmp_package_base_init (gpointer klass);
+
+/* Define the Dummy Type */
+GType
+zmp_package_get_type (void)
+{
+    static GType zmp_package_iface_type = 0;
+
+    if(zmp_package_iface_type == 0)
+    {
+        static const GTypeInfo info =
+        {
+            sizeof (ZmpPackageInterface),
+            zmp_package_base_init,        /* base_init */
+            NULL                          /* base_finalize */
+        };
+
+        zmp_package_iface_type =
+            g_type_register_static(G_TYPE_INTERFACE,
+                                   "ZmpPackage",
+                                   &info,
+                                   0);
+    }
+
+    return zmp_package_iface_type;
+}
+
+/* Interface Functions */
+static void
+zmp_package_base_init(gpointer klass)
+{
+    static gboolean initialized = FALSE;
+
+    if(!initialized)
+    {
+        g_object_interface_install_property(klass,
+                                            g_param_spec_string(
+                                                "package",
+                                                "Package",
+                                                "The name of the ZMP Package",
+                                                NULL,
+                                                G_PARAM_READABLE));
+
+        initialized = TRUE;
+    }
+}
+
+/* Interface Methods */
+void
+zmp_package_register_commands(ZmpPackage *self, MudTelnetZmp *zmp)
+{
+    g_return_if_fail(MUD_IS_TELNET_ZMP(zmp));
+
+    ZMP_PACKAGE_GET_INTERFACE (self)->register_commands(zmp);
+}
+

Added: trunk/src/zmp/zmp-package-interface.h
==============================================================================
--- (empty file)
+++ trunk/src/zmp/zmp-package-interface.h	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,52 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-package-interface.h
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef ZMP_PACKAGE_INTERFACE_H
+#define ZMP_PACKAGE_INTERFACE_H
+
+G_BEGIN_DECLS
+
+#define ZMP_PACKAGE_TYPE                (zmp_package_get_type ())
+#define ZMP_PACKAGE(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZMP_PACKAGE_TYPE, ZmpPackage))
+#define ZMP_IS_PACKAGE(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZMP_PACKAGE_TYPE))
+#define ZMP_PACKAGE_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), ZMP_PACKAGE_TYPE, ZmpPackageInterface))
+
+typedef struct _ZmpPackage ZmpPackage; // Dummy object
+typedef struct _ZmpPackageInterface ZmpPackageInterface;
+
+#include <glib.h>
+#include "mud-telnet.h"
+#include "handlers/mud-telnet-handlers.h"
+
+struct _ZmpPackageInterface
+{
+    GTypeInterface parent;
+
+    /* Interface Methods */
+    void (*register_commands)(MudTelnetZmp *zmp);
+};
+
+GType zmp_package_get_type (void);
+
+void zmp_package_register_commands(ZmpPackage *self, MudTelnetZmp *zmp);
+
+G_END_DECLS
+
+#endif // ZMP_PACKAGE_INTERFACE_H
+

Modified: trunk/src/zmp/zmp-subwindow.c
==============================================================================
--- trunk/src/zmp/zmp-subwindow.c	(original)
+++ trunk/src/zmp/zmp-subwindow.c	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,246 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-subwindow.c
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <string.h>
+
+#include "gnome-mud.h"
+#include "mud-telnet.h"
+#include "handlers/mud-telnet-handlers.h"
+#include "zmp-package-interface.h"
+#include "zmp-subwindow.h"
+
+struct _ZmpSubwindowPrivate
+{
+    /* Interface Properties */
+    gchar *package;
+
+    /* Private Instance Members */
+};
+
+/* Property Identifiers */
+enum
+{
+    PROP_ZMP_SUBWINDOW_0,
+    PROP_PACKAGE,
+};
+
+/* Class Functions */
+static void zmp_subwindow_init (ZmpSubwindow *self);
+static void zmp_subwindow_class_init (ZmpSubwindowClass *klass);
+static void zmp_subwindow_interface_init(ZmpPackageInterface *iface);
+static void zmp_subwindow_finalize (GObject *object);
+static GObject *zmp_subwindow_constructor (GType gtype,
+                                           guint n_properties,
+                                           GObjectConstructParam *properties);
+static void zmp_subwindow_set_property(GObject *object,
+                                       guint prop_id,
+                                       const GValue *value,
+                                       GParamSpec *pspec);
+static void zmp_subwindow_get_property(GObject *object,
+                                       guint prop_id,
+                                       GValue *value,
+                                       GParamSpec *pspec);
+
+/* Interface Implementation */
+static void zmp_subwindow_register_commands(MudTelnetZmp *zmp);
+
+/* Subwindow Commands */
+static void zmp_subwindow_open(MudTelnetZmp *self, gint argc, gchar **argv);
+static void zmp_subwindow_close(MudTelnetZmp *self, gint argc, gchar **argv);
+static void zmp_subwindow_size(MudTelnetZmp *self, gint argc, gchar **argv);
+static void zmp_subwindow_set_input(MudTelnetZmp *self, gint argc, gchar **argv);
+static void zmp_subwindow_select(MudTelnetZmp *self, gint argc, gchar **argv);
+
+/* Create the Type. We implement ZmpPackageInterface */
+G_DEFINE_TYPE_WITH_CODE(ZmpSubwindow, zmp_subwindow, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (ZMP_PACKAGE_TYPE,
+                                               zmp_subwindow_interface_init));
+/* ZmpSubwindow class functions */
+static void
+zmp_subwindow_class_init (ZmpSubwindowClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    /* Override base object constructor */
+    object_class->constructor = zmp_subwindow_constructor;
+
+    /* Override base object's finalize */
+    object_class->finalize = zmp_subwindow_finalize;
+
+    /* Override base object property methods */
+    object_class->set_property = zmp_subwindow_set_property;
+    object_class->get_property = zmp_subwindow_get_property;
+
+    /* Add private data to class */
+    g_type_class_add_private(klass, sizeof(ZmpSubwindowPrivate));
+
+    /* Override Implementation Properties */
+    g_object_class_override_property(object_class,
+                                     PROP_PACKAGE,
+                                     "package");
+}
+
+static void
+zmp_subwindow_interface_init(ZmpPackageInterface *iface)
+{
+    iface->register_commands = zmp_subwindow_register_commands;
+}
+
+static void
+zmp_subwindow_init (ZmpSubwindow *self)
+{
+    /* Get our private data */
+    self->priv = ZMP_SUBWINDOW_GET_PRIVATE(self);
+
+    /* Set the defaults */
+    self->priv->package = NULL;
+}
+
+static GObject *
+zmp_subwindow_constructor (GType gtype,
+                           guint n_properties,
+                           GObjectConstructParam *properties)
+{
+    ZmpSubwindow *self;
+    GObject *obj;
+    ZmpSubwindowClass *klass;
+    GObjectClass *parent_class;
+
+    /* Chain up to parent constructor */
+    klass = ZMP_SUBWINDOW_CLASS( g_type_class_peek(ZMP_TYPE_SUBWINDOW) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
+
+    self = ZMP_SUBWINDOW(obj);
+
+    self->priv->package = g_strdup("zmp.");
+
+    return obj;
+}
+
+static void
+zmp_subwindow_finalize (GObject *object)
+{
+    ZmpSubwindow *self;
+    GObjectClass *parent_class;
+
+    self = ZMP_SUBWINDOW(object);
+
+    g_free(self->priv->package);
+
+    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
+    parent_class->finalize(object);
+}
+
+static void
+zmp_subwindow_set_property(GObject *object,
+                           guint prop_id,
+                           const GValue *value,
+                           GParamSpec *pspec)
+{
+    ZmpSubwindow *self;
+
+    self = ZMP_SUBWINDOW(object);
+
+    switch(prop_id)
+    {
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void
+zmp_subwindow_get_property(GObject *object,
+                           guint prop_id,
+                           GValue *value,
+                           GParamSpec *pspec)
+{
+    ZmpSubwindow *self;
+
+    self = ZMP_SUBWINDOW(object);
+
+    switch(prop_id)
+    {
+        case PROP_PACKAGE:
+            g_value_set_string(value, self->priv->package);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+/* Interface Implementation */
+static void
+zmp_subwindow_register_commands(MudTelnetZmp *zmp)
+{
+    g_return_if_fail(MUD_IS_TELNET_ZMP(zmp));
+
+    mud_zmp_register(zmp, mud_zmp_new_command("subwindow.",
+                                              "subwindow.open",
+                                              zmp_subwindow_open));
+    mud_zmp_register(zmp, mud_zmp_new_command("subwindow.",
+                                              "subwindow.close",
+                                              zmp_subwindow_close));
+    mud_zmp_register(zmp, mud_zmp_new_command("subwindow.",
+                                              "subwindow.size",
+                                              zmp_subwindow_size));
+    mud_zmp_register(zmp, mud_zmp_new_command("subwindow.",
+                                              "subwindow.set-input",
+                                              zmp_subwindow_set_input));
+    mud_zmp_register(zmp, mud_zmp_new_command("subwindow.",
+                                              "subwindow.select",
+                                              zmp_subwindow_select));
+}
+
+/* ZmpSubwindow Commands */
+static void
+zmp_subwindow_open(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+}
+
+static void
+zmp_subwindow_close(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+}
+
+static void
+zmp_subwindow_size(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+}
+
+static void
+zmp_subwindow_set_input(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+}
+
+static void
+zmp_subwindow_select(MudTelnetZmp *self, gint argc, gchar **argv)
+{
+}
+

Modified: trunk/src/zmp/zmp-subwindow.h
==============================================================================
--- trunk/src/zmp/zmp-subwindow.h	(original)
+++ trunk/src/zmp/zmp-subwindow.h	Tue Mar 17 20:39:59 2009
@@ -0,0 +1,57 @@
+/* GNOME-Mud - A simple Mud Client
+ * zmp-subwindow.h
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef ZMP_SUBWINDOW_H
+#define ZMP_SUBWINDOW_H
+
+G_BEGIN_DECLS
+
+#include <glib.h>
+
+#define ZMP_TYPE_SUBWINDOW              (zmp_subwindow_get_type ())
+#define ZMP_SUBWINDOW(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), ZMP_TYPE_SUBWINDOW, ZmpSubwindow))
+#define ZMP_SUBWINDOW_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), ZMP_TYPE_SUBWINDOW, ZmpSubwindowClass))
+#define ZMP_IS_SUBWINDOW(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), ZMP_TYPE_SUBWINDOW))
+#define ZMP_IS_SUBWINDOW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), ZMP_TYPE_SUBWINDOW))
+#define ZMP_SUBWINDOW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), ZMP_TYPE_SUBWINDOW, ZmpSubwindowClass))
+#define ZMP_SUBWINDOW_GET_PRIVATE(obj)  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZMP_TYPE_SUBWINDOW, ZmpSubwindowPrivate))
+
+typedef struct _ZmpSubwindow            ZmpSubwindow;
+typedef struct _ZmpSubwindowClass       ZmpSubwindowClass;
+typedef struct _ZmpSubwindowPrivate     ZmpSubwindowPrivate;
+
+struct _ZmpSubwindowClass
+{
+    GObjectClass parent_class;
+};
+
+struct _ZmpSubwindow
+{
+    GObject parent_instance;
+
+    /*< private >*/
+    ZmpSubwindowPrivate *priv;
+};
+
+GType zmp_subwindow_get_type (void);
+
+G_END_DECLS
+
+#endif // ZMP_SUBWINDOW_H
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]