Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |
| 6 | #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 7 | |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 8 | // TODO(garnold) Much of the functionality in this module was adapted from the |
| 9 | // update engine's connection_manager. We need to make sure to deprecate use of |
| 10 | // connection manager when the time comes. |
| 11 | |
| 12 | #include <string> |
| 13 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 14 | #include <base/time/time.h> |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 15 | |
| 16 | #include "update_engine/clock_interface.h" |
| 17 | #include "update_engine/dbus_wrapper_interface.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 18 | #include "update_engine/update_manager/generic_variables.h" |
| 19 | #include "update_engine/update_manager/shill_provider.h" |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 20 | |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 21 | using chromeos_update_engine::ClockInterface; |
| 22 | using chromeos_update_engine::DBusWrapperInterface; |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 23 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 24 | namespace chromeos_update_manager { |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 25 | |
| 26 | // ShillProvider concrete implementation. |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 27 | class RealShillProvider : public ShillProvider { |
| 28 | public: |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 29 | RealShillProvider(DBusWrapperInterface* dbus, ClockInterface* clock) |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 30 | : dbus_(dbus), clock_(clock) {} |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 31 | |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 32 | virtual ~RealShillProvider(); |
| 33 | |
Alex Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 34 | // Initializes the provider and returns whether it succeeded. |
| 35 | bool Init(); |
| 36 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 37 | Variable<bool>* var_is_connected() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 38 | return &var_is_connected_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 41 | Variable<ConnectionType>* var_conn_type() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 42 | return &var_conn_type_; |
| 43 | } |
| 44 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 45 | Variable<ConnectionTethering>* var_conn_tethering() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 46 | return &var_conn_tethering_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 49 | Variable<base::Time>* var_conn_last_changed() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 50 | return &var_conn_last_changed_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 53 | // Helper methods for converting shill strings into symbolic values. |
| 54 | static ConnectionType ParseConnectionType(const char* type_str); |
| 55 | static ConnectionTethering ParseConnectionTethering( |
| 56 | const char* tethering_str); |
| 57 | |
David Zeuthen | 21716e2 | 2014-04-23 15:42:05 -0700 | [diff] [blame] | 58 | private: |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 59 | // Return a DBus proxy for a given |path| and |interface| within shill. |
| 60 | DBusGProxy* GetProxy(const char* path, const char* interface); |
| 61 | |
| 62 | // Issues a GetProperties call through a given |proxy|, storing the result to |
| 63 | // |*result_p|. Returns true on success. |
| 64 | bool GetProperties(DBusGProxy* proxy, GHashTable** result_p); |
| 65 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 66 | // Process a default connection value, update last change time as needed. |
| 67 | bool ProcessDefaultService(GValue* value); |
| 68 | |
| 69 | // A handler for manager PropertyChanged signal, and a static version. |
| 70 | void HandlePropertyChanged(DBusGProxy* proxy, const char *name, |
| 71 | GValue* value); |
| 72 | static void HandlePropertyChangedStatic(DBusGProxy* proxy, const char* name, |
| 73 | GValue* value, void* data); |
| 74 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 75 | // The current default service path, if connected. |
| 76 | std::string default_service_path_; |
| 77 | |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 78 | // The DBus interface (mockable), connection, and a shill manager proxy. |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 79 | DBusWrapperInterface* const dbus_; |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 80 | DBusGConnection* connection_ = NULL; |
| 81 | DBusGProxy* manager_proxy_ = NULL; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 82 | |
| 83 | // A clock abstraction (mockable). |
| 84 | ClockInterface* const clock_; |
| 85 | |
Gilad Arnold | d3df25f | 2014-04-22 08:39:48 -0700 | [diff] [blame] | 86 | // The provider's variables. |
| 87 | AsyncCopyVariable<bool> var_is_connected_{"is_connected"}; |
| 88 | AsyncCopyVariable<ConnectionType> var_conn_type_{"conn_type"}; |
| 89 | AsyncCopyVariable<ConnectionTethering> var_conn_tethering_{"conn_tethering"}; |
| 90 | AsyncCopyVariable<base::Time> var_conn_last_changed_{"conn_last_changed"}; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 91 | |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 92 | DISALLOW_COPY_AND_ASSIGN(RealShillProvider); |
| 93 | }; |
| 94 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 95 | } // namespace chromeos_update_manager |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 96 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 97 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |