diff options
Diffstat (limited to 'test/sms-get.py')
-rwxr-xr-x | test/sms-get.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/sms-get.py b/test/sms-get.py new file mode 100755 index 000000000..c302459e3 --- /dev/null +++ b/test/sms-get.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# +# 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) 2009 Novell, Inc. +# Copyright (C) 2009 - 2012 Red Hat, Inc. +# + +# An example on how to read SMS messages using ModemManager + +import sys +import dbus +import os + +MM_DBUS_SERVICE='org.freedesktop.ModemManager' +MM_DBUS_PATH='/org/freedesktop/ModemManager' +MM_DBUS_INTERFACE_MODEM='org.freedesktop.ModemManager.Modem' +MM_DBUS_INTERFACE_MODEM_SMS='org.freedesktop.ModemManager.Modem.Gsm.SMS' + +arglen = len(sys.argv) +if arglen != 2 and arglen != 3: + print "Usage: %s <modem path> [message #]" % sys.argv[0] + sys.exit(1) + +msgnum = None +if len(sys.argv) == 3: + msgnum = int(sys.argv[2]) + +objpath = sys.argv[1] +if objpath[:1] != '/': + objpath = "/org/freedesktop/ModemManager/Modems/" + str(objpath) + +# Create the modem properties proxy +bus = dbus.SystemBus() +proxy = bus.get_object(MM_DBUS_SERVICE, objpath) +modem = dbus.Interface(proxy, dbus_interface="org.freedesktop.DBus.Properties") + +# Make sure the modem is enabled first +if modem.Get(MM_DBUS_INTERFACE_MODEM, "Enabled") == False: + print "Modem is not enabled" + sys.exit(1) + +# Create the SMS interface proxy +sms = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM_SMS) + +msgs = sms.List() +print msgs |