summaryrefslogtreecommitdiff
path: root/commands.cpp
diff options
context:
space:
mode:
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);
}