examples: add sms-watch-python
Add an example that watches for and prints all SMS messages of all modems. Signed-off-by: Dan Williams <dan@ioncontrol.co>
This commit is contained in:
committed by
Aleksander Morgado
parent
bc7198df8a
commit
c320e50753
@@ -28,7 +28,7 @@ class ModemWatcher:
|
||||
The ModemWatcher class is responsible for monitoring ModemManager.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, modem_cb):
|
||||
# Flag for initial logs
|
||||
self.initializing = True
|
||||
# Setup DBus monitoring
|
||||
@@ -40,6 +40,7 @@ class ModemWatcher:
|
||||
# IDs for added/removed signals
|
||||
self.object_added_id = 0
|
||||
self.object_removed_id = 0
|
||||
self.modem_callback = modem_cb
|
||||
# Follow availability of the ModemManager process
|
||||
self.available = False
|
||||
self.manager.connect('notify::name-owner', self.on_name_owner)
|
||||
@@ -109,6 +110,8 @@ class ModemWatcher:
|
||||
obj.get_object_path())
|
||||
else:
|
||||
modem.connect('state-changed', self.on_modem_state_updated)
|
||||
if self.modem_callback != None:
|
||||
self.modem_callback(obj, True)
|
||||
|
||||
def on_object_removed(self, manager, obj):
|
||||
"""
|
||||
@@ -116,3 +119,6 @@ class ModemWatcher:
|
||||
"""
|
||||
print('[ModemWatcher] %s: modem unmanaged by ModemManager' %
|
||||
obj.get_object_path())
|
||||
if self.modem_callback != None:
|
||||
self.modem_callback(obj, False)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ def signal_handler(loop):
|
||||
def main():
|
||||
"""Main routine."""
|
||||
# Create modem watcher
|
||||
ModemWatcher.ModemWatcher()
|
||||
ModemWatcher.ModemWatcher(None)
|
||||
|
||||
# Main loop
|
||||
main_loop = GLib.MainLoop()
|
||||
|
||||
Reference in New Issue
Block a user