blob: 5cde0d1c05fd3fb7424b7fab30d8720f0542d300 [file] [log] [blame]
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "shill/shill_daemon.h"
#include <stdio.h>
#include <string>
#include <vector>
#include <base/file_path.h>
#include <base/logging.h>
#include "shill/dhcp_provider.h"
#include "shill/error.h"
#include "shill/nss.h"
#include "shill/proxy_factory.h"
#include "shill/routing_table.h"
#include "shill/rtnl_handler.h"
#include "shill/scope_logger.h"
#include "shill/shill_config.h"
using std::string;
using std::vector;
namespace shill {
Daemon::Daemon(Config *config, ControlInterface *control)
: config_(config),
control_(control),
nss_(NSS::GetInstance()),
proxy_factory_(ProxyFactory::GetInstance()),
rtnl_handler_(RTNLHandler::GetInstance()),
routing_table_(RoutingTable::GetInstance()),
dhcp_provider_(DHCPProvider::GetInstance()),
manager_(new Manager(control_,
&dispatcher_,
&metrics_,
&glib_,
config->GetRunDirectory(),
config->GetStorageDirectory(),
config->GetUserStorageDirectoryFormat())) {
}
Daemon::~Daemon() {}
void Daemon::AddDeviceToBlackList(const string &device_name) {
manager_->AddDeviceToBlackList(device_name);
}
void Daemon::SetStartupPortalList(const string &portal_list) {
manager_->SetStartupPortalList(portal_list);
}
void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
Error error;
manager_->set_startup_profiles(profile_name_list);
}
void Daemon::Run() {
Start();
SLOG(Daemon, 1) << "Running main loop.";
dispatcher_.DispatchForever();
SLOG(Daemon, 1) << "Exited main loop.";
Stop();
}
void Daemon::Quit() {
dispatcher_.PostTask(MessageLoop::QuitClosure());
}
void Daemon::Start() {
glib_.TypeInit();
nss_->Init(&glib_);
proxy_factory_->Init();
rtnl_handler_->Start(&dispatcher_, &sockets_);
routing_table_->Start();
dhcp_provider_->Init(control_, &dispatcher_, &glib_);
manager_->Start();
}
void Daemon::Stop() {
manager_->Stop();
}
} // namespace shill