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 | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 8 | #include <memory> |
Vitaly Buka | 63cc3d2 | 2015-06-23 20:11:36 -0700 | [diff] [blame] | 9 | #include <set> |
Alex Vakulenko | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 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 | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 22 | #include "buffet/org.chromium.Buffet.Manager.h" |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 23 | #include "weave/device.h" |
Christopher Wiley | aa3f29c | 2014-03-27 14:51:26 -0700 | [diff] [blame] | 24 | |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 25 | namespace chromeos { |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 26 | namespace dbus_utils { |
| 27 | class ExportedObjectManager; |
| 28 | } // namespace dbus_utils |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 29 | } // namespace chromeos |
| 30 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 31 | namespace buffet { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 32 | |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 33 | class DBusCommandDispacher; |
Vitaly Buka | ddb2e38 | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 34 | class PeerdClient; |
| 35 | class ShillClient; |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 36 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 37 | template<typename... Types> |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 38 | using DBusMethodResponsePtr = |
Alex Vakulenko | 41f73a9 | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 39 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 40 | |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 41 | template<typename... Types> |
| 42 | using DBusMethodResponse = |
| 43 | chromeos::dbus_utils::DBusMethodResponse<Types...>; |
| 44 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 45 | // The Manager is responsible for global state of Buffet. It exposes |
| 46 | // interfaces which affect the entire device such as device registration and |
| 47 | // device state. |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 48 | class Manager final : public org::chromium::Buffet::ManagerInterface { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 49 | public: |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 50 | explicit Manager( |
| 51 | const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& |
| 52 | object_manager); |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 53 | ~Manager(); |
| 54 | |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 55 | void Start(const weave::Device::Options& options, |
Vitaly Buka | ddb2e38 | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 56 | const std::set<std::string>& device_whitelist, |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 57 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 58 | |
| 59 | void Stop(); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 60 | |
| 61 | private: |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 62 | // DBus methods: |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 63 | void CheckDeviceRegistered( |
| 64 | DBusMethodResponsePtr<std::string> response) override; |
| 65 | void GetDeviceInfo(DBusMethodResponsePtr<std::string> response) override; |
| 66 | void RegisterDevice(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | cad2e33 | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 67 | const std::string& ticket_id) override; |
Vitaly Buka | fa94706 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 68 | bool UpdateDeviceInfo(chromeos::ErrorPtr* error, |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 69 | const std::string& name, |
| 70 | const std::string& description, |
| 71 | const std::string& location) override; |
Vitaly Buka | ff81db6 | 2015-05-14 21:25:45 -0700 | [diff] [blame] | 72 | bool UpdateServiceConfig(chromeos::ErrorPtr* error, |
| 73 | const std::string& client_id, |
| 74 | const std::string& client_secret, |
| 75 | const std::string& api_key, |
| 76 | const std::string& oauth_url, |
| 77 | const std::string& service_url) override; |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 78 | void UpdateState(DBusMethodResponsePtr<> response, |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 79 | const chromeos::VariantDictionary& property_set) override; |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 80 | bool GetState(chromeos::ErrorPtr* error, std::string* state) override; |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 81 | void AddCommand(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | b209842 | 2015-05-31 23:32:46 -0700 | [diff] [blame] | 82 | const std::string& json_command, |
| 83 | const std::string& in_user_role) override; |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 84 | void GetCommand(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | 3886e8f | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 85 | const std::string& id) override; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 86 | std::string TestMethod(const std::string& message) override; |
Vitaly Buka | 505c413 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 87 | bool EnableWiFiBootstrapping( |
| 88 | chromeos::ErrorPtr* error, |
| 89 | const dbus::ObjectPath& in_listener_path, |
| 90 | const chromeos::VariantDictionary& in_options) override; |
| 91 | bool DisableWiFiBootstrapping(chromeos::ErrorPtr* error) override; |
| 92 | bool EnableGCDBootstrapping( |
| 93 | chromeos::ErrorPtr* error, |
| 94 | const dbus::ObjectPath& in_listener_path, |
| 95 | const chromeos::VariantDictionary& in_options) override; |
| 96 | bool DisableGCDBootstrapping(chromeos::ErrorPtr* error) override; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 97 | |
Alex Vakulenko | 266b2b1 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 98 | void OnGetDeviceInfoSuccess( |
| 99 | const std::shared_ptr<DBusMethodResponse<std::string>>& response, |
| 100 | const base::DictionaryValue& device_info); |
| 101 | void OnGetDeviceInfoError( |
| 102 | const std::shared_ptr<DBusMethodResponse<std::string>>& response, |
| 103 | const chromeos::Error* error); |
| 104 | |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 105 | void StartPrivet(const weave::Device::Options& options, |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 106 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 107 | |
Vitaly Buka | dbb8c35 | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 108 | void OnStateChanged(); |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 109 | void OnRegistrationChanged(weave::RegistrationStatus status); |
Vitaly Buka | bc3e8bd | 2015-07-20 00:37:48 -0700 | [diff] [blame] | 110 | void OnConfigChanged(const weave::Settings& settings); |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 111 | void UpdateWiFiBootstrapState(weave::WifiSetupState state); |
Vitaly Buka | 505c413 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 112 | void OnPairingStart(const std::string& session_id, |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 113 | weave::PairingType pairing_type, |
Vitaly Buka | 505c413 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 114 | const std::vector<uint8_t>& code); |
| 115 | void OnPairingEnd(const std::string& session_id); |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 116 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 117 | org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this}; |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 118 | chromeos::dbus_utils::DBusObject dbus_object_; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 119 | |
Vitaly Buka | 7302c05 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 120 | std::unique_ptr<PeerdClient> peerd_client_; |
Vitaly Buka | ddb2e38 | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 121 | std::unique_ptr<ShillClient> shill_client_; |
Vitaly Buka | 0fa51e5 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 122 | std::unique_ptr<weave::Device> device_; |
Vitaly Buka | f9d5029 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 123 | std::unique_ptr<DBusCommandDispacher> command_dispatcher_; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 124 | |
Vitaly Buka | 5e6ff6c | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 125 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 126 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 127 | }; |
| 128 | |
| 129 | } // namespace buffet |
| 130 | |
| 131 | #endif // BUFFET_MANAGER_H_ |