summaryrefslogtreecommitdiff
path: root/test/sms-get.py
blob: c302459e3ad08785c2728d900f5922d99848bb4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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