Remove weave::Commands

Methods were moved into weave::Device.

BUG:24267885
Change-Id: I9116269a5ca1a32ee3b263377af5e9bd368bbef9
Reviewed-on: https://weave-review.googlesource.com/1243
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/libweave/examples/ubuntu/main.cc b/libweave/examples/ubuntu/main.cc
index d9c1283..9b062ef 100644
--- a/libweave/examples/ubuntu/main.cc
+++ b/libweave/examples/ubuntu/main.cc
@@ -29,8 +29,8 @@
 class CommandHandler {
  public:
   explicit CommandHandler(weave::Device* device) : device_{device} {
-    device->GetCommands()->AddCommandAddedCallback(base::Bind(
-        &CommandHandler::OnNewCommand, weak_ptr_factory_.GetWeakPtr()));
+    device->AddCommandAddedCallback(base::Bind(&CommandHandler::OnNewCommand,
+                                               weak_ptr_factory_.GetWeakPtr()));
   }
 
  private:
diff --git a/libweave/include/weave/commands.h b/libweave/include/weave/commands.h
deleted file mode 100644
index cfbfe63..0000000
--- a/libweave/include/weave/commands.h
+++ /dev/null
@@ -1,43 +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_COMMANDS_H_
-#define LIBWEAVE_INCLUDE_WEAVE_COMMANDS_H_
-
-#include <string>
-
-#include <base/callback.h>
-#include <base/values.h>
-#include <weave/error.h>
-#include <weave/command.h>
-
-namespace weave {
-
-class Commands {
- public:
-  using CommandCallback = base::Callback<void(Command*)>;
-
-  // Adds notification callback for a new command being added to the queue.
-  virtual void AddCommandAddedCallback(const CommandCallback& callback) = 0;
-
-  // Adds notification callback for a command being removed from the queue.
-  virtual void AddCommandRemovedCallback(const CommandCallback& callback) = 0;
-
-  // Adds a new command to the command queue.
-  virtual bool AddCommand(const base::DictionaryValue& command,
-                          std::string* id,
-                          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/device.h b/libweave/include/weave/device.h
index 03e3984..c81dd04 100644
--- a/libweave/include/weave/device.h
+++ b/libweave/include/weave/device.h
@@ -9,7 +9,7 @@
 #include <set>
 #include <string>
 
-#include <weave/commands.h>
+#include <weave/command.h>
 #include <weave/export.h>
 #include <weave/provider/bluetooth.h>
 #include <weave/provider/config_store.h>
@@ -35,16 +35,34 @@
   virtual ~Device() = default;
 
   // Returns reference the current settings.
-  virtual const Settings& GetSettings() = 0;
+  virtual const Settings& GetSettings() const = 0;
 
   // Callback type for AddSettingsChangedCallback.
   using SettingsChangedCallback =
       base::Callback<void(const Settings& settings)>;
+
   // Subscribes to notification settings changes.
   virtual void AddSettingsChangedCallback(
       const SettingsChangedCallback& callback) = 0;
 
-  virtual Commands* GetCommands() = 0;
+  // Callback type for AddCommandAddedCallback and AddCommandRemovedCallback.
+  using CommandCallback = base::Callback<void(Command*)>;
+
+  // Adds notification callback for a new command being added to the queue.
+  virtual void AddCommandAddedCallback(const CommandCallback& callback) = 0;
+
+  // Adds notification callback for a command being removed from the queue.
+  virtual void AddCommandRemovedCallback(const CommandCallback& callback) = 0;
+
+  // Adds a new command to the command queue.
+  virtual bool AddCommand(const base::DictionaryValue& command,
+                          std::string* id,
+                          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;
 
   // Sets callback which is called when stat is changed.
   virtual void AddStateChangedCallback(const base::Closure& callback) = 0;
@@ -72,6 +90,7 @@
 
   // Callback type for GcdStatusCallback.
   using GcdStateChangedCallback = base::Callback<void(GcdState state)>;
+
   // Sets callback which is called when state of server connection changed.
   virtual void AddGcdStateChangedCallback(
       const GcdStateChangedCallback& callback) = 0;
@@ -86,10 +105,12 @@
       base::Callback<void(const std::string& session_id,
                           PairingType pairing_type,
                           const std::vector<uint8_t>& code)>;
+
   // Handler should stop displaying pin code.
   using PairingEndCallback =
       base::Callback<void(const std::string& session_id)>;
   // Subscribes to notification about client pairing events.
+
   virtual void AddPairingChangedCallbacks(
       const PairingBeginCallback& begin_callback,
       const PairingEndCallback& end_callback) = 0;
diff --git a/libweave/include/weave/test/mock_commands.h b/libweave/include/weave/test/mock_commands.h
deleted file mode 100644
index 9bae29c..0000000
--- a/libweave/include/weave/test/mock_commands.h
+++ /dev/null
@@ -1,31 +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_TEST_MOCK_COMMANDS_H_
-#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMANDS_H_
-
-#include <weave/commands.h>
-
-#include <string>
-
-#include <gmock/gmock.h>
-
-namespace weave {
-namespace test {
-
-class MockCommands : public Commands {
- public:
-  ~MockCommands() override = default;
-
-  MOCK_METHOD1(AddCommandAddedCallback, void(const CommandCallback&));
-  MOCK_METHOD1(AddCommandRemovedCallback, void(const CommandCallback&));
-  MOCK_METHOD3(AddCommand,
-               bool(const base::DictionaryValue&, std::string*, ErrorPtr*));
-  MOCK_METHOD1(FindCommand, Command*(const std::string&));
-};
-
-}  // namespace test
-}  // namespace weave
-
-#endif  // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_COMMANDS_H_
diff --git a/libweave/include/weave/test/mock_device.h b/libweave/include/weave/test/mock_device.h
new file mode 100644
index 0000000..44298bb
--- /dev/null
+++ b/libweave/include/weave/test/mock_device.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_TEST_MOCK_DEVICE_H_
+#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_DEVICE_H_
+
+#include <weave/device.h>
+
+#include <string>
+
+#include <gmock/gmock.h>
+
+namespace weave {
+namespace test {
+
+class MockDevice : public Device {
+ public:
+  ~MockDevice() override = default;
+
+  MOCK_CONST_METHOD0(GetSettings, const Settings&());
+  MOCK_METHOD1(AddSettingsChangedCallback,
+               void(const SettingsChangedCallback& callback));
+  MOCK_METHOD1(AddCommandAddedCallback, void(const CommandCallback&));
+  MOCK_METHOD1(AddCommandRemovedCallback, void(const CommandCallback&));
+  MOCK_METHOD3(AddCommand,
+               bool(const base::DictionaryValue&, std::string*, ErrorPtr*));
+  MOCK_METHOD1(FindCommand, Command*(const std::string&));
+  MOCK_METHOD1(AddStateChangedCallback, void(const base::Closure& callback));
+  MOCK_CONST_METHOD1(GetStateProperty,
+                     std::unique_ptr<base::Value>(const std::string& name));
+  MOCK_METHOD3(SetStateProperty,
+               bool(const std::string& name,
+                    const base::Value& value,
+                    ErrorPtr* error));
+  MOCK_METHOD2(SetStateProperties,
+               bool(const base::DictionaryValue& property_set,
+                    ErrorPtr* error));
+  MOCK_CONST_METHOD0(GetState, std::unique_ptr<base::DictionaryValue>());
+  MOCK_CONST_METHOD0(GetGcdState, GcdState());
+  MOCK_METHOD1(AddGcdStateChangedCallback,
+               void(const GcdStateChangedCallback& callback));
+  MOCK_METHOD2(Register,
+               std::string(const std::string& ticket_id, ErrorPtr* error));
+  MOCK_METHOD2(AddPairingChangedCallbacks,
+               void(const PairingBeginCallback& begin_callback,
+                    const PairingEndCallback& end_callback));
+};
+
+}  // namespace test
+}  // namespace weave
+
+#endif  // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_DEVICE_H_
diff --git a/libweave/src/commands/command_definition.h b/libweave/src/commands/command_definition.h
index 305e8f5..2c5dd77 100644
--- a/libweave/src/commands/command_definition.h
+++ b/libweave/src/commands/command_definition.h
@@ -9,7 +9,6 @@
 #include <string>
 
 #include <base/macros.h>
-#include <weave/commands.h>
 
 #include "src/commands/object_schema.h"
 
diff --git a/libweave/src/commands/command_manager.cc b/libweave/src/commands/command_manager.cc
index 11a1c40..60b3d1c 100644
--- a/libweave/src/commands/command_manager.cc
+++ b/libweave/src/commands/command_manager.cc
@@ -175,12 +175,13 @@
   return true;
 }
 
-void CommandManager::AddCommandAddedCallback(const CommandCallback& callback) {
+void CommandManager::AddCommandAddedCallback(
+    const Device::CommandCallback& callback) {
   command_queue_.AddCommandAddedCallback(callback);
 }
 
 void CommandManager::AddCommandRemovedCallback(
-    const CommandCallback& callback) {
+    const Device::CommandCallback& callback) {
   command_queue_.AddCommandRemovedCallback(callback);
 }
 
diff --git a/libweave/src/commands/command_manager.h b/libweave/src/commands/command_manager.h
index 2b2f83d..605f770 100644
--- a/libweave/src/commands/command_manager.h
+++ b/libweave/src/commands/command_manager.h
@@ -12,7 +12,6 @@
 #include <base/callback.h>
 #include <base/macros.h>
 #include <base/memory/weak_ptr.h>
-#include <weave/commands.h>
 
 #include "src/commands/command_dictionary.h"
 #include "src/commands/command_queue.h"
@@ -28,19 +27,18 @@
 // 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 : public Commands {
+class CommandManager final {
  public:
   CommandManager();
 
-  ~CommandManager() override;
+  ~CommandManager();
 
-  // Commands overrides.
   bool AddCommand(const base::DictionaryValue& command,
                   std::string* id,
-                  ErrorPtr* error) override;
-  CommandInstance* FindCommand(const std::string& id) override;
-  void AddCommandAddedCallback(const CommandCallback& callback) override;
-  void AddCommandRemovedCallback(const CommandCallback& callback) override;
+                  ErrorPtr* error);
+  CommandInstance* FindCommand(const std::string& id);
+  void AddCommandAddedCallback(const Device::CommandCallback& callback);
+  void AddCommandRemovedCallback(const Device::CommandCallback& callback);
 
   // Sets callback which is called when command definitions is changed.
   void AddCommandDefChanged(const base::Closure& callback);
diff --git a/libweave/src/commands/command_queue.cc b/libweave/src/commands/command_queue.cc
index 46385de..e580048 100644
--- a/libweave/src/commands/command_queue.cc
+++ b/libweave/src/commands/command_queue.cc
@@ -14,7 +14,7 @@
 }
 
 void CommandQueue::AddCommandAddedCallback(
-    const Commands::CommandCallback& callback) {
+    const Device::CommandCallback& callback) {
   on_command_added_.push_back(callback);
   // Send all pre-existed commands.
   for (const auto& command : map_)
@@ -22,7 +22,7 @@
 }
 
 void CommandQueue::AddCommandRemovedCallback(
-    const Commands::CommandCallback& callback) {
+    const Device::CommandCallback& callback) {
   on_command_removed_.push_back(callback);
 }
 
diff --git a/libweave/src/commands/command_queue.h b/libweave/src/commands/command_queue.h
index 4b2e47c..c3e86d5 100644
--- a/libweave/src/commands/command_queue.h
+++ b/libweave/src/commands/command_queue.h
@@ -15,7 +15,7 @@
 #include <base/callback.h>
 #include <base/macros.h>
 #include <base/time/time.h>
-#include <weave/commands.h>
+#include <weave/device.h>
 
 #include "src/commands/command_instance.h"
 
@@ -26,10 +26,10 @@
   CommandQueue() = default;
 
   // Adds notifications callback for a new command is added to the queue.
-  void AddCommandAddedCallback(const Commands::CommandCallback& callback);
+  void AddCommandAddedCallback(const Device::CommandCallback& callback);
 
   // Adds notifications callback for a command is removed from the queue.
-  void AddCommandRemovedCallback(const Commands::CommandCallback& callback);
+  void AddCommandRemovedCallback(const Device::CommandCallback& callback);
 
   // Checks if the command queue is empty.
   bool IsEmpty() const { return map_.empty(); }
@@ -75,7 +75,7 @@
   // Queue of commands to be removed.
   std::queue<std::pair<base::Time, std::string>> remove_queue_;
 
-  using CallbackList = std::vector<Commands::CommandCallback>;
+  using CallbackList = std::vector<Device::CommandCallback>;
   CallbackList on_command_added_;
   CallbackList on_command_removed_;
 
diff --git a/libweave/src/device_manager.cc b/libweave/src/device_manager.cc
index 79ef5d1..aedd425 100644
--- a/libweave/src/device_manager.cc
+++ b/libweave/src/device_manager.cc
@@ -59,7 +59,7 @@
 
 DeviceManager::~DeviceManager() {}
 
-const Settings& DeviceManager::GetSettings() {
+const Settings& DeviceManager::GetSettings() const {
   return device_info_->GetSettings();
 }
 
@@ -68,10 +68,6 @@
   device_info_->GetMutableConfig()->AddOnChangedCallback(callback);
 }
 
-Commands* DeviceManager::GetCommands() {
-  return command_manager_.get();
-}
-
 Config* DeviceManager::GetConfig() {
   return device_info_->GetMutableConfig();
 }
@@ -101,6 +97,24 @@
   state_manager_->AddChangedCallback(callback);
 }
 
+bool DeviceManager::AddCommand(const base::DictionaryValue& command,
+                               std::string* id,
+                               ErrorPtr* error) {
+  return command_manager_->AddCommand(command, id, error);
+}
+
+Command* DeviceManager::FindCommand(const std::string& id) {
+  return command_manager_->FindCommand(id);
+}
+
+void DeviceManager::AddCommandAddedCallback(const CommandCallback& callback) {
+  return command_manager_->AddCommandAddedCallback(callback);
+}
+
+void DeviceManager::AddCommandRemovedCallback(const CommandCallback& callback) {
+  return command_manager_->AddCommandRemovedCallback(callback);
+}
+
 bool DeviceManager::SetStateProperties(
     const base::DictionaryValue& property_set,
     ErrorPtr* error) {
diff --git a/libweave/src/device_manager.h b/libweave/src/device_manager.h
index fbf2871..d28d0b0 100644
--- a/libweave/src/device_manager.h
+++ b/libweave/src/device_manager.h
@@ -34,11 +34,15 @@
   ~DeviceManager() override;
 
   // Device implementation.
-  const Settings& GetSettings() override;
+  const Settings& GetSettings() const override;
   void AddSettingsChangedCallback(
       const SettingsChangedCallback& callback) override;
-  Commands* GetCommands() override;
-
+  bool AddCommand(const base::DictionaryValue& command,
+                  std::string* id,
+                  ErrorPtr* error) override;
+  Command* FindCommand(const std::string& id) override;
+  void AddCommandAddedCallback(const CommandCallback& callback) override;
+  void AddCommandRemovedCallback(const CommandCallback& callback) override;
   void AddStateChangedCallback(const base::Closure& callback) override;
   bool SetStateProperties(const base::DictionaryValue& property_set,
                           ErrorPtr* error) override;
@@ -48,13 +52,10 @@
                         const base::Value& value,
                         ErrorPtr* error) override;
   std::unique_ptr<base::DictionaryValue> GetState() const override;
-
   std::string Register(const std::string& ticket_id, ErrorPtr* error) override;
-
   GcdState GetGcdState() const override;
   void AddGcdStateChangedCallback(
       const GcdStateChangedCallback& callback) override;
-
   void AddPairingChangedCallbacks(
       const PairingBeginCallback& begin_callback,
       const PairingEndCallback& end_callback) override;
diff --git a/libweave/src/weave_unittest.cc b/libweave/src/weave_unittest.cc
index 9ab0a2a..ac6f9b8 100644
--- a/libweave/src/weave_unittest.cc
+++ b/libweave/src/weave_unittest.cc
@@ -14,7 +14,7 @@
 #include <weave/provider/test/mock_http_server.h>
 #include <weave/provider/test/mock_network.h>
 #include <weave/provider/test/mock_wifi.h>
-#include <weave/test/mock_commands.h>
+#include <weave/test/mock_device.h>
 #include <weave/test/unittest_utils.h>
 
 #include "src/bind_lambda.h"
@@ -270,6 +270,12 @@
   std::unique_ptr<weave::Device> device_;
 };
 
+TEST_F(WeaveTest, MockDevice) {
+  // Test checks if mock implements entire interface and mock can be
+  // instantiated.
+  test::MockDevice device;
+}
+
 TEST_F(WeaveTest, StartMinimal) {
   InitConfigStore();
   device_ = weave::Device::Create(&config_store_, &task_runner_, &http_client_,