blob: 3cf702116041d108f726ad21ec9dd12ad8fae686 [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>
Alex Vakulenkoacec6aa2015-04-20 11:00:54 -070011#include <vector>
Alex Vakulenko24aa1222014-05-12 15:55:25 -070012
Christopher Wiley357deca2015-02-07 18:29:32 -080013#include <base/files/file_path.h>
Alex Vakulenko274226b2014-09-04 08:59:43 -070014#include <base/macros.h>
Christopher Wileyd71774f2014-05-07 09:58:45 -070015#include <base/memory/weak_ptr.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070016#include <base/values.h>
Alex Vakulenko95877b52014-09-19 15:31:09 -070017#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkob6351532014-08-15 11:49:35 -070018#include <chromeos/dbus/dbus_object.h>
Alex Vakulenko24e5f5d2014-08-27 11:00:57 -070019#include <chromeos/dbus/exported_property_set.h>
20#include <chromeos/errors/error.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070021
Alex Vakulenkoec41a0c2015-04-17 15:35:34 -070022#include "buffet/commands/command_manager.h"
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070023#include "buffet/device_registration_info.h"
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080024#include "buffet/org.chromium.Buffet.Manager.h"
Christopher Wiley106686a2014-03-27 14:51:26 -070025
Christopher Wiley1aa980e2014-08-11 10:51:20 -070026namespace chromeos {
Christopher Wileyd71774f2014-05-07 09:58:45 -070027namespace dbus_utils {
28class ExportedObjectManager;
29} // namespace dbus_utils
Christopher Wiley1aa980e2014-08-11 10:51:20 -070030} // namespace chromeos
31
32namespace buffet {
33
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070034class StateChangeQueue;
Alex Vakulenko95877b52014-09-19 15:31:09 -070035class StateManager;
Vitaly Buka760d6322015-04-17 00:41:31 -070036class BuffetConfig;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070037
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080038template<typename... Types>
39using DBusMethodResponse =
40 scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
41
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070042// The Manager is responsible for global state of Buffet. It exposes
43// interfaces which affect the entire device such as device registration and
44// device state.
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080045class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070046 public:
Alex Vakulenkob6351532014-08-15 11:49:35 -070047 explicit Manager(
48 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
49 object_manager);
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070050 ~Manager();
51
Vitaly Bukae46525b2015-04-16 11:39:02 -070052 void Start(
Christopher Wiley357deca2015-02-07 18:29:32 -080053 const base::FilePath& config_path,
54 const base::FilePath& state_path,
Christopher Wileyc39f4a32015-02-12 13:42:16 -080055 const base::FilePath& test_definitions_path,
Christopher Wiley1d35ecc2015-04-07 11:11:18 -070056 bool xmpp_enabled,
Alex Vakulenkob6351532014-08-15 11:49:35 -070057 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070058
59 private:
Alex Vakulenkob6351532014-08-15 11:49:35 -070060 // DBus methods:
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080061 void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080062 void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080063 void RegisterDevice(DBusMethodResponse<std::string> response,
64 const chromeos::VariantDictionary& params) override;
Vitaly Buka760d6322015-04-17 00:41:31 -070065 bool UpdateDeviceInfo(chromeos::ErrorPtr* error,
66 const std::string& in_name,
67 const std::string& in_description,
68 const std::string& in_location) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080069 void UpdateState(DBusMethodResponse<> response,
70 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenkoceab1772015-01-20 10:50:04 -080071 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Vitaly Buka59af7ac2015-03-24 12:42:24 -070072 void AddCommand(DBusMethodResponse<std::string> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080073 const std::string& json_command) override;
Vitaly Buka5515de02015-03-24 11:39:40 -070074 void GetCommand(DBusMethodResponse<std::string> response,
75 const std::string& id) override;
Alex Vakulenkoacec6aa2015-04-20 11:00:54 -070076 void SetCommandVisibility(
77 scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response,
78 const std::vector<std::string>& in_names,
79 const std::string& in_visibility) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080080 std::string TestMethod(const std::string& message) override;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070081
Vitaly Buka1fa69012015-03-18 23:33:44 -070082 void OnCommandDefsChanged();
Christopher Wiley2f772932015-02-15 15:42:04 -080083
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080084 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkob6351532014-08-15 11:49:35 -070085 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070086
Alex Vakulenkocf9c1462014-07-23 10:57:58 -070087 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070088 std::unique_ptr<StateChangeQueue> state_change_queue_;
Alex Vakulenko95877b52014-09-19 15:31:09 -070089 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko98025c22014-07-23 11:13:15 -070090 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070091
Alex Vakulenkoec41a0c2015-04-17 15:35:34 -070092 // Token given by Command Manager to track the registered Command Definition
93 // change callback.
94 CommandManager::CallbackToken command_changed_callback_token_;
95
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070096 DISALLOW_COPY_AND_ASSIGN(Manager);
97};
98
99} // namespace buffet
100
101#endif // BUFFET_MANAGER_H_