blob: 1f89a016fb3781822ad61ed195ecaed3ce212bf9 [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 Vakulenko12e2c1a2014-11-21 08:57:57 -080023#include "buffet/org.chromium.Buffet.Manager.h"
Christopher Wiley106686a2014-03-27 14:51:26 -070024
Christopher Wiley1aa980e2014-08-11 10:51:20 -070025namespace chromeos {
Christopher Wileyd71774f2014-05-07 09:58:45 -070026namespace dbus_utils {
27class ExportedObjectManager;
28} // namespace dbus_utils
Christopher Wiley1aa980e2014-08-11 10:51:20 -070029} // namespace chromeos
30
Vitaly Buka3b086312015-07-09 14:59:23 -070031namespace buffet {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070032
Vitaly Bukaa0305d32015-07-27 16:08:51 -070033class DBusCommandDispacher;
Vitaly Buka00882b72015-08-06 00:32:11 -070034class HttpTransportClient;
Vitaly Buka58a288b2015-07-31 00:33:31 -070035class PeerdClient;
36class ShillClient;
Vitaly Buka974647f2015-08-02 20:57:43 -070037class WebServClient;
Vitaly Bukaa0305d32015-07-27 16:08:51 -070038
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080039template<typename... Types>
Alex Vakulenko6c375262015-06-19 11:01:42 -070040using DBusMethodResponsePtr =
Alex Vakulenko8d78ebf2015-04-24 18:09:32 -070041 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080042
Alex Vakulenko6c375262015-06-19 11:01:42 -070043template<typename... Types>
44using DBusMethodResponse =
45 chromeos::dbus_utils::DBusMethodResponse<Types...>;
46
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070047// The Manager is responsible for global state of Buffet. It exposes
48// interfaces which affect the entire device such as device registration and
49// device state.
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080050class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070051 public:
Alex Vakulenkob6351532014-08-15 11:49:35 -070052 explicit Manager(
53 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
54 object_manager);
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070055 ~Manager();
56
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070057 void Start(const weave::Device::Options& options,
Vitaly Buka58a288b2015-07-31 00:33:31 -070058 const std::set<std::string>& device_whitelist,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070059 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
60
61 void Stop();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070062
63 private:
Alex Vakulenkob6351532014-08-15 11:49:35 -070064 // DBus methods:
Alex Vakulenko6c375262015-06-19 11:01:42 -070065 void CheckDeviceRegistered(
66 DBusMethodResponsePtr<std::string> response) override;
67 void GetDeviceInfo(DBusMethodResponsePtr<std::string> response) override;
68 void RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -070069 const std::string& ticket_id) override;
Vitaly Buka760d6322015-04-17 00:41:31 -070070 bool UpdateDeviceInfo(chromeos::ErrorPtr* error,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070071 const std::string& name,
72 const std::string& description,
73 const std::string& location) override;
Vitaly Buka7cd01972015-05-14 21:25:45 -070074 bool UpdateServiceConfig(chromeos::ErrorPtr* error,
75 const std::string& client_id,
76 const std::string& client_secret,
77 const std::string& api_key,
78 const std::string& oauth_url,
79 const std::string& service_url) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070080 void UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080081 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenkoceab1772015-01-20 10:50:04 -080082 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070083 void AddCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Bukac03ec2b2015-05-31 23:32:46 -070084 const std::string& json_command,
85 const std::string& in_user_role) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070086 void GetCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Buka5515de02015-03-24 11:39:40 -070087 const std::string& id) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080088 std::string TestMethod(const std::string& message) override;
Vitaly Buka7b3ba792015-06-09 17:01:54 -070089 bool EnableWiFiBootstrapping(
90 chromeos::ErrorPtr* error,
91 const dbus::ObjectPath& in_listener_path,
92 const chromeos::VariantDictionary& in_options) override;
93 bool DisableWiFiBootstrapping(chromeos::ErrorPtr* error) override;
94 bool EnableGCDBootstrapping(
95 chromeos::ErrorPtr* error,
96 const dbus::ObjectPath& in_listener_path,
97 const chromeos::VariantDictionary& in_options) override;
98 bool DisableGCDBootstrapping(chromeos::ErrorPtr* error) override;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070099
Alex Vakulenko6c375262015-06-19 11:01:42 -0700100 void OnGetDeviceInfoSuccess(
101 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
102 const base::DictionaryValue& device_info);
103 void OnGetDeviceInfoError(
104 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
105 const chromeos::Error* error);
106
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700107 void StartPrivet(const weave::Device::Options& options,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -0700108 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
109
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700110 void OnStateChanged();
Vitaly Buka3b086312015-07-09 14:59:23 -0700111 void OnRegistrationChanged(weave::RegistrationStatus status);
Vitaly Buka00b83492015-07-20 00:37:48 -0700112 void OnConfigChanged(const weave::Settings& settings);
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700113 void UpdateWiFiBootstrapState(weave::WifiSetupState state);
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700114 void OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700115 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700116 const std::vector<uint8_t>& code);
117 void OnPairingEnd(const std::string& session_id);
Christopher Wiley2f772932015-02-15 15:42:04 -0800118
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800119 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkob6351532014-08-15 11:49:35 -0700120 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700121
Vitaly Buka00882b72015-08-06 00:32:11 -0700122 std::unique_ptr<HttpTransportClient> http_client_;
Vitaly Buka58a288b2015-07-31 00:33:31 -0700123 std::unique_ptr<ShillClient> shill_client_;
Vitaly Buka974647f2015-08-02 20:57:43 -0700124 std::unique_ptr<PeerdClient> peerd_client_;
125 std::unique_ptr<WebServClient> web_serv_client_;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700126 std::unique_ptr<weave::Device> device_;
Vitaly Bukaa0305d32015-07-27 16:08:51 -0700127 std::unique_ptr<DBusCommandDispacher> command_dispatcher_;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700128
Vitaly Bukae43871f2015-05-11 15:41:33 -0700129 base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700130 DISALLOW_COPY_AND_ASSIGN(Manager);
131};
132
133} // namespace buffet
134
135#endif // BUFFET_MANAGER_H_