blob: d7e83778ff9ce7741aa2c5ee951af00d67f95b19 [file] [log] [blame]
Christopher Wiley4b5f04c2014-03-27 14:45:37 -07001// 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 Vakulenko24aa1222014-05-12 15:55:25 -07008#include <memory>
Vitaly Bukada2312c2015-06-23 20:11:36 -07009#include <set>
Alex Vakulenko24aa1222014-05-12 15:55:25 -070010#include <string>
Alex Vakulenkoacec6aa2015-04-20 11:00:54 -070011#include <vector>
Alex Vakulenko24aa1222014-05-12 15:55:25 -070012
Christopher Wiley357deca2015-02-07 18:29:32 -080013#include <base/files/file_path.h>
Alex Vakulenko274226b2014-09-04 08:59:43 -070014#include <base/macros.h>
Christopher Wileyd71774f2014-05-07 09:58:45 -070015#include <base/memory/weak_ptr.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070016#include <base/values.h>
Alex Vakulenko95877b52014-09-19 15:31:09 -070017#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkob6351532014-08-15 11:49:35 -070018#include <chromeos/dbus/dbus_object.h>
Alex Vakulenko24e5f5d2014-08-27 11:00:57 -070019#include <chromeos/dbus/exported_property_set.h>
20#include <chromeos/errors/error.h>
Vitaly Bukae2713ac2015-08-03 13:50:01 -070021#include <weave/device.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070022
Alex Vakulenko0022b752015-10-02 11:09:59 -070023#include "buffet/buffet_config.h"
Alex Vakulenko63bdf082015-08-21 09:27:12 -070024#include "buffet/dbus_bindings/com.android.Weave.Manager.h"
Christopher Wiley106686a2014-03-27 14:51:26 -070025
Christopher Wiley1aa980e2014-08-11 10:51:20 -070026namespace chromeos {
Christopher Wileyd71774f2014-05-07 09:58:45 -070027namespace dbus_utils {
28class ExportedObjectManager;
29} // namespace dbus_utils
Christopher Wiley1aa980e2014-08-11 10:51:20 -070030} // namespace chromeos
31
Vitaly Buka3b086312015-07-09 14:59:23 -070032namespace buffet {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070033
Robert Gindaf86123d2015-09-11 16:10:43 -070034class BluetoothClient;
Vitaly Bukaa0305d32015-07-27 16:08:51 -070035class DBusCommandDispacher;
Vitaly Buka00882b72015-08-06 00:32:11 -070036class HttpTransportClient;
Alex Vakulenkof0f55342015-08-18 15:51:40 -070037class MdnsClient;
Peter Qiu786a9062015-10-02 11:45:01 -070038class ShillClient;
Alex Vakulenko1642bec2015-08-19 09:34:58 -070039class WebServClient;
Vitaly Bukaa0305d32015-07-27 16:08:51 -070040
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080041template<typename... Types>
Alex Vakulenko6c375262015-06-19 11:01:42 -070042using DBusMethodResponsePtr =
Alex Vakulenko8d78ebf2015-04-24 18:09:32 -070043 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080044
Alex Vakulenko6c375262015-06-19 11:01:42 -070045template<typename... Types>
46using DBusMethodResponse =
47 chromeos::dbus_utils::DBusMethodResponse<Types...>;
48
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070049// 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 Vakulenko63bdf082015-08-21 09:27:12 -070052class Manager final : public com::android::Weave::ManagerInterface {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070053 public:
Alex Vakulenko0022b752015-10-02 11:09:59 -070054 struct Options {
55 bool xmpp_enabled = true;
56 bool disable_privet = false;
57 bool enable_ping = false;
58 };
59
Alex Vakulenkob6351532014-08-15 11:49:35 -070060 explicit Manager(
61 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
62 object_manager);
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070063 ~Manager();
64
Alex Vakulenko0022b752015-10-02 11:09:59 -070065 void Start(const Options& options,
66 const BuffetConfig::Options& config_options,
Vitaly Buka58a288b2015-07-31 00:33:31 -070067 const std::set<std::string>& device_whitelist,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070068 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
69
70 void Stop();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070071
72 private:
Alex Vakulenkob6351532014-08-15 11:49:35 -070073 // DBus methods:
Alex Vakulenko6c375262015-06-19 11:01:42 -070074 void RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -070075 const std::string& ticket_id) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070076 void UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080077 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenkoceab1772015-01-20 10:50:04 -080078 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070079 void AddCommand(DBusMethodResponsePtr<std::string> response,
Alex Vakulenko0022b752015-10-02 11:09:59 -070080 const std::string& json_command) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070081 void GetCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Buka5515de02015-03-24 11:39:40 -070082 const std::string& id) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080083 std::string TestMethod(const std::string& message) override;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070084
Alex Vakulenko0022b752015-10-02 11:09:59 -070085 void StartPrivet(const Options& options,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070086 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
87
Vitaly Buka2b30e7a2015-05-27 09:27:08 -070088 void OnStateChanged();
Alex Vakulenko0022b752015-10-02 11:09:59 -070089 void OnGcdStateChanged(weave::GcdState state);
Vitaly Buka00b83492015-07-20 00:37:48 -070090 void OnConfigChanged(const weave::Settings& settings);
Vitaly Buka7b3ba792015-06-09 17:01:54 -070091 void OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070092 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -070093 const std::vector<uint8_t>& code);
94 void OnPairingEnd(const std::string& session_id);
Christopher Wiley2f772932015-02-15 15:42:04 -080095
Alex Vakulenko63bdf082015-08-21 09:27:12 -070096 com::android::Weave::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkob6351532014-08-15 11:49:35 -070097 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070098
Vitaly Bukae74c8722015-08-13 00:33:00 -070099 class TaskRunner;
100 std::unique_ptr<TaskRunner> task_runner_;
Robert Gindaf86123d2015-09-11 16:10:43 -0700101 std::unique_ptr<BluetoothClient> bluetooth_client_;
Vitaly Buka00882b72015-08-06 00:32:11 -0700102 std::unique_ptr<HttpTransportClient> http_client_;
Peter Qiu786a9062015-10-02 11:45:01 -0700103 std::unique_ptr<ShillClient> shill_client_;
Alex Vakulenkof0f55342015-08-18 15:51:40 -0700104 std::unique_ptr<MdnsClient> mdns_client_;
Alex Vakulenko1642bec2015-08-19 09:34:58 -0700105 std::unique_ptr<WebServClient> web_serv_client_;
Vitaly Buka1175a9b2015-08-15 10:42:17 -0700106 std::unique_ptr<BuffetConfig> config_;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700107 std::unique_ptr<weave::Device> device_;
Vitaly Bukaa0305d32015-07-27 16:08:51 -0700108 std::unique_ptr<DBusCommandDispacher> command_dispatcher_;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700109
Vitaly Bukae43871f2015-05-11 15:41:33 -0700110 base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700111 DISALLOW_COPY_AND_ASSIGN(Manager);
112};
113
114} // namespace buffet
115
116#endif // BUFFET_MANAGER_H_