blob: 1dc338890953d8ac1173b37aa2dedb6e513ed371 [file] [log] [blame]
Chris Sosa45d9f102014-03-24 11:18:54 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
Christopher Wileye0fdeee2015-02-07 18:29:32 -08007#include <base/files/file_path.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -07008#include <chromeos/dbus/async_event_sequencer.h>
9#include <chromeos/dbus/exported_object_manager.h>
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070010#include <chromeos/daemons/dbus_daemon.h>
Christopher Wileye0fdeee2015-02-07 18:29:32 -080011#include <chromeos/flag_helper.h>
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070012#include <chromeos/syslog_logging.h>
Chris Sosa45d9f102014-03-24 11:18:54 -070013
Alex Vakulenko420e49f2014-12-01 17:53:27 -080014#include "buffet/dbus_constants.h"
Christopher Wileya4915c42014-03-27 14:45:37 -070015#include "buffet/manager.h"
Chris Sosa45d9f102014-03-24 11:18:54 -070016
Christopher Wiley2d2d92b2014-07-29 14:07:10 -070017using chromeos::dbus_utils::AsyncEventSequencer;
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070018using chromeos::DBusServiceDaemon;
19using buffet::dbus_constants::kServiceName;
20using buffet::dbus_constants::kRootServicePath;
Christopher Wiley90016242014-04-01 17:33:29 -070021
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070022namespace buffet {
Chris Sosa45d9f102014-03-24 11:18:54 -070023
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070024class Daemon : public DBusServiceDaemon {
25 public:
Christopher Wileye0fdeee2015-02-07 18:29:32 -080026 Daemon(const base::FilePath& config_path,
27 const base::FilePath& state_path)
28 : DBusServiceDaemon(kServiceName, kRootServicePath),
29 config_path_{config_path},
30 state_path_{state_path} {}
Chris Sosaababc5c2014-04-09 15:42:01 -070031
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070032 protected:
33 void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override {
34 manager_.reset(new buffet::Manager(object_manager_->AsWeakPtr()));
35 manager_->RegisterAsync(
Christopher Wileye0fdeee2015-02-07 18:29:32 -080036 config_path_,
37 state_path_,
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070038 sequencer->GetHandler("Manager.RegisterAsync() failed.", true));
Chris Sosa45d9f102014-03-24 11:18:54 -070039 }
Chris Sosa45d9f102014-03-24 11:18:54 -070040
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070041 private:
42 std::unique_ptr<buffet::Manager> manager_;
Christopher Wileye0fdeee2015-02-07 18:29:32 -080043 const base::FilePath config_path_;
44 const base::FilePath state_path_;
Chris Sosa45d9f102014-03-24 11:18:54 -070045
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070046 DISALLOW_COPY_AND_ASSIGN(Daemon);
47};
Chris Sosa45d9f102014-03-24 11:18:54 -070048
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070049} // namespace buffet
Chris Sosa45d9f102014-03-24 11:18:54 -070050
Christopher Wileye0fdeee2015-02-07 18:29:32 -080051namespace {
52
53const char kDefaultConfigFilePath[] = "/etc/buffet/buffet.conf";
54const char kDefaultStateFilePath[] = "/var/lib/buffet/device_reg_info";
55
56} // namespace
57
Chris Sosa45d9f102014-03-24 11:18:54 -070058int main(int argc, char* argv[]) {
Christopher Wileye0fdeee2015-02-07 18:29:32 -080059 DEFINE_string(config_path, kDefaultConfigFilePath,
60 "Path to file containing config information.");
61 DEFINE_string(state_path, kDefaultStateFilePath,
62 "Path to file containing state information.");
63 if (FLAGS_config_path.empty())
64 FLAGS_config_path = kDefaultConfigFilePath;
65 if (FLAGS_state_path.empty())
66 FLAGS_state_path = kDefaultStateFilePath;
67 chromeos::FlagHelper::Init(argc, argv, "Privet protocol handler daemon");
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070068 chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogHeader);
Christopher Wileye0fdeee2015-02-07 18:29:32 -080069 buffet::Daemon daemon{base::FilePath{FLAGS_config_path},
70 base::FilePath{FLAGS_state_path}};
Alex Vakulenko74bd01b2014-09-08 17:07:19 -070071 return daemon.Run();
Chris Sosa45d9f102014-03-24 11:18:54 -070072}