mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-16 23:22:31 +00:00
* Added system.method.{insert,erase} commands that allows
user-specified commands. "system.method.insert=foo,print=Bar" git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1069 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -50,7 +50,7 @@ class CommandFunction : public Command {
|
||||
public:
|
||||
CommandFunction(const std::string& cmd = std::string()) : m_command(cmd) {}
|
||||
|
||||
const std::string& command() const { return m_command; }
|
||||
const std::string& command() const { return m_command; }
|
||||
void set_command(const std::string& cmd) { m_command = cmd; }
|
||||
|
||||
static const torrent::Object call(Command* rawCommand, target_type target, const torrent::Object& args);
|
||||
|
||||
+21
-1
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <vector>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/data/file_list_iterator.h>
|
||||
@@ -46,13 +47,18 @@
|
||||
namespace rpc {
|
||||
|
||||
CommandMap::~CommandMap() {
|
||||
std::vector<const char*> keys;
|
||||
|
||||
for (iterator itr = base_type::begin(), last = base_type::end(); itr != last; itr++) {
|
||||
if (!(itr->second.m_flags & flag_dont_delete))
|
||||
delete itr->second.m_variable;
|
||||
|
||||
if (itr->second.m_flags & flag_delete_key)
|
||||
; // Remove from map and then delte the key.
|
||||
keys.push_back(itr->first);
|
||||
}
|
||||
|
||||
for (std::vector<const char*>::iterator itr = keys.begin(), last = keys.end(); itr != last; itr++)
|
||||
delete [] *itr;
|
||||
}
|
||||
|
||||
CommandMap::iterator
|
||||
@@ -79,6 +85,20 @@ CommandMap::insert(key_type key, const command_map_data_type src) {
|
||||
itr->second.m_genericSlot = src.m_genericSlot;
|
||||
}
|
||||
|
||||
void
|
||||
CommandMap::erase(iterator itr) {
|
||||
if (itr == end())
|
||||
return;
|
||||
|
||||
if (!(itr->second.m_flags & flag_dont_delete))
|
||||
delete itr->second.m_variable;
|
||||
|
||||
const char* key = itr->second.m_flags & flag_delete_key ? itr->first : NULL;
|
||||
|
||||
base_type::erase(itr);
|
||||
delete [] key;
|
||||
}
|
||||
|
||||
const CommandMap::mapped_type
|
||||
CommandMap::call_command(key_type key, const mapped_type& arg, target_type target) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
@@ -122,6 +122,7 @@ public:
|
||||
}
|
||||
|
||||
void insert(key_type key, const command_map_data_type src);
|
||||
void erase(iterator itr);
|
||||
|
||||
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)Command::target_generic, NULL));
|
||||
const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int)Command::target_generic, NULL));
|
||||
|
||||
Reference in New Issue
Block a user