libweave: Interfaces for subcomponents of libweave External components should include only weave/include files BUG=brillo:1242 TEST='FEATURES=test emerge-gizmo buffet' Change-Id: I278ab55f6ffe9298d3d2b8d5c7b47c050886cdfe Reviewed-on: https://chromium-review.googlesource.com/285832 Tested-by: Vitaly Buka <vitalybuka@chromium.org> Trybot-Ready: Vitaly Buka <vitalybuka@chromium.org> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp index 33e22e8..ca9a11d 100644 --- a/buffet/buffet.gyp +++ b/buffet/buffet.gyp
@@ -65,6 +65,7 @@ '../libweave/src/privet/privet_types.cc', '../libweave/src/privet/security_manager.cc', '../libweave/src/privet/shill_client.cc', + '../libweave/src/privet/privet_types.cc', '../libweave/src/privet/wifi_bootstrap_manager.cc', '../libweave/src/privet/wifi_ssid_generator.cc', '../libweave/src/registration_status.cc',
diff --git a/buffet/manager.cc b/buffet/manager.cc index 572963e..06de9f1 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc
@@ -185,8 +185,7 @@ void Manager::GetCommand(DBusMethodResponsePtr<std::string> response, const std::string& id) { - const weave::CommandInstance* command = - device_->GetCommands()->FindCommand(id); + const weave::Command* command = device_->GetCommands()->FindCommand(id); if (!command) { response->ReplyWithError(FROM_HERE, kErrorDomain, "unknown_command", "Can't find command with id: " + id);
diff --git a/libweave/include/weave/cloud.h b/libweave/include/weave/cloud.h new file mode 100644 index 0000000..daa39f1 --- /dev/null +++ b/libweave/include/weave/cloud.h
@@ -0,0 +1,75 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBWEAVE_INCLUDE_WEAVE_CLOUD_H_ +#define LIBWEAVE_INCLUDE_WEAVE_CLOUD_H_ + +#include <string> + +#include <base/callback.h> +#include <base/values.h> +#include <chromeos/errors/error.h> + +namespace weave { + +// See the DBus interface XML file for complete descriptions of these states. +enum class RegistrationStatus { + kUnconfigured, // We have no credentials. + kConnecting, // We have credentials but not yet connected. + kConnected, // We're registered and connected to the cloud. + kInvalidCredentials, // Our registration has been revoked. +}; + +class Cloud { + public: + using OnRegistrationChangedCallback = + base::Callback<void(RegistrationStatus satus)>; + using OnCloudRequestCallback = + base::Callback<void(const base::DictionaryValue& response)>; + using OnCloudRequestErrorCallback = + base::Callback<void(const chromeos::Error* error)>; + + // Sets callback which is called when registration state is changed. + virtual void AddOnRegistrationChangedCallback( + const OnRegistrationChangedCallback& callback) = 0; + + // Gets the full device description JSON object asynchronously. + // Passes the device info as the first argument to |callback|, or nullptr if + // the device is not registered or in case of communication failure. + virtual void GetDeviceInfo( + const OnCloudRequestCallback& success_callback, + const OnCloudRequestErrorCallback& error_callback) = 0; + + // Registers the device. + // Returns a device ID on success. + virtual std::string RegisterDevice(const std::string& ticket_id, + chromeos::ErrorPtr* error) = 0; + + // Updates basic device information. + virtual bool UpdateDeviceInfo(const std::string& name, + const std::string& description, + const std::string& location, + chromeos::ErrorPtr* error) = 0; + + // Updates base device config. + virtual bool UpdateBaseConfig(const std::string& anonymous_access_role, + bool local_discovery_enabled, + bool local_pairing_enabled, + chromeos::ErrorPtr* error) = 0; + + // Updates GCD service configuration. Usually for testing. + virtual bool UpdateServiceConfig(const std::string& client_id, + const std::string& client_secret, + const std::string& api_key, + const std::string& oauth_url, + const std::string& service_url, + chromeos::ErrorPtr* error) = 0; + + protected: + virtual ~Cloud() = default; +}; + +} // namespace weave + +#endif // LIBWEAVE_INCLUDE_WEAVE_CLOUD_H_
diff --git a/libweave/include/weave/command.h b/libweave/include/weave/command.h new file mode 100644 index 0000000..0df4878 --- /dev/null +++ b/libweave/include/weave/command.h
@@ -0,0 +1,24 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_ +#define LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_ + +#include <base/values.h> +#include <chromeos/errors/error.h> + +namespace weave { + +class Command { + public: + // Returns JSON representation of the command. + virtual std::unique_ptr<base::DictionaryValue> ToJson() const = 0; + + protected: + virtual ~Command() = default; +}; + +} // namespace weave + +#endif // LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_
diff --git a/libweave/include/weave/commands.h b/libweave/include/weave/commands.h new file mode 100644 index 0000000..2937cbe --- /dev/null +++ b/libweave/include/weave/commands.h
@@ -0,0 +1,44 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBWEAVE_INCLUDE_WEAVE_COMMANDS_H_ +#define LIBWEAVE_INCLUDE_WEAVE_COMMANDS_H_ + +#include <string> + +#include <base/callback.h> +#include <base/values.h> +#include <chromeos/errors/error.h> + +#include "weave/command.h" + +namespace weave { + +enum class UserRole { + kViewer, + kUser, + kManager, + kOwner, +}; + +class Commands { + public: + // Adds a new command to the command queue. + virtual bool AddCommand(const base::DictionaryValue& command, + UserRole role, + std::string* id, + chromeos::ErrorPtr* error) = 0; + + // Finds a command by the command |id|. Returns nullptr if the command with + // the given |id| is not found. The returned pointer should not be persisted + // for a long period of time. + virtual Command* FindCommand(const std::string& id) = 0; + + protected: + virtual ~Commands() = default; +}; + +} // namespace weave + +#endif // LIBWEAVE_INCLUDE_WEAVE_COMMANDS_H_
diff --git a/libweave/include/weave/config.h b/libweave/include/weave/config.h new file mode 100644 index 0000000..6b87385 --- /dev/null +++ b/libweave/include/weave/config.h
@@ -0,0 +1,62 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBWEAVE_INCLUDE_WEAVE_CONFIG_H_ +#define LIBWEAVE_INCLUDE_WEAVE_CONFIG_H_ + +#include <set> +#include <string> + +#include <base/callback.h> + +#include "weave/enum_to_string.h" +#include "weave/privet.h" + +namespace weave { + +struct Settings { + std::string client_id; + std::string client_secret; + std::string api_key; + std::string oauth_url; + std::string service_url; + std::string name; + std::string description; + std::string location; + std::string local_anonymous_access_role; + bool local_discovery_enabled{true}; + bool local_pairing_enabled{true}; + std::string oem_name; + std::string model_name; + std::string model_id; + std::string device_kind; + base::TimeDelta polling_period; + base::TimeDelta backup_polling_period; + + bool wifi_auto_setup_enabled{true}; + std::set<PairingType> pairing_modes; + base::FilePath embedded_code_path; + + std::string device_id; + std::string refresh_token; + std::string robot_account; + std::string last_configured_ssid; +}; + +class Config { + public: + using OnChangedCallback = base::Callback<void(const Settings& settings)>; + + // Sets callback which is called when config is changed. + virtual void AddOnChangedCallback(const OnChangedCallback& callback) = 0; + + virtual const Settings& GetSettings() const = 0; + + protected: + virtual ~Config() = default; +}; + +} // namespace weave + +#endif // LIBWEAVE_INCLUDE_WEAVE_CONFIG_H_
diff --git a/libweave/include/weave/device.h b/libweave/include/weave/device.h index 4adaa53..81289e9 100644 --- a/libweave/include/weave/device.h +++ b/libweave/include/weave/device.h
@@ -13,7 +13,11 @@ #include <chromeos/errors/error.h> #include <chromeos/variant_dictionary.h> -#include "weave/types.h" +#include "weave/cloud.h" +#include "weave/commands.h" +#include "weave/config.h" +#include "weave/privet.h" +#include "weave/state.h" namespace chromeos { namespace dbus_utils { @@ -24,21 +28,6 @@ namespace weave { -class CommandManager; -class StateManager; -class BuffetConfig; -class DeviceRegistrationInfo; -namespace privet { -class Manager; -} - -// TODO(vitalybuka): Replace with interfaces. -using Commands = CommandManager; -using State = StateManager; -using Config = BuffetConfig; -using Cloud = DeviceRegistrationInfo; -using Privet = privet::Manager; - class Device { public: struct Options { @@ -71,11 +60,4 @@ } // namespace weave -// TODO(vitalybuka): Replace with interfaces -#include "libweave/src/buffet_config.h" -#include "libweave/src/commands/command_manager.h" -#include "libweave/src/device_registration_info.h" -#include "libweave/src/privet/privet_manager.h" -#include "libweave/src/states/state_manager.h" - #endif // LIBWEAVE_INCLUDE_WEAVE_DEVICE_H_
diff --git a/libweave/include/weave/privet.h b/libweave/include/weave/privet.h new file mode 100644 index 0000000..60acbeb --- /dev/null +++ b/libweave/include/weave/privet.h
@@ -0,0 +1,53 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBWEAVE_INCLUDE_WEAVE_PRIVET_H_ +#define LIBWEAVE_INCLUDE_WEAVE_PRIVET_H_ + +#include <string> +#include <vector> + +#include <base/callback.h> + +namespace weave { + +enum class PairingType { + kPinCode, + kEmbeddedCode, + kUltrasound32, + kAudible32, +}; + +enum class WifiSetupState { + kDisabled, + kBootstrapping, + kMonitoring, + kConnecting, +}; + +class Privet { + public: + using OnWifiSetupChangedCallback = base::Callback<void(WifiSetupState state)>; + using OnPairingStartedCallback = + base::Callback<void(const std::string& session_id, + PairingType pairing_type, + const std::vector<uint8_t>& code)>; + using OnPairingEndedCallback = + base::Callback<void(const std::string& session_id)>; + + // Sets callback which is called when WiFi state is changed. + virtual void AddOnWifiSetupChangedCallback( + const OnWifiSetupChangedCallback& callback) = 0; + + virtual void AddOnPairingChangedCallbacks( + const OnPairingStartedCallback& on_start, + const OnPairingEndedCallback& on_end) = 0; + + protected: + virtual ~Privet() = default; +}; + +} // namespace weave + +#endif // LIBWEAVE_INCLUDE_WEAVE_PRIVET_H_
diff --git a/libweave/include/weave/state.h b/libweave/include/weave/state.h new file mode 100644 index 0000000..bf87a64 --- /dev/null +++ b/libweave/include/weave/state.h
@@ -0,0 +1,34 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBWEAVE_INCLUDE_WEAVE_STATE_H_ +#define LIBWEAVE_INCLUDE_WEAVE_STATE_H_ + +#include <base/callback.h> +#include <base/values.h> +#include <chromeos/variant_dictionary.h> + +namespace weave { + +class State { + public: + // Sets callback which is called when stat is changed. + virtual void AddOnChangedCallback(const base::Closure& callback) = 0; + + // Updates a multiple property values. + virtual bool SetProperties(const chromeos::VariantDictionary& property_set, + chromeos::ErrorPtr* error) = 0; + + // Returns aggregated state properties across all registered packages as + // a JSON object that can be used to send the device state to the GCD server. + virtual std::unique_ptr<base::DictionaryValue> GetStateValuesAsJson( + chromeos::ErrorPtr* error) const = 0; + + protected: + virtual ~State() = default; +}; + +} // namespace weave + +#endif // LIBWEAVE_INCLUDE_WEAVE_STATE_H_
diff --git a/libweave/include/weave/types.h b/libweave/include/weave/types.h deleted file mode 100644 index 55a1fb0..0000000 --- a/libweave/include/weave/types.h +++ /dev/null
@@ -1,36 +0,0 @@ -// Copyright 2015 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef LIBWEAVE_INCLUDE_WEAVE_TYPES_H_ -#define LIBWEAVE_INCLUDE_WEAVE_TYPES_H_ - -#include <string> - -namespace weave { - -// See the DBus interface XML file for complete descriptions of these states. -enum class RegistrationStatus { - kUnconfigured, // We have no credentials. - kConnecting, // We have credentials but not yet connected. - kConnected, // We're registered and connected to the cloud. - kInvalidCredentials, // Our registration has been revoked. -}; - -enum class PairingType { - kPinCode, - kEmbeddedCode, - kUltrasound32, - kAudible32, -}; - -enum class WifiSetupState { - kDisabled, - kBootstrapping, - kMonitoring, - kConnecting, -}; - -} // namespace weave - -#endif // LIBWEAVE_INCLUDE_WEAVE_TYPES_H_
diff --git a/libweave/src/buffet_config.h b/libweave/src/buffet_config.h index d0296da..8924365 100644 --- a/libweave/src/buffet_config.h +++ b/libweave/src/buffet_config.h
@@ -15,51 +15,25 @@ #include <chromeos/key_value_store.h> #include "libweave/src/privet/security_delegate.h" +#include "weave/config.h" namespace weave { class StorageInterface; -struct Settings { - std::string client_id; - std::string client_secret; - std::string api_key; - std::string oauth_url; - std::string service_url; - std::string name; - std::string description; - std::string location; - std::string local_anonymous_access_role; - bool local_discovery_enabled{true}; - bool local_pairing_enabled{true}; - std::string oem_name; - std::string model_name; - std::string model_id; - std::string device_kind; - base::TimeDelta polling_period; - base::TimeDelta backup_polling_period; - - bool wifi_auto_setup_enabled{true}; - std::set<PairingType> pairing_modes; - base::FilePath embedded_code_path; - - std::string device_id; - std::string refresh_token; - std::string robot_account; - std::string last_configured_ssid; -}; - // Handles reading buffet config and state files. -class BuffetConfig final { +class BuffetConfig final : public Config { public: using OnChangedCallback = base::Callback<void(const Settings&)>; + ~BuffetConfig() override = default; explicit BuffetConfig(std::unique_ptr<StorageInterface> storage); explicit BuffetConfig(const base::FilePath& state_path); - void AddOnChangedCallback(const OnChangedCallback& callback); - const Settings& GetSettings() const; + // Config overrides. + void AddOnChangedCallback(const OnChangedCallback& callback) override; + const Settings& GetSettings() const override; void Load(const base::FilePath& config_path); void Load(const chromeos::KeyValueStore& store);
diff --git a/libweave/src/commands/command_definition.h b/libweave/src/commands/command_definition.h index 9c0d370..769427a 100644 --- a/libweave/src/commands/command_definition.h +++ b/libweave/src/commands/command_definition.h
@@ -11,7 +11,7 @@ #include <base/macros.h> #include "libweave/src/commands/object_schema.h" -#include "libweave/src/commands/user_role.h" +#include "weave/commands.h" namespace weave {
diff --git a/libweave/src/commands/command_instance.h b/libweave/src/commands/command_instance.h index 73d4646..5142d98 100644 --- a/libweave/src/commands/command_instance.h +++ b/libweave/src/commands/command_instance.h
@@ -15,6 +15,7 @@ #include "libweave/src/commands/prop_values.h" #include "libweave/src/commands/schema_utils.h" +#include "weave/command.h" namespace base { class Value; @@ -27,7 +28,7 @@ class CommandProxyInterface; class CommandQueue; -class CommandInstance final { +class CommandInstance final : public Command { public: // Construct a command instance given the full command |name| which must // be in format "<package_name>.<command_name>", a command |category| and @@ -36,7 +37,10 @@ const std::string& origin, const CommandDefinition* command_definition, const native_types::Object& parameters); - ~CommandInstance(); + ~CommandInstance() override; + + // Command overrides. + std::unique_ptr<base::DictionaryValue> ToJson() const override; // Returns the full command ID. const std::string& GetID() const { return id_; } @@ -74,9 +78,6 @@ std::string* command_id, chromeos::ErrorPtr* error); - // Returns JSON representation of the command. - std::unique_ptr<base::DictionaryValue> ToJson() const; - // Sets the command ID (normally done by CommandQueue when the command // instance is added to it). void SetID(const std::string& id) { id_ = id; }
diff --git a/libweave/src/commands/command_manager.cc b/libweave/src/commands/command_manager.cc index 1b59da6..a312051 100644 --- a/libweave/src/commands/command_manager.cc +++ b/libweave/src/commands/command_manager.cc
@@ -29,6 +29,13 @@ base::Unretained(&command_dispatcher_))); } +CommandManager::~CommandManager() {} + +void CommandManager::AddOnCommandDefChanged(const base::Closure& callback) { + on_command_changed_.push_back(callback); + callback.Run(); +} + const CommandDictionary& CommandManager::GetCommandDictionary() const { return dictionary_; } @@ -125,7 +132,7 @@ return true; } -CommandInstance* CommandManager::FindCommand(const std::string& id) const { +CommandInstance* CommandManager::FindCommand(const std::string& id) { return command_queue_.Find(id); }
diff --git a/libweave/src/commands/command_manager.h b/libweave/src/commands/command_manager.h index 0aa703d..c894f71 100644 --- a/libweave/src/commands/command_manager.h +++ b/libweave/src/commands/command_manager.h
@@ -17,6 +17,7 @@ #include "libweave/src/commands/command_dictionary.h" #include "libweave/src/commands/command_queue.h" #include "libweave/src/commands/dbus_command_dispatcher.h" +#include "weave/commands.h" namespace chromeos { namespace dbus_utils { @@ -31,18 +32,24 @@ // CommandManager class that will have a list of all the device command // schemas as well as the live command queue of pending command instances // dispatched to the device. -class CommandManager final { +class CommandManager final : public Commands { public: CommandManager(); explicit CommandManager( const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& object_manager); + ~CommandManager() override; + + // Commands overrides. + bool AddCommand(const base::DictionaryValue& command, + UserRole role, + std::string* id, + chromeos::ErrorPtr* error) override; + CommandInstance* FindCommand(const std::string& id) override; + // Sets callback which is called when command definitions is changed. - void AddOnCommandDefChanged(const base::Closure& callback) { - on_command_changed_.push_back(callback); - callback.Run(); - } + void AddOnCommandDefChanged(const base::Closure& callback); // Returns the command definitions for the device. const CommandDictionary& GetCommandDictionary() const; @@ -87,15 +94,6 @@ // Adds a new command to the command queue. void AddCommand(std::unique_ptr<CommandInstance> command_instance); - bool AddCommand(const base::DictionaryValue& command, - UserRole role, - std::string* id, - chromeos::ErrorPtr* error); - - // Finds a command by the command |id|. Returns nullptr if the command with - // the given |id| is not found. The returned pointer should not be persisted - // for a long period of time. - CommandInstance* FindCommand(const std::string& id) const; // Changes the visibility of commands. bool SetCommandVisibility(const std::vector<std::string>& command_names,
diff --git a/libweave/src/commands/user_role.cc b/libweave/src/commands/user_role.cc index 87edad1..0cad7ad 100644 --- a/libweave/src/commands/user_role.cc +++ b/libweave/src/commands/user_role.cc
@@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "libweave/src/commands/user_role.h" - #include <chromeos/errors/error.h> #include "libweave/src/commands/schema_constants.h" +#include "weave/commands.h" #include "weave/enum_to_string.h" namespace weave {
diff --git a/libweave/src/commands/user_role.h b/libweave/src/commands/user_role.h deleted file mode 100644 index 5f5b3d7..0000000 --- a/libweave/src/commands/user_role.h +++ /dev/null
@@ -1,22 +0,0 @@ -// Copyright 2015 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef LIBWEAVE_SRC_COMMANDS_USER_ROLE_H_ -#define LIBWEAVE_SRC_COMMANDS_USER_ROLE_H_ - -#include <string> -#include <chromeos/errors/error.h> - -namespace weave { - -enum class UserRole { - kViewer, - kUser, - kManager, - kOwner, -}; - -} // namespace weave - -#endif // LIBWEAVE_SRC_COMMANDS_USER_ROLE_H_
diff --git a/libweave/src/device_manager.cc b/libweave/src/device_manager.cc index 7d2943b..709f4bb 100644 --- a/libweave/src/device_manager.cc +++ b/libweave/src/device_manager.cc
@@ -6,12 +6,14 @@ #include <string> -#include <chromeos/dbus/dbus_object.h> - #include <base/message_loop/message_loop.h> +#include <chromeos/dbus/dbus_object.h> +#include <chromeos/http/http_transport.h> #include "libweave/src/base_api_handler.h" +#include "libweave/src/buffet_config.h" #include "libweave/src/commands/command_manager.h" +#include "libweave/src/device_registration_info.h" #include "libweave/src/privet/privet_manager.h" #include "libweave/src/privet/shill_client.h" #include "libweave/src/states/state_change_queue.h" @@ -69,23 +71,23 @@ StartPrivet(options, dbus_object, sequencer); } -CommandManager* DeviceManager::GetCommands() { +Commands* DeviceManager::GetCommands() { return command_manager_.get(); } -StateManager* DeviceManager::GetState() { +State* DeviceManager::GetState() { return state_manager_.get(); } -BuffetConfig* DeviceManager::GetConfig() { +Config* DeviceManager::GetConfig() { return device_info_->GetMutableConfig(); } -DeviceRegistrationInfo* DeviceManager::GetCloud() { +Cloud* DeviceManager::GetCloud() { return device_info_.get(); } -privet::Manager* DeviceManager::GetPrivet() { +Privet* DeviceManager::GetPrivet() { return privet_.get(); }
diff --git a/libweave/src/device_manager.h b/libweave/src/device_manager.h index 0eba82a..7faf586 100644 --- a/libweave/src/device_manager.h +++ b/libweave/src/device_manager.h
@@ -5,6 +5,8 @@ #ifndef LIBWEAVE_SRC_DEVICE_MANAGER_H_ #define LIBWEAVE_SRC_DEVICE_MANAGER_H_ +#include <base/memory/weak_ptr.h> + #include "weave/device.h" namespace chromeos { @@ -36,11 +38,11 @@ chromeos::dbus_utils::DBusObject* dbus_object, chromeos::dbus_utils::AsyncEventSequencer* sequencer) override; - CommandManager* GetCommands() override; - StateManager* GetState() override; - BuffetConfig* GetConfig() override; - DeviceRegistrationInfo* GetCloud() override; - privet::Manager* GetPrivet() override; + Commands* GetCommands() override; + State* GetState() override; + Config* GetConfig() override; + Cloud* GetCloud() override; + Privet* GetPrivet() override; private: void StartPrivet(const Options& options,
diff --git a/libweave/src/device_registration_info.h b/libweave/src/device_registration_info.h index 4dff0a5..88039dc 100644 --- a/libweave/src/device_registration_info.h +++ b/libweave/src/device_registration_info.h
@@ -31,6 +31,8 @@ #include "libweave/src/notification/pull_channel.h" #include "libweave/src/states/state_change_queue_interface.h" #include "libweave/src/storage_interface.h" +#include "weave/cloud.h" +#include "weave/config.h" namespace base { class DictionaryValue; @@ -53,13 +55,12 @@ extern const char kErrorDomainGCDServer[]; // The DeviceRegistrationInfo class represents device registration information. -class DeviceRegistrationInfo : public NotificationDelegate, +class DeviceRegistrationInfo : public Cloud, + public NotificationDelegate, public CloudCommandUpdateInterface { public: - using OnRegistrationChangedCallback = - base::Callback<void(RegistrationStatus)>; using CloudRequestCallback = - base::Callback<void(const base::DictionaryValue&)>; + base::Callback<void(const base::DictionaryValue& response)>; using CloudRequestErrorCallback = base::Callback<void(const chromeos::Error* error)>; @@ -74,13 +75,31 @@ ~DeviceRegistrationInfo() override; - // Add callback to listen for changes in registration status. + // Cloud overrides. void AddOnRegistrationChangedCallback( - const OnRegistrationChangedCallback& callback); + const OnRegistrationChangedCallback& callback) override; + void GetDeviceInfo( + const OnCloudRequestCallback& success_callback, + const OnCloudRequestErrorCallback& error_callback) override; + std::string RegisterDevice(const std::string& ticket_id, + chromeos::ErrorPtr* error) override; + bool UpdateDeviceInfo(const std::string& name, + const std::string& description, + const std::string& location, + chromeos::ErrorPtr* error) override; + bool UpdateBaseConfig(const std::string& anonymous_access_role, + bool local_discovery_enabled, + bool local_pairing_enabled, + chromeos::ErrorPtr* error) override; + bool UpdateServiceConfig(const std::string& client_id, + const std::string& client_secret, + const std::string& api_key, + const std::string& oauth_url, + const std::string& service_url, + chromeos::ErrorPtr* error) override; // Add callback to listen for changes in config. - void AddOnConfigChangedCallback( - const BuffetConfig::OnChangedCallback& callback); + void AddOnConfigChangedCallback(const Config::OnChangedCallback& callback); // Returns the authorization HTTP header that can be used to talk // to GCD server for authenticated device communication. @@ -123,43 +142,12 @@ // are available. bool VerifyRegistrationCredentials(chromeos::ErrorPtr* error) const; - // Gets the full device description JSON object asynchronously. - // Passes the device info as the first argument to |callback|, or nullptr if - // the device is not registered or in case of communication failure. - void GetDeviceInfo(const CloudRequestCallback& success_callback, - const CloudRequestErrorCallback& error_callback); - - // Registers the device. - // Returns a device ID on success. - std::string RegisterDevice(const std::string& ticket_id, - chromeos::ErrorPtr* error); - // Updates a command (override from CloudCommandUpdateInterface). void UpdateCommand(const std::string& command_id, const base::DictionaryValue& command_patch, const base::Closure& on_success, const base::Closure& on_error) override; - // Updates basic device information. - bool UpdateDeviceInfo(const std::string& name, - const std::string& description, - const std::string& location, - chromeos::ErrorPtr* error); - - // Updates base device config. - bool UpdateBaseConfig(const std::string& anonymous_access_role, - bool local_discovery_enabled, - bool local_pairing_enabled, - chromeos::ErrorPtr* error); - - // Updates GCD service configuration. Usually for testing. - bool UpdateServiceConfig(const std::string& client_id, - const std::string& client_secret, - const std::string& api_key, - const std::string& oauth_url, - const std::string& service_url, - chromeos::ErrorPtr* error); - // TODO(vitalybuka): remove getters and pass config to dependent code. const BuffetConfig& GetConfig() const { return *config_; } BuffetConfig* GetMutableConfig() { return config_.get(); }
diff --git a/libweave/src/privet/cloud_delegate.cc b/libweave/src/privet/cloud_delegate.cc index 9ef680d..80f8086 100644 --- a/libweave/src/privet/cloud_delegate.cc +++ b/libweave/src/privet/cloud_delegate.cc
@@ -22,7 +22,6 @@ #include "libweave/src/device_registration_info.h" #include "libweave/src/privet/constants.h" #include "libweave/src/states/state_manager.h" -#include "weave/enum_to_string.h" using chromeos::ErrorPtr; using chromeos::VariantDictionary;
diff --git a/libweave/src/privet/privet_manager.h b/libweave/src/privet/privet_manager.h index 3a01f13..9ec3984 100644 --- a/libweave/src/privet/privet_manager.h +++ b/libweave/src/privet/privet_manager.h
@@ -48,10 +48,10 @@ class SecurityManager; class ShillClient; -class Manager : public CloudDelegate::Observer { +class Manager : public Privet, public CloudDelegate::Observer { public: Manager(); - ~Manager(); + ~Manager() override; void Start(const weave::Device::Options& options, const scoped_refptr<dbus::Bus>& bus, @@ -64,11 +64,11 @@ std::string GetCurrentlyConnectedSsid() const; void AddOnWifiSetupChangedCallback( - const WifiBootstrapManager::StateListener& callback); + const OnWifiSetupChangedCallback& callback) override; void AddOnPairingChangedCallbacks( - const SecurityManager::PairingStartListener& on_start, - const SecurityManager::PairingEndListener& on_end); + const OnPairingStartedCallback& on_start, + const OnPairingEndedCallback& on_end) override; void Shutdown();
diff --git a/libweave/src/privet/privet_types.cc b/libweave/src/privet/privet_types.cc index 7c68929..dcf3209 100644 --- a/libweave/src/privet/privet_types.cc +++ b/libweave/src/privet/privet_types.cc
@@ -7,7 +7,7 @@ #include <string> #include "weave/enum_to_string.h" -#include "weave/types.h" +#include "weave/privet.h" namespace weave {
diff --git a/libweave/src/privet/security_delegate.h b/libweave/src/privet/security_delegate.h index 616cc3d..e7444e9 100644 --- a/libweave/src/privet/security_delegate.h +++ b/libweave/src/privet/security_delegate.h
@@ -13,7 +13,7 @@ #include <chromeos/secure_blob.h> #include "libweave/src/privet/privet_types.h" -#include "weave/types.h" +#include "weave/privet.h" namespace weave { namespace privet {
diff --git a/libweave/src/registration_status.cc b/libweave/src/registration_status.cc index 8392d57..550360e 100644 --- a/libweave/src/registration_status.cc +++ b/libweave/src/registration_status.cc
@@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "weave/cloud.h" #include "weave/enum_to_string.h" -#include "weave/types.h" namespace weave {
diff --git a/libweave/src/states/state_manager.cc b/libweave/src/states/state_manager.cc index 7b867ca..d694464 100644 --- a/libweave/src/states/state_manager.cc +++ b/libweave/src/states/state_manager.cc
@@ -29,6 +29,8 @@ CHECK(state_change_queue_) << "State change queue not specified"; } +StateManager::~StateManager() {} + void StateManager::AddOnChangedCallback(const base::Closure& callback) { on_changed_.push_back(callback); callback.Run(); // Force to read current state.
diff --git a/libweave/src/states/state_manager.h b/libweave/src/states/state_manager.h index a60c0dc..99f561d 100644 --- a/libweave/src/states/state_manager.h +++ b/libweave/src/states/state_manager.h
@@ -19,6 +19,7 @@ #include "libweave/src/states/state_change_queue_interface.h" #include "libweave/src/states/state_package.h" +#include "weave/state.h" namespace base { class DictionaryValue; @@ -31,25 +32,22 @@ // StateManager is the class that aggregates the device state fragments // provided by device daemons and makes the aggregate device state available // to the GCD cloud server and local clients. -class StateManager final { +class StateManager final : public State { public: explicit StateManager(StateChangeQueueInterface* state_change_queue); + ~StateManager() override; - void AddOnChangedCallback(const base::Closure& callback); + // State overrides. + void AddOnChangedCallback(const base::Closure& callback) override; + bool SetProperties(const chromeos::VariantDictionary& property_set, + chromeos::ErrorPtr* error) override; + std::unique_ptr<base::DictionaryValue> GetStateValuesAsJson( + chromeos::ErrorPtr* error) const override; // Initializes the state manager and load device state fragments. // Called by Buffet daemon at startup. void Startup(); - // Returns aggregated state properties across all registered packages as - // a JSON object that can be used to send the device state to the GCD server. - std::unique_ptr<base::DictionaryValue> GetStateValuesAsJson( - chromeos::ErrorPtr* error) const; - - // Updates a multiple property values. - bool SetProperties(const chromeos::VariantDictionary& property_set, - chromeos::ErrorPtr* error); - // Returns all the categories the state properties are registered from. // As with GCD command handling, the category normally represent a device // service (daemon) that is responsible for a set of properties.