summaryrefslogtreecommitdiff
path: root/commands.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-01-02 03:55:52 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2011-01-02 03:55:52 +0100
commite19efcb8e7ba2cf4d4ce59c5f76e78a41a19ba24 (patch)
treeef89bb164d0e06f30396e84804cbc33c074ac065 /commands.cpp
parent0473fa912e2d2531529fec14a201efa3b20e2ef3 (diff)
Command handling changes as a result of adding the update command.
Diffstat (limited to 'commands.cpp')
-rw-r--r--commands.cpp33
1 files changed, 20 insertions, 13 deletions
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 <boost/format.hpp>
#include <boost/algorithm/string/join.hpp>
+#include <boost/bind.hpp>
#include <iostream>
-static std::vector<std::string> ls(const std::vector<std::string>& args) {
+std::vector<std::string> commands::Commands::ls() {
if(args.size() != 2) {
throw commands::CommandException("usage: ls DIR");
}
@@ -29,10 +29,7 @@ static std::vector<std::string> ls(const std::vector<std::string>& args) {
return result;
}
-typedef boost::function<std::vector<MusicListing::p> (const std::string artist)> FindFunction;
-std::map<std::string, FindFunction> find_handlers;
-
-static std::vector<std::string> find(const std::vector<std::string>& args) {
+std::vector<std::string> commands::Commands::find() {
if(args.size() != 3) {
throw commands::CommandException("usage: find TYPE SEARCH");
}
@@ -63,20 +60,30 @@ static std::vector<std::string> find(const std::vector<std::string>& args) {
return result;
}
-std::map<std::string, commands::Handler> commands::handlers;
+std::vector<std::string> 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<std::string> v;
+ return v;
+}
-void commands::init() {
- handlers["ls"] = ls;
- handlers["find"] = find;
+commands::Commands::Commands(boost::asio::io_service& io_service_, std::vector<std::string>& 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<std::string> commands::execute(const std::vector<std::string>& args) {
+std::vector<std::string> 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);
}