blob: 5549327ec254d37955f6323fd641d659f97de452 [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkova7b89492011-07-27 12:48:17 -07005#include "shill/shill_daemon.h"
Paul Stewart75897df2011-04-27 09:05:53 -07006
Darin Petkova7b89492011-07-27 12:48:17 -07007#include <stdio.h>
8
Paul Stewart75897df2011-04-27 09:05:53 -07009#include <string>
Gaurav Shah71354762011-11-28 19:22:49 -080010#include <vector>
Paul Stewart75897df2011-04-27 09:05:53 -070011
Chris Masone2ae797d2011-08-23 20:41:00 -070012#include <base/file_path.h>
Chris Masoneee929b72011-05-10 10:02:18 -070013#include <base/logging.h>
14
Darin Petkova7b89492011-07-27 12:48:17 -070015#include "shill/dhcp_provider.h"
Gaurav Shah71354762011-11-28 19:22:49 -080016#include "shill/error.h"
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020017#include "shill/nss.h"
Darin Petkovab565bb2011-10-06 02:55:51 -070018#include "shill/proxy_factory.h"
Paul Stewartc1dec4d2011-12-08 15:25:28 -080019#include "shill/routing_table.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070020#include "shill/rtnl_handler.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070021#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070022
Paul Stewart75897df2011-04-27 09:05:53 -070023using std::string;
Gaurav Shah71354762011-11-28 19:22:49 -080024using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070025
26namespace shill {
27
Darin Petkova7b89492011-07-27 12:48:17 -070028Daemon::Daemon(Config *config, ControlInterface *control)
29 : config_(config),
30 control_(control),
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020031 nss_(NSS::GetInstance()),
Thieu Lefb46caf2012-03-08 11:57:15 -080032 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 Masone2ae797d2011-08-23 20:41:00 -070043}
Paul Stewart75897df2011-04-27 09:05:53 -070044Daemon::~Daemon() {}
45
mukesh agrawal8f317b62011-07-15 11:53:23 -070046void Daemon::AddDeviceToBlackList(const string &device_name) {
Thieu Lefb46caf2012-03-08 11:57:15 -080047 manager_->AddDeviceToBlackList(device_name);
mukesh agrawal8f317b62011-07-15 11:53:23 -070048}
49
Gaurav Shah71354762011-11-28 19:22:49 -080050void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
51 Error error;
Thieu Lefb46caf2012-03-08 11:57:15 -080052 manager_->set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000053}
54
Paul Stewart75897df2011-04-27 09:05:53 -070055void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070056 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070057 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070058 dispatcher_.DispatchForever();
Thieu Le1271d682011-11-02 22:48:19 +000059 VLOG(1) << "Exited main loop.";
60 Stop();
61}
62
63void Daemon::Quit() {
Eric Shienbrood3e20a232012-02-16 11:35:56 -050064 dispatcher_.PostTask(MessageLoop::QuitClosure());
Paul Stewart75897df2011-04-27 09:05:53 -070065}
66
Gaurav Shah71354762011-11-28 19:22:49 -080067void Daemon::Start() {
68 glib_.TypeInit();
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020069 nss_->Init(&glib_);
Thieu Lefb46caf2012-03-08 11:57:15 -080070 proxy_factory_->Init();
71 rtnl_handler_->Start(&dispatcher_, &sockets_);
72 routing_table_->Start();
73 dhcp_provider_->Init(control_, &dispatcher_, &glib_);
74 manager_->Start();
Gaurav Shah71354762011-11-28 19:22:49 -080075}
76
77void Daemon::Stop() {
Thieu Lefb46caf2012-03-08 11:57:15 -080078 manager_->Stop();
Gaurav Shah71354762011-11-28 19:22:49 -080079}
Paul Stewart75897df2011-04-27 09:05:53 -070080
81} // namespace shill