]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
* python/dbus_bindings.pyx.in: removed
authorJohn (J5) Palmieri <johnp@redhat.com>
Tue, 12 Jul 2005 18:16:07 +0000 (18:16 +0000)
committerJohn (J5) Palmieri <johnp@redhat.com>
Tue, 12 Jul 2005 18:16:07 +0000 (18:16 +0000)
* python/dbus_bindings.pyx: Added.
- Fixed some memleaks (patch from
  Sean Meiners <sean.meiners@linspireinc.com>)
- Broke out the #include "dbus_h_wrapper.h" and put it in its
  own pxd file (Pyrex definition)
- Broke out glib dependancies into its own pyx module

* python/dbus_bindings.pdx: Added.
- Defines C class Connection for exporting to other modules

* python/dbus_glib_bindings.pyx: Added.
- New module to handle lowlevel dbus-glib mainloop integration

* python/glib.py: Added.
- Registers the glib mainloop when you import this module

* python/services.py: Removed (renamed to service.py)

* python/service.py: Added.
- (class Server): renamed Name

* python/__init__.py: Bump ro version (0,41,0)
- don't import the decorators or service module
      by default.  These now reside in the dbus.service namespace

* python/_dbus.py (Bus::__init__): Add code run the main loop
  setup function on creation

* python/examples/example-service.py,
  python/examples/example-signal-emitter.py: update examples

* python/examples/gconf-proxy-service.py,
  python/examples/gconf-proxy-service2.py: TODO fix these up

* doc/TODO: Addition
- Added a Python Bindings 1.0 section
- added "Add match on args or match on details to match rules"

14 files changed:
ChangeLog
doc/TODO
python/Makefile.am
python/__init__.py
python/_dbus.py
python/dbus_bindings.pxd.in [new file with mode: 0644]
python/dbus_bindings.pyx [moved from python/dbus_bindings.pyx.in with 98% similarity]
python/dbus_glib_bindings.pyx [new file with mode: 0644]
python/examples/example-service.py
python/examples/example-signal-emitter.py
python/examples/gconf-proxy-service.py
python/examples/gconf-proxy-service2.py
python/glib.py [new file with mode: 0644]
python/service.py [moved from python/services.py with 96% similarity]

index 97c641788289424e5d832726b50f59222459d67a..01fbb957b9fbb5dc7fc5216ecb2c9083f68e1e91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,45 @@
+2005-07-12  John (J5) Palmieri  <johnp@redhat.com>
+       * python/dbus_bindings.pyx.in: removed
+
+       * python/dbus_bindings.pyx: Added.
+       - Fixed some memleaks (patch from 
+       Sean Meiners <sean.meiners@linspireinc.com>)
+       - Broke out the #include "dbus_h_wrapper.h" and put it in its
+       own pxd file (Pyrex definition)
+       - Broke out glib dependancies into its own pyx module
+       
+       * python/dbus_bindings.pdx: Added.
+       - Defines C class Connection for exporting to other modules
+
+       * python/dbus_glib_bindings.pyx: Added.
+       - New module to handle lowlevel dbus-glib mainloop integration
+
+       * python/glib.py: Added.
+       - Registers the glib mainloop when you import this module
+
+       * python/services.py: Removed (renamed to service.py)
+       
+       * python/service.py: Added.
+       - (class Server): renamed Name
+
+       * python/__init__.py: Bump ro version (0,41,0)
+       -don't import the decorators or service module
+       by default.  These now reside in the dbus.service namespace
+
+       * python/_dbus.py (Bus::__init__): Add code run the main loop 
+       setup function on creation 
+
+       * python/examples/example-service.py,
+       python/examples/example-signal-emitter.py: update examples
+
+       * python/examples/gconf-proxy-service.py,
+       python/examples/gconf-proxy-service2.py: TODO fix these up
+
+       * doc/TODO: Addition
+       - Added a Python Bindings 1.0 section
+       - added "Add match on args or match on details to match rules"
+
+
 2005-07-12  Colin Walters  <walters@verbum.org>
 
        * glib/examples/statemachine/Makefile.am (statemachine-server-glue.h) 
index 38fbe57c13dd1be93656d4b39973b45099df46d3..03e156dc4c3f2d53d41488a76579fab0853742eb 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -25,6 +25,8 @@ Important for 1.0
 
  - Add a test case for handling the Ping message 
 
