blob: 1c891ecadb844bf8354f46d815fa351e3d12a9fa [file] [log] [blame]
Christopher Wiley4b5f04c2014-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 Vakulenkob6351532014-08-15 11:49:35 -07008#include <map>
Alex Vakulenko24aa1222014-05-12 15:55:25 -07009#include <memory>
10#include <string>
11
Christopher Wiley357deca2015-02-07 18:29:32 -080012#include <base/files/file_path.h>
Alex Vakulenko274226b2014-09-04 08:59:43 -070013#include <base/macros.h>
Christopher Wileyd71774f2014-05-07 09:58:45 -070014#include <base/memory/weak_ptr.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070015#include <base/values.h>
Alex Vakulenko95877b52014-09-19 15:31:09 -070016#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkob6351532014-08-15 11:49:35 -070017#include <chromeos/dbus/dbus_object.h>
Alex Vakulenko24e5f5d2014-08-27 11:00:57 -070018#include <chromeos/dbus/exported_property_set.h>
19#include <chromeos/errors/error.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070020
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070021#include "buffet/device_registration_info.h"
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080022#include "buffet/org.chromium.Buffet.Manager.h"
Christopher Wiley106686a2014-03-27 14:51:26 -070023
Christopher Wiley1aa980e2014-08-11 10:51:20 -070024namespace chromeos {
Christopher Wileyd71774f2014-05-07 09:58:45 -070025namespace dbus_utils {
26class ExportedObjectManager;
27} // namespace dbus_utils
Christopher Wiley1aa980e2014-08-11 10:51:20 -070028} // namespace chromeos
29
30namespace buffet {
31
32class CommandManager;
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070033class StateChangeQueue;
Alex Vakulenko95877b52014-09-19 15:31:09 -070034class StateManager;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070035
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080036template<typename... Types>
37using DBusMethodResponse =
38 scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
39
Christopher Wiley4b5f04c2014-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 Vakulenko12e2c1a2014-11-21 08:57:57 -080043class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070044 public:
Alex Vakulenkob6351532014-08-15 11:49:35 -070045 explicit Manager(
46 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
47 object_manager);
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070048 ~Manager();
49
Alex Vakulenko4a8d9de2014-08-24 15:05:06 -070050 void RegisterAsync(
Christopher Wiley357deca2015-02-07 18:29:32 -080051 const base::FilePath& config_path,
52 const base::FilePath& state_path,
Christopher Wileyc39f4a32015-02-12 13:42:16 -080053 const base::FilePath& test_definitions_path,
Alex Vakulenkob6351532014-08-15 11:49:35 -070054 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070055
56 private:
Alex Vakulenkob6351532014-08-15 11:49:35 -070057 // DBus methods:
Anton Muhin914b1382014-10-01 18:06:54 +040058 // Handles calls to org.chromium.Buffet.Manager.StartDevice().
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080059 void StartDevice(DBusMethodResponse<> response) override;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070060 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080061 void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070062 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080063 void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
Anton Muhin9cc03fd2014-10-16 18:59:57 +040064 // Handles calls to org.chromium.Buffet.Manager.RegisterDevice().
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080065 void RegisterDevice(DBusMethodResponse<std::string> response,
66 const chromeos::VariantDictionary& params) override;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070067 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080068 void UpdateState(DBusMethodResponse<> response,
69 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenkoceab1772015-01-20 10:50:04 -080070 // Handles calls to org.chromium.Buffet.Manager.GetState().
71 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko4f7778e2014-09-11 16:57:24 -070072 // Handles calls to org.chromium.Buffet.Manager.AddCommand().
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080073 void AddCommand(DBusMethodResponse<> response,
74 const std::string& json_command) override;
Christopher Wiley2ffa0042014-05-05 16:09:16 -070075 // Handles calls to org.chromium.Buffet.Manager.Test()
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080076 std::string TestMethod(const std::string& message) override;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070077
Christopher Wiley2f772932015-02-15 15:42:04 -080078 void OnRegistrationStatusChange(RegistrationStatus status);
79
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080080 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkob6351532014-08-15 11:49:35 -070081 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070082
Alex Vakulenkocf9c1462014-07-23 10:57:58 -070083 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070084 std::unique_ptr<StateChangeQueue> state_change_queue_;
Alex Vakulenko95877b52014-09-19 15:31:09 -070085 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko98025c22014-07-23 11:13:15 -070086 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070087
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070088 DISALLOW_COPY_AND_ASSIGN(Manager);
89};
90
91} // namespace buffet
92
93#endif // BUFFET_MANAGER_H_