Fix a crash when adding a default command handler
It is allowed to call ComponentManager::AddCommandHandler with
empty component and command name to indicate that we are installing
a default command handler. The CHECK() condition should be only
verified if a specific command handler is specified.
Change-Id: Ib4c0f633e5e4ddc396a4f5030a6ebd4e411f911e
Reviewed-on: https://weave-review.googlesource.com/1820
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/component_manager_impl.cc b/src/component_manager_impl.cc
index 8f685b3..a23f34d 100644
--- a/src/component_manager_impl.cc
+++ b/src/component_manager_impl.cc
@@ -266,8 +266,12 @@
const std::string& component_path,
const std::string& command_name,
const Device::CommandHandlerCallback& callback) {
- CHECK(FindCommandDefinition(command_name))
- << "Command undefined: " << command_name;
+ // If both component_path and command_name are empty, we are adding the
+ // default handler for all commands.
+ if (!component_path.empty() || !command_name.empty()) {
+ CHECK(FindCommandDefinition(command_name))
+ << "Command undefined: " << command_name;
+ }
command_queue_.AddCommandHandler(component_path, command_name, callback);
}