python decorations

John (J5) Palmieri johnp at redhat.com
Fri Jun 9 10:05:07 PDT 2006


You are confusing Names, Interfaces and Object Paths.  Names, what you
call a Service identify a server on the bus.  They are analogous to
Domain Names on the Internet.  

Object paths are analogous to C/C++ pointers or URL paths.  They point
to a resource which the internal implementation routes messages to.  So
names are used by the Bus to route messages and Object paths are used by
the program (in this case the bindings does it for you) to route
messages to the correct handler.

Interfaces, of which the decorators take, simply partition the API into
logical groups.  They should never be dynamic as API's shouldn't change
from under you.  DBus interfaces are analogous to C++ or Java
interfaces. Interfaces are used to further route messages to the correct
handler should there be more than one for a particular message.


On Fri, 2006-06-09 at 17:38 +0200, hrotzing at kip.uni-heidelberg.de wrote:
> Hi all,
> 
> I'm quite new to dbus and python but I want to use the python dbus bindings to 
> write a few programs which communicate over dbus.
> All these small programs should use a python base class similar to this 
> 
> class  service(dbus.service.Object):
> 	def __init__(self, ServiceName):
	 def __init__(self, bus_name, object_path='/x/y'): #when you create a
service you want to create the name outside the object because you might
want to have more than one object per service	 
> 		self.InterfaceServiceName='/x.../y.../'
		 #you are using this as an ObjectPath, it is not an interface.  Again
you want to pass this into init here with a default value so you can
inherit from base objects.  I think you used ... as an ellipse but
object paths can not have periods in them 
> 		self.MyServiceName=ServiceName 
> 			bus = dbus.Bus()	
> 			bus_name = dbus.service.BusName(ServiceName,
> 							bus=dbus.SessionBus())
                 #again creating a bus in an exported object is not
recommended, especially if you are doing inheritance 
> 		dbus.service.Object.__init__(self, bus_name,InterfaceServiceName)
		 dbus.service.Object.__init__(self, bus_name, object_path)
>       		# a set of  default functions for every inherited object, e.g.
> 		@dbus.service.method(MyServiceName)
		 @dbus.service.method("my.service.Echo.Interface") #here you specify
an interface which contains the method EchoString which takes one
argument
> 		def EchoString(self, original):
> 			return original
> 		...
> 
> and inherit this class in this way 
> 
> ServiceName='org.valid.testName'
> class MySubClass(service):
>         @dbus.service.method(ServiceName)
>         def func(self):
>                 return "foo"
> 
> service_obj = MySubClass(ServiceName)

You want to inherit on Objects not Services.

> This works, if the ServiceName is set statically before the service class gets 
> called.
> 
> Setting the ServiceName in the __init_() func of the service class like above 
> did not work. The @dbus.service.method(MyServiceName) decoration is always 
> throwing exceptions, usually from the 
> _util._validate_interface_or_name(dbus_interface)  function showing that the 
> string MyServiceName was not set.
> 
> Is it possible to modify the @dbus.service.method(MyServiceName) decoration at 
> run time ? If I would use a static bus_interface, all objects would use the 
> same bus_interface name on the bus.



-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list