From e19efcb8e7ba2cf4d4ce59c5f76e78a41a19ba24 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 2 Jan 2011 03:55:52 +0100 Subject: Command handling changes as a result of adding the update command. --- commands.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'commands.cpp') diff --git a/commands.cpp b/commands.cpp index 03af48c..db693e5 100644 --- a/commands.cpp +++ b/commands.cpp @@ -1,12 +1,12 @@ #include "commands.h" -#include "music.h" #include #include +#include #include -static std::vector ls(const std::vector& args) { +std::vector commands::Commands::ls() { if(args.size() != 2) { throw commands::CommandException("usage: ls DIR"); } @@ -29,10 +29,7 @@ static std::vector ls(const std::vector& args) { return result; } -typedef boost::function (const std::string artist)> FindFunction; -std::map find_handlers; - -static std::vector find(const std::vector& args) { +std::vector commands::Commands::find() { if(args.size() != 3) { throw commands::CommandException("usage: find TYPE SEARCH"); } @@ -63,20 +60,30 @@ static std::vector find(const std::vector& args) { return result; } -std::map commands::handlers; +std::vector commands::Commands::update() { + if(args.size() != 2) { + throw commands::CommandException("usage: update DIR"); + } + + io_service.post(boost::bind(music::begin_update, args[1])); + + std::vector v; + return v; +} -void commands::init() { - handlers["ls"] = ls; - handlers["find"] = find; +commands::Commands::Commands(boost::asio::io_service& io_service_, std::vector& args_) : io_service(io_service_), args(args_) { + handlers["ls"] = &commands::Commands::ls; + handlers["find"] = &commands::Commands::find; find_handlers["artist"] = music::find_artist; + handlers["update"] = &commands::Commands::update; } -std::vector commands::execute(const std::vector& args) { +std::vector commands::Commands::operator()() { assert(args.size()); - Handler h = commands::handlers[args[0]]; + Handler h = handlers[args[0]]; if(!h) { throw CommandException(boost::str(boost::format("unknown command \"%s\"") % args[0])); } - return h(args); + return h(this); } -- cgit v1.2.3