blob: 5cde0d1c05fd3fb7424b7fab30d8720f0542d300 [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"
Ben Chanfad4a0b2012-04-18 15:49:59 -070021#include "shill/scope_logger.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070022#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070023
Paul Stewart75897df2011-04-27 09:05:53 -070024using std::string;
Gaurav Shah71354762011-11-28 19:22:49 -080025using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070026
27namespace shill {
28
Darin Petkova7b89492011-07-27 12:48:17 -070029Daemon::Daemon(Config *config, ControlInterface *control)
30 : config_(config),
31 control_(control),
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020032 nss_(NSS::GetInstance()),
Thieu Lefb46caf2012-03-08 11:57:15 -080033 proxy_factory_(ProxyFactory::GetInstance()),
34 rtnl_handler_(RTNLHandler::GetInstance()),
35 routing_table_(RoutingTable::GetInstance()),
36 dhcp_provider_(DHCPProvider::GetInstance()),
37 manager_(new Manager(control_,
38 &dispatcher_,
39 &metrics_,
40 &glib_,
41 config->GetRunDirectory(),
42 config->GetStorageDirectory(),
43 config->GetUserStorageDirectoryFormat())) {
Chris Masone2ae797d2011-08-23 20:41:00 -070044}
Paul Stewart75897df2011-04-27 09:05:53 -070045Daemon::~Daemon() {}
46
mukesh agrawal8f317b62011-07-15 11:53:23 -070047void Daemon::AddDeviceToBlackList(const string &device_name) {
Thieu Lefb46caf2012-03-08 11:57:15 -080048 manager_->AddDeviceToBlackList(device_name);
mukesh agrawal8f317b62011-07-15 11:53:23 -070049}
50
Paul Stewart10e9e4e2012-04-26 19:46:28 -070051void Daemon::SetStartupPortalList(const string &portal_list) {
52 manager_->SetStartupPortalList(portal_list);
53}
54
Gaurav Shah71354762011-11-28 19:22:49 -080055void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
56 Error error;
Thieu Lefb46caf2012-03-08 11:57:15 -080057 manager_->set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000058}
59
Paul Stewart75897df2011-04-27 09:05:53 -070060void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070061 Start();
Ben Chanfad4a0b2012-04-18 15:49:59 -070062 SLOG(Daemon, 1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070063 dispatcher_.DispatchForever();
Ben Chanfad4a0b2012-04-18 15:49:59 -070064 SLOG(Daemon, 1) << "Exited main loop.";
Thieu Le1271d682011-11-02 22:48:19 +000065 Stop();
66}
67
68void Daemon::Quit() {
Eric Shienbrood3e20a232012-02-16 11:35:56 -050069 dispatcher_.PostTask(MessageLoop::QuitClosure());
Paul Stewart75897df2011-04-27 09:05:53 -070070}
71
Gaurav Shah71354762011-11-28 19:22:49 -080072void Daemon::Start() {
73 glib_.TypeInit();
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020074 nss_->Init(&glib_);
Thieu Lefb46caf2012-03-08 11:57:15 -080075 proxy_factory_->Init();
76 rtnl_handler_->Start(&dispatcher_, &sockets_);
77 routing_table_->Start();
78 dhcp_provider_->Init(control_, &dispatcher_, &glib_);
79 manager_->Start();
Gaurav Shah71354762011-11-28 19:22:49 -080080}
81
82void Daemon::Stop() {
Thieu Lefb46caf2012-03-08 11:57:15 -080083 manager_->Stop();
Gaurav Shah71354762011-11-28 19:22:49 -080084}
Paul Stewart75897df2011-04-27 09:05:53 -070085
86} // namespace shill