blob: 11d780aceedb28e29e38aa43dae1a56438c93cf5 [file] [log] [blame] [edit]
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fcntl.h>
#include <stdlib.h>
#include <sysexits.h>
#include <memory>
#include <utility>
#include <brillo/compression/compressor_interface.h>
#include <brillo/compression/zlib_compressor.h>
#include <brillo/daemons/daemon.h>
#include <brillo/flag_helper.h>
#include <brillo/message_loops/message_loop.h>
#include <brillo/syslog_logging.h>
#include <chromeos/dbus/service_constants.h>
#include <dbus/bus.h>
#include <dbus/exported_object.h>
#include <dbus/message.h>
#include <dbus/object_proxy.h>
#include "featured/service.h"
#include "featured/store_impl.h"
#include "featured/store_interface.h"
#include "featured/tmp_storage_impl.h"
#include "featured/tmp_storage_interface.h"
namespace {
class FeatureDaemon : public brillo::Daemon {
public:
FeatureDaemon() = default;
FeatureDaemon(const FeatureDaemon&) = delete;
FeatureDaemon& operator=(const FeatureDaemon&) = delete;
};
} // namespace
int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderr);
// Perform necessary initialization for dbus
// NOTE: If this declaration moves to _after_ the service->Start() call,
// service->Start segfaults.
FeatureDaemon daemon;
dbus::Bus::Options options;
options.bus_type = dbus::Bus::SYSTEM;
scoped_refptr<dbus::Bus> bus = new dbus::Bus(std::move(options));
std::unique_ptr<featured::StoreInterface> store =
featured::StoreImpl::Create();
if (!store) {
LOG(ERROR) << "Could not create StoreImpl instance.";
return EX_UNAVAILABLE;
}
std::unique_ptr<featured::TmpStorageInterface> tmp_storage_impl(nullptr);
if (store) {
tmp_storage_impl = std::make_unique<featured::TmpStorageImpl>();
}
std::unique_ptr<brillo::CompressorInterface> decompressor =
std::make_unique<brillo::ZlibDecompressor>(
brillo::ZlibDecompressor::InflateFormat::Gzip);
if (!decompressor->Initialize()) {
LOG(ERROR) << "Could not initialize ZlibDecompressor instance.";
return EX_UNAVAILABLE;
}
std::shared_ptr<featured::DbusFeaturedService> service =
std::make_shared<featured::DbusFeaturedService>(
std::move(store), std::move(tmp_storage_impl),
std::move(decompressor));
CHECK(service->Start(bus.get(), service)) << "Failed to start featured!";
int rc = daemon.Run();
return rc == EX_UNAVAILABLE ? EX_OK : rc;
}