blob: 2bb9d5f23aec48084295ad9b0d9b80fd8516b1c7 [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_MANAGER_H_
#define BUFFET_MANAGER_H_
#include <memory>
#include <string>
#include <base/basictypes.h>
#include <base/memory/scoped_ptr.h>
#include <base/memory/weak_ptr.h>
#include <base/values.h>
#include <chromeos/exported_property_set.h>
#include <dbus/bus.h>
#include <dbus/message.h>
#include <dbus/object_path.h>
#include "buffet/dbus_constants.h"
#include "buffet/device_registration_info.h"
namespace chromeos {
namespace dbus_utils {
class ExportedObjectManager;
} // namespace dbus_utils
} // namespace chromeos
namespace buffet {
class CommandManager;
// The Manager is responsible for global state of Buffet. It exposes
// interfaces which affect the entire device such as device registration and
// device state.
class Manager {
public:
typedef base::Callback<void(bool success)> OnInitFinish;
Manager(const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
object_manager);
~Manager();
void Init(const OnInitFinish& cb);
private:
struct Properties: public chromeos::dbus_utils::ExportedPropertySet {
public:
chromeos::dbus_utils::ExportedProperty<std::string> state_;
explicit Properties(dbus::Bus* bus)
: chromeos::dbus_utils::ExportedPropertySet(
bus, dbus::ObjectPath(dbus_constants::kManagerServicePath)) {
RegisterProperty(dbus_constants::kManagerInterface, "State", &state_);
}
virtual ~Properties() {}
};
// Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
scoped_ptr<dbus::Response> HandleCheckDeviceRegistered(
dbus::MethodCall* method_call);
// Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
scoped_ptr<dbus::Response> HandleGetDeviceInfo(
dbus::MethodCall* method_call);
// Handles calls to org.chromium.Buffet.Manager.StartRegisterDevice().
scoped_ptr<dbus::Response> HandleStartRegisterDevice(
dbus::MethodCall* method_call);
// Handles calls to org.chromium.Buffet.Manager.FinishRegisterDevice().
scoped_ptr<dbus::Response> HandleFinishRegisterDevice(
dbus::MethodCall* method_call);
// Handles calls to org.chromium.Buffet.Manager.UpdateState().
scoped_ptr<dbus::Response> HandleUpdateState(
dbus::MethodCall* method_call);
// Handles calls to org.chromium.Buffet.Manager.Test()
scoped_ptr<::dbus::Response> HandleTestMethod(
::dbus::MethodCall* method_call);
dbus::ExportedObject* exported_object_; // weak; owned by the Bus object.
base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager> object_manager_;
scoped_ptr<Properties> properties_;
std::shared_ptr<CommandManager> command_manager_;
std::unique_ptr<DeviceRegistrationInfo> device_info_;
DISALLOW_COPY_AND_ASSIGN(Manager);
};
} // namespace buffet
#endif // BUFFET_MANAGER_H_