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