blob: 586431900522cbb8c99d816c0b602aee53f35e22 [file] [log] [blame]
Gilad Arnold55f39b72014-01-28 12:51:45 -08001// 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 Arnold48415f12014-06-27 07:10:58 -07005#ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_
Gilad Arnold55f39b72014-01-28 12:51:45 -08007
Gilad Arnold5ef9c482014-03-03 13:51:02 -08008// 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 Vakulenko75039d72014-03-25 12:36:28 -070014#include <base/time/time.h>
Gilad Arnold5ef9c482014-03-03 13:51:02 -080015
16#include "update_engine/clock_interface.h"
Alex Deymo30534502015-07-20 15:06:33 -070017#include "update_engine/dbus_proxies.h"
18#include "update_engine/shill_proxy_interface.h"
Alex Deymo63784a52014-05-28 10:46:14 -070019#include "update_engine/update_manager/generic_variables.h"
20#include "update_engine/update_manager/shill_provider.h"
Gilad Arnold55f39b72014-01-28 12:51:45 -080021
Alex Deymo63784a52014-05-28 10:46:14 -070022namespace chromeos_update_manager {
Gilad Arnold55f39b72014-01-28 12:51:45 -080023
24// ShillProvider concrete implementation.
Gilad Arnold55f39b72014-01-28 12:51:45 -080025class RealShillProvider : public ShillProvider {
26 public:
Alex Deymo30534502015-07-20 15:06:33 -070027 RealShillProvider(chromeos_update_engine::ShillProxyInterface* shill_proxy,
28 chromeos_update_engine::ClockInterface* clock)
29 : shill_proxy_(shill_proxy), clock_(clock) {}
Gilad Arnold55f39b72014-01-28 12:51:45 -080030
Alex Deymo30534502015-07-20 15:06:33 -070031 ~RealShillProvider() override = default;
Gilad Arnoldef120fa2014-04-09 12:52:10 -070032
Alex Deymo42c30c32014-04-24 18:41:18 -070033 // Initializes the provider and returns whether it succeeded.
34 bool Init();
35
Alex Vakulenko157fe302014-08-11 15:59:58 -070036 Variable<bool>* var_is_connected() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070037 return &var_is_connected_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070038 }
39
Alex Vakulenko157fe302014-08-11 15:59:58 -070040 Variable<ConnectionType>* var_conn_type() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070041 return &var_conn_type_;
42 }
43
Alex Vakulenko157fe302014-08-11 15:59:58 -070044 Variable<ConnectionTethering>* var_conn_tethering() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070045 return &var_conn_tethering_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070046 }
47
Alex Vakulenko157fe302014-08-11 15:59:58 -070048 Variable<base::Time>* var_conn_last_changed() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070049 return &var_conn_last_changed_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070050 }
51
Gilad Arnoldef120fa2014-04-09 12:52:10 -070052 // Helper methods for converting shill strings into symbolic values.
Alex Deymo30534502015-07-20 15:06:33 -070053 static ConnectionType ParseConnectionType(const std::string& type_str);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070054 static ConnectionTethering ParseConnectionTethering(
Alex Deymo30534502015-07-20 15:06:33 -070055 const std::string& tethering_str);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070056
David Zeuthen21716e22014-04-23 15:42:05 -070057 private:
Alex Deymo30534502015-07-20 15:06:33 -070058 // A handler for ManagerProxy.PropertyChanged signal.
59 void OnManagerPropertyChanged(const std::string& name,
60 const chromeos::Any& value);
Gilad Arnoldef120fa2014-04-09 12:52:10 -070061
Alex Deymo30534502015-07-20 15:06:33 -070062 // 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 Arnoldef120fa2014-04-09 12:52:10 -070066
Alex Deymo30534502015-07-20 15:06:33 -070067 // 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 Arnoldbeb39e92014-03-11 11:34:50 -070070
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070071 // The current default service path, if connected.
72 std::string default_service_path_;
73
Alex Deymo30534502015-07-20 15:06:33 -070074 // The mockable interface to access the shill DBus proxies, owned by the
75 // caller.
76 chromeos_update_engine::ShillProxyInterface* shill_proxy_;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080077
78 // A clock abstraction (mockable).
Alex Deymo30534502015-07-20 15:06:33 -070079 chromeos_update_engine::ClockInterface* const clock_;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080080
Gilad Arnoldd3df25f2014-04-22 08:39:48 -070081 // 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 Arnolddf3dd242014-04-09 07:15:51 -070086
Gilad Arnold55f39b72014-01-28 12:51:45 -080087 DISALLOW_COPY_AND_ASSIGN(RealShillProvider);
88};
89
Alex Deymo63784a52014-05-28 10:46:14 -070090} // namespace chromeos_update_manager
Gilad Arnold55f39b72014-01-28 12:51:45 -080091
Gilad Arnold48415f12014-06-27 07:10:58 -070092#endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_