Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 1 | // 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 Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 8 | #include <map> |
Alex Vakulenko | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <string> |
| 11 | |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 12 | #include <base/files/file_path.h> |
Alex Vakulenko | 132617a | 2014-09-04 08:59:43 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 14 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 15 | #include <base/values.h> |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 16 | #include <chromeos/dbus/data_serialization.h> |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/dbus_object.h> |
Alex Vakulenko | a8b95bc | 2014-08-27 11:00:57 -0700 | [diff] [blame] | 18 | #include <chromeos/dbus/exported_property_set.h> |
| 19 | #include <chromeos/errors/error.h> |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 20 | |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 21 | #include "buffet/device_registration_info.h" |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 22 | #include "buffet/org.chromium.Buffet.Manager.h" |
Christopher Wiley | aa3f29c | 2014-03-27 14:51:26 -0700 | [diff] [blame] | 23 | |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 24 | namespace chromeos { |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 25 | namespace dbus_utils { |
| 26 | class ExportedObjectManager; |
| 27 | } // namespace dbus_utils |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 28 | } // namespace chromeos |
| 29 | |
| 30 | namespace buffet { |
| 31 | |
| 32 | class CommandManager; |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 33 | class StateChangeQueue; |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 34 | class StateManager; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 35 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 36 | template<typename... Types> |
| 37 | using DBusMethodResponse = |
| 38 | scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; |
| 39 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 40 | // 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 Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 43 | class Manager final : public org::chromium::Buffet::ManagerInterface { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 44 | public: |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 45 | explicit Manager( |
| 46 | const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& |
| 47 | object_manager); |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 48 | ~Manager(); |
| 49 | |
Alex Vakulenko | be9c383 | 2014-08-24 15:05:06 -0700 | [diff] [blame] | 50 | void RegisterAsync( |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 51 | const base::FilePath& config_path, |
| 52 | const base::FilePath& state_path, |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 53 | const base::FilePath& test_definitions_path, |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 54 | const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 55 | |
| 56 | private: |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 57 | // DBus methods: |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 58 | // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered(). |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 59 | void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 60 | // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo(). |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 61 | void GetDeviceInfo(DBusMethodResponse<std::string> response) override; |
Anton Muhin | beb1c5b | 2014-10-16 18:59:57 +0400 | [diff] [blame] | 62 | // Handles calls to org.chromium.Buffet.Manager.RegisterDevice(). |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 63 | void RegisterDevice(DBusMethodResponse<std::string> response, |
| 64 | const chromeos::VariantDictionary& params) override; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 65 | // Handles calls to org.chromium.Buffet.Manager.UpdateState(). |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 66 | void UpdateState(DBusMethodResponse<> response, |
| 67 | const chromeos::VariantDictionary& property_set) override; |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 68 | // Handles calls to org.chromium.Buffet.Manager.GetState(). |
| 69 | bool GetState(chromeos::ErrorPtr* error, std::string* state) override; |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 70 | // Handles calls to org.chromium.Buffet.Manager.AddCommand(). |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 71 | void AddCommand(DBusMethodResponse<> response, |
| 72 | const std::string& json_command) override; |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 73 | // Handles calls to org.chromium.Buffet.Manager.Test() |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 74 | std::string TestMethod(const std::string& message) override; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 75 | |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 76 | void OnRegistrationStatusChanged(); |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 77 | void OnCommandDefsChanged(); |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 78 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 79 | org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this}; |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 80 | chromeos::dbus_utils::DBusObject dbus_object_; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 81 | |
Alex Vakulenko | c2bc9a4 | 2014-07-23 10:57:58 -0700 | [diff] [blame] | 82 | std::shared_ptr<CommandManager> command_manager_; |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 83 | std::unique_ptr<StateChangeQueue> state_change_queue_; |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 84 | std::shared_ptr<StateManager> state_manager_; |
Alex Vakulenko | 1f30a62 | 2014-07-23 11:13:15 -0700 | [diff] [blame] | 85 | std::unique_ptr<DeviceRegistrationInfo> device_info_; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 86 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 88 | }; |
| 89 | |
| 90 | } // namespace buffet |
| 91 | |
| 92 | #endif // BUFFET_MANAGER_H_ |