+ - Add match on args or match on details to match rules
+
 Important for 1.0 GLib Bindings
 ===
 
@@ -32,6 +34,17 @@ Important for 1.0 GLib Bindings
 
  - Add support for getting sender
 
+Important for 1.0 Python bindings
+===
+
+ - Hammer down API
+
+ - Fix removing of signals from the match tree
+
+ - Fix refcounting and userdata lifecycles
+
+ - Write a generic mainloop
+
 Might as Well for 1.0
 ===
 
index b5ee4243af616fb46759f0ae8a34b04ed15e7af6..81a8367a8ef601100bfae007abca2a807b9aa727 100644 (file)
@@ -1,30 +1,42 @@
 SUBDIRS=examples
 
-INCLUDES=-I$(top_builddir) -I$(top_builddir)/dbus $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_GLIB_TOOL_CFLAGS) $(PYTHON_INCLUDES) -DDBUS_COMPILATION=1
+INCLUDES=-I$(top_builddir) -I$(top_builddir)/dbus $(DBUS_CLIENT_CFLAGS) $(PYTHON_INCLUDES) -DDBUS_COMPILATION=1
 
 dbusdir = $(pythondir)/dbus
-dbus_PYTHON = __init__.py _dbus.py decorators.py exceptions.py services.py proxies.py _util.py types.py matchrules.py
+dbus_PYTHON = __init__.py _dbus.py decorators.py exceptions.py service.py proxies.py _util.py types.py matchrules.py glib.py
 
 dbusbindingsdir = $(pyexecdir)/dbus
-dbusbindings_LTLIBRARIES = dbus_bindings.la
+dbusbindings_LTLIBRARIES = dbus_bindings.la dbus_glib_bindings.la
 
 dbus_bindings_la_LDFLAGS = -module -avoid-version -fPIC -export-symbols-regex initdbus_bindings
-dbus_bindings_la_LIBADD = $(top_builddir)/dbus/libdbus-1.la $(top_builddir)/glib/libdbus-glib-1.la
+dbus_bindings_la_LIBADD = $(top_builddir)/dbus/libdbus-1.la
 nodist_dbus_bindings_la_SOURCES = dbus_bindings.c
 
+dbus_glib_bindings_la_LDFLAGS = -module -avoid-version -fPIC -export-symbols-regex initdbus_glib_bindings 
+dbus_glib_bindings_la_LIBADD = $(top_builddir)/dbus/libdbus-1.la $(top_builddir)/glib/libdbus-glib-1.la
+dbus_glib_bindings_la_CFLAGS = $(DBUS_GLIB_CFLAGS) $(DBUS_GLIB_TOOL_CFLAGS)
+nodist_dbus_glib_bindings_la_SOURCES = dbus_glib_bindings.c
+
 
 EXTRA_DIST =                   \
        dbus_h_wrapper.h        \
-       dbus_bindings.pyx.in    \
+       dbus_bindings.pyx       \
+       dbus_glib_bindings.pyx  \
+       dbus_bindings.pxd       \
        extract.py
 
 CLEANFILES =                   \
-       dbus_bindings.pyx       \
-       dbus_bindings.c
+       dbus_bindings.pxd       \
+       dbus_bindings.c         \
+       dbus_glib_bindings.c    
+
 
+dbus_bindings.pxd: dbus_bindings.pxd.in extract.py
+       -$(PYTHON) extract.py dbus_bindings.pxd.in -I$(top_builddir)  > dbus_bindings.pxd
 
-dbus_bindings.pyx: dbus_bindings.pyx.in extract.py
-       -$(PYTHON) extract.py dbus_bindings.pyx.in -I$(top_builddir)  > dbus_bindings.pyx
+dbus_bindings.c: dbus_bindings.pyx dbus_bindings.pxd 
+       -pyrexc dbus_bindings.pyx 
 
-dbus_bindings.c: dbus_bindings.pyx
-       -pyrexc dbus_bindings.pyx
+dbus_glib_bindings.c: dbus_glib_bindings.pyx dbus_bindings.pxd 
+       -pyrexc dbus_glib_bindings.pyx 
+               
index ebeb4208bf7e8703778e6bccd8c6480d7bcdf83b..069a432be6517e64df2b1d5b70d8b3164c3ce8b4 100644 (file)
@@ -1,6 +1,5 @@
 from _dbus import *
