blob: d21f06200194fab8ab95bab8bc3760fce9e6999f [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,
Christopher Wileyd732bd02015-04-07 11:11:18 -070054 bool xmpp_enabled,
Alex Vakulenkof2784de2014-08-15 11:49:35 -070055 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wileya4915c42014-03-27 14:45:37 -070056
57 private:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070058 // DBus methods:
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070059 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
Alex Vakulenko2348e422014-11-21 08:57:57 -080060 void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070061 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
Alex Vakulenko2348e422014-11-21 08:57:57 -080062 void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
Anton Muhinbeb1c5b2014-10-16 18:59:57 +040063 // Handles calls to org.chromium.Buffet.Manager.RegisterDevice().
Alex Vakulenko2348e422014-11-21 08:57:57 -080064 void RegisterDevice(DBusMethodResponse<std::string> response,
65 const chromeos::VariantDictionary& params) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070066 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
Alex Vakulenko2348e422014-11-21 08:57:57 -080067 void UpdateState(DBusMethodResponse<> response,
68 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenko61ad4db2015-01-20 10:50:04 -080069 // Handles calls to org.chromium.Buffet.Manager.GetState().
70 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko665c8852014-09-11 16:57:24 -070071 // Handles calls to org.chromium.Buffet.Manager.AddCommand().
Vitaly Buka64fc5fc2015-03-24 12:42:24 -070072 void AddCommand(DBusMethodResponse<std::string> response,
Alex Vakulenko2348e422014-11-21 08:57:57 -080073 const std::string& json_command) override;
Vitaly Buka3886e8f2015-03-24 11:39:40 -070074 // Handles calls to org.chromium.Buffet.Manager.GetCommand().
75 void GetCommand(DBusMethodResponse<std::string> response,
76 const std::string& id) override;
Christopher Wileyb76eb292014-05-05 16:09:16 -070077 // Handles calls to org.chromium.Buffet.Manager.Test()
Alex Vakulenko2348e422014-11-21 08:57:57 -080078 std::string TestMethod(const std::string& message) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070079
Vitaly Buka7ad8ffb2015-03-20 09:46:57 -070080 void OnRegistrationStatusChanged();
Vitaly Bukaaabadee2015-03-18 23:33:44 -070081 void OnCommandDefsChanged();
Christopher Wileyc900e482015-02-15 15:42:04 -080082
Alex Vakulenko2348e422014-11-21 08:57:57 -080083 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkof2784de2014-08-15 11:49:35 -070084 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wileya4915c42014-03-27 14:45:37 -070085
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070086 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenko57123b22014-10-28 13:50:16 -070087 std::unique_ptr<StateChangeQueue> state_change_queue_;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070088 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko1f30a622014-07-23 11:13:15 -070089 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070090
Christopher Wileya4915c42014-03-27 14:45:37 -070091 DISALLOW_COPY_AND_ASSIGN(Manager);
92};
93
94} // namespace buffet
95
96#endif // BUFFET_MANAGER_H_