blob: 9dc84d87dbea77c1642bdf9ba9dfca49683641d6 [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
Vitaly Bukaa0305d32015-07-27 16:08:51 -070033class DBusCommandDispacher;
34
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080035template<typename... Types>
Alex Vakulenko6c375262015-06-19 11:01:42 -070036using DBusMethodResponsePtr =
Alex Vakulenko8d78ebf2015-04-24 18:09:32 -070037 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080038
Alex Vakulenko6c375262015-06-19 11:01:42 -070039template<typename... Types>
40using DBusMethodResponse =
41 chromeos::dbus_utils::DBusMethodResponse<Types...>;
42
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070043// 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 Vakulenko12e2c1a2014-11-21 08:57:57 -080046class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070047 public:
Alex Vakulenkob6351532014-08-15 11:49:35 -070048 explicit Manager(
49 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
50 object_manager);
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070051 ~Manager();
52
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070053 void Start(const weave::Device::Options& options,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070054 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
55
56 void Stop();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070057
58 private:
Alex Vakulenkob6351532014-08-15 11:49:35 -070059 // DBus methods:
Alex Vakulenko6c375262015-06-19 11:01:42 -070060 void CheckDeviceRegistered(
61 DBusMethodResponsePtr<std::string> response) override;
62 void GetDeviceInfo(DBusMethodResponsePtr<std::string> response) override;
63 void RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -070064 const std::string& ticket_id) override;
Vitaly Buka760d6322015-04-17 00:41:31 -070065 bool UpdateDeviceInfo(chromeos::ErrorPtr* error,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070066 const std::string& name,
67 const std::string& description,
68 const std::string& location) override;
Vitaly Buka7cd01972015-05-14 21:25:45 -070069 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 Vakulenko6c375262015-06-19 11:01:42 -070075 void UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080076 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenkoceab1772015-01-20 10:50:04 -080077 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Alex Vakulenko6c375262015-06-19 11:01:42 -070078 void AddCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Bukac03ec2b2015-05-31 23:32:46 -070079 const std::string& json_command,
80 const std::string& in_user_role) 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;
Vitaly Buka7b3ba792015-06-09 17:01:54 -070084 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 Wiley4b5f04c2014-03-27 14:45:37 -070094
Alex Vakulenko6c375262015-06-19 11:01:42 -070095 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 Buka0c6dcd22015-07-10 00:12:25 -0700102 void StartPrivet(const weave::Device::Options& options,
Vitaly Buka84fd6dd2015-06-09 17:22:18 -0700103 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
104
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700105 void OnStateChanged();
Vitaly Buka3b086312015-07-09 14:59:23 -0700106 void OnRegistrationChanged(weave::RegistrationStatus status);
Vitaly Buka00b83492015-07-20 00:37:48 -0700107 void OnConfigChanged(const weave::Settings& settings);
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700108 void UpdateWiFiBootstrapState(weave::WifiSetupState state);
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700109 void OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700110 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700111 const std::vector<uint8_t>& code);
112 void OnPairingEnd(const std::string& session_id);
Christopher Wiley2f772932015-02-15 15:42:04 -0800113
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800114 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkob6351532014-08-15 11:49:35 -0700115 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700116
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700117 std::unique_ptr<weave::Device> device_;
Vitaly Bukaa0305d32015-07-27 16:08:51 -0700118 std::unique_ptr<DBusCommandDispacher> command_dispatcher_;
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700119
Vitaly Bukae43871f2015-05-11 15:41:33 -0700120 base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700121 DISALLOW_COPY_AND_ASSIGN(Manager);
122};
123
124} // namespace buffet
125
126#endif // BUFFET_MANAGER_H_