blob: 1e0dc23b9ed28748778a2c586b562251cfaaca33 [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>
Paul Stewart75897df2011-04-27 09:05:53 -070010
Chris Masone2ae797d2011-08-23 20:41:00 -070011#include <base/file_path.h>
Chris Masoneee929b72011-05-10 10:02:18 -070012#include <base/logging.h>
13
Darin Petkova7b89492011-07-27 12:48:17 -070014#include "shill/dhcp_provider.h"
Darin Petkovab565bb2011-10-06 02:55:51 -070015#include "shill/proxy_factory.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070016#include "shill/rtnl_handler.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070017#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070018
Paul Stewart75897df2011-04-27 09:05:53 -070019using std::string;
Paul Stewart75897df2011-04-27 09:05:53 -070020
21namespace shill {
22
Paul Stewart75897df2011-04-27 09:05:53 -070023// Daemon: Main for connection manager. Starts main process and holds event
24// loop.
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
Paul Stewart0af98bf2011-05-10 17:38:08 -070042void Daemon::Start() {
Darin Petkova7b89492011-07-27 12:48:17 -070043 glib_.TypeInit();
Darin Petkovab565bb2011-10-06 02:55:51 -070044 ProxyFactory::GetInstance()->Init();
Darin Petkov633ac6f2011-07-08 13:56:13 -070045 RTNLHandler::GetInstance()->Start(&dispatcher_, &sockets_);
Darin Petkova7b89492011-07-27 12:48:17 -070046 DHCPProvider::GetInstance()->Init(control_, &dispatcher_, &glib_);
Paul Stewart0af98bf2011-05-10 17:38:08 -070047 manager_.Start();
48}
Paul Stewart75897df2011-04-27 09:05:53 -070049
Thieu Le1271d682011-11-02 22:48:19 +000050void Daemon::Stop() {
51 manager_.Stop();
52}
53
Paul Stewart75897df2011-04-27 09:05:53 -070054void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070055 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070056 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070057 dispatcher_.DispatchForever();
Thieu Le1271d682011-11-02 22:48:19 +000058 VLOG(1) << "Exited main loop.";
59 Stop();
60}
61
62void Daemon::Quit() {
63 dispatcher_.PostTask(new MessageLoop::QuitTask);
Paul Stewart75897df2011-04-27 09:05:53 -070064}
65
66
67} // namespace shill