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
# This example shows how to access Avahi on the D-BUS.

from __future__ import print_function, unicode_literals
from __future__ import division, absolute_import

from tdbus import SimpleDBusConnection, DBUS_BUS_SYSTEM, DBusHandler, signal_handler, DBusError

import logging

logging.basicConfig(level=logging.DEBUG)

CONN_AVAHI = 'org.freedesktop.Avahi'
PATH_SERVER = '/'
IFACE_SERVER = 'org.freedesktop.Avahi.Server'

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()
Exemplo n.º 3
0
#!/usr/bin/env python
#
# This file is part of python-tdbus. Python-tdbus is free software
# available under the terms of the MIT license. See the file "LICENSE" that
# was provided together with this source file for the licensing terms.
#
# Copyright (c) 2012 the python-tdbus authors. See the file "AUTHORS" for a
# complete list.

# This example shows how to do a blocking method call. We call the bus function
# ListNames to list all bus names.

from tdbus import SimpleDBusConnection
import tdbus

conn = SimpleDBusConnection(tdbus.DBUS_BUS_SESSION)

print 'Listing all well-known services on the system bus:'
print

result = conn.call_method(tdbus.DBUS_PATH_DBUS,
                          'ListNames',
                          tdbus.DBUS_INTERFACE_DBUS,
                          destination=tdbus.DBUS_SERVICE_DBUS)

for name in result.get_args()[0]:
    if not name.startswith(':'):
        print '  %s' % name
print
Exemplo n.º 4
0
                <method name="Hello">
                        <arg type="s" name="message" direction="in" />
                        <arg type="s" name="hello_world" direction="out" />
                </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
Exemplo n.º 5
0
 def test_get_unique_name(self):
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     name = conn.get_unique_name()
     assert name.startswith(':')
     conn.close()
Exemplo n.º 6
0
 def test_connection_multiple_open(self):
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     conn.close()
     conn.open(DBUS_BUS_SESSION)
     conn.close()
Exemplo n.º 7
0
 def test_connection_init(self):
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     conn.close()