From ee4cf5dc2d3eaa43794a8ac736a6409e08082882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 29 Sep 2016 20:53:40 +0200 Subject: Add AdhocCommandHandlers::add_command to simplify the usage of this class And make things a little bit clearer --- louloulibs/xmpp/adhoc_commands_handler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'louloulibs/xmpp/adhoc_commands_handler.cpp') diff --git a/louloulibs/xmpp/adhoc_commands_handler.cpp b/louloulibs/xmpp/adhoc_commands_handler.cpp index 17c4e67..573c9ec 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.cpp +++ b/louloulibs/xmpp/adhoc_commands_handler.cpp @@ -15,9 +15,9 @@ const std::map& AdhocCommandsHandler::get return this->commands; } -std::map& AdhocCommandsHandler::get_commands() +void AdhocCommandsHandler::add_command(std::string name, AdhocCommand command) { - return this->commands; + this->commands.emplace(std::make_pair(std::move(name), std::move(command))); } XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node) -- cgit v1.2.3 From 265b5df61b5f3d4b5f30bbc6518f833f73bda1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 29 Sep 2016 23:10:41 +0200 Subject: Re-add the ad-hoc command the was removed by mistake in the previous commit Thank you, e2e tests --- louloulibs/xmpp/adhoc_commands_handler.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'louloulibs/xmpp/adhoc_commands_handler.cpp') diff --git a/louloulibs/xmpp/adhoc_commands_handler.cpp b/louloulibs/xmpp/adhoc_commands_handler.cpp index 573c9ec..540cac0 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.cpp +++ b/louloulibs/xmpp/adhoc_commands_handler.cpp @@ -17,6 +17,9 @@ const std::map& AdhocCommandsHandler::get void AdhocCommandsHandler::add_command(std::string name, AdhocCommand command) { + const auto found = this->commands.find(name); + if (found != this->commands.end()) + throw std::runtime_error("Trying to add an ad-hoc command that already exist: "s + name); this->commands.emplace(std::make_pair(std::move(name), std::move(command))); } -- cgit v1.2.3