> On 01 September 2017 at 17:17 Dan Williams <[email protected]> wrote: > > On Fri, 2017-09-01 at 10:51 -0500, Dan Williams wrote: > > > On Fri, 2017-09-01 at 14:26 +0100, [email protected] > > wrote: > > > > > I've been having a look at the modem-watcher-python example, and > > > would like > > > to do something similar - namely wait until the modem has > > > registered > > > on the > > > network and then grab the MCC/MNC. > > > Is there some sort of event I can hook for this (similar to what > > > the > > > example > > > does with ' object-added'), or do I just need to poll? > > > Thanks > > > > ModemWatcher.py has the modem watching stuff already. What you want > > to > > do is modify the on_object_added() method to: > > > > 1) check modem.get_state() >= ModemManager.ModemState.REGISTERED > > 2) if yes, then grab the MCC/MNC with something like: > > > > mccmnc = obj.get_modem_3gpp().get_operator_code() > > > > 3) if no, then connect to the 'state' property notifier: > > > > modem.connect('notify::state', self.modem_state_changed, obj) > > > > and then have a separate function that handles that change: > > > > def modem_state_changed(self, modem, prop, obj): > > if modem.get_state() >= ModemManager.ModemState.REGISTERED: > > mccmnc = obj.get_modem_3gpp().get_operator_code() > > ... >
Thanks for the pointers, Dan. But isn't there a risk of race hazard (the state change) in between #1 and #3? In which case I was thinking (bearing in mind it's dinner time on a Friday...): Connect to the 'state' property notifier *straight away* in the on_object_added() method; *then* also check modem.get_state() in there too. [Provided I'm ok with the resultant code being potentially called twice] _______________________________________________ ModemManager-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel
