summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2005-07-12 18:16:07 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2005-07-12 18:16:07 +0000
commitd06bfe528bb8d5e2ad2b4844c36fe43155739b3d (patch)
treede42ec761fbc3db67ea65f69e0a3c0fa90403e59 /python
parent922d6bb194903583c6d8bb61ac0fc1a7077637b9 (diff)
* 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"
Diffstat (limited to 'python')
-rw-r--r--python/Makefile.am34
-rw-r--r--python/__init__.py5
-rw-r--r--python/_dbus.py19
-rw-r--r--python/dbus_bindings.pxd.in8
-rw-r--r--python/dbus_bindings.pyx (renamed from python/dbus_bindings.pyx.in)36
-rw-r--r--python/dbus_glib_bindings.pyx19
-rw-r--r--python/examples/example-service.py19
-rw-r--r--python/examples/example-signal-emitter.py15
-rw-r--r--python/examples/gconf-proxy-service.py2
-rw-r--r--python/examples/gconf-proxy-service2.py2
-rw-r--r--python/glib.py15
-rw-r--r--python/service.py (renamed from python/services.py)12
12 files changed, 117 insertions, 69 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index b5ee4243..81a8367a 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -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
+
diff --git a/python/__init__.py b/python/__init__.py
index ebeb4208..069a432b 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -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
diff --git a/python/_dbus.py b/python/_dbus.py
index d559ce18..d52aa8fc 100644
--- a/python/_dbus.py
+++ b/python/_dbus.py
@@ -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
index 00000000..f1707208
--- /dev/null
+++ b/python/dbus_bindings.pxd.in
@@ -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)
diff --git a/python/dbus_bindings.pyx.in b/python/dbus_bindings.pyx
index 34341c4a..608ef544 100644
--- a/python/dbus_bindings.pyx.in
+++ b/python/dbus_bindings.pyx
@@ -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
index 00000000..314fadad
--- /dev/null
+++ b/python/dbus_glib_bindings.pyx
@@ -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 ()
diff --git a/python/examples/example-service.py b/python/examples/example-service.py
index 9963454f..9e2f193b 100644
--- a/python/examples/example-service.py
+++ b/python/examples/example-service.py
@@ -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()
diff --git a/python/examples/example-signal-emitter.py b/python/examples/example-signal-emitter.py
index 428f1440..64c7f177 100644
--- a/python/examples/example-signal-emitter.py
+++ b/python/examples/example-signal-emitter.py
@@ -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()
diff --git a/python/examples/gconf-proxy-service.py b/python/examples/gconf-proxy-service.py
index 18c8047f..b9bdef14 100644
--- a/python/examples/gconf-proxy-service.py
+++ b/python/examples/gconf-proxy-service.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-
+#FIXME: Doesn't work with the new bindings
import dbus
import gtk
diff --git a/python/examples/gconf-proxy-service2.py b/python/examples/gconf-proxy-service2.py
index 3667a853..ba8d249b 100644
--- a/python/examples/gconf-proxy-service2.py
+++ b/python/examples/gconf-proxy-service2.py
@@ -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
index 00000000..8e781422
--- /dev/null
+++ b/python/glib.py
@@ -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)
diff --git a/python/services.py b/python/service.py
index 7e0b58b7..fc044af0 100644
--- a/python/services.py
+++ b/python/service.py
@@ -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()