blob: 233b24df28eb707c1bdc8943136b7f099c4852ea [file] [log] [blame]
Darin Petkov633ac6f2011-07-08 13:56:13 -07001// Copyright (c) 2011 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_,
32 &glib_,
Chris Masoneb9c00592011-10-06 13:10:39 -070033 config->GetRunDirectory(),
34 config->GetStorageDirectory(),
35 config->GetUserStorageDirectoryFormat()) {
Chris Masone2ae797d2011-08-23 20:41:00 -070036}
Paul Stewart75897df2011-04-27 09:05:53 -070037Daemon::~Daemon() {}
38
mukesh agrawal8f317b62011-07-15 11:53:23 -070039void Daemon::AddDeviceToBlackList(const string &device_name) {
40 manager_.AddDeviceToBlackList(device_name);
41}
42
Gaurav Shah71354762011-11-28 19:22:49 -080043void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
44 Error error;
45 manager_.set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000046}
47
Paul Stewart75897df2011-04-27 09:05:53 -070048void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070049 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070050 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070051 dispatcher_.DispatchForever();
Thieu Le1271d682011-11-02 22:48:19 +000052 VLOG(1) << "Exited main loop.";
53 Stop();
54}
55
56void Daemon::Quit() {
57 dispatcher_.PostTask(new MessageLoop::QuitTask);
Paul Stewart75897df2011-04-27 09:05:53 -070058}
59
Gaurav Shah71354762011-11-28 19:22:49 -080060void Daemon::Start() {
61 glib_.TypeInit();
62 ProxyFactory::GetInstance()->Init();
63 RTNLHandler::GetInstance()->Start(&dispatcher_, &sockets_);
Paul Stewartc1dec4d2011-12-08 15:25:28 -080064 RoutingTable::GetInstance()->Start();
Gaurav Shah71354762011-11-28 19:22:49 -080065 DHCPProvider::GetInstance()->Init(control_, &dispatcher_, &glib_);
66 manager_.Start();
67}
68
69void Daemon::Stop() {
70 manager_.Stop();
71}
Paul Stewart75897df2011-04-27 09:05:53 -070072
73} // namespace shill