bluetooth: Refactor device validity management

There are several intertwined changes that I couldn't separate into
nicer commits. This is mostly just refactoring, but this also fixes
a bug: the old code set the device valid in parse_device_properties()
even if the device's adapter was invalid (had NULL address).

To improve the clarity of the code, I split the device_info_valid
variable into two booleans: properties_received and valid.

I added function device_update_valid() that checks all conditions that
affect the device validity. The function can then be called from any
place where something changes that potentially affects the device
validity. However, currently the only validity-affecting thing that
can change is the device adapter, so device_update_valid() is only
called from set_device_adapter().

I added the aforementioned set_device_adapter() function so that
whenever the adapter is set, the device validity gets updated
automatically.

The new properties_received variable allowed me to remove the
is_property_update function parameters.
This commit is contained in:
Tanu Kaskinen 2014-05-24 12:56:35 +03:00
parent a61d065dcc
commit de0d803e3c
2 changed files with 71 additions and 52 deletions

View file

@ -76,7 +76,9 @@ struct pa_bluetooth_device {
pa_bluetooth_discovery *discovery;
pa_bluetooth_adapter *adapter;
int device_info_valid; /* 0: no results yet; 1: good results; -1: bad results ... */
bool properties_received;
bool tried_to_link_with_adapter;
bool valid;
/* Device information */
char *path;