3 # Copyright (C) 2004 Red Hat Inc. <http://www.redhat.com/>
4 # Copyright (C) 2005, 2006 Collabora Ltd. <http://www.collabora.co.uk/>
6 # Licensed under the Academic Free License version 2.1
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 builddir
= os
.environ
["DBUS_TOP_BUILDDIR"]
31 sys
.path
.insert(0, pydir
)
32 sys
.path
.insert(0, pydir
+ 'dbus')
36 if not dbus
.__file
__.startswith(pydir
):
37 raise Exception("DBus modules are not being picked up from the package")
45 logging
.basicConfig(filename
=pydir
+ '/test-service.log', filemode
='w')
46 logging
.getLogger().setLevel(1)
47 logger
= logging
.getLogger('test-service')
50 class TestInterface(dbus
.service
.Interface
):
51 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='', out_signature
='b')
52 def CheckInheritance(self
):
55 class TestObject(dbus
.service
.Object
, TestInterface
):
56 def __init__(self
, bus_name
, object_path
="/org/freedesktop/DBus/TestSuitePythonObject"):
57 dbus
.service
.Object
.__init
__(self
, bus_name
, object_path
)
59 """ Echo whatever is sent
61 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface")
65 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface")
66 def GetComplexArray(self
):
68 for i
in range(0,100):
69 ret
.append((random
.randint(0,100), random
.randint(0,100), str(random
.randint(0,100))))
71 return dbus
.Array(ret
, signature
="(uus)")
73 def returnValue(self
, test
):
89 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='u', out_signature
='s')
90 def ReturnOneString(self
, test
):
91 return self
.returnValue(test
)
93 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='u', out_signature
='ss')
94 def ReturnTwoStrings(self
, test
):
95 return self
.returnValue(test
)
97 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='u', out_signature
='(ss)')
98 def ReturnStruct(self
, test
):
99 logger
.info('ReturnStruct(%r) -> %r', test
, self
.returnValue(test
))
100 return self
.returnValue(test
)
102 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='u', out_signature
='as')
103 def ReturnArray(self
, test
):
104 return self
.returnValue(test
)
106 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='u', out_signature
='a{ss}')
107 def ReturnDict(self
, test
):
108 return self
.returnValue(test
)
110 @dbus.service
.signal("org.freedesktop.DBus.TestSuiteInterface", signature
='s')
111 def SignalOneString(self
, test
):
112 logger
.info('SignalOneString(%r)', test
)
114 @dbus.service
.signal("org.freedesktop.DBus.TestSuiteInterface", signature
='ss')
115 def SignalTwoStrings(self
, test
, test2
):
116 logger
.info('SignalTwoStrings(%r, %r)', test
, test2
)
118 @dbus.service
.signal("org.freedesktop.DBus.TestSuiteInterface", signature
='(ss)')
119 def SignalStruct(self
, test
):
120 logger
.info('SignalStruct(%r)', test
)
122 @dbus.service
.signal("org.freedesktop.DBus.TestSuiteInterface", signature
='as')
123 def SignalArray(self
, test
):
126 @dbus.service
.signal("org.freedesktop.DBus.TestSuiteInterface", signature
='a{ss}')
127 def SignalDict(self
, test
):
130 @dbus.service
.method("org.freedesktop.DBus.TestSuiteInterface", in_signature
='su', out_signature
='')
131 def EmitSignal(self
, signal
, value
):
132 sig
= getattr(self
, str(signal
), None)
135 val
= self
.returnValue(value
)
136 # make two string case work by passing arguments in by tuple
137 if (signal
== 'SignalTwoStrings' and (value
== 1 or value
== 5)):
142 logger
.info('Emitting %s with %r', signal
, val
)
145 def CheckInheritance(self
):
148 @dbus.service
.method('org.freedesktop.DBus.TestSuiteInterface', in_signature
='bbv', out_signature
='v', async_callbacks
=('return_cb', 'error_cb'))
149 def AsynchronousMethod(self
, async, fail
, variant
, return_cb
, error_cb
):
152 gobject
.timeout_add(500, self
.AsynchronousMethod
, False, fail
, variant
, return_cb
, error_cb
)
160 return False # do not run again
164 @dbus.service
.method('org.freedesktop.DBus.TestSuiteInterface', in_signature
='', out_signature
='s', sender_keyword
='sender')
165 def WhoAmI(self
, sender
):
168 session_bus
= dbus
.SessionBus()
169 name
= dbus
.service
.BusName("org.freedesktop.DBus.TestSuitePythonService", bus
=session_bus
)
170 object = TestObject(name
)
171 loop
= gobject
.MainLoop()