diff options
author | Dan Williams <dcbw@redhat.com> | 2011-09-30 14:38:11 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-09-30 14:38:11 -0500 |
commit | 7a7014330cde29fedb64dff772f53e44c45516cd (patch) | |
tree | d0e2100847a6bb5ac6d3a8eaef07800178201648 /test | |
parent | 30a67862ecddf2ee9c29ea933d473567988b1769 (diff) |
examples: add example of auto-enabling modems
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 3 | ||||
-rwxr-xr-x | test/modem-autoenable.py | 50 |
2 files changed, 52 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 8249131f..ff091ffd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -26,5 +26,6 @@ EXTRA_DIST = \ list-modems.py \ location.py \ mm-send-sms.py \ - send-pin.py + send-pin.py \ + modem-autoenable.py diff --git a/test/modem-autoenable.py b/test/modem-autoenable.py new file mode 100755 index 00000000..d637d3ff --- /dev/null +++ b/test/modem-autoenable.py @@ -0,0 +1,50 @@ +#!/usr/bin/python +# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details: +# +# Copyright (C) 2011 Red Hat, Inc. +# + +import gobject, sys, dbus +from dbus.mainloop.glib import DBusGMainLoop + +DBusGMainLoop(set_as_default=True) + +MM_DBUS_SERVICE='org.freedesktop.ModemManager' +MM_DBUS_PATH='/org/freedesktop/ModemManager' +MM_DBUS_INTERFACE='org.freedesktop.ModemManager' +MM_DBUS_INTERFACE_MODEM='org.freedesktop.ModemManager.Modem' + +def modemAdded(modem_path): + proxy = bus.get_object(MM_DBUS_SERVICE, modem_path) + modem = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM) + modem.Enable (True) + +bus = dbus.SystemBus() + +manager_proxy = bus.get_object(MM_DBUS_SERVICE, MM_DBUS_PATH) +manager_iface = dbus.Interface(manager_proxy, dbus_interface=MM_DBUS_INTERFACE) + +# Enable modems that are already known +for m in manager_iface.EnumerateDevices(): + modemAdded(m) + +# Listen for new modems +manager_iface.connect_to_signal("DeviceAdded", modemAdded) + +# Start the mainloop and listen +loop = gobject.MainLoop() +try: + loop.run() +except KeyboardInterrupt: + pass +sys.exit(0) |