blob: 318ee746f893075725580c5b9b180475f8965cc0 [file] [log] [blame]
Christopher Wileya4915c42014-03-27 14:45:37 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BUFFET_MANAGER_H_
6#define BUFFET_MANAGER_H_
7
Alex Vakulenkof2784de2014-08-15 11:49:35 -07008#include <map>
Alex Vakulenko33797062014-05-12 15:55:25 -07009#include <memory>
10#include <string>
11
Alex Vakulenko132617a2014-09-04 08:59:43 -070012#include <base/macros.h>
Christopher Wileyadb901d2014-05-07 09:58:45 -070013#include <base/memory/weak_ptr.h>
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070014#include <base/values.h>
Alex Vakulenko07216fe2014-09-19 15:31:09 -070015#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkof2784de2014-08-15 11:49:35 -070016#include <chromeos/dbus/dbus_object.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -070017#include <chromeos/dbus/exported_property_set.h>
18#include <chromeos/errors/error.h>
Christopher Wileya4915c42014-03-27 14:45:37 -070019
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070020#include "buffet/device_registration_info.h"
Alex Vakulenko2348e422014-11-21 08:57:57 -080021#include "buffet/org.chromium.Buffet.Manager.h"
Christopher Wileyaa3f29c2014-03-27 14:51:26 -070022
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070023namespace chromeos {
Christopher Wileyadb901d2014-05-07 09:58:45 -070024namespace dbus_utils {
25class ExportedObjectManager;
26} // namespace dbus_utils
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070027} // namespace chromeos
28
29namespace buffet {
30
31class CommandManager;
Alex Vakulenko57123b22014-10-28 13:50:16 -070032class StateChangeQueue;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070033class StateManager;
Christopher Wileya4915c42014-03-27 14:45:37 -070034
Alex Vakulenko2348e422014-11-21 08:57:57 -080035template<typename... Types>
36using DBusMethodResponse =
37 scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
38
Christopher Wileya4915c42014-03-27 14:45:37 -070039// The Manager is responsible for global state of Buffet. It exposes
40// interfaces which affect the entire device such as device registration and
41// device state.
Alex Vakulenko2348e422014-11-21 08:57:57 -080042class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wileya4915c42014-03-27 14:45:37 -070043 public:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070044 explicit Manager(
45 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
46 object_manager);
Alex Vakulenko57123b22014-10-28 13:50:16 -070047 ~Manager();
48
Alex Vakulenkobe9c3832014-08-24 15:05:06 -070049 void RegisterAsync(
Alex Vakulenkof2784de2014-08-15 11:49:35 -070050 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wileya4915c42014-03-27 14:45:37 -070051
52 private:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070053 // DBus methods:
Anton Muhin86d67fe2014-10-01 18:06:54 +040054 // Handles calls to org.chromium.Buffet.Manager.StartDevice().
Alex Vakulenko2348e422014-11-21 08:57:57 -080055 void StartDevice(DBusMethodResponse<> response) override;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070056 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
Alex Vakulenko2348e422014-11-21 08:57:57 -080057 void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070058 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
Alex Vakulenko2348e422014-11-21 08:57:57 -080059 void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
Anton Muhinbeb1c5b2014-10-16 18:59:57 +040060 // Handles calls to org.chromium.Buffet.Manager.RegisterDevice().
Alex Vakulenko2348e422014-11-21 08:57:57 -080061 void RegisterDevice(DBusMethodResponse<std::string> response,
62 const chromeos::VariantDictionary& params) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070063 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
Alex Vakulenko2348e422014-11-21 08:57:57 -080064 void UpdateState(DBusMethodResponse<> response,
65 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenko665c8852014-09-11 16:57:24 -070066 // Handles calls to org.chromium.Buffet.Manager.AddCommand().
Alex Vakulenko2348e422014-11-21 08:57:57 -080067 void AddCommand(DBusMethodResponse<> response,
68 const std::string& json_command) override;
Christopher Wileyb76eb292014-05-05 16:09:16 -070069 // Handles calls to org.chromium.Buffet.Manager.Test()
Alex Vakulenko2348e422014-11-21 08:57:57 -080070 std::string TestMethod(const std::string& message) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070071
Alex Vakulenko2348e422014-11-21 08:57:57 -080072 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkof2784de2014-08-15 11:49:35 -070073 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wileya4915c42014-03-27 14:45:37 -070074
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070075 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenko57123b22014-10-28 13:50:16 -070076 std::unique_ptr<StateChangeQueue> state_change_queue_;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070077 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko1f30a622014-07-23 11:13:15 -070078 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070079
Christopher Wileya4915c42014-03-27 14:45:37 -070080 DISALLOW_COPY_AND_ASSIGN(Manager);
81};
82
83} // namespace buffet
84
85#endif // BUFFET_MANAGER_H_