blob: 13aa8f42fc3658d72275b9a5e78be4f6d0354ac9 [file] [log] [blame]
// Copyright 2014 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 BUFFET_DBUS_MANAGER_H_
#define BUFFET_DBUS_MANAGER_H_
#include <string>
#include <base/memory/scoped_ptr.h>
#include <dbus/bus.h>
#include <dbus/exported_object.h>
#include <dbus/message.h>
namespace buffet {
// Class that manages dbus interactions in buffet.
class DBusManager {
public:
typedef base::Callback<void(bool success)> OnInitFinish;
DBusManager(dbus::Bus* bus);
virtual ~DBusManager();
void Init(const OnInitFinish& cb);
void Finalize();
// Get an object owned by the ::dbus::Bus object. This object
// has methods to export DBus facing methods.
::dbus::ExportedObject* GetExportedObject(
const std::string& object_path);
// Exports |method_name| on |exported_object| and uses |member|
// to handle calls.
void ExportDBusMethod(
::dbus::ExportedObject* exported_object,
const std::string& interface_name,
const std::string& method_name,
base::Callback<scoped_ptr<::dbus::Response>(
::dbus::MethodCall*)> handler);
private:
// Connects to the D-Bus system bus and exports methods.
void InitDBus();
void ShutDownDBus();
// Callbacks for handling D-Bus signals and method calls.
scoped_ptr<::dbus::Response> HandleTestMethod(
::dbus::MethodCall* method_call);
scoped_refptr<::dbus::Bus> bus_; // Must outlive this object.
dbus::ExportedObject* exported_object_; // Owned by the bus.
DISALLOW_COPY_AND_ASSIGN(DBusManager);
};
} // namespace buffet
#endif // BUFFET_DBUS_MANAGER_H_