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> |
Vitaly Buka | e2713ac | 2015-08-03 13:50:01 -0700 | [diff] [blame] | 21 | #include <weave/device.h> |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 22 | |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame^] | 23 | #include "buffet/buffet_config.h" |
Alex Vakulenko | 63bdf08 | 2015-08-21 09:27:12 -0700 | [diff] [blame] | 24 | #include "buffet/dbus_bindings/com.android.Weave.Manager.h" |
Christopher Wiley | 106686a | 2014-03-27 14:51:26 -0700 | [diff] [blame] | 25 | |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 26 | namespace chromeos { |
Christopher Wiley | d71774f | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 27 | namespace dbus_utils { |
| 28 | class ExportedObjectManager; |
| 29 | } // namespace dbus_utils |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 30 | } // namespace chromeos |
| 31 | |
Vitaly Buka | 3b08631 | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 32 | namespace buffet { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 33 | |
Robert Ginda | f86123d | 2015-09-11 16:10:43 -0700 | [diff] [blame] | 34 | class BluetoothClient; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 35 | class DBusCommandDispacher; |
Vitaly Buka | 00882b7 | 2015-08-06 00:32:11 -0700 | [diff] [blame] | 36 | class HttpTransportClient; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 37 | class MdnsClient; |
Peter Qiu | 786a906 | 2015-10-02 11:45:01 -0700 | [diff] [blame] | 38 | class ShillClient; |
Alex Vakulenko | 1642bec | 2015-08-19 09:34:58 -0700 | [diff] [blame] | 39 | class WebServClient; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 40 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 41 | template<typename... Types> |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 42 | using DBusMethodResponsePtr = |
Alex Vakulenko | 8d78ebf | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 43 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 44 | |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 45 | template<typename... Types> |
| 46 | using DBusMethodResponse = |
| 47 | chromeos::dbus_utils::DBusMethodResponse<Types...>; |
| 48 | |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 49 | // The Manager is responsible for global state of Buffet. It exposes |
| 50 | // interfaces which affect the entire device such as device registration and |
| 51 | // device state. |
Alex Vakulenko | 63bdf08 | 2015-08-21 09:27:12 -0700 | [diff] [blame] | 52 | class Manager final : public com::android::Weave::ManagerInterface { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 53 | public: |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame^] | 54 | struct Options { |
| 55 | bool xmpp_enabled = true; |
| 56 | bool disable_privet = false; |
| 57 | bool enable_ping = false; |
| 58 | }; |
| 59 | |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 60 | explicit Manager( |
| 61 | const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& |
| 62 | object_manager); |
Alex Vakulenko | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 63 | ~Manager(); |
| 64 | |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame^] | 65 | void Start(const Options& options, |
| 66 | const BuffetConfig::Options& config_options, |
Vitaly Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 67 | const std::set<std::string>& device_whitelist, |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 68 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 69 | |
| 70 | void Stop(); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 71 | |
| 72 | private: |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 73 | // DBus methods: |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 74 | void RegisterDevice(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | cbadabe | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 75 | const std::string& ticket_id) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 76 | void UpdateState(DBusMethodResponsePtr<> response, |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 77 | const chromeos::VariantDictionary& property_set) override; |
Alex Vakulenko | ceab177 | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 78 | bool GetState(chromeos::ErrorPtr* error, std::string* state) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 79 | void AddCommand(DBusMethodResponsePtr<std::string> response, |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame^] | 80 | const std::string& json_command) 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; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 84 | |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame^] | 85 | void StartPrivet(const Options& options, |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 86 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 87 | |
Vitaly Buka | 2b30e7a | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 88 | void OnStateChanged(); |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame^] | 89 | void OnGcdStateChanged(weave::GcdState state); |
Vitaly Buka | 00b8349 | 2015-07-20 00:37:48 -0700 | [diff] [blame] | 90 | void OnConfigChanged(const weave::Settings& settings); |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 91 | void OnPairingStart(const std::string& session_id, |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 92 | weave::PairingType pairing_type, |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 93 | const std::vector<uint8_t>& code); |
| 94 | void OnPairingEnd(const std::string& session_id); |
Christopher Wiley | 2f77293 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 95 | |
Alex Vakulenko | 63bdf08 | 2015-08-21 09:27:12 -0700 | [diff] [blame] | 96 | com::android::Weave::ManagerAdaptor dbus_adaptor_{this}; |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 97 | chromeos::dbus_utils::DBusObject dbus_object_; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 98 | |
Vitaly Buka | e74c872 | 2015-08-13 00:33:00 -0700 | [diff] [blame] | 99 | class TaskRunner; |
| 100 | std::unique_ptr<TaskRunner> task_runner_; |
Robert Ginda | f86123d | 2015-09-11 16:10:43 -0700 | [diff] [blame] | 101 | std::unique_ptr<BluetoothClient> bluetooth_client_; |
Vitaly Buka | 00882b7 | 2015-08-06 00:32:11 -0700 | [diff] [blame] | 102 | std::unique_ptr<HttpTransportClient> http_client_; |
Peter Qiu | 786a906 | 2015-10-02 11:45:01 -0700 | [diff] [blame] | 103 | std::unique_ptr<ShillClient> shill_client_; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 104 | std::unique_ptr<MdnsClient> mdns_client_; |
Alex Vakulenko | 1642bec | 2015-08-19 09:34:58 -0700 | [diff] [blame] | 105 | std::unique_ptr<WebServClient> web_serv_client_; |
Vitaly Buka | 1175a9b | 2015-08-15 10:42:17 -0700 | [diff] [blame] | 106 | std::unique_ptr<BuffetConfig> config_; |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 107 | std::unique_ptr<weave::Device> device_; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 108 | std::unique_ptr<DBusCommandDispacher> command_dispatcher_; |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 109 | |
Vitaly Buka | e43871f | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 110 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 111 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 112 | }; |
| 113 | |
| 114 | } // namespace buffet |
| 115 | |
| 116 | #endif // BUFFET_MANAGER_H_ |