Exemplo n.º 1
0
 def setUpClass(cls):
     super(TestMessageASimple, cls).setUpClass()
     handler = EchoHandlerInherit()
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     conn.add_handler(handler)
     cls.server_name = conn.get_unique_name()
     cls.server = Thread(target=cls.dbus_server, args=(conn,))
     cls.server.start()
     cls.client = SimpleDBusConnection(DBUS_BUS_SESSION)
Exemplo n.º 2
0
bluez = conn.call_method(adapter, 'Set',
          interface='org.freedesktop.DBus.Properties', 
          format = 'ssv', 
          args=('org.bluez.Adapter1', 'Powered', ('b', True)),
          destination='org.bluez')


import sys
sys.exit()

print 'Avahi is available at %s' % CONN_AVAHI
print 'Avahi version: %s' % result.get_args()[0]
print
print 'Browsing service types on domain: local'
print 'Press CTRL-c to exit'
print

result = conn.call_method('/', 'ServiceTypeBrowserNew', interface=IFACE_SERVER,
                    destination=CONN_AVAHI, format='iisu', args=(-1, 0, 'local', 0))
browser = result.get_args()[0]
print browser
class AvahiHandler(DBusHandler):

    @signal_handler()
    def ItemNew(self, message):
	args = message.get_args()
    	print 'service %s exists on domain %s' % (args[2], args[3])

conn.add_handler(AvahiHandler())
conn.dispatch()
Exemplo n.º 3
0
conn = SimpleDBusConnection(DBUS_BUS_SYSTEM)

try:
    result = conn.call_method(PATH_SERVER, 'GetVersionString',
                        interface=IFACE_SERVER, destination=CONN_AVAHI)
except DBusError:
    print('Avahi NOT available.')
    raise

print('Avahi is available at %s' % CONN_AVAHI)
print('Avahi version: %s' % result.get_args()[0])
print()
print('Browsing service types on domain: local')
print('Press CTRL-c to exit')
print()

result = conn.call_method('/', 'ServiceTypeBrowserNew', interface=IFACE_SERVER,
                    destination=CONN_AVAHI, format='iisu', args=(-1, 0, 'local', 0))
browser = result.get_args()[0]
print(browser)

class AvahiHandler(DBusHandler):

    @signal_handler()
    def ItemNew(self, message):
        args = message.get_args()
        print('service %s exists on domain %s' % (args[2], args[3]))

conn.add_handler(AvahiHandler())
conn.dispatch()
Exemplo n.º 4
0
# but signal_handler() also accepts keyword arguments to only listen for
# specific signals.

from tdbus import DBusHandler, signal_handler, SimpleDBusConnection, DBUS_BUS_SESSION

class SignalHandler(DBusHandler):

    @signal_handler()
    def Signal(self, message):
         print 'signal received: %s, args = %s' % (message.get_member(), repr(message.get_args()))


conn = SimpleDBusConnection(DBUS_BUS_SESSION)
handler = SignalHandler()

conn.add_handler(handler)

# the next method needs to be called explicitly after all add_handler calls
conn.subscribe_to_signals()


print 'Listening for signals. Press CTRL-c to quit.'
print 'In another terminal, issue:'
print
print '  $ dbus-send --session --type=signal --dest={} /com/example/TDBus com.example.Hello.Signal'.format(conn.get_unique_name())
print
print 'or (only when subscribe_to_signals() is used)'
print '  $ dbus-send --session --type=signal /com/example/TDBus com.example.Hello.Signal'
print
print 'Press CTRL-c to exit.'
print
Exemplo n.º 5
0
                </method>
                <method name="HelloException">
                        <arg type="s" name="message" direction="in" />
                        <arg type="s" name="hello_world" direction="out" />
                </method>
        </interface>
</node>"""

        self.set_response("s", [xml])

EXAMPLE_NAME = "com.example.Hello"

conn = SimpleDBusConnection(DBUS_BUS_SESSION)
conn.register_name(EXAMPLE_NAME)
handler = MethodHandler()
conn.add_handler(handler)

print 'Exposing a hello world method on the bus.'
print 'In another terminal, issue:'
print
print '  $ dbus-send --session --print-reply --type=method_call --dest={} /com/example/TDBus com.example.Hello.Hello'.format(conn.get_unique_name())
print
print 'or'
print
print '  $ dbus-send --session --print-reply --type=method_call --dest={} /com/example/TDBus com.example.Hello.Hello'.format(EXAMPLE_NAME)
print
print 'or'
print
print '  $ dbus-send --session --print-reply --type=method_call --dest={} /com/example/TDBus com.example.Hello.HelloException'.format(EXAMPLE_NAME)
print
print 'Press CTRL-c to exit.'