Example #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)
Example #2
0
# complete list.

# This example shows how to access Avahi on the D-BUS.


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

import logging

logging.basicConfig(level=logging.DEBUG)

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

conn = SimpleDBusConnection(DBUS_BUS_SYSTEM)

try:
    bluez = conn.call_method('/', 'GetManagedObjects',
              interface='org.freedesktop.DBus.ObjectManager', 
              destination='org.bluez')
except DBusError:
    print "Bluez not available"
    raise

var = bluez.get_args()[0]
for p, dev  in var.iteritems():
    if 'org.bluez.Adapter1' in dev:
        print "Found adapter {}".format(p)
        adapter = p
Example #3
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()
Example #4
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
Example #5
0

# This example shows how to listen for signals. Here we listen for any signal
# 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'
Example #6
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
Example #7
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()
print('or')
Example #8
0
 def test_connection_multiple_open(self):
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     conn.close()
     conn.open(DBUS_BUS_SESSION)
     conn.close()
Example #9
0
 def test_get_unique_name(self):
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     name = conn.get_unique_name()
     assert name.startswith(':')
     conn.close()
Example #10
0
 def test_connection_init(self):
     conn = SimpleDBusConnection(DBUS_BUS_SESSION)
     conn.close()
Example #11
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
Example #12
0
# Copyright (c) 2012 the python-tdbus authors. See the file "AUTHORS" for a
# complete list.

# This example shows how to access Avahi on the D-BUS.

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

import logging

logging.basicConfig(level=logging.DEBUG)

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

conn = SimpleDBusConnection(DBUS_BUS_SYSTEM)

try:
    bluez = conn.call_method('/',
                             'GetManagedObjects',
                             interface='org.freedesktop.DBus.ObjectManager',
                             destination='org.bluez')
except DBusError:
    print "Bluez not available"
    raise

var = bluez.get_args()[0]
for p, dev in var.iteritems():
    if 'org.bluez.Adapter1' in dev:
        print "Found adapter {}".format(p)
        adapter = p
Example #13
0
# This example shows how to listen for signals. Here we listen for any signal
# 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'
Example #14
0
                        <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