#!/usr/bin/env python

from twisted.internet import reactor

from txdbus import client, objects
from txdbus.interface import DBusInterface, Method, Signal


class MyObj (objects.DBusObject):

    iface = DBusInterface('org.example.MyIFace',
                          Method('exampleMethod', arguments='s', returns='s' ))

    dbusInterfaces = [iface]

    def __init__(self, objectPath):
        objects.DBusObject.__init__(self, objectPath)


    def dbus_exampleMethod(self, arg):
    	print 'Received remote call. Argument: ', arg
        return 'You sent (%s)' % arg
        
    
def onConnected(conn):
    print 'Connected to the system bus!'
    conn.exportObject( MyObj('/MyObjPath') )
    return conn.requestBusName('org.example')


def onReady(ignore):
    print 'Exporting object /MyObjPath on bus name "org.exmaple"'

    
def onErr(err):
    print 'Failed to export object: ', err.getErrorMessage()


d = client.connect(reactor, 'system')

d.addCallback(onConnected)
d.addCallback(onReady)
d.addErrback(onErr)

reactor.run()

