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 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 5 | #include "shill/shill_daemon.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 6 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 7 | #include <stdio.h> |
| 8 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 9 | #include <string> |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 10 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 11 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 12 | #include <base/file_path.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 13 | #include <base/logging.h> |
| 14 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 15 | #include "shill/dhcp_provider.h" |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 16 | #include "shill/error.h" |
Darin Petkov | 3c5e4dc | 2012-04-02 14:44:27 +0200 | [diff] [blame] | 17 | #include "shill/nss.h" |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 18 | #include "shill/proxy_factory.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 19 | #include "shill/routing_table.h" |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 20 | #include "shill/rtnl_handler.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 21 | #include "shill/shill_config.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 23 | using std::string; |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 24 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 25 | |
| 26 | namespace shill { |
| 27 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 28 | Daemon::Daemon(Config *config, ControlInterface *control) |
| 29 | : config_(config), |
| 30 | control_(control), |
Darin Petkov | 3c5e4dc | 2012-04-02 14:44:27 +0200 | [diff] [blame] | 31 | nss_(NSS::GetInstance()), |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 32 | proxy_factory_(ProxyFactory::GetInstance()), |
| 33 | rtnl_handler_(RTNLHandler::GetInstance()), |
| 34 | routing_table_(RoutingTable::GetInstance()), |
| 35 | dhcp_provider_(DHCPProvider::GetInstance()), |
| 36 | manager_(new Manager(control_, |
| 37 | &dispatcher_, |
| 38 | &metrics_, |
| 39 | &glib_, |
| 40 | config->GetRunDirectory(), |
| 41 | config->GetStorageDirectory(), |
| 42 | config->GetUserStorageDirectoryFormat())) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 43 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 44 | Daemon::~Daemon() {} |
| 45 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 46 | void Daemon::AddDeviceToBlackList(const string &device_name) { |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 47 | manager_->AddDeviceToBlackList(device_name); |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 50 | void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) { |
| 51 | Error error; |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 52 | manager_->set_startup_profiles(profile_name_list); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 55 | void Daemon::Run() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 56 | Start(); |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 57 | VLOG(1) << "Running main loop."; |
Chris Masone | c5b392e | 2011-05-14 16:31:01 -0700 | [diff] [blame] | 58 | dispatcher_.DispatchForever(); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 59 | VLOG(1) << "Exited main loop."; |
| 60 | Stop(); |
| 61 | } |
| 62 | |
| 63 | void Daemon::Quit() { |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 64 | dispatcher_.PostTask(MessageLoop::QuitClosure()); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 67 | void Daemon::Start() { |
| 68 | glib_.TypeInit(); |
Darin Petkov | 3c5e4dc | 2012-04-02 14:44:27 +0200 | [diff] [blame] | 69 | nss_->Init(&glib_); |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 70 | proxy_factory_->Init(); |
| 71 | rtnl_handler_->Start(&dispatcher_, &sockets_); |
| 72 | routing_table_->Start(); |
| 73 | dhcp_provider_->Init(control_, &dispatcher_, &glib_); |
| 74 | manager_->Start(); |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void Daemon::Stop() { |
Thieu Le | fb46caf | 2012-03-08 11:57:15 -0800 | [diff] [blame] | 78 | manager_->Stop(); |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 79 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 80 | |
| 81 | } // namespace shill |