-from decorators import *
-from services import *
 from types import *
 
-version = (0, 40, 2)
+version = (0, 41, 0)
+_dbus_main_loop_setup_function = None
index d559ce1845e306de3946581f275e1fcfc0e84edc..d52aa8fc3529286ebc4fa3737ace2fe0b4d049a9 100644 (file)
@@ -42,7 +42,8 @@ print(dbus_object.ListServices())
 """
 
 import dbus_bindings
-from decorators import *
+
+import dbus
 from proxies import *
 from exceptions import *
 from services import *
@@ -51,13 +52,6 @@ from matchrules import *
 import re
 import inspect
 
-_threads_initialized = 0
-def init_gthreads ():
-    global _threads_initialized
-    if not _threads_initialized:
-        dbus_bindings.init_gthreads ()
-        _threads_initialized = 1
-
 class Bus:
     """A connection to a DBus daemon.
 
@@ -76,13 +70,16 @@ class Bus:
     START_REPLY_SUCCESS = dbus_bindings.DBUS_START_REPLY_SUCCESS
     START_REPLY_ALREADY_RUNNING = dbus_bindings.DBUS_START_REPLY_ALREADY_RUNNING 
 
-    def __init__(self, bus_type=TYPE_SESSION, glib_mainloop=True):
+    def __init__(self, bus_type=TYPE_SESSION, use_default_mainloop=True):
         self._connection = dbus_bindings.bus_get(bus_type)
 
         self._connection.add_filter(self._signal_func)
         self._match_rule_tree = SignalMatchTree()
-        if (glib_mainloop):
-            self._connection.setup_with_g_main()
+
+        if use_default_mainloop:
+            func = getattr(dbus, "_dbus_mainloop_setup_function", None)
+            if func != None:
+                func(self)
 
     def get_connection(self):
         return self._connection
diff --git a/python/dbus_bindings.pxd.in b/python/dbus_bindings.pxd.in
new file mode 100644 (file)
index 0000000..f170720
--- /dev/null
@@ -0,0 +1,8 @@
+#include "dbus_h_wrapper.h"
+
+cdef class Connection:
+    cdef DBusConnection *conn
+
+    cdef __cinit__(self, address, DBusConnection *_conn)
+    cdef _set_conn(self, DBusConnection *conn)
+    cdef DBusConnection *_get_conn(self)
similarity index 98%
rename from python/dbus_bindings.pyx.in
rename to python/dbus_bindings.pyx
index 34341c4a6125b638df6a0baf48663774236f2c4c..608ef544d4aa5ede9645dc69909b1db5d0acda77 100644 (file)
@@ -15,21 +15,11 @@ cdef extern from "sys/types.h":
 cdef extern from "sys/cdefs.h":
     ctypedef __signed
 
-#include "dbus_h_wrapper.h"
-
 cdef extern from "stdlib.h":
     cdef void *malloc(size_t size)
     cdef void free(void *ptr)
     cdef void *calloc(size_t nmemb, size_t size)
 
-cdef extern from "dbus-glib.h":
-    ctypedef struct GMainContext
-    cdef void dbus_connection_setup_with_g_main (DBusConnection *connection,
-                                                 GMainContext   *context)
-    cdef void dbus_server_setup_with_g_main     (DBusServer     *server,
-                                                 GMainContext   *context)
-    cdef void dbus_g_thread_init ()
-
 cdef extern from "Python.h":
     void Py_XINCREF (object)
     void Py_XDECREF (object)
@@ -153,7 +143,6 @@ class Dictionary(dict):
         dict.__init__(value)
 
 #forward delcerations
-cdef class Connection
 cdef class Message
 cdef class PendingCall
 cdef class Watch
