blob: d307ca2161c796a1dec5d1336805e9dddc019515 [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
Christopher Wileye0fdeee2015-02-07 18:29:32 -080012#include <base/files/file_path.h>
Alex Vakulenko132617a2014-09-04 08:59:43 -070013#include <base/macros.h>
Christopher Wileyadb901d2014-05-07 09:58:45 -070014#include <base/memory/weak_ptr.h>
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070015#include <base/values.h>
Alex Vakulenko07216fe2014-09-19 15:31:09 -070016#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkof2784de2014-08-15 11:49:35 -070017#include <chromeos/dbus/dbus_object.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -070018#include <chromeos/dbus/exported_property_set.h>
19#include <chromeos/errors/error.h>
Christopher Wileya4915c42014-03-27 14:45:37 -070020
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070021#include "buffet/device_registration_info.h"
Alex Vakulenko2348e422014-11-21 08:57:57 -080022#include "buffet/org.chromium.Buffet.Manager.h"
Christopher Wileyaa3f29c2014-03-27 14:51:26 -070023
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070024namespace chromeos {
Christopher Wileyadb901d2014-05-07 09:58:45 -070025namespace dbus_utils {
26class ExportedObjectManager;
27} // namespace dbus_utils
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070028} // namespace chromeos
29
30namespace buffet {
31
32class CommandManager;
Alex Vakulenko57123b22014-10-28 13:50:16 -070033class StateChangeQueue;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070034class StateManager;
Christopher Wileya4915c42014-03-27 14:45:37 -070035
Alex Vakulenko2348e422014-11-21 08:57:57 -080036template<typename... Types>
37using DBusMethodResponse =
38 scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
39
Christopher Wileya4915c42014-03-27 14:45:37 -070040// The Manager is responsible for global state of Buffet. It exposes
41// interfaces which affect the entire device such as device registration and
42// device state.
Alex Vakulenko2348e422014-11-21 08:57:57 -080043class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wileya4915c42014-03-27 14:45:37 -070044 public:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070045 explicit Manager(
46 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
47 object_manager);
Alex Vakulenko57123b22014-10-28 13:50:16 -070048 ~Manager();
49
Alex Vakulenkobe9c3832014-08-24 15:05:06 -070050 void RegisterAsync(
Christopher Wileye0fdeee2015-02-07 18:29:32 -080051 const base::FilePath& config_path,
52 const base::FilePath& state_path,
Christopher Wileybb5b8482015-02-12 13:42:16 -080053 const base::FilePath& test_definitions_path,
Alex Vakulenkof2784de2014-08-15 11:49:35 -070054 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wileya4915c42014-03-27 14:45:37 -070055
56 private:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070057 // DBus methods:
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070058 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
Alex Vakulenko2348e422014-11-21 08:57:57 -080059 void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070060 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
Alex Vakulenko2348e422014-11-21 08:57:57 -080061 void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
Anton Muhinbeb1c5b2014-10-16 18:59:57 +040062 // Handles calls to org.chromium.Buffet.Manager.RegisterDevice().
Alex Vakulenko2348e422014-11-21 08:57:57 -080063 void RegisterDevice(DBusMethodResponse<std::string> response,
64 const chromeos::VariantDictionary& params) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070065 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
Alex Vakulenko2348e422014-11-21 08:57:57 -080066 void UpdateState(DBusMethodResponse<> response,
67 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenko61ad4db2015-01-20 10:50:04 -080068 // Handles calls to org.chromium.Buffet.Manager.GetState().
69 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko665c8852014-09-11 16:57:24 -070070 // Handles calls to org.chromium.Buffet.Manager.AddCommand().
Alex Vakulenko2348e422014-11-21 08:57:57 -080071 void AddCommand(DBusMethodResponse<> response,
72 const std::string& json_command) override;
Christopher Wileyb76eb292014-05-05 16:09:16 -070073 // Handles calls to org.chromium.Buffet.Manager.Test()
Alex Vakulenko2348e422014-11-21 08:57:57 -080074 std::string TestMethod(const std::string& message) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070075
Vitaly Buka7ad8ffb2015-03-20 09:46:57 -070076 void OnRegistrationStatusChanged();
Vitaly Bukaaabadee2015-03-18 23:33:44 -070077 void OnCommandDefsChanged();
Christopher Wileyc900e482015-02-15 15:42:04 -080078
Alex Vakulenko2348e422014-11-21 08:57:57 -080079 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkof2784de2014-08-15 11:49:35 -070080 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wileya4915c42014-03-27 14:45:37 -070081
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070082 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenko57123b22014-10-28 13:50:16 -070083 std::unique_ptr<StateChangeQueue> state_change_queue_;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070084 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko1f30a622014-07-23 11:13:15 -070085 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070086
Christopher Wileya4915c42014-03-27 14:45:37 -070087 DISALLOW_COPY_AND_ASSIGN(Manager);
88};
89
90} // namespace buffet
91
92#endif // BUFFET_MANAGER_H_