Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_SHILL_DAEMON_H_ |
| 6 | #define SHILL_SHILL_DAEMON_H_ |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 8 | #include <memory> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 9 | #include <string> |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 10 | #include <vector> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 11 | |
Paul Stewart | ca32474 | 2014-08-29 14:41:59 -0700 | [diff] [blame] | 12 | #include "shill/control_interface.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 13 | #include "shill/event_dispatcher.h" |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 14 | #include "shill/glib.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 15 | #include "shill/manager.h" |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 16 | |
| 17 | #if !defined(DISABLE_WIFI) |
Ben Chan | d6a8b51 | 2014-11-18 10:45:15 -0800 | [diff] [blame] | 18 | #include "shill/wifi/callback80211_metrics.h" |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 19 | #endif // DISABLE_WIFI |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | |
| 21 | namespace shill { |
| 22 | |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 23 | class Config; |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 24 | class DHCPProvider; |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 25 | class Error; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 26 | class GLib; |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 27 | class Metrics; |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 28 | class RoutingTable; |
| 29 | class RTNLHandler; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 30 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 31 | #if !defined(DISABLE_WIFI) |
| 32 | class NetlinkManager; |
| 33 | #endif // DISABLE_WIFI |
| 34 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | class Daemon { |
| 36 | public: |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 37 | // Run-time settings retrieved from command line. |
| 38 | struct Settings { |
| 39 | Settings() |
| 40 | : ignore_unknown_ethernet(false), |
| 41 | minimum_mtu(0), |
| 42 | passive_mode(false), |
| 43 | use_portal_list(false) {} |
| 44 | std::string accept_hostname_from; |
| 45 | std::string default_technology_order; |
| 46 | std::vector<std::string> device_blacklist; |
| 47 | std::vector<std::string> dhcpv6_enabled_devices; |
| 48 | bool ignore_unknown_ethernet; |
| 49 | int minimum_mtu; |
| 50 | bool passive_mode; |
| 51 | std::string portal_list; |
| 52 | std::string prepend_dns_servers; |
| 53 | bool use_portal_list; |
| 54 | }; |
| 55 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 56 | Daemon(Config* config, ControlInterface* control); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 57 | ~Daemon(); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 58 | |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 59 | // Apply run-time settings to the manager. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 60 | void ApplySettings(const Settings& settings); |
Peter Qiu | 1d499ed | 2015-01-30 16:01:27 -0800 | [diff] [blame] | 61 | |
Darin Petkov | 3c5e4dc | 2012-04-02 14:44:27 +0200 | [diff] [blame] | 62 | // Main for connection manager. Starts main process and holds event loop. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 63 | void Run(); |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 64 | |
| 65 | // Starts the termination actions in the manager. |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 66 | void Quit(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 67 | |
| 68 | private: |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 69 | friend class ShillDaemonTest; |
| 70 | |
Ben Chan | a3ac096 | 2014-06-12 01:46:18 -0700 | [diff] [blame] | 71 | // Called when the termination actions are completed. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 72 | void TerminationActionsCompleted(const Error& error); |
Ben Chan | a3ac096 | 2014-06-12 01:46:18 -0700 | [diff] [blame] | 73 | |
| 74 | // Calls Stop() and then causes the dispatcher message loop to terminate and |
| 75 | // return to the main function which started the daemon. |
| 76 | void StopAndReturnToMain(); |
| 77 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 78 | void Start(); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 79 | void Stop(); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 80 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 81 | Config* config_; |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 82 | std::unique_ptr<ControlInterface> control_; |
Ben Chan | b7bf216 | 2014-06-12 02:12:28 -0700 | [diff] [blame] | 83 | EventDispatcher dispatcher_; |
| 84 | GLib glib_; |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 85 | std::unique_ptr<Metrics> metrics_; |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 86 | RTNLHandler* rtnl_handler_; |
| 87 | RoutingTable* routing_table_; |
| 88 | DHCPProvider* dhcp_provider_; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 89 | #if !defined(DISABLE_WIFI) |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 90 | NetlinkManager* netlink_manager_; |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 91 | Callback80211Metrics callback80211_metrics_; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 92 | #endif // DISABLE_WIFI |
| 93 | std::unique_ptr<Manager> manager_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace shill |
| 97 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 98 | #endif // SHILL_SHILL_DAEMON_H_ |