@@ -203,12 +192,11 @@ cdef DBusHandlerResult cmessage_function_handler (DBusConnection *connection,
         PyGILState_Release(gil)
        
 cdef class Connection:
-    cdef DBusConnection *conn
-    
     def __init__(self, address=None, Connection _conn=None):
         cdef DBusConnection *c_conn
         cdef char *c_address
         c_conn=NULL
+        self.conn = NULL
         if (_conn != None):
             c_conn = _conn.conn
 
@@ -229,6 +217,9 @@ cdef class Connection:
             if dbus_error_is_set(&error):
                 raise DBusException, error.message
 
+    def __del__(self):
+        if self.conn != NULL:
+            dbus_connection_unref(self.conn)
 
     cdef _set_conn(self, DBusConnection *conn):
         self.conn = conn
@@ -239,9 +230,6 @@ cdef class Connection:
     def get_unique_name(self):
         return bus_get_unique_name(self)
 
-    def setup_with_g_main(self):
-        dbus_connection_setup_with_g_main(self.conn, NULL)
-
     def disconnect(self):
         dbus_connection_disconnect(self.conn)
 
@@ -497,6 +485,7 @@ cdef class PendingCall:
     cdef DBusPendingCall *pending_call
 
     def __init__(self, PendingCall _pending_call=None):
+        self.pending_call = NULL
         if (_pending_call != None):
             self.__cinit__(_pending_call.pending_call)
 
@@ -504,6 +493,10 @@ cdef class PendingCall:
         self.pending_call = _pending_call
         dbus_pending_call_ref(self.pending_call)
 
+    def __del__(self):
+        if self.pending_call != NULL:
+            dbus_pending_call_unref(self.pending_call)
+
     cdef DBusPendingCall *_get_pending_call(self):
         return self.pending_call
 
@@ -1125,6 +1118,8 @@ cdef class Message:
                  Message reply_to=None, error_name=None, error_message=None,
                  _create=1):
 
+        self.msg = NULL
+
         cdef char *cservice
         cdef char *ciface
         cdef DBusMessage *cmsg
@@ -1150,6 +1145,10 @@ cdef class Message:
         elif message_type == MESSAGE_TYPE_ERROR:
             cmsg = reply_to._get_msg()
             self.msg = dbus_message_new_error(cmsg, error_name, error_message)
+
+    def __del__(self):
+        if self.msg != NULL:
+            dbus_message_unref(self.msg)
             
     def type_to_name(self, type):
         if type == MESSAGE_TYPE_SIGNAL:
@@ -1339,9 +1338,6 @@ cdef class Server:
         if dbus_error_is_set(&error):
             raise DBusException, error.message
 
-    def setup_with_g_main (self):
-        dbus_server_setup_with_g_main(self.server, NULL)
-
     def disconnect(self):
         dbus_server_disconnect(self.server)
 
@@ -1490,5 +1486,3 @@ def bus_remove_match(Connection connection, rule):
     if dbus_error_is_set(&error):
         raise DBusException, error.message
 
-def init_gthreads ():
-        dbus_g_thread_init ()
diff --git a/python/dbus_glib_bindings.pyx b/python/dbus_glib_bindings.pyx
new file mode 100644 (file)
index 0000000..314fada
--- /dev/null
@@ -0,0 +1,19 @@
+cdef extern from "dbus.h":
+    ctypedef struct DBusConnection
+
+cdef extern from "dbus-glib.h":
+    ctypedef struct GMainContext
+    cdef void dbus_connection_setup_with_g_main (DBusConnection *connection,
+                                                 GMainContext   *context)
+    cdef void dbus_g_thread_init ()
+
+cimport dbus_bindings
+import dbus_bindings
+
+def setup_with_g_main(conn):
+   cdef dbus_bindings.Connection connection
+   connection = conn
+   dbus_connection_setup_with_g_main(connection._get_conn(), NULL)
+
+def init_gthreads ():
+    dbus_g_thread_init ()
index 9963454f08f18a83ba6e53f4189a4ceb1ed5dbb0..9e2f193b891170f56086d47c5b823dfaba96f084 100644 (file)
@@ -1,29 +1,32 @@
 #!/usr/bin/env python
 
 import dbus
+import dbus.service
 
+
+import dbus.glib
 import pygtk
 import gtk
 
-class SomeObject(dbus.Object):
-    def __init__(self, service):
-        dbus.Object.__init__(self, "/SomeObject", service)
+class SomeObject(dbus.service.Object):
+    def __init__(self, name):
+        dbus.service.Object.__init__(self, "/SomeObject", name)
 
-    @dbus.method("org.designfu.SampleInterface")
+    @dbus.service.method("org.designfu.SampleInterface")
     def HelloWorld(self, hello_message):
         print (str(hello_message))
         return ["Hello", " from example-service.py"]
 
