Python bindings

Aleksander Morgado aleksander at lanedo.com
Sun Nov 18 08:04:32 PST 2012


>    I think there's something odd about the return values that indicate 
> success/failure. For instance:
> 
> def start_network_ready(client, result, arg):                                   
>     m = client.start_network_finish(result)                                     
>     print "attempt finished"                                                    
>     print m.get_result()                                                        
> 
> def device_allocate_wds_client_ready(device, result, arg):                      
>     client = device.allocate_client_finish(result)                              
>     print "allocated"                                                                                
>                                                                                 
>     info = Qmi.MessageWdsStartNetworkInput()                                    
>     info.set_apn("internet2")                                                   
>     info.set_username("web")                                                    
>     info.set_password("web")                                                    
>     client.start_network(info, 15, None, start_network_ready, None)             
> 
> I try to connect to the network and I wish to print the result. If it 
> connected, then True is returned. If it failed I get an exception e.g.
> 
> Traceback (most recent call last):
>   File "qmi.py", line 98, in start_network_ready
>     print m.get_result()
>   File "/usr/lib/python2.7/site-packages/gi/types.py", line 43, in function
>     return info.invoke(*args, **kwargs)
> gi._glib.GError: QMI protocol error (14): 'CallFailed'
> 
> Is that what you expect to happen? Usually in Python we'd either use True / 
> False else use try / except, but rarely mix the two. At this point I can't see 
> how False could ever be returned to the caller.

There are two levels of error in the operations:

 (a) Error in the QMI transaction itself; generated by the internal code
of libqmi; e.g. version of the QMI request is newer than the one
supported by the device (when opening with
QMI_DEVICE_OPEN_FLAGS_VERSION_INFO).

 (b) Error returned by the QMI device as a result of the QMI operation;
the QMI transaction itself is correct here. E.g. Couldn't connect.

In other words:
  * client.start_network_finish() will return NULL in case (a)
  * m.get_result() will return FALSE in case (b).

Merging both cases in the same logic, e.g. returning a GError in
finish() for both cases, didn't help as for case (b) you really want to
have the output bundle returned, in other to get additional TLVs that
you may have during failed cases (e.g. call end reason).

Cheers!

-- 
Aleksander


More information about the libqmi-devel mailing list