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, |
| 27 | const base::FilePath& state_path) |
| 28 | : DBusServiceDaemon(kServiceName, kRootServicePath), |
| 29 | config_path_{config_path}, |
| 30 | state_path_{state_path} {} |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 31 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 32 | protected: |
| 33 | void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override { |
| 34 | manager_.reset(new buffet::Manager(object_manager_->AsWeakPtr())); |
| 35 | manager_->RegisterAsync( |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 36 | config_path_, |
| 37 | state_path_, |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 38 | sequencer->GetHandler("Manager.RegisterAsync() failed.", true)); |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 39 | } |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 40 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 41 | private: |
| 42 | std::unique_ptr<buffet::Manager> manager_; |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 43 | const base::FilePath config_path_; |
| 44 | const base::FilePath state_path_; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 45 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 46 | DISALLOW_COPY_AND_ASSIGN(Daemon); |
| 47 | }; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 48 | |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 49 | } // namespace buffet |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 50 | |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 51 | namespace { |
| 52 | |
| 53 | const char kDefaultConfigFilePath[] = "/etc/buffet/buffet.conf"; |
| 54 | const char kDefaultStateFilePath[] = "/var/lib/buffet/device_reg_info"; |
| 55 | |
| 56 | } // namespace |
| 57 | |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 58 | int main(int argc, char* argv[]) { |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 59 | 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 Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 68 | chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogHeader); |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 69 | buffet::Daemon daemon{base::FilePath{FLAGS_config_path}, |
| 70 | base::FilePath{FLAGS_state_path}}; |
Alex Vakulenko | 74bd01b | 2014-09-08 17:07:19 -0700 | [diff] [blame] | 71 | return daemon.Run(); |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 72 | } |