-    @dbus.method("org.designfu.SampleInterface")
+    @dbus.service.method("org.designfu.SampleInterface")
     def GetTuple(self):
         return ("Hello Tuple", " from example-service.py")
 
-    @dbus.method("org.designfu.SampleInterface")
+    @dbus.service.method("org.designfu.SampleInterface")
     def GetDict(self):
         return {"first": "Hello Dict", "second": " from example-service.py"}
 
 session_bus = dbus.SessionBus()
-service = dbus.Service("org.designfu.SampleService", bus=session_bus)
-object = SomeObject(service)
+name = dbus.service.Name("org.designfu.SampleService", bus=session_bus)
+object = SomeObject(name)
 
 gtk.main()
index 428f1440d44614e8b17da5bd7d5a429a8a58b6c7..64c7f1779749943e103a171c9ecbf50a224f21ae 100644 (file)
@@ -1,26 +1,27 @@
 #!/usr/bin/env python
 
 import dbus
+import dbus.service
 import gtk
 
-class TestObject(dbus.Object):
-    def __init__(self, service):
-        dbus.Object.__init__(self, "/org/designfu/TestService/object", service)
+class TestObject(dbus.service.Object):
+    def __init__(self, name):
+        dbus.service.Object.__init__(self, "/org/designfu/TestService/object", name)
 
-    @dbus.signal('org.designfu.TestService')
+    @dbus.service.signal('org.designfu.TestService')
     def HelloSignal(self, message):
         # The signal is emitted when this method exits
         # You can have code here if you wish
         pass
 
-    @dbus.method('org.designfu.TestService')
+    @dbus.service.method('org.designfu.TestService')
     def emitHelloSignal(self):
         #you emit signals by calling the signal's skeleton method
         self.HelloSignal("Hello")
         return "Signal emitted"
 
 session_bus = dbus.SessionBus()
-service = dbus.Service("org.designfu.TestService", bus=session_bus)
-object = TestObject(service)
+name = dbus.service.Name("org.designfu.TestService", bus=session_bus)
+object = TestObject(name)
 
 gtk.main()
index 18c8047fd1e5b4b1021f91fa5c48dc026440f65f..b9bdef1481a2d8454cb071e543521a35c21ee885 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-
+#FIXME: Doesn't work with the new bindings
 import dbus
 
 import gtk
index 3667a853c575ef1d7ef6986188bedf505eccae9a..ba8d249babefe45b9fd2599bb1f65ff8d919d93d 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-
+#FIXME: doesn't work with the new bindings
 import dbus
 
 import gtk
diff --git a/python/glib.py b/python/glib.py
new file mode 100644 (file)
index 0000000..8e78142
--- /dev/null
@@ -0,0 +1,15 @@
+import dbus
+import dbus_glib_bindings
+
+def _setup_with_g_main(conn):
+    dbus_glib_bindings.setup_with_g_main(conn._connection)
+
+_dbus_gthreads_initialized = False
+def init_threads():
+    global _dbus_gthreads_initialized
+    if not _dbus_gthreads_initialized:
+        dbus_glib_bindings.init_gthreads ()
+        _dbus_gthreads_initialized = True
+
+
+setattr(dbus, "_dbus_mainloop_setup_function", _setup_with_g_main)
similarity index 96%
rename from python/services.py
rename to python/service.py
index 7e0b58b773a6218aff0fc430e704c86ad97f2769..fc044af057a3187d1c3c0c226da5de536e3a8628 100644 (file)
@@ -2,10 +2,10 @@ from decorators import *
 
 import dbus_bindings 
 
-class Service:
-    """A base class for exporting your own Services across the Bus
+class Name:
+    """A base class for exporting your own Named Services across the Bus
 
-    Just inherit from Service, providing the name of your service
+    Just inherit from Name, providing the name of your service
     (e.g. org.designfu.SampleService).
     """
     def __init__(self, named_service, bus=None):
@@ -155,10 +155,10 @@ class Object:
     """
     __metaclass__ = ObjectType
     
-    def __init__(self, object_path, service):
+    def __init__(self, object_path, name):
         self._object_path = object_path
-        self._service = service
-        self._bus = service.get_bus()
+        self._name = name 
+        self._bus = name.get_bus()
             
         self._connection = self._bus.get_connection()