blob: ae05866a0d6f9522df9537ce29a1d47677e6257e [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 Petkovab565bb2011-10-06 02:55:51 -070017#include "shill/proxy_factory.h"
Paul Stewartc1dec4d2011-12-08 15:25:28 -080018#include "shill/routing_table.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070019#include "shill/rtnl_handler.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070020#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070021
Paul Stewart75897df2011-04-27 09:05:53 -070022using std::string;
Gaurav Shah71354762011-11-28 19:22:49 -080023using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070024
25namespace shill {
26
Darin Petkova7b89492011-07-27 12:48:17 -070027Daemon::Daemon(Config *config, ControlInterface *control)
28 : config_(config),
29 control_(control),
Chris Masone2ae797d2011-08-23 20:41:00 -070030 manager_(control_,
31 &dispatcher_,
Thieu Le3426c8f2012-01-11 17:35:11 -080032 &metrics_,
Chris Masone2ae797d2011-08-23 20:41:00 -070033 &glib_,
Chris Masoneb9c00592011-10-06 13:10:39 -070034 config->GetRunDirectory(),
35 config->GetStorageDirectory(),
36 config->GetUserStorageDirectoryFormat()) {
Chris Masone2ae797d2011-08-23 20:41:00 -070037}
Paul Stewart75897df2011-04-27 09:05:53 -070038Daemon::~Daemon() {}
39
mukesh agrawal8f317b62011-07-15 11:53:23 -070040void Daemon::AddDeviceToBlackList(const string &device_name) {
41 manager_.AddDeviceToBlackList(device_name);
42}
43
Gaurav Shah71354762011-11-28 19:22:49 -080044void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
45 Error error;
46 manager_.set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000047}
48
Paul Stewart75897df2011-04-27 09:05:53 -070049void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070050 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070051 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070052 dispatcher_.DispatchForever();
Thieu Le1271d682011-11-02 22:48:19 +000053 VLOG(1) << "Exited main loop.";
54 Stop();
55}
56
57void Daemon::Quit() {
58 dispatcher_.PostTask(new MessageLoop::QuitTask);
Paul Stewart75897df2011-04-27 09:05:53 -070059}
60
Gaurav Shah71354762011-11-28 19:22:49 -080061void Daemon::Start() {
62 glib_.TypeInit();
63 ProxyFactory::GetInstance()->Init();
64 RTNLHandler::GetInstance()->Start(&dispatcher_, &sockets_);
Paul Stewartc1dec4d2011-12-08 15:25:28 -080065 RoutingTable::GetInstance()->Start();
Gaurav Shah71354762011-11-28 19:22:49 -080066 DHCPProvider::GetInstance()->Init(control_, &dispatcher_, &glib_);
67 manager_.Start();
68}
69
70void Daemon::Stop() {
71 manager_.Stop();
72}
Paul Stewart75897df2011-04-27 09:05:53 -070073
74} // namespace shill