blob: 9c15700ab6c3f72cb63a06f1516b390bb96f17c9 [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 Arnold2cbb3852014-03-07 12:40:50 -08005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_REAL_SHILL_PROVIDER_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_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"
17#include "update_engine/dbus_wrapper_interface.h"
Gilad Arnoldef120fa2014-04-09 12:52:10 -070018#include "update_engine/policy_manager/generic_variables.h"
Gilad Arnold55f39b72014-01-28 12:51:45 -080019#include "update_engine/policy_manager/shill_provider.h"
20
Gilad Arnold5ef9c482014-03-03 13:51:02 -080021using chromeos_update_engine::ClockInterface;
22using chromeos_update_engine::DBusWrapperInterface;
Gilad Arnold55f39b72014-01-28 12:51:45 -080023
24namespace chromeos_policy_manager {
25
26// ShillProvider concrete implementation.
Gilad Arnold55f39b72014-01-28 12:51:45 -080027class RealShillProvider : public ShillProvider {
28 public:
Gilad Arnold5ef9c482014-03-03 13:51:02 -080029 RealShillProvider(DBusWrapperInterface* dbus, ClockInterface* clock)
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070030 : dbus_(dbus), clock_(clock) {}
Gilad Arnold55f39b72014-01-28 12:51:45 -080031
Gilad Arnoldef120fa2014-04-09 12:52:10 -070032 virtual ~RealShillProvider();
33
David Zeuthen21716e22014-04-23 15:42:05 -070034 virtual Variable<bool>* var_is_connected() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070035 return &var_is_connected_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070036 }
37
David Zeuthen21716e22014-04-23 15:42:05 -070038 virtual Variable<ConnectionType>* var_conn_type() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070039 return &var_conn_type_;
40 }
41
David Zeuthen21716e22014-04-23 15:42:05 -070042 virtual Variable<ConnectionTethering>* var_conn_tethering() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070043 return &var_conn_tethering_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070044 }
45
David Zeuthen21716e22014-04-23 15:42:05 -070046 virtual Variable<base::Time>* var_conn_last_changed() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070047 return &var_conn_last_changed_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070048 }
49
Gilad Arnoldef120fa2014-04-09 12:52:10 -070050 // Helper methods for converting shill strings into symbolic values.
51 static ConnectionType ParseConnectionType(const char* type_str);
52 static ConnectionTethering ParseConnectionTethering(
53 const char* tethering_str);
54
David Zeuthen21716e22014-04-23 15:42:05 -070055 private:
Gilad Arnolddf3dd242014-04-09 07:15:51 -070056 virtual bool DoInit() override;
Gilad Arnold55f39b72014-01-28 12:51:45 -080057
Gilad Arnoldef120fa2014-04-09 12:52:10 -070058 // Return a DBus proxy for a given |path| and |interface| within shill.
59 DBusGProxy* GetProxy(const char* path, const char* interface);
60
61 // Issues a GetProperties call through a given |proxy|, storing the result to
62 // |*result_p|. Returns true on success.
63 bool GetProperties(DBusGProxy* proxy, GHashTable** result_p);
64
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070065 // Process a default connection value, update last change time as needed.
66 bool ProcessDefaultService(GValue* value);
67
68 // A handler for manager PropertyChanged signal, and a static version.
69 void HandlePropertyChanged(DBusGProxy* proxy, const char *name,
70 GValue* value);
71 static void HandlePropertyChangedStatic(DBusGProxy* proxy, const char* name,
72 GValue* value, void* data);
73
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070074 // The current default service path, if connected.
75 std::string default_service_path_;
76
Gilad Arnoldef120fa2014-04-09 12:52:10 -070077 // The DBus interface (mockable), connection, and a shill manager proxy.
Gilad Arnold5ef9c482014-03-03 13:51:02 -080078 DBusWrapperInterface* const dbus_;
Gilad Arnoldef120fa2014-04-09 12:52:10 -070079 DBusGConnection* connection_ = NULL;
80 DBusGProxy* manager_proxy_ = NULL;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080081
82 // A clock abstraction (mockable).
83 ClockInterface* const clock_;
84
Gilad Arnoldd3df25f2014-04-22 08:39:48 -070085 // The provider's variables.
86 AsyncCopyVariable<bool> var_is_connected_{"is_connected"};
87 AsyncCopyVariable<ConnectionType> var_conn_type_{"conn_type"};
88 AsyncCopyVariable<ConnectionTethering> var_conn_tethering_{"conn_tethering"};
89 AsyncCopyVariable<base::Time> var_conn_last_changed_{"conn_last_changed"};
Gilad Arnolddf3dd242014-04-09 07:15:51 -070090
Gilad Arnold55f39b72014-01-28 12:51:45 -080091 DISALLOW_COPY_AND_ASSIGN(RealShillProvider);
92};
93
94} // namespace chromeos_policy_manager
95
Gilad Arnold2cbb3852014-03-07 12:40:50 -080096#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_REAL_SHILL_PROVIDER_H_