blob: 6db50fe0e9715b3b93960ae78461467e28d397ec [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>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070021
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080022#include "buffet/org.chromium.Buffet.Manager.h"
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070023#include "weave/device.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
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080033template<typename... Types>
Alex Vakulenko6c375262015-06-19 11:01:42 -070034using DBusMethodResponsePtr =
Alex Vakulenko8d78ebf2015-04-24 18:09:32 -070035 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080036
Alex Vakulenko6c375262015-06-19 11:01:42 -070037template<typename... Types>
38using DBusMethodResponse =
39 chromeos::dbus_utils::DBusMethodResponse<Types...>;
40
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070041// 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 Vakulenko12e2c1a2014-11-21 08:57:57 -080044class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070045 public:
Alex Vakulenkob6351532014-08-15 11:49:35 -070046 explicit Manager(
47 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
48 object_manager);
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070049 ~Manager();
50
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070051 void Start(const weave::Device::Options& options,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070052 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
53
54 void Stop();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070055
56 private:
Alex Vakulenkob6351532014-08-15 11:49:35 -070057 // DBus methods:
Alex Vakulenko6c375262015-06-19 11:01:42 -070058 void CheckDeviceRegistered(
59 DBusMethodResponsePtr<std::string> response) override;
60 void GetDeviceInfo(DBusMethodResponsePtr<std::string> response) override;
61 void RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -070062 const std::string& ticket_id) override;
Vitaly Buka760d6322015-04-17 00:41:31 -070063 bool UpdateDeviceInfo(chromeos::ErrorPtr* error,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070064 const std::string& name,
65 const std::string& description,
66 const std::string& location) override;
Vitaly Buka7cd01972015-05-14 21:25:45 -070067 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 Vakulenko6c375262015-06-19 11:01:42 -070073 void UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080074 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenkoceab1772015-01-20 10:50:04 -080075 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070076 void AddCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Bukac03ec2b2015-05-31 23:32:46 -070077 const std::string& json_command,
78 const std::string& in_user_role) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070079 void GetCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Buka5515de02015-03-24 11:39:40 -070080 const std::string& id) override;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080081 std::string TestMethod(const std::string& message) override;
Vitaly Buka7b3ba792015-06-09 17:01:54 -070082 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 Wiley4b5f04c2014-03-27 14:45:37 -070092
Alex Vakulenko6c375262015-06-19 11:01:42 -070093 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 Buka0c6dcd22015-07-10 00:12:25 -0700100 void StartPrivet(const weave::Device::Options& options,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -0700101 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
102
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700103 void OnStateChanged();
Vitaly Buka3b086312015-07-09 14:59:23 -0700104 void OnRegistrationChanged(weave::RegistrationStatus status);
Vitaly Buka00b83492015-07-20 00:37:48 -0700105 void OnConfigChanged(const weave::Settings& settings);
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700106 void UpdateWiFiBootstrapState(weave::WifiSetupState state);
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700107 void OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700108 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700109 const std::vector<uint8_t>& code);
110 void OnPairingEnd(const std::string& session_id);
Christopher Wiley2f772932015-02-15 15:42:04 -0800111
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800112 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkob6351532014-08-15 11:49:35 -0700113 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700114
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700115 std::unique_ptr<weave::Device> device_;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700116
Vitaly Bukae43871f2015-05-11 15:41:33 -0700117 base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700118 DISALLOW_COPY_AND_ASSIGN(Manager);
119};
120
121} // namespace buffet
122
123#endif // BUFFET_MANAGER_H_