summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands.cpp28
-rw-r--r--commands.h42
-rw-r--r--telnet_connection.cpp4
3 files changed, 36 insertions, 38 deletions
diff --git a/commands.cpp b/commands.cpp
index db693e5..3000f31 100644
--- a/commands.cpp
+++ b/commands.cpp
@@ -6,14 +6,14 @@
#include <iostream>
-std::vector<std::string> commands::Commands::ls() {
+std::vector<std::string> Commands::ls() {
if(args.size() != 2) {
- throw commands::CommandException("usage: ls DIR");
+ throw CommandException("usage: ls DIR");
}
MusicDirectory::p dir = music::get_directory(args[1]);
if(!dir) {
- throw commands::CommandException("no such directory");
+ throw CommandException("no such directory");
}
std::cout << dir->path << std::endl;
std::vector<std::string> result;
@@ -29,9 +29,9 @@ std::vector<std::string> commands::Commands::ls() {
return result;
}
-std::vector<std::string> commands::Commands::find() {
+std::vector<std::string> Commands::find() {
if(args.size() != 3) {
- throw commands::CommandException("usage: find TYPE SEARCH");
+ throw CommandException("usage: find TYPE SEARCH");
}
FindFunction ff;
@@ -43,12 +43,12 @@ std::vector<std::string> commands::Commands::find() {
types.push_back(it->first);
}
std::string s = boost::str(boost::format("unknown search type, must be one of %s") % boost::algorithm::join(types, ", "));
- throw commands::CommandException(s.c_str());
+ throw CommandException(s.c_str());
}
std::vector<MusicListing::p> ml = ff(args[2]);
if(!ml.size()) {
- throw commands::CommandException("no results");
+ throw CommandException("no results");
}
std::vector<std::string> result;
@@ -60,9 +60,9 @@ std::vector<std::string> commands::Commands::find() {
return result;
}
-std::vector<std::string> commands::Commands::update() {
+std::vector<std::string> Commands::update() {
if(args.size() != 2) {
- throw commands::CommandException("usage: update DIR");
+ throw CommandException("usage: update DIR");
}
io_service.post(boost::bind(music::begin_update, args[1]));
@@ -71,14 +71,14 @@ std::vector<std::string> commands::Commands::update() {
return v;
}
-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;
+Commands::Commands(boost::asio::io_service& io_service_, std::vector<std::string>& args_) : io_service(io_service_), args(args_) {
+ handlers["ls"] = &Commands::ls;
+ handlers["find"] = &Commands::find;
find_handlers["artist"] = music::find_artist;
- handlers["update"] = &commands::Commands::update;
+ handlers["update"] = &Commands::update;
}
-std::vector<std::string> commands::Commands::operator()() {
+std::vector<std::string> Commands::operator()() {
assert(args.size());
Handler h = handlers[args[0]];
if(!h) {
diff --git a/commands.h b/commands.h
index ae5dc84..084dd02 100644
--- a/commands.h
+++ b/commands.h
@@ -11,35 +11,33 @@
#include <map>
#include <stdexcept>
-namespace commands {
- class Commands;
+class Commands;
- class CommandException : public std::runtime_error {
- public:
- CommandException(const char *s) : std::runtime_error(s) {};
- CommandException(std::string s) : std::runtime_error(s.c_str()) {};
- };
+class CommandException : public std::runtime_error {
+ public:
+ CommandException(const char *s) : std::runtime_error(s) {};
+ CommandException(std::string s) : std::runtime_error(s.c_str()) {};
+};
- class Commands {
- private:
- typedef boost::function<std::vector<std::string> (Commands*)> Handler;
- std::map<std::string, Handler> handlers;
+class Commands {
+ private:
+ typedef boost::function<std::vector<std::string> (Commands*)> Handler;
+ std::map<std::string, Handler> handlers;
- typedef boost::function<std::vector<MusicListing::p> (const std::string artist)> FindFunction;
- std::map<std::string, FindFunction> find_handlers;
+ typedef boost::function<std::vector<MusicListing::p> (const std::string artist)> FindFunction;
+ std::map<std::string, FindFunction> find_handlers;
- boost::asio::io_service& io_service;
- std::vector<std::string>& args;
+ boost::asio::io_service& io_service;
+ std::vector<std::string>& args;
- std::vector<std::string> ls();
- std::vector<std::string> find();
- std::vector<std::string> update();
+ std::vector<std::string> ls();
+ std::vector<std::string> find();
+ std::vector<std::string> update();
- public:
- Commands(boost::asio::io_service& io_service, std::vector<std::string>& args);
- std::vector<std::string> operator()();
+ public:
+ Commands(boost::asio::io_service& io_service, std::vector<std::string>& args);
+ std::vector<std::string> operator()();
- };
};
#endif
diff --git a/telnet_connection.cpp b/telnet_connection.cpp
index c9089a9..2cc723e 100644
--- a/telnet_connection.cpp
+++ b/telnet_connection.cpp
@@ -34,9 +34,9 @@ void telnet::Connection::handle_read(const boost::system::error_code& error, siz
std::vector<std::string> r;
try {
- commands::Commands cmd(socket.get_io_service(), args);
+ Commands cmd(socket.get_io_service(), args);
r = cmd();
- } catch(commands::CommandException& ce) {
+ } catch(CommandException& ce) {
std::string s(ce.what());
s += '\n';
boost::asio::write(socket, boost::asio::buffer(s));