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> |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 11 | #include <vector> |
Alex Vakulenko | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 12 | |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 13 | #include <base/files/file_path.h> |
Alex Vakulenko | 132617a | 2014-09-04 08:59:43 -0700 | [diff] [blame] | 14 | #include <base/macros.h> |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 15 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 16 | #include <base/values.h> |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/data_serialization.h> |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 18 | #include <chromeos/dbus/dbus_object.h> |
Alex Vakulenko | a8b95bc | 2014-08-27 11:00:57 -0700 | [diff] [blame] | 19 | #include <chromeos/dbus/exported_property_set.h> |
| 20 | #include <chromeos/errors/error.h> |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 21 | |
Alex Vakulenko | 9ea5a32 | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 22 | #include "buffet/commands/command_manager.h" |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 23 | #include "buffet/device_registration_info.h" |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 24 | #include "buffet/org.chromium.Buffet.Manager.h" |
Christopher Wiley | aa3f29c | 2014-03-27 14:51:26 -0700 | [diff] [blame] | 25 | |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 26 | namespace chromeos { |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 27 | namespace dbus_utils { |
| 28 | class ExportedObjectManager; |
| 29 | } // namespace dbus_utils |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 30 | } // namespace chromeos |
| 31 | |
| 32 | namespace buffet { |
| 33 | |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 34 | class BaseApiHandler; |
| 35 | class BuffetConfig; |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 36 | class StateChangeQueue; |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 37 | class StateManager; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 38 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 39 | template<typename... Types> |
| 40 | using DBusMethodResponse = |
Alex Vakulenko | 41f73a9 | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 41 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 42 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 43 | // The Manager is responsible for global state of Buffet. It exposes |
| 44 | // interfaces which affect the entire device such as device registration and |
| 45 | // device state. |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 46 | class Manager final : public org::chromium::Buffet::ManagerInterface { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 47 | public: |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 48 | explicit Manager( |
| 49 | const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& |
| 50 | object_manager); |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 51 | ~Manager(); |
| 52 | |
Vitaly Buka | 76e7059 | 2015-04-16 11:39:02 -0700 | [diff] [blame] | 53 | void Start( |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 54 | const base::FilePath& config_path, |
| 55 | const base::FilePath& state_path, |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 56 | const base::FilePath& test_definitions_path, |
Christopher Wiley | d732bd0 | 2015-04-07 11:11:18 -0700 | [diff] [blame] | 57 | bool xmpp_enabled, |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 58 | const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 61 | // DBus methods: |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 62 | void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 63 | void GetDeviceInfo(DBusMethodResponse<std::string> response) override; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 64 | void RegisterDevice(DBusMethodResponse<std::string> response, |
Vitaly Buka | cad2e33 | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 65 | const std::string& ticket_id) override; |
Vitaly Buka | fa94706 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 66 | bool UpdateDeviceInfo(chromeos::ErrorPtr* error, |
| 67 | const std::string& in_name, |
| 68 | const std::string& in_description, |
| 69 | const std::string& in_location) override; |
Vitaly Buka | ff81db6 | 2015-05-14 21:25:45 -0700 | [diff] [blame] | 70 | bool UpdateServiceConfig(chromeos::ErrorPtr* error, |
| 71 | const std::string& client_id, |
| 72 | const std::string& client_secret, |
| 73 | const std::string& api_key, |
| 74 | const std::string& oauth_url, |
| 75 | const std::string& service_url) override; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 76 | void UpdateState(DBusMethodResponse<> response, |
| 77 | const chromeos::VariantDictionary& property_set) override; |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 78 | bool GetState(chromeos::ErrorPtr* error, std::string* state) override; |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 79 | void AddCommand(DBusMethodResponse<std::string> response, |
Vitaly Buka | b209842 | 2015-05-31 23:32:46 -0700 | [diff] [blame] | 80 | const std::string& json_command, |
| 81 | const std::string& in_user_role) override; |
Vitaly Buka | 3886e8f | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 82 | void GetCommand(DBusMethodResponse<std::string> response, |
| 83 | const std::string& id) override; |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 84 | void SetCommandVisibility( |
Alex Vakulenko | 41f73a9 | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 85 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response, |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 86 | const std::vector<std::string>& in_names, |
| 87 | const std::string& in_visibility) override; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 88 | std::string TestMethod(const std::string& message) override; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 89 | |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 90 | void OnCommandDefsChanged(); |
Vitaly Buka | dbb8c35 | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 91 | void OnStateChanged(); |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 92 | void OnRegistrationChanged(RegistrationStatus status); |
| 93 | void OnConfigChanged(const BuffetConfig& config); |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 94 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 95 | org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this}; |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 96 | chromeos::dbus_utils::DBusObject dbus_object_; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 97 | |
Alex Vakulenko | c2bc9a4 | 2014-07-23 10:57:58 -0700 | [diff] [blame] | 98 | std::shared_ptr<CommandManager> command_manager_; |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 99 | std::unique_ptr<StateChangeQueue> state_change_queue_; |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 100 | std::shared_ptr<StateManager> state_manager_; |
Alex Vakulenko | 1f30a62 | 2014-07-23 11:13:15 -0700 | [diff] [blame] | 101 | std::unique_ptr<DeviceRegistrationInfo> device_info_; |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 102 | std::unique_ptr<BaseApiHandler> base_api_handler_; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 103 | |
Vitaly Buka | 5e6ff6c | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 104 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 106 | }; |
| 107 | |
| 108 | } // namespace buffet |
| 109 | |
| 110 | #endif // BUFFET_MANAGER_H_ |