Christopher Wiley | 4b5f04c | 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 | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 8 | #include <memory> |
Vitaly Buka | da2312c | 2015-06-23 20:11:36 -0700 | [diff] [blame] | 9 | #include <set> |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 10 | #include <string> |
Alex Vakulenko | acec6aa | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 11 | #include <vector> |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 12 | |
Christopher Wiley | 357deca | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 13 | #include <base/files/file_path.h> |
Alex Vakulenko | 274226b | 2014-09-04 08:59:43 -0700 | [diff] [blame] | 14 | #include <base/macros.h> |
Christopher Wiley | d71774f | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 15 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 16 | #include <base/values.h> |
Alex Vakulenko | 95877b5 | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/data_serialization.h> |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 18 | #include <chromeos/dbus/dbus_object.h> |
Alex Vakulenko | 24e5f5d | 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 | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 21 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 22 | #include "buffet/org.chromium.Buffet.Manager.h" |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 23 | #include "weave/device.h" |
Christopher Wiley | 106686a | 2014-03-27 14:51:26 -0700 | [diff] [blame] | 24 | |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 25 | namespace chromeos { |
Christopher Wiley | d71774f | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 26 | namespace dbus_utils { |
| 27 | class ExportedObjectManager; |
| 28 | } // namespace dbus_utils |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 29 | } // namespace chromeos |
| 30 | |
Vitaly Buka | 3b08631 | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 31 | namespace buffet { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 32 | |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame^] | 33 | class DBusCommandDispacher; |
| 34 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 35 | template<typename... Types> |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 36 | using DBusMethodResponsePtr = |
Alex Vakulenko | 8d78ebf | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 37 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 38 | |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 39 | template<typename... Types> |
| 40 | using DBusMethodResponse = |
| 41 | chromeos::dbus_utils::DBusMethodResponse<Types...>; |
| 42 | |
Christopher Wiley | 4b5f04c | 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 | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 46 | class Manager final : public org::chromium::Buffet::ManagerInterface { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 47 | public: |
Alex Vakulenko | b635153 | 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 | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 51 | ~Manager(); |
| 52 | |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 53 | void Start(const weave::Device::Options& options, |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 54 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 55 | |
| 56 | void Stop(); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 57 | |
| 58 | private: |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 59 | // DBus methods: |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 60 | void CheckDeviceRegistered( |
| 61 | DBusMethodResponsePtr<std::string> response) override; |
| 62 | void GetDeviceInfo(DBusMethodResponsePtr<std::string> response) override; |
| 63 | void RegisterDevice(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | cbadabe | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 64 | const std::string& ticket_id) override; |
Vitaly Buka | 760d632 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 65 | bool UpdateDeviceInfo(chromeos::ErrorPtr* error, |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 66 | const std::string& name, |
| 67 | const std::string& description, |
| 68 | const std::string& location) override; |
Vitaly Buka | 7cd0197 | 2015-05-14 21:25:45 -0700 | [diff] [blame] | 69 | bool UpdateServiceConfig(chromeos::ErrorPtr* error, |
| 70 | const std::string& client_id, |
| 71 | const std::string& client_secret, |
| 72 | const std::string& api_key, |
| 73 | const std::string& oauth_url, |
| 74 | const std::string& service_url) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 75 | void UpdateState(DBusMethodResponsePtr<> response, |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 76 | const chromeos::VariantDictionary& property_set) override; |
Alex Vakulenko | ceab177 | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 77 | bool GetState(chromeos::ErrorPtr* error, std::string* state) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 78 | void AddCommand(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | c03ec2b | 2015-05-31 23:32:46 -0700 | [diff] [blame] | 79 | const std::string& json_command, |
| 80 | const std::string& in_user_role) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 81 | void GetCommand(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | 5515de0 | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 82 | const std::string& id) override; |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 83 | std::string TestMethod(const std::string& message) override; |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 84 | bool EnableWiFiBootstrapping( |
| 85 | chromeos::ErrorPtr* error, |
| 86 | const dbus::ObjectPath& in_listener_path, |
| 87 | const chromeos::VariantDictionary& in_options) override; |
| 88 | bool DisableWiFiBootstrapping(chromeos::ErrorPtr* error) override; |
| 89 | bool EnableGCDBootstrapping( |
| 90 | chromeos::ErrorPtr* error, |
| 91 | const dbus::ObjectPath& in_listener_path, |
| 92 | const chromeos::VariantDictionary& in_options) override; |
| 93 | bool DisableGCDBootstrapping(chromeos::ErrorPtr* error) override; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 94 | |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 95 | void OnGetDeviceInfoSuccess( |
| 96 | const std::shared_ptr<DBusMethodResponse<std::string>>& response, |
| 97 | const base::DictionaryValue& device_info); |
| 98 | void OnGetDeviceInfoError( |
| 99 | const std::shared_ptr<DBusMethodResponse<std::string>>& response, |
| 100 | const chromeos::Error* error); |
| 101 | |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 102 | void StartPrivet(const weave::Device::Options& options, |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 103 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 104 | |
Vitaly Buka | 2b30e7a | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 105 | void OnStateChanged(); |
Vitaly Buka | 3b08631 | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 106 | void OnRegistrationChanged(weave::RegistrationStatus status); |
Vitaly Buka | 00b8349 | 2015-07-20 00:37:48 -0700 | [diff] [blame] | 107 | void OnConfigChanged(const weave::Settings& settings); |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 108 | void UpdateWiFiBootstrapState(weave::WifiSetupState state); |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 109 | void OnPairingStart(const std::string& session_id, |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 110 | weave::PairingType pairing_type, |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 111 | const std::vector<uint8_t>& code); |
| 112 | void OnPairingEnd(const std::string& session_id); |
Christopher Wiley | 2f77293 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 113 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 114 | org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this}; |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 115 | chromeos::dbus_utils::DBusObject dbus_object_; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 116 | |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 117 | std::unique_ptr<weave::Device> device_; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame^] | 118 | std::unique_ptr<DBusCommandDispacher> command_dispatcher_; |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 119 | |
Vitaly Buka | e43871f | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 120 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 122 | }; |
| 123 | |
| 124 | } // namespace buffet |
| 125 | |
| 126 | #endif // BUFFET_MANAGER_H_ |