blob: 382aa1e7fa8c3a2c941cda77531d9f90307577a4 [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"
17#include "update_engine/dbus_wrapper_interface.h"
Alex Deymo63784a52014-05-28 10:46:14 -070018#include "update_engine/update_manager/generic_variables.h"
19#include "update_engine/update_manager/shill_provider.h"
Gilad Arnold55f39b72014-01-28 12:51:45 -080020
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
Alex Deymo63784a52014-05-28 10:46:14 -070024namespace chromeos_update_manager {
Gilad Arnold55f39b72014-01-28 12:51:45 -080025
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
Alex Deymo42c30c32014-04-24 18:41:18 -070034 // Initializes the provider and returns whether it succeeded.
35 bool Init();
36
Alex Vakulenko157fe302014-08-11 15:59:58 -070037 Variable<bool>* var_is_connected() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070038 return &var_is_connected_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070039 }
40
Alex Vakulenko157fe302014-08-11 15:59:58 -070041 Variable<ConnectionType>* var_conn_type() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070042 return &var_conn_type_;
43 }
44
Alex Vakulenko157fe302014-08-11 15:59:58 -070045 Variable<ConnectionTethering>* var_conn_tethering() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070046 return &var_conn_tethering_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070047 }
48
Alex Vakulenko157fe302014-08-11 15:59:58 -070049 Variable<base::Time>* var_conn_last_changed() override {
Gilad Arnoldef120fa2014-04-09 12:52:10 -070050 return &var_conn_last_changed_;
Gilad Arnolddf3dd242014-04-09 07:15:51 -070051 }
52
Gilad Arnoldef120fa2014-04-09 12:52:10 -070053 // 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 Zeuthen21716e22014-04-23 15:42:05 -070058 private:
Gilad Arnoldef120fa2014-04-09 12:52:10 -070059 // 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 Arnoldbeb39e92014-03-11 11:34:50 -070066 // 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 Arnoldbeb39e92014-03-11 11:34:50 -070075 // The current default service path, if connected.
76 std::string default_service_path_;
77
Gilad Arnoldef120fa2014-04-09 12:52:10 -070078 // The DBus interface (mockable), connection, and a shill manager proxy.
Gilad Arnold5ef9c482014-03-03 13:51:02 -080079 DBusWrapperInterface* const dbus_;
Gilad Arnoldef120fa2014-04-09 12:52:10 -070080 DBusGConnection* connection_ = NULL;
81 DBusGProxy* manager_proxy_ = NULL;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080082
83 // A clock abstraction (mockable).
84 ClockInterface* const clock_;
85
Gilad Arnoldd3df25f2014-04-22 08:39:48 -070086 // 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 Arnolddf3dd242014-04-09 07:15:51 -070091
Gilad Arnold55f39b72014-01-28 12:51:45 -080092 DISALLOW_COPY_AND_ASSIGN(RealShillProvider);
93};
94
Alex Deymo63784a52014-05-28 10:46:14 -070095} // namespace chromeos_update_manager
Gilad Arnold55f39b72014-01-28 12:51:45 -080096
Gilad Arnold48415f12014-06-27 07:10:58 -070097#endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_SHILL_PROVIDER_H_