Brad Bishop | b2571e2 | 2015-09-21 22:01:13 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Contributors Listed Below - COPYRIGHT 2015 |
| 4 | # [+] International Business Machines Corp. |
| 5 | # |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 16 | # implied. See the License for the specific language governing |
| 17 | # permissions and limitations under the License. |
| 18 | |
| 19 | import dbus |
| 20 | import dbus.service |
| 21 | import dbus.mainloop.glib |
| 22 | import gobject |
| 23 | |
| 24 | SERVICE_PREFIX = 'org.openbmc.examples' |
| 25 | IFACE_PREFIX = 'org.openbmc.examples' |
| 26 | BASE_OBJ_PATH = '/org/openbmc/examples/' |
| 27 | |
| 28 | def signal_callback(*a, **kw): |
| 29 | print "Got signal:" |
| 30 | print "intf: " + kw.get('intf', 'none') |
| 31 | print "path: " + kw.get('path', 'none') |
| 32 | print "member: " + kw.get('member', 'none') |
| 33 | |
| 34 | if __name__ == '__main__': |
| 35 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 36 | |
| 37 | bus = dbus.SystemBus() |
| 38 | |
Brad Bishop | a08884d | 2016-07-07 08:42:10 -0400 | [diff] [blame] | 39 | obj0 = bus.get_object(SERVICE_PREFIX + '.PythonService', |
Brad Bishop | b2571e2 | 2015-09-21 22:01:13 -0400 | [diff] [blame] | 40 | BASE_OBJ_PATH + 'path0/PythonObj') |
Brad Bishop | a08884d | 2016-07-07 08:42:10 -0400 | [diff] [blame] | 41 | obj1 = bus.get_object(SERVICE_PREFIX + '.PythonService', |
Brad Bishop | b2571e2 | 2015-09-21 22:01:13 -0400 | [diff] [blame] | 42 | BASE_OBJ_PATH + 'path1/PythonObj') |
| 43 | echo0= dbus.Interface(obj0, |
| 44 | dbus_interface=IFACE_PREFIX + '.Echo') |
| 45 | echo1= dbus.Interface(obj0, |
| 46 | dbus_interface=IFACE_PREFIX + '.Echo') |
| 47 | |
| 48 | print "Invoking Echo methods...." |
| 49 | print(echo0.Echo("hello")) |
| 50 | print(echo1.Echo("there")) |
| 51 | |
| 52 | bus.add_signal_receiver(signal_callback, interface_keyword = 'intf', |
| 53 | path_keyword = 'path', |
| 54 | member_keyword = 'member') |
| 55 | |
| 56 | print "Waiting for signals... (call a sample method to see something here)" |
| 57 | print "Press Ctrl^C to quit" |
| 58 | mainloop = gobject.MainLoop() |
| 59 | |
| 60 | mainloop.run() |