blob: 3b0d5409a74d7ee9a7e5118ab1046cce32e215b4 [file] [log] [blame]
// 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.
#ifndef RMAD_DBUS_SERVICE_H_
#define RMAD_DBUS_SERVICE_H_
#include <memory>
#include <brillo/daemons/dbus_daemon.h>
#include <brillo/dbus/dbus_method_response.h>
#include <brillo/dbus/dbus_object.h>
#include <dbus/bus.h>
#include "rmad/rmad_interface.h"
namespace rmad {
class DBusService : public brillo::DBusServiceDaemon {
public:
explicit DBusService(RmadInterface* rmad_interface);
// Used to inject a mock bus.
DBusService(const scoped_refptr<dbus::Bus>& bus,
RmadInterface* rmad_interface);
DBusService(const DBusService&) = delete;
DBusService& operator=(const DBusService&) = delete;
~DBusService() override;
protected:
// brillo::DBusServiceDaemon overrides.
int OnInit() override;
void RegisterDBusObjectsAsync(
brillo::dbus_utils::AsyncEventSequencer* sequencer) override;
private:
friend class DBusServiceTest;
// Handler for GetCurrentState D-Bus call.
using GetCurrentStateResponse =
brillo::dbus_utils::DBusMethodResponse<const GetCurrentStateReply&>;
void HandleGetCurrentState(std::unique_ptr<GetCurrentStateResponse> response,
const GetCurrentStateRequest& request);
template <typename ResponseType, typename ReplyProtobufType>
void ReplyAndQuit(std::shared_ptr<ResponseType> response,
const ReplyProtobufType& reply);
// Schedule an asynchronous D-Bus shutdown and exit the daemon.
void PostQuitTask();
std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_;
RmadInterface* rmad_interface_;
};
} // namespace rmad
#endif // RMAD_DBUS_SERVICE_H_