blob: 323f285d2a5706d998583d676a319d6aadd7cd68 [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"
Paul Stewarta3c56f92011-05-26 07:08:52 -070015#include "shill/rtnl_handler.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070016#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070017
Paul Stewart75897df2011-04-27 09:05:53 -070018using std::string;
Paul Stewart75897df2011-04-27 09:05:53 -070019
20namespace shill {
21
Paul Stewart75897df2011-04-27 09:05:53 -070022// Daemon: Main for connection manager. Starts main process and holds event
23// loop.
24
Darin Petkova7b89492011-07-27 12:48:17 -070025Daemon::Daemon(Config *config, ControlInterface *control)
26 : config_(config),
27 control_(control),
Chris Masone2ae797d2011-08-23 20:41:00 -070028 manager_(control_,
29 &dispatcher_,
30 &glib_,
31 config->RunDirectory(),
32 config->StorageDirectory(),
33 config->UserStorageDirectoryFormat()) {
34}
Paul Stewart75897df2011-04-27 09:05:53 -070035Daemon::~Daemon() {}
36
mukesh agrawal8f317b62011-07-15 11:53:23 -070037void Daemon::AddDeviceToBlackList(const string &device_name) {
38 manager_.AddDeviceToBlackList(device_name);
39}
40
Paul Stewart0af98bf2011-05-10 17:38:08 -070041void Daemon::Start() {
Darin Petkova7b89492011-07-27 12:48:17 -070042 glib_.TypeInit();
43 proxy_factory_.Init();
44 ProxyFactory::set_factory(&proxy_factory_);
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
50void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070051 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070052 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070053 dispatcher_.DispatchForever();
Paul Stewart75897df2011-04-27 09:05:53 -070054}
55
56
57} // namespace shill