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> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 10 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 11 | #include <base/file_path.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 12 | #include <base/logging.h> |
| 13 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 14 | #include "shill/dhcp_provider.h" |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 15 | #include "shill/rtnl_handler.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 16 | #include "shill/shill_config.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 17 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 18 | using std::string; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 19 | |
| 20 | namespace shill { |
| 21 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | // Daemon: Main for connection manager. Starts main process and holds event |
| 23 | // loop. |
| 24 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 25 | Daemon::Daemon(Config *config, ControlInterface *control) |
| 26 | : config_(config), |
| 27 | control_(control), |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 28 | manager_(control_, |
| 29 | &dispatcher_, |
| 30 | &glib_, |
| 31 | config->RunDirectory(), |
| 32 | config->StorageDirectory(), |
| 33 | config->UserStorageDirectoryFormat()) { |
| 34 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | Daemon::~Daemon() {} |
| 36 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 37 | void Daemon::AddDeviceToBlackList(const string &device_name) { |
| 38 | manager_.AddDeviceToBlackList(device_name); |
| 39 | } |
| 40 | |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 41 | void Daemon::Start() { |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 42 | glib_.TypeInit(); |
| 43 | proxy_factory_.Init(); |
| 44 | ProxyFactory::set_factory(&proxy_factory_); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 45 | RTNLHandler::GetInstance()->Start(&dispatcher_, &sockets_); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 46 | DHCPProvider::GetInstance()->Init(control_, &dispatcher_, &glib_); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 47 | manager_.Start(); |
| 48 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 49 | |
| 50 | void Daemon::Run() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 51 | Start(); |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 52 | VLOG(1) << "Running main loop."; |
Chris Masone | c5b392e | 2011-05-14 16:31:01 -0700 | [diff] [blame] | 53 | dispatcher_.DispatchForever(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
| 57 | } // namespace shill |