blob: 8f622482d0348193d1bf3a3ef4d80d5b9f814928 [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 Stewarta3c56f92011-05-26 07:08:52 -070018#include "shill/rtnl_handler.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070019#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070020
Paul Stewart75897df2011-04-27 09:05:53 -070021using std::string;
Gaurav Shah71354762011-11-28 19:22:49 -080022using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070023
24namespace shill {
25
Darin Petkova7b89492011-07-27 12:48:17 -070026Daemon::Daemon(Config *config, ControlInterface *control)
27 : config_(config),
28 control_(control),
Chris Masone2ae797d2011-08-23 20:41:00 -070029 manager_(control_,
30 &dispatcher_,
31 &glib_,
Chris Masoneb9c00592011-10-06 13:10:39 -070032 config->GetRunDirectory(),
33 config->GetStorageDirectory(),
34 config->GetUserStorageDirectoryFormat()) {
Chris Masone2ae797d2011-08-23 20:41:00 -070035}
Paul Stewart75897df2011-04-27 09:05:53 -070036Daemon::~Daemon() {}
37
mukesh agrawal8f317b62011-07-15 11:53:23 -070038void Daemon::AddDeviceToBlackList(const string &device_name) {
39 manager_.AddDeviceToBlackList(device_name);
40}
41
Gaurav Shah71354762011-11-28 19:22:49 -080042void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
43 Error error;
44 manager_.set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000045}
46
Paul Stewart75897df2011-04-27 09:05:53 -070047void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070048 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070049 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070050 dispatcher_.DispatchForever();
Thieu Le1271d682011-11-02 22:48:19 +000051 VLOG(1) << "Exited main loop.";
52 Stop();
53}
54
55void Daemon::Quit() {
56 dispatcher_.PostTask(new MessageLoop::QuitTask);
Paul Stewart75897df2011-04-27 09:05:53 -070057}
58
Gaurav Shah71354762011-11-28 19:22:49 -080059void Daemon::Start() {
60 glib_.TypeInit();
61 ProxyFactory::GetInstance()->Init();
62 RTNLHandler::GetInstance()->Start(&dispatcher_, &sockets_);
63 DHCPProvider::GetInstance()->Init(control_, &dispatcher_, &glib_);
64 manager_.Start();
65}
66
67void Daemon::Stop() {
68 manager_.Stop();
69}
Paul Stewart75897df2011-04-27 09:05:53 -070070
71} // namespace shill