PM: ShillProvider now provides the connection tethering mode.
This adds a connection tethering variable to the RealShillProvider. In
doing so, we:
* Query the default service attributes (type, tethering) eagerly, as
soon as a default service signal is received (but only if the default
service has actually changed).
* All variables are reduced to CopyVariable instances, migrating all
DBus communication logic into the RealShillProvider and eliminating
the ShillConnector helper class. This also allows us to turn variables
into contained members and initialize them during construction.
BUG=chromium:355732
TEST=Unit tests.
Change-Id: I8d9798075a4bd5b9e2cec65cb437d0018654d2c6
Reviewed-on: https://chromium-review.googlesource.com/193927
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/real_shill_provider.h b/policy_manager/real_shill_provider.h
index 13f0fe4..833e147 100644
--- a/policy_manager/real_shill_provider.h
+++ b/policy_manager/real_shill_provider.h
@@ -15,6 +15,7 @@
#include "update_engine/clock_interface.h"
#include "update_engine/dbus_wrapper_interface.h"
+#include "update_engine/policy_manager/generic_variables.h"
#include "update_engine/policy_manager/shill_provider.h"
using chromeos_update_engine::ClockInterface;
@@ -22,91 +23,51 @@
namespace chromeos_policy_manager {
-// A DBus connector for making all shill related calls.
-class ShillConnector {
- public:
- // Expected type for the PropertyChanged signal handler.
- typedef void (*PropertyChangedHandler)(DBusGProxy*, const char*, GValue*,
- void*);
-
- ShillConnector(DBusWrapperInterface* dbus,
- PropertyChangedHandler signal_handler, void* signal_data)
- : dbus_(dbus), signal_handler_(signal_handler),
- signal_data_(signal_data) {}
-
- ~ShillConnector();
-
- // Initializes the DBus connector. Returns |true| on success.
- bool Init();
-
- // Obtains the type of a network connection described by |service_path|,
- // storing it to |*conn_type_p|. Returns |true| on success; |false| on
- // failure, in which case no value is written.
- bool GetConnectionType(const std::string& service_path,
- ConnectionType* conn_type_p);
-
- // Issues a GetProperties call to shill's manager interface, storing the
- // result to |*result_p|. Returns |true| on success.
- bool GetManagerProperties(GHashTable** result_p) {
- return GetProperties(manager_proxy_, result_p);
- }
-
- // Converts a shill connection type string into a symbolic value.
- static ConnectionType ParseConnectionType(const char* str);
-
- private:
- // Issues a GetProperties call through a given |proxy|, storing the result to
- // |*result_p|. Returns |true| on success.
- bool GetProperties(DBusGProxy* proxy, GHashTable** result_p);
-
- struct ConnStrToType {
- const char *str;
- ConnectionType type;
- };
-
- // A mapping from shill connection type strings to enum values.
- static const ConnStrToType shill_conn_str_to_type[];
-
- // An initialization flag.
- bool is_init_ = false;
-
- // The DBus interface and connection, and a shill manager proxy.
- DBusWrapperInterface* dbus_;
- DBusGConnection* connection_ = NULL;
- DBusGProxy* manager_proxy_ = NULL;
-
- // The shill manager signal handler credentials.
- PropertyChangedHandler signal_handler_ = NULL;
- void* signal_data_ = NULL;
-
- // Return a DBus proxy for a given |path| and |interface| within shill.
- DBusGProxy* GetProxy(const char* path, const char* interface);
-
- DISALLOW_COPY_AND_ASSIGN(ShillConnector);
-};
-
// ShillProvider concrete implementation.
class RealShillProvider : public ShillProvider {
public:
RealShillProvider(DBusWrapperInterface* dbus, ClockInterface* clock)
: dbus_(dbus), clock_(clock) {}
+ virtual ~RealShillProvider();
+
virtual inline Variable<bool>* var_is_connected() override {
- return var_is_connected_.get();
+ return &var_is_connected_;
}
virtual inline Variable<ConnectionType>* var_conn_type() override {
- return var_conn_type_.get();
+ return &var_conn_type_;
+ }
+
+ virtual inline Variable<ConnectionTethering>* var_conn_tethering() override {
+ return &var_conn_tethering_;
}
virtual inline Variable<base::Time>* var_conn_last_changed() override {
- return var_conn_last_changed_.get();
+ return &var_conn_last_changed_;
}
+ // Helper methods for converting shill strings into symbolic values.
+ static ConnectionType ParseConnectionType(const char* type_str);
+ static ConnectionTethering ParseConnectionTethering(
+ const char* tethering_str);
+
protected:
virtual bool DoInit() override;
private:
+ // Default error strings for variables.
+ static const char* kConnStatusUnavailable;
+ static const char* kConnTypeUnavailable;
+ static const char* kConnTetheringUnavailable;
+
+ // Return a DBus proxy for a given |path| and |interface| within shill.
+ DBusGProxy* GetProxy(const char* path, const char* interface);
+
+ // Issues a GetProperties call through a given |proxy|, storing the result to
+ // |*result_p|. Returns true on success.
+ bool GetProperties(DBusGProxy* proxy, GHashTable** result_p);
+
// Process a default connection value, update last change time as needed.
bool ProcessDefaultService(GValue* value);
@@ -116,7 +77,6 @@
static void HandlePropertyChangedStatic(DBusGProxy* proxy, const char* name,
GValue* value, void* data);
-
// Whether the connection status has been properly initialized.
bool is_conn_status_init_ = false;
@@ -126,30 +86,39 @@
// The current connection status.
bool is_connected_;
+ // The default connection type and whether its value is valid.
+ ConnectionType conn_type_;
+ bool conn_type_is_valid_ = false;
+
+ // The default connection tethering mode and whether its value is valid.
+ ConnectionTethering conn_tethering_;
+ bool conn_tethering_is_valid_ = false;
+
// The current default service path, if connected.
std::string default_service_path_;
- // The last known type of the default connection.
- ConnectionType conn_type_ = ConnectionType::kUnknown;
-
- // Whether the last known connection type is valid.
- bool is_conn_type_valid_ = false;
-
- // A shill DBus connector.
- scoped_ptr<ShillConnector> connector_;
-
- // The DBus interface object (mockable).
+ // The DBus interface (mockable), connection, and a shill manager proxy.
DBusWrapperInterface* const dbus_;
+ DBusGConnection* connection_ = NULL;
+ DBusGProxy* manager_proxy_ = NULL;
// A clock abstraction (mockable).
ClockInterface* const clock_;
- // Pointers to all variable objects.
- scoped_ptr<Variable<bool>> var_is_connected_;
- scoped_ptr<Variable<ConnectionType>> var_conn_type_;
- scoped_ptr<Variable<base::Time>> var_conn_last_changed_;
+ // The provider's variable.
+ CopyVariable<bool> var_is_connected_{
+ "is_connected", kVariableModePoll, is_connected_, &is_conn_status_init_,
+ kConnStatusUnavailable};
+ CopyVariable<ConnectionType> var_conn_type_{
+ "conn_type", kVariableModePoll, conn_type_, &conn_type_is_valid_,
+ kConnTypeUnavailable};
+ CopyVariable<ConnectionTethering> var_conn_tethering_{
+ "conn_tethering", kVariableModePoll, conn_tethering_,
+ &conn_tethering_is_valid_, kConnTetheringUnavailable};
+ CopyVariable<base::Time> var_conn_last_changed_{
+ "conn_last_changed", kVariableModePoll, conn_last_changed_,
+ &is_conn_status_init_, kConnStatusUnavailable};
- friend class ConnTypeVariable;
DISALLOW_COPY_AND_ASSIGN(RealShillProvider);
};