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" |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 17 | #include "update_engine/dbus_proxies.h" |
| 18 | #include "update_engine/shill_proxy_interface.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 19 | #include "update_engine/update_manager/generic_variables.h" |
| 20 | #include "update_engine/update_manager/shill_provider.h" |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 21 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 22 | namespace chromeos_update_manager { |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 23 | |
| 24 | // ShillProvider concrete implementation. |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 25 | class RealShillProvider : public ShillProvider { |
| 26 | public: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 27 | RealShillProvider(chromeos_update_engine::ShillProxyInterface* shill_proxy, |
| 28 | chromeos_update_engine::ClockInterface* clock) |
| 29 | : shill_proxy_(shill_proxy), clock_(clock) {} |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 30 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 31 | ~RealShillProvider() override = default; |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 32 | |
Alex Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 33 | // Initializes the provider and returns whether it succeeded. |
| 34 | bool Init(); |
| 35 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 36 | Variable<bool>* var_is_connected() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 37 | return &var_is_connected_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 40 | Variable<ConnectionType>* var_conn_type() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 41 | return &var_conn_type_; |
| 42 | } |
| 43 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 44 | Variable<ConnectionTethering>* var_conn_tethering() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 45 | return &var_conn_tethering_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 48 | Variable<base::Time>* var_conn_last_changed() override { |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 49 | return &var_conn_last_changed_; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 52 | // Helper methods for converting shill strings into symbolic values. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 53 | static ConnectionType ParseConnectionType(const std::string& type_str); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 54 | static ConnectionTethering ParseConnectionTethering( |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 55 | const std::string& tethering_str); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 56 | |
David Zeuthen | 21716e2 | 2014-04-23 15:42:05 -0700 | [diff] [blame] | 57 | private: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 58 | // A handler for ManagerProxy.PropertyChanged signal. |
| 59 | void OnManagerPropertyChanged(const std::string& name, |
| 60 | const chromeos::Any& value); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 61 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 62 | // Called when the signal in ManagerProxy.PropertyChanged is connected. |
| 63 | void OnSignalConnected(const std::string& interface_name, |
| 64 | const std::string& signal_name, |
| 65 | bool successful); |
Gilad Arnold | ef120fa | 2014-04-09 12:52:10 -0700 | [diff] [blame] | 66 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 67 | // Get the connection and populate the type and tethering status of the given |
| 68 | // default connection. |
| 69 | bool ProcessDefaultService(const std::string& default_service_path); |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 70 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame] | 71 | // The current default service path, if connected. |
| 72 | std::string default_service_path_; |
| 73 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 74 | // The mockable interface to access the shill DBus proxies, owned by the |
| 75 | // caller. |
| 76 | chromeos_update_engine::ShillProxyInterface* shill_proxy_; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 77 | |
| 78 | // A clock abstraction (mockable). |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame^] | 79 | chromeos_update_engine::ClockInterface* const clock_; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 80 | |
Gilad Arnold | d3df25f | 2014-04-22 08:39:48 -0700 | [diff] [blame] | 81 | // The provider's variables. |
| 82 | AsyncCopyVariable<bool> var_is_connected_{"is_connected"}; |
| 83 | AsyncCopyVariable<ConnectionType> var_conn_type_{"conn_type"}; |
| 84 | AsyncCopyVariable<ConnectionTethering> var_conn_tethering_{"conn_tethering"}; |
| 85 | AsyncCopyVariable<base::Time> var_conn_last_changed_{"conn_last_changed"}; |
Gilad Arnold | df3dd24 | 2014-04-09 07:15:51 -0700 | [diff] [blame] | 86 | |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(RealShillProvider); |
| 88 | }; |
| 89 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 90 | } // namespace chromeos_update_manager |
Gilad Arnold | 55f39b7 | 2014-01-28 12:51:45 -0800 | [diff] [blame] | 91 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 92 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_ |