Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 17 | #include "shill/proxy_factory.h" |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 18 | #include "shill/rtnl_handler.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 19 | #include "shill/shill_config.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 21 | using std::string; |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame^] | 22 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 23 | |
| 24 | namespace shill { |
| 25 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 26 | Daemon::Daemon(Config *config, ControlInterface *control) |
| 27 | : config_(config), |
| 28 | control_(control), |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 29 | manager_(control_, |
| 30 | &dispatcher_, |
| 31 | &glib_, |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 32 | config->GetRunDirectory(), |
| 33 | config->GetStorageDirectory(), |
| 34 | config->GetUserStorageDirectoryFormat()) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 35 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 36 | Daemon::~Daemon() {} |
| 37 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 38 | void Daemon::AddDeviceToBlackList(const string &device_name) { |
| 39 | manager_.AddDeviceToBlackList(device_name); |
| 40 | } |
| 41 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame^] | 42 | void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) { |
| 43 | Error error; |
| 44 | manager_.set_startup_profiles(profile_name_list); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 47 | void Daemon::Run() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 48 | Start(); |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 49 | VLOG(1) << "Running main loop."; |
Chris Masone | c5b392e | 2011-05-14 16:31:01 -0700 | [diff] [blame] | 50 | dispatcher_.DispatchForever(); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 51 | VLOG(1) << "Exited main loop."; |
| 52 | Stop(); |
| 53 | } |
| 54 | |
| 55 | void Daemon::Quit() { |
| 56 | dispatcher_.PostTask(new MessageLoop::QuitTask); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame^] | 59 | void Daemon::Start() { |
| 60 | glib_.TypeInit(); |
| 61 | ProxyFactory::GetInstance()->Init(); |
| 62 | RTNLHandler::GetInstance()->Start(&dispatcher_, &sockets_); |
| 63 | DHCPProvider::GetInstance()->Init(control_, &dispatcher_, &glib_); |
| 64 | manager_.Start(); |
| 65 | } |
| 66 | |
| 67 | void Daemon::Stop() { |
| 68 | manager_.Stop(); |
| 69 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 70 | |
| 71 | } // namespace shill |