Received SMS with python
Dan Williams
dcbw at redhat.com
Fri Sep 22 16:10:18 UTC 2017
On Fri, 2017-09-22 at 14:26 +0100, Colin Helliwell wrote:
> > On 21 September 2017 at 11:54 Colin Helliwell <colin.helliwell at ln-s
> > ystems.com> wrote:
> >
> > > On 19 September 2017 at 17:39 Aleksander Morgado <aleksander at alek
> > > sander.es> wrote:
> > >
> > > ...
> > >
> > > Another (better?) option would be to listen to updates in the
> > > "Messages" property itself. E.g. just
> > > msging.connect('notify::messages',...) and setup a callback that
> > > will
> > > get called any time the Messages property is updated (and you can
> > > call
> > > list_sync() inside the callback). If you get a clean example with
> > > that
> > > logic we could add it to the examples/ directory in git ;)
> >
> > A first attempt attached - any critique welcome! (especially w.r.t.
> > cleanup or race hazards etc)
> >
> > I notice that I get the callback if the modem is disabled, but not
> > when it is re-enabled? Perhaps I'm missing something there, or
> > perhaps it doesn't matter?
> > Also, I'm seeing a message come and go - somewhere around deleting
> > a message and/or disabling/reenabling the modem. At first I thought
> > it was being deleted, but it does seem to reappear at a later
> > point. I've not yet pinned down a repeatable sequence (or even 100%
> > convinced myself I'm not imagining it).
> >
> > Next step would be to copy the messages and then delete from the
> > modem (to avoid filling the me storage) - since the actual
> > processing of them may take some time. I'd prefer to copy the whole
> > Sms object rather than just, say, the text - what's a safe way to
> > do that, across all eventualites?
>
> So, I've been looking for a way to copy/clone a whole
> ModemManager.Sms, but haven't been able to find anything in the API
> (?), so I've fallen back on copying out the essential 'properties'
> instead.
>
> I'm now deleting the messages [in the modem] after copying, and find
> that - in the start-up case - I also get a 'notify::messages'
> callback when *deleting* messages. Is there a way to examine deeper
> the detail of the notification?
Any time the list of messages has changed, you'll get a notification
for the 'messages' property of the Gobject. That includes deletion.
The property is a GStrv, which is basically an array of 'char*',
containing the D-Bus object paths of each SMS message. In python that
may literally just be an array of strings that you can iterate with
'for'.
Not sure what you'd specifically do with that information though,
typically you'd listen to the 'added' and 'deleted' signals to get
information on each specific message.
So for example, were you to delete a message in your code with
call_delete_sync() or whatever you're using, you'd get two signals from
the object, assuming you connect to them:
notify::messages (contains all SMS object paths except the deleted one)
deleted (contains the object path of the deleted message)
Once you have the object path, you can get the actual backing object
from it by calling the get_object() method on the MMManager object
(which is actually the g_dbus_object_manager_get_object() call of the
GDBusObjectManager interface that MMManager just implements).
Dan
More information about the ModemManager-devel
mailing list