buffet: Read config/state paths from commandline
This allows us to use custom paths and configurations in test without
altering normal system operation.
BUG=brillo:172
TEST=unittests
Change-Id: I1a969093683205d5f600ff88ebba8b22c05368b4
Reviewed-on: https://chromium-review.googlesource.com/247504
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/buffet/main.cc b/buffet/main.cc
index 7cb37fb..1dc3388 100644
--- a/buffet/main.cc
+++ b/buffet/main.cc
@@ -4,10 +4,11 @@
#include <string>
-#include <base/command_line.h>
+#include <base/files/file_path.h>
#include <chromeos/dbus/async_event_sequencer.h>
#include <chromeos/dbus/exported_object_manager.h>
#include <chromeos/daemons/dbus_daemon.h>
+#include <chromeos/flag_helper.h>
#include <chromeos/syslog_logging.h>
#include "buffet/dbus_constants.h"
@@ -22,26 +23,50 @@
class Daemon : public DBusServiceDaemon {
public:
- Daemon() : DBusServiceDaemon(kServiceName, kRootServicePath) {}
+ Daemon(const base::FilePath& config_path,
+ const base::FilePath& state_path)
+ : DBusServiceDaemon(kServiceName, kRootServicePath),
+ config_path_{config_path},
+ state_path_{state_path} {}
protected:
void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override {
manager_.reset(new buffet::Manager(object_manager_->AsWeakPtr()));
manager_->RegisterAsync(
+ config_path_,
+ state_path_,
sequencer->GetHandler("Manager.RegisterAsync() failed.", true));
}
private:
std::unique_ptr<buffet::Manager> manager_;
+ const base::FilePath config_path_;
+ const base::FilePath state_path_;
DISALLOW_COPY_AND_ASSIGN(Daemon);
};
} // namespace buffet
+namespace {
+
+const char kDefaultConfigFilePath[] = "/etc/buffet/buffet.conf";
+const char kDefaultStateFilePath[] = "/var/lib/buffet/device_reg_info";
+
+} // namespace
+
int main(int argc, char* argv[]) {
- CommandLine::Init(argc, argv);
+ DEFINE_string(config_path, kDefaultConfigFilePath,
+ "Path to file containing config information.");
+ DEFINE_string(state_path, kDefaultStateFilePath,
+ "Path to file containing state information.");
+ if (FLAGS_config_path.empty())
+ FLAGS_config_path = kDefaultConfigFilePath;
+ if (FLAGS_state_path.empty())
+ FLAGS_state_path = kDefaultStateFilePath;
+ chromeos::FlagHelper::Init(argc, argv, "Privet protocol handler daemon");
chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogHeader);
- buffet::Daemon daemon;
+ buffet::Daemon daemon{base::FilePath{FLAGS_config_path},
+ base::FilePath{FLAGS_state_path}};
return daemon.Run();
}