Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 1 | // 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 Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 7 | #include <base/files/file_path.h> |
Alex Vakulenko | a8b95bc | 2014-08-27 11:00:57 -0700 | [diff] [blame] | 8 | #include <chromeos/dbus/async_event_sequencer.h> |
| 9 | #include <chromeos/dbus/exported_object_manager.h> |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 10 | #include <chromeos/daemons/dbus_daemon.h> |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 11 | #include <chromeos/flag_helper.h> |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 12 | #include <chromeos/syslog_logging.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 13 | |
Alex Vakulenko | 420e49f | 2014-12-01 17:53:27 -0800 | [diff] [blame] | 14 | #include "buffet/dbus_constants.h" |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 15 | #include "buffet/manager.h" |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 16 | |
Christopher Wiley | 2d2d92b | 2014-07-29 14:07:10 -0700 | [diff] [blame] | 17 | using chromeos::dbus_utils::AsyncEventSequencer; |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 18 | using chromeos::DBusServiceDaemon; |
| 19 | using buffet::dbus_constants::kServiceName; |
| 20 | using buffet::dbus_constants::kRootServicePath; |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 21 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 22 | namespace buffet { |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 23 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 24 | class Daemon : public DBusServiceDaemon { |
| 25 | public: |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 26 | Daemon(const base::FilePath& config_path, |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 27 | const base::FilePath& state_path, |
| 28 | const base::FilePath& test_definitions_path) |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 29 | : DBusServiceDaemon(kServiceName, kRootServicePath), |
| 30 | config_path_{config_path}, |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 31 | state_path_{state_path}, |
| 32 | test_definitions_path_{test_definitions_path} {} |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 33 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 34 | protected: |
| 35 | void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override { |
| 36 | manager_.reset(new buffet::Manager(object_manager_->AsWeakPtr())); |
| 37 | manager_->RegisterAsync( |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 38 | config_path_, |
| 39 | state_path_, |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 40 | test_definitions_path_, |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 41 | sequencer->GetHandler("Manager.RegisterAsync() failed.", true)); |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 42 | } |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 43 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 44 | private: |
Christopher Wiley | 583d64b | 2015-03-24 14:30:17 -0700 | [diff] [blame] | 45 | BuffetConfig config_; |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 46 | std::unique_ptr<buffet::Manager> manager_; |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 47 | const base::FilePath config_path_; |
| 48 | const base::FilePath state_path_; |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 49 | const base::FilePath test_definitions_path_; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 50 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 51 | DISALLOW_COPY_AND_ASSIGN(Daemon); |
| 52 | }; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 53 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 54 | } // namespace buffet |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 55 | |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 56 | namespace { |
| 57 | |
| 58 | const char kDefaultConfigFilePath[] = "/etc/buffet/buffet.conf"; |
| 59 | const char kDefaultStateFilePath[] = "/var/lib/buffet/device_reg_info"; |
| 60 | |
| 61 | } // namespace |
| 62 | |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 63 | int main(int argc, char* argv[]) { |
Vitaly Buka | c5e9b4d | 2015-03-13 23:54:21 -0700 | [diff] [blame] | 64 | DEFINE_bool(log_to_stderr, false, "log trace messages to stderr as well"); |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 65 | DEFINE_string(config_path, kDefaultConfigFilePath, |
| 66 | "Path to file containing config information."); |
| 67 | DEFINE_string(state_path, kDefaultStateFilePath, |
| 68 | "Path to file containing state information."); |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 69 | DEFINE_string(test_definitions_path, "", |
| 70 | "Path to directory containing additional command " |
| 71 | "and state definitions. For use in test only."); |
Aaron Kemp | 292cc84 | 2015-02-11 08:00:06 -0800 | [diff] [blame] | 72 | chromeos::FlagHelper::Init(argc, argv, "Privet protocol handler daemon"); |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 73 | if (FLAGS_config_path.empty()) |
| 74 | FLAGS_config_path = kDefaultConfigFilePath; |
| 75 | if (FLAGS_state_path.empty()) |
| 76 | FLAGS_state_path = kDefaultStateFilePath; |
Vitaly Buka | c5e9b4d | 2015-03-13 23:54:21 -0700 | [diff] [blame] | 77 | int flags = chromeos::kLogToSyslog | chromeos::kLogHeader; |
| 78 | if (FLAGS_log_to_stderr) |
| 79 | flags |= chromeos::kLogToStderr; |
| 80 | chromeos::InitLog(flags); |
| 81 | |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 82 | buffet::Daemon daemon{base::FilePath{FLAGS_config_path}, |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 83 | base::FilePath{FLAGS_state_path}, |
| 84 | base::FilePath{FLAGS_test_definitions_path}}; |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 85 | return daemon.Run(); |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 86 | } |