| // Copyright 2021 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "minios/daemon.h" |
| |
| #include <brillo/message_loops/message_loop.h> |
| #include <dbus/minios/dbus-constants.h> |
| #include <sysexits.h> |
| |
| namespace minios { |
| |
| Daemon::Daemon() : DBusServiceDaemon(kMiniOsServiceName) {} |
| |
| void Daemon::Start() { |
| mini_os_->Run(); |
| } |
| |
| int Daemon::OnEventLoopStarted() { |
| int return_code = brillo::DBusServiceDaemon::OnEventLoopStarted(); |
| if (return_code != EX_OK) |
| return return_code; |
| |
| brillo::MessageLoop::current()->PostTask( |
| FROM_HERE, base::Bind(&Daemon::Start, base::Unretained(this))); |
| return EX_OK; |
| } |
| |
| void Daemon::RegisterDBusObjectsAsync( |
| brillo::dbus_utils::AsyncEventSequencer* sequencer) { |
| dbus_object_ = std::make_unique<brillo::dbus_utils::DBusObject>( |
| nullptr, bus_, org::chromium::MiniOsInterfaceAdaptor::GetObjectPath()); |
| |
| mini_os_ = std::make_shared<MiniOs>(); |
| dbus_adaptor_ = |
| std::make_unique<DBusAdaptor>(std::make_unique<DBusService>(mini_os_)); |
| |
| dbus_adaptor_->RegisterWithDBusObject(dbus_object_.get()); |
| dbus_object_->RegisterAsync( |
| sequencer->GetHandler("RegisterAsync() failed.", true)); |
| } |
| |
| } // namespace minios |