Author: WalterMundt
Date: 2009-01-18 03:45:46 -0500 (Sun, 18 Jan 2009)
New Revision: 1492

Added:
   trunk/concordance/src/globals.h
Modified:
   trunk/concordance/src/_core/__init__.c
   trunk/concordance/src/_core/__init__.h
Log:
Revise core globals handling; code changes untested.


Modified: trunk/concordance/src/_core/__init__.c
===================================================================
--- trunk/concordance/src/_core/__init__.c      2009-01-18 08:07:12 UTC (rev 
1491)
+++ trunk/concordance/src/_core/__init__.c      2009-01-18 08:45:46 UTC (rev 
1492)
@@ -30,8 +30,10 @@
                                                   gboolean is_running);
      void               g_main_loop_run          (GMainLoop *loop);
   */
-  mainloop = g_main_loop_new(context, 0);
-  g_main_loop_run(mainloop);
+  concordGlobals *globals = (concordGlobals *)n;
+
+  globals->mainloop = g_main_loop_new(globals->context, 0);
+  g_main_loop_run(globals->mainloop);
   return NULL;
 }
 
@@ -40,12 +42,11 @@
   { NULL, NULL }
 };
 
-
 static struct PyModuleDef concord_Module = {
   PyModuleDef_HEAD_INIT,
   "_core",                             /*m_name*/
   "Test Help",                         /*m_doc*/
-  -1,                                  /*m_size*/
+  sizeof(concordGlobals),              /*m_size*/
   concord_Methods,                     /*m_methods*/
   NULL,                                /*m_reload*/
   NULL,                                /*m_traverse*/
@@ -58,6 +59,7 @@
 PyInit__core(void) {                                                      /*\
   cdef :                                                                  \*/
     PyObject* module;
+    concordGlobals *globals;
 
   /* Initialize Glib threading support
 
@@ -89,12 +91,25 @@
   #endif
   
   
+  /* Create concordance module object
+
+     PyObject* PyModule_Create(struct PyModuleDef*)
+  */
+  module = PyModule_Create(&concord_Module);
+  
+  /* Retrieve the module-global state, which will be initialized to
+     zero by the above based on m_size in concord_Module
+    
+     void* PyModule_GetState(PyObject*);
+   */
+  globals = (concordGlobals*)PyModule_GetState(module);
+  
   /* We use a non-default context to avoid conflict with other glib-based
      Python packages which may have their own GMainLoop in other threads.
 
      GMainContext*      g_main_context_new       (void);
   */
-  context = g_main_context_new();
+  globals->context = g_main_context_new();
 
 
   /* launch _core_loop thread
@@ -104,16 +119,8 @@
                                         gboolean joinable,
                                         GError **error);
   */
-  threadid = g_thread_create((GThreadFunc) _core_loop, NULL, 0, NULL);  
-  
-  
-  /* Create concordance module object
+  globals->threadid = g_thread_create((GThreadFunc) _core_loop, globals, 0, 
NULL);
 
-     PyObject* PyModule_Create(struct PyModuleDef*)
-  */
-  module = PyModule_Create(&concord_Module);
-
-
   /* return the module object to Python */
   return module;
 }

Modified: trunk/concordance/src/_core/__init__.h
===================================================================
--- trunk/concordance/src/_core/__init__.h      2009-01-18 08:07:12 UTC (rev 
1491)
+++ trunk/concordance/src/_core/__init__.h      2009-01-18 08:45:46 UTC (rev 
1492)
@@ -38,9 +38,6 @@
 #endif
 
 #include "utils.h"
+#include "../globals.h"
 
-GMainContext*    context;              /* Concordance's Glib context */
-GMainLoop*       mainloop;             /* Concordance's Glib mainloop */
-GThread*         threadid;             /* thread ID for mainloop thread */
-
 #endif

Added: trunk/concordance/src/globals.h
===================================================================
--- trunk/concordance/src/globals.h                             (rev 0)
+++ trunk/concordance/src/globals.h     2009-01-18 08:45:46 UTC (rev 1492)
@@ -0,0 +1,35 @@
+/*
+# Concordance XMPP Service Framework
+#
+# Copyright (C) 2009 Copyleft Games Group
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU Affero 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 Affero General Public License for more details.
+#
+#  You should have received a copy of the GNU Affero General Public License
+#  along with this program; if not, see http://www.gnu.org/licenses
+#
+# $Id$
+*/
+
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+#include "glib.h"
+#include "gsasl.h"
+#include "expat.h"
+
+typedef struct {
+  GMainContext*    context;              /* Concordance's Glib context */
+  GMainLoop*       mainloop;             /* Concordance's Glib mainloop */
+  GThread*         threadid;             /* thread ID for mainloop thread */
+} concordGlobals;
+
+#endif


Property changes on: trunk/concordance/src/globals.h
___________________________________________________________________
Added: svn:keywords
   + Id

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to