* Made rpc::CommandSlot into a template class and removed

"command_*_slot.{cc,h}".

* Added 'if' command. 


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@971 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-09-02 15:07:37 +00:00
parent ac2f5a8882
commit 1cc1374c7a
23 changed files with 467 additions and 1701 deletions
+12 -14
View File
@@ -49,9 +49,7 @@
#include "core/download.h"
#include "core/manager.h"
#include "rpc/command_slot.h"
#include "rpc/command_variable.h"
#include "rpc/command_download_slot.h"
#include "globals.h"
#include "control.h"
@@ -293,20 +291,20 @@ t_multicall(core::Download* download, const torrent::Object& rawArgs) {
#define ADD_CD_SLOT(key, function, slot, parm, doc) \
commandDownloadSlotsItr->set_slot(slot); \
rpc::commands.insert_download(key, commandDownloadSlotsItr++, &rpc::CommandDownloadSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_download(key, commandDownloadSlotsItr++, &rpc::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
#define ADD_CD_SLOT_PUBLIC(key, function, slot, parm, doc) \
commandDownloadSlotsItr->set_slot(slot); \
rpc::commands.insert_download(key, commandDownloadSlotsItr++, &rpc::CommandDownloadSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_download(key, commandDownloadSlotsItr++, &rpc::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_CD_VOID(key, slot) \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_d_fn(slot), "i:", "")
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_fn(slot), "i:", "")
#define ADD_CD_V_VOID(key, slot) \
ADD_CD_SLOT_PUBLIC("d." key, call_unknown, rpc::object_d_fn(slot), "i:", "")
ADD_CD_SLOT_PUBLIC("d." key, call_unknown, rpc::object_fn(slot), "i:", "")
#define ADD_CD_F_VOID(key, slot) \
ADD_CD_SLOT_PUBLIC("d." key, call_unknown, rpc::object_void_d_fn(slot), "i:", "")
ADD_CD_SLOT_PUBLIC("d." key, call_unknown, rpc::object_void_fn<core::Download*>(slot), "i:", "")
#define ADD_CD_LIST_OBSOLETE(key, slot) \
ADD_CD_SLOT_PUBLIC(key, call_list, slot, "i:", "")
@@ -331,24 +329,24 @@ t_multicall(core::Download* download, const torrent::Object& rawArgs) {
ADD_CD_SLOT_PUBLIC("d.set_" key, call_string, rpc::set_variable_d_fn(firstKey, secondKey), "i:s", "");
#define ADD_CD_VALUE_UNI(key, get) \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "")
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_fn<core::Download*>(get), "i:", "")
#define ADD_CD_VALUE_BI(key, set, get) \
ADD_CD_SLOT_PUBLIC("d.set_" key, call_value, rpc::object_value_d_fn(set), "i:i", "") \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "")
ADD_CD_SLOT_PUBLIC("d.set_" key, call_value, rpc::object_value_fn<core::Download*>(set), "i:i", "") \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_fn<core::Download*>(get), "i:", "")
#define ADD_CD_VALUE_MEM_BI(key, target, set, get) \
ADD_CD_VALUE_BI(key, rak::on2(std::mem_fun(target), std::mem_fun(set)), rak::on(std::mem_fun(target), std::mem_fun(get)));
#define ADD_CD_VALUE_MEM_UNI(key, target, get) \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(rak::on(rak::on(std::mem_fun(&core::Download::download), std::mem_fun(target)), std::mem_fun(get))), "i:", "");
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_fn<core::Download*>(rak::on(rak::on(std::mem_fun(&core::Download::download), std::mem_fun(target)), std::mem_fun(get))), "i:", "");
#define ADD_CD_STRING_UNI(key, get) \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "")
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_fn<core::Download*>(get), "s:", "")
#define ADD_CD_STRING_BI(key, set, get) \
ADD_CD_SLOT_PUBLIC("d.set_" key, call_string, rpc::object_string_d_fn(set), "i:s", "") \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "")
ADD_CD_SLOT_PUBLIC("d.set_" key, call_string, rpc::object_string_fn<core::Download*>(set), "i:s", "") \
ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_fn<core::Download*>(get), "s:", "")
void
add_copy_to_download(const char* src, const char* dest) {
+7 -9
View File
@@ -42,8 +42,6 @@
#include <torrent/data/file_list.h>
#include "core/manager.h"
#include "rpc/command_slot.h"
#include "rpc/command_file_slot.h"
#include "globals.h"
#include "control.h"
@@ -89,24 +87,24 @@ apply_f_path_depth(torrent::File* file) {
#define ADD_CF_SLOT(key, function, slot, parm, doc) \
commandFileSlotsItr->set_slot(slot); \
rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandFileSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
#define ADD_CF_SLOT_PUBLIC(key, function, slot, parm, doc) \
commandFileSlotsItr->set_slot(slot); \
rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandFileSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_CF_VOID(key, slot) \
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_f_fn(slot), "i:", "")
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_fn(slot), "i:", "")
#define ADD_CF_VALUE_UNI(key, get) \
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_f_fn(get), "i:", "")
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn<torrent::File*>(get), "i:", "")
#define ADD_CF_VALUE_BI(key, set, get) \
ADD_CF_SLOT_PUBLIC("f.set_" key, call_value, rpc::object_value_f_fn(set), "i:i", "") \
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_f_fn(get), "i:", "")
ADD_CF_SLOT_PUBLIC("f.set_" key, call_value, rpc::object_value_fn<torrent::File*>(set), "i:i", "") \
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn<torrent::File*>(get), "i:", "")
#define ADD_CF_STRING_UNI(key, get) \
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_f_fn(get), "s:", "")
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn<torrent::File*>(get), "s:", "")
void
initialize_command_file() {
+18 -19
View File
@@ -40,30 +40,27 @@
#include "rpc/command_slot.h"
#include "rpc/command_variable.h"
#include "rpc/command_download_slot.h"
#include "rpc/command_file_slot.h"
#include "rpc/command_file_itr_slot.h"
#include "rpc/command_peer_slot.h"
#include "rpc/command_tracker_slot.h"
#include "globals.h"
#include "control.h"
#include "command_helpers.h"
rpc::CommandSlot commandSlots[COMMAND_SLOTS_SIZE];
rpc::CommandSlot* commandSlotsItr = commandSlots;
rpc::CommandSlot<void> commandSlots[COMMAND_SLOTS_SIZE];
rpc::CommandSlot<void>* commandSlotsItr = commandSlots;
rpc::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE];
rpc::CommandVariable* commandVariablesItr = commandVariables;
rpc::CommandDownloadSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE];
rpc::CommandDownloadSlot* commandDownloadSlotsItr = commandDownloadSlots;
rpc::CommandFileSlot commandFileSlots[COMMAND_FILE_SLOTS_SIZE];
rpc::CommandFileSlot* commandFileSlotsItr = commandFileSlots;
rpc::CommandFileItrSlot commandFileItrSlots[COMMAND_FILE_ITR_SLOTS_SIZE];
rpc::CommandFileItrSlot* commandFileItrSlotsItr = commandFileItrSlots;
rpc::CommandPeerSlot commandPeerSlots[COMMAND_PEER_SLOTS_SIZE];
rpc::CommandPeerSlot* commandPeerSlotsItr = commandPeerSlots;
rpc::CommandTrackerSlot commandTrackerSlots[COMMAND_TRACKER_SLOTS_SIZE];
rpc::CommandTrackerSlot* commandTrackerSlotsItr = commandTrackerSlots;
rpc::CommandSlot<core::Download*> commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE];
rpc::CommandSlot<core::Download*>* commandDownloadSlotsItr = commandDownloadSlots;
rpc::CommandSlot<torrent::File*> commandFileSlots[COMMAND_FILE_SLOTS_SIZE];
rpc::CommandSlot<torrent::File*>* commandFileSlotsItr = commandFileSlots;
rpc::CommandSlot<torrent::FileListIterator*> commandFileItrSlots[COMMAND_FILE_ITR_SLOTS_SIZE];
rpc::CommandSlot<torrent::FileListIterator*>* commandFileItrSlotsItr = commandFileItrSlots;
rpc::CommandSlot<torrent::Peer*> commandPeerSlots[COMMAND_PEER_SLOTS_SIZE];
rpc::CommandSlot<torrent::Peer*>* commandPeerSlotsItr = commandPeerSlots;
rpc::CommandSlot<torrent::Tracker*> commandTrackerSlots[COMMAND_TRACKER_SLOTS_SIZE];
rpc::CommandSlot<torrent::Tracker*>* commandTrackerSlotsItr = commandTrackerSlots;
rpc::CommandSlot<rpc::target_type> commandAnySlots[COMMAND_ANY_SLOTS_SIZE];
rpc::CommandSlot<rpc::target_type>* commandAnySlotsItr = commandAnySlots;
void initialize_command_download();
void initialize_command_events();
@@ -91,14 +88,16 @@ initialize_commands() {
commandDownloadSlotsItr > commandDownloadSlots + COMMAND_DOWNLOAD_SLOTS_SIZE ||
commandFileSlotsItr > commandFileSlots + COMMAND_FILE_SLOTS_SIZE ||
commandPeerSlotsItr > commandPeerSlots + COMMAND_PEER_SLOTS_SIZE ||
commandTrackerSlotsItr > commandTrackerSlots + COMMAND_TRACKER_SLOTS_SIZE)
commandTrackerSlotsItr > commandTrackerSlots + COMMAND_TRACKER_SLOTS_SIZE ||
commandAnySlotsItr > commandAnySlots + COMMAND_ANY_SLOTS_SIZE)
#else
if (commandSlotsItr != commandSlots + COMMAND_SLOTS_SIZE ||
commandVariablesItr != commandVariables + COMMAND_VARIABLES_SIZE ||
commandDownloadSlotsItr != commandDownloadSlots + COMMAND_DOWNLOAD_SLOTS_SIZE ||
commandFileSlotsItr != commandFileSlots + COMMAND_FILE_SLOTS_SIZE ||
commandPeerSlotsItr != commandPeerSlots + COMMAND_PEER_SLOTS_SIZE ||
commandTrackerSlotsItr != commandTrackerSlots + COMMAND_TRACKER_SLOTS_SIZE)
commandTrackerSlotsItr != commandTrackerSlots + COMMAND_TRACKER_SLOTS_SIZE ||
commandAnySlotsItr != commandAnySlots + COMMAND_ANY_SLOTS_SIZE)
#endif
throw torrent::internal_error("initialize_commands() static command array size mismatch.");
}
+30 -22
View File
@@ -37,16 +37,11 @@
#ifndef RTORRENT_UTILS_COMMAND_HELPERS_H
#define RTORRENT_UTILS_COMMAND_HELPERS_H
#include "rpc/command_slot.h"
#include "rpc/parse_commands.h"
namespace rpc {
class CommandSlot;
class CommandVariable;
class CommandDownloadSlot;
class CommandFileSlot;
class CommandFileItrSlot;
class CommandPeerSlot;
class CommandTrackerSlot;
}
// By using a static array we avoid allocating the variables on the
@@ -58,23 +53,26 @@ namespace rpc {
#define COMMAND_FILE_ITR_SLOTS_SIZE 10
#define COMMAND_PEER_SLOTS_SIZE 20
#define COMMAND_TRACKER_SLOTS_SIZE 15
#define COMMAND_ANY_SLOTS_SIZE 20
#define ADDING_COMMANDS
extern rpc::CommandSlot commandSlots[COMMAND_SLOTS_SIZE];
extern rpc::CommandSlot* commandSlotsItr;
extern rpc::CommandSlot<void> commandSlots[COMMAND_SLOTS_SIZE];
extern rpc::CommandSlot<void>* commandSlotsItr;
extern rpc::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE];
extern rpc::CommandVariable* commandVariablesItr;
extern rpc::CommandDownloadSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE];
extern rpc::CommandDownloadSlot* commandDownloadSlotsItr;
extern rpc::CommandFileSlot commandFileSlots[COMMAND_FILE_SLOTS_SIZE];
extern rpc::CommandFileSlot* commandFileSlotsItr;
extern rpc::CommandFileItrSlot commandFileItrSlots[COMMAND_FILE_ITR_SLOTS_SIZE];
extern rpc::CommandFileItrSlot* commandFileItrSlotsItr;
extern rpc::CommandPeerSlot commandPeerSlots[COMMAND_PEER_SLOTS_SIZE];
extern rpc::CommandPeerSlot* commandPeerSlotsItr;
extern rpc::CommandTrackerSlot commandTrackerSlots[COMMAND_TRACKER_SLOTS_SIZE];
extern rpc::CommandTrackerSlot* commandTrackerSlotsItr;
extern rpc::CommandSlot<core::Download*> commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE];
extern rpc::CommandSlot<core::Download*>* commandDownloadSlotsItr;
extern rpc::CommandSlot<torrent::File*> commandFileSlots[COMMAND_FILE_SLOTS_SIZE];
extern rpc::CommandSlot<torrent::File*>* commandFileSlotsItr;
extern rpc::CommandSlot<torrent::FileListIterator*> commandFileItrSlots[COMMAND_FILE_ITR_SLOTS_SIZE];
extern rpc::CommandSlot<torrent::FileListIterator*>* commandFileItrSlotsItr;
extern rpc::CommandSlot<torrent::Peer*> commandPeerSlots[COMMAND_PEER_SLOTS_SIZE];
extern rpc::CommandSlot<torrent::Peer*>* commandPeerSlotsItr;
extern rpc::CommandSlot<torrent::Tracker*> commandTrackerSlots[COMMAND_TRACKER_SLOTS_SIZE];
extern rpc::CommandSlot<torrent::Tracker*>* commandTrackerSlotsItr;
extern rpc::CommandSlot<rpc::target_type> commandAnySlots[COMMAND_ANY_SLOTS_SIZE];
extern rpc::CommandSlot<rpc::target_type>* commandAnySlotsItr;
void initialize_commands();
@@ -97,17 +95,21 @@ add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::stri
#define ADD_COMMAND_SLOT(key, function, slot, parm, doc) \
commandSlotsItr->set_slot(slot); \
rpc::commands.insert_generic(key, commandSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_generic(key, commandSlotsItr++, &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_ANY_SLOT(key, function, slot, parm, doc) \
commandAnySlotsItr->set_slot(slot); \
rpc::commands.insert_any(key, commandAnySlotsItr++, &rpc::CommandSlot<rpc::target_type>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_COMMAND_SLOT_PRIVATE(key, function, slot) \
commandSlotsItr->set_slot(slot); \
rpc::commands.insert_generic(key, commandSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);
rpc::commands.insert_generic(key, commandSlotsItr++, &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);
#define ADD_COMMAND_COPY(key, function, parm, doc) \
rpc::commands.insert_generic(key, (commandSlotsItr - 1), &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_generic(key, (commandSlotsItr - 1), &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_COMMAND_COPY_PRIVATE(key, function) \
rpc::commands.insert_generic(key, (commandSlotsItr - 1), &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);
rpc::commands.insert_generic(key, (commandSlotsItr - 1), &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);
#define ADD_COMMAND_VALUE_TRI(key, set, get) \
ADD_COMMAND_SLOT_PRIVATE(key, call_value, rpc::object_value_fn(set)) \
@@ -154,6 +156,12 @@ add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::stri
#define ADD_COMMAND_LIST(key, slot) \
ADD_COMMAND_SLOT(key, call_list, slot, "i:", "")
#define ADD_COMMAND_NONE(key, slot) \
ADD_COMMAND_SLOT(key, call_unknown, slot, "i:", "")
#define ADD_ANY_NONE(key, slot) \
ADD_ANY_SLOT(key, call_unknown, slot, "i:", "")
#define ADD_COMMAND_NONE_L(key, slot) \
ADD_COMMAND_SLOT(key, call_unknown, slot, "A:", "")
+7 -9
View File
@@ -41,8 +41,6 @@
#include <torrent/peer/peer.h>
#include "core/manager.h"
#include "rpc/command_slot.h"
#include "rpc/command_peer_slot.h"
#include "globals.h"
#include "control.h"
@@ -88,24 +86,24 @@
#define ADD_CP_SLOT(key, function, slot, parm, doc) \
commandPeerSlotsItr->set_slot(slot); \
rpc::commands.insert_peer(key, commandPeerSlotsItr++, &rpc::CommandPeerSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_peer(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
#define ADD_CP_SLOT_PUBLIC(key, function, slot, parm, doc) \
commandPeerSlotsItr->set_slot(slot); \
rpc::commands.insert_peer(key, commandPeerSlotsItr++, &rpc::CommandPeerSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_peer(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_CP_VOID(key, slot) \
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_f_fn(slot), "i:", "")
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_fn(slot), "i:", "")
#define ADD_CP_VALUE_UNI(key, get) \
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_f_fn(get), "i:", "")
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "i:", "")
#define ADD_CP_VALUE_BI(key, set, get) \
ADD_CP_SLOT_PUBLIC("p.set_" key, call_value, rpc::object_value_f_fn(set), "i:i", "") \
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_f_fn(get), "i:", "")
ADD_CP_SLOT_PUBLIC("p.set_" key, call_value, rpc::object_value_fn<torrent::Peer*>(set), "i:i", "") \
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "i:", "")
#define ADD_CP_STRING_UNI(key, get) \
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_f_fn(get), "s:", "")
ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "s:", "")
void
initialize_command_peer() {
+7 -9
View File
@@ -40,8 +40,6 @@
#include <torrent/tracker.h>
#include "core/manager.h"
#include "rpc/command_slot.h"
#include "rpc/command_tracker_slot.h"
#include "globals.h"
#include "control.h"
@@ -57,24 +55,24 @@ apply_t_set_enabled(torrent::Tracker* tracker, int64_t state) {
#define ADD_CT_SLOT(key, function, slot, parm, doc) \
commandTrackerSlotsItr->set_slot(slot); \
rpc::commands.insert_tracker(key, commandTrackerSlotsItr++, &rpc::CommandTrackerSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_tracker(key, commandTrackerSlotsItr++, &rpc::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
#define ADD_CT_SLOT_PUBLIC(key, function, slot, parm, doc) \
commandTrackerSlotsItr->set_slot(slot); \
rpc::commands.insert_tracker(key, commandTrackerSlotsItr++, &rpc::CommandTrackerSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_tracker(key, commandTrackerSlotsItr++, &rpc::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_CT_VOID(key, slot) \
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_t_fn(slot), "i:", "")
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_fn(slot), "i:", "")
#define ADD_CT_VALUE_UNI(key, get) \
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_t_fn(get), "i:", "")
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn<torrent::Tracker*>(get), "i:", "")
#define ADD_CT_VALUE_BI(key, set, get) \
ADD_CT_SLOT_PUBLIC("t.set_" key, call_value, rpc::object_value_t_fn(set), "i:i", "") \
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_t_fn(get), "i:", "")
ADD_CT_SLOT_PUBLIC("t.set_" key, call_value, rpc::object_value_fn<torrent::Tracker*>(set), "i:i", "") \
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn<torrent::Tracker*>(get), "i:", "")
#define ADD_CT_STRING_UNI(key, get) \
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_t_fn(get), "s:", "")
ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn<torrent::Tracker*>(get), "s:", "")
void
initialize_command_tracker() {
+52 -16
View File
@@ -108,7 +108,7 @@ apply_view_list(const torrent::Object&) {
}
torrent::Object
apply_print(const torrent::Object& rawArgs) {
apply_print(rpc::target_type target, const torrent::Object& rawArgs) {
char buffer[1024];
rpc::print_object(buffer, buffer + 1024, &rawArgs, 0);
@@ -117,30 +117,65 @@ apply_print(const torrent::Object& rawArgs) {
}
torrent::Object
apply_cat(const torrent::Object& rawArgs) {
apply_cat(rpc::target_type target, const torrent::Object& rawArgs) {
std::string result;
rpc::print_object_std(&result, &rawArgs, 0);
return result;
}
// torrent::Object
// apply_if(const torrent::Object& rawArgs) {
// const torrent::Object::list_type& args = rawArgs.as_list();
// A series of if/else statements. Every even arguments are
// conditionals and odd arguments are branches to be executed, except
// the last one which is always a branch.
//
// if (cond1) { branch1 }
// <cond1>,<branch1>
//
// if (cond1) { branch1 } else if (cond2) { branch2 } else { branch3 }
// <cond1>,<branch1>,<cond2>,<branch2>,<branch3>
torrent::Object
apply_if(rpc::target_type target, const torrent::Object& rawArgs) {
const torrent::Object::list_type& args = rawArgs.as_list();
torrent::Object::list_type::const_iterator itr = args.begin();
// torrent::Object::list_type::const_iterator itr = args.begin();
while (itr != args.end() && itr != --args.end()) {
torrent::Object tmp;
const torrent::Object* conditional;
// while (itr != args.end()) {
// if (itr->is_string() && *itr->as_string().c_str() == '$') {
if (itr->is_string() && *itr->as_string().c_str() == '$')
conditional = &(tmp = rpc::parse_command(target, itr->as_string().c_str() + 1, itr->as_string().c_str() + itr->as_string().size()).first);
else
conditional = &*itr;
// torrent::Object tmp = rpc::parse_command(
bool result;
// } else {
// }
// }
switch (conditional->type()) {
case torrent::Object::TYPE_STRING:
result = !conditional->as_string().empty();
break;
case torrent::Object::TYPE_VALUE:
result = conditional->as_value();
break;
default:
throw torrent::input_error("Type not supported by 'if'.");
};
// return torrent::Object();
// }
itr++;
if (result)
break;
itr++;
}
if (itr == args.end())
return torrent::Object();
if (itr->is_string() && *itr->as_string().c_str() == '$')
return rpc::parse_command(target, itr->as_string().c_str() + 1, itr->as_string().c_str() + itr->as_string().size()).first;
else
return *itr;
}
void
initialize_command_ui() {
@@ -158,6 +193,7 @@ initialize_command_ui() {
// ADD_COMMAND_LIST("view_sort_current", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_sort_current));
ADD_COMMAND_LIST("print", rak::ptr_fn(&apply_print));
ADD_COMMAND_LIST("cat", rak::ptr_fn(&apply_cat));
ADD_ANY_NONE("print", rak::ptr_fn(&apply_print));
ADD_ANY_NONE("cat", rak::ptr_fn(&apply_cat));
ADD_ANY_NONE("if", rak::ptr_fn(&apply_if));
}
+29
View File
@@ -89,4 +89,33 @@ TextElementCString::copy_string(char* first, char* last, rpc::target_type target
return first + length;
}
// char*
// TextElementCommand::print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
// Attributes baseAttribute = attributes->back();
// push_attribute(attributes, Attributes(first, m_attributes, Attributes::color_invalid));
// if (first == last)
// return first;
// if (m_flags & flag_escape_hex) {
// char buffer[last - first];
// char* bufferLast = copy_string(buffer, buffer + (last - first), target);
// first = rak::transform_hex(buffer, bufferLast, first, last);
// } else if (m_flags & flag_escape_html) {
// char buffer[last - first];
// char* bufferLast = copy_string(buffer, buffer + (last - first), target);
// first = rak::copy_escape_html(buffer, bufferLast, first, last);
// } else {
// first = copy_string(first, last, target);
// }
// push_attribute(attributes, Attributes(first, baseAttribute));
// return first;
// }
}
+31
View File
@@ -155,6 +155,37 @@ text_element_string_slot(const slot_type& slot,
return new TextElementStringSlot<slot_type>(slot, flags, attributes, length);
}
//
// New TE's for calling commands directly. Move to a better place.
//
class TextElementCommand : public TextElement {
public:
static const int flag_normal = 0;
static const int flag_escape_hex = (1 << 0);
static const int flag_escape_html = (1 << 1);
static const int flag_fixed_width = (1 << 8);
TextElementCommand(const char* command) : m_command(command) {}
int flags() const { return m_flags; }
void set_flags(int flags) { m_flags = flags; }
int attributes() const { return m_attributes; }
void set_attributes(int a) { m_attributes = a; }
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target);
protected:
int m_flags;
int m_attributes;
const char* m_command;
};
}
#endif
-10
View File
@@ -2,16 +2,6 @@ noinst_LIBRARIES = libsub_rpc.a
libsub_rpc_a_SOURCES = \
command.h \
command_download_slot.cc \
command_download_slot.h \
command_file_slot.cc \
command_file_slot.h \
command_file_itr_slot.cc \
command_file_itr_slot.h \
command_peer_slot.cc \
command_peer_slot.h \
command_tracker_slot.cc \
command_tracker_slot.h \
command_map.cc \
command_map.h \
command_scheduler.cc \
-142
View File
@@ -1,142 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include "core/download.h"
#include "parse.h"
#include "command_download_slot.h"
namespace rpc {
const torrent::Object
CommandDownloadSlot::call_unknown(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) {
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
return command->m_slot(download, rawArgs);
}
const torrent::Object
CommandDownloadSlot::call_list(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) {
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
switch (rawArgs.type()) {
case torrent::Object::TYPE_LIST:
return command->m_slot(download, rawArgs);
case torrent::Object::TYPE_VALUE:
case torrent::Object::TYPE_STRING:
// case torrent::Object::TYPE_NONE:
{
torrent::Object tmpList(torrent::Object::TYPE_LIST);
tmpList.as_list().push_back(rawArgs);
return command->m_slot(download, tmpList);
}
default:
throw torrent::input_error("Not a list.");
}
}
const torrent::Object
CommandDownloadSlot::call_value_base(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs, int base, int unit) {
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_VALUE:
// Should shift this one too, so it gives the right unit.
return command->m_slot(download, arg);
case torrent::Object::TYPE_STRING:
{
torrent::Object argValue(torrent::Object::TYPE_VALUE);
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
throw torrent::input_error("Not a value.");
return command->m_slot(download, argValue);
}
default:
throw torrent::input_error("Not a value.");
}
}
const torrent::Object
CommandDownloadSlot::call_string(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) {
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
return command->m_slot(download, arg);
// case torrent::Object::TYPE_NONE:
// throw torrent::input_error("CDS: void.");
// case torrent::Object::TYPE_VALUE:
// throw torrent::input_error("CDS: value.");
// case torrent::Object::TYPE_LIST:
// throw torrent::input_error("CDS: list.");
default:
throw torrent::input_error("Not a string.");
}
}
torrent::Object
set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
if (m_firstKey == NULL)
download->bencode()->get_key(m_secondKey) = arg1;
else
download->bencode()->get_key(m_firstKey).get_key(m_secondKey) = arg1;
return torrent::Object();
}
torrent::Object
get_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
if (m_firstKey == NULL)
return download->bencode()->get_key(m_secondKey);
else
return download->bencode()->get_key(m_firstKey).get_key(m_secondKey);
}
}
-204
View File
@@ -1,204 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_RPC_COMMAND_DOWNLOAD_SLOT_H
#define RTORRENT_RPC_COMMAND_DOWNLOAD_SLOT_H
#include <functional>
#include <limits>
#include <inttypes.h>
#include <torrent/object.h>
#include <rak/functional_fun.h>
#include "command.h"
namespace core {
class Download;
}
namespace rpc {
class CommandDownloadSlot : public Command {
public:
typedef rak::function2<torrent::Object, core::Download*, const torrent::Object&> slot_type;
CommandDownloadSlot() {}
CommandDownloadSlot(slot_type::base_type* s) {
m_slot.set(s);
}
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, core::Download* download, const torrent::Object& args);
static const torrent::Object call_list(Command* rawCommand, core::Download* download, const torrent::Object& args);
static const torrent::Object call_string(Command* rawCommand, core::Download* download, const torrent::Object& args);
static const torrent::Object call_value_base(Command* rawCommand, core::Download* download, const torrent::Object& args, int base, int unit);
static const torrent::Object call_value(Command* rawCommand, core::Download* download, const torrent::Object& args) { return call_value_base(rawCommand, download, args, 0, 1); }
static const torrent::Object call_value_kb(Command* rawCommand, core::Download* download, const torrent::Object& args) { return call_value_base(rawCommand, download, args, 0, 1 << 10); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, core::Download* download, const torrent::Object& args) { return call_value_base(rawCommand, download, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
private:
slot_type m_slot;
};
// Some slots that convert torrent::Object arguments to proper
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_void_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_void_d_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) { return torrent::Object(m_func(download)); }
private:
Func m_func;
};
template <typename Func>
class object_void_d_fn_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_void_d_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
m_func(download);
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_value_d_fn1_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_value_d_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
return torrent::Object((int64_t)m_func(download, arg1.as_value()));
}
private:
Func m_func;
};
template <typename Func>
class object_value_d_fn1_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_value_d_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
m_func(download, arg1.as_value());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_string_d_fn1_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_string_d_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) { return torrent::Object(m_func(download, arg1.as_string())); }
private:
Func m_func;
};
template <typename Func>
class object_string_d_fn1_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_string_d_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
m_func(download, arg1.as_string());
return torrent::Object();
}
private:
Func m_func;
};
class set_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
set_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1);
private:
const char* m_firstKey;
const char* m_secondKey;
};
class get_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
get_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1);
private:
const char* m_firstKey;
const char* m_secondKey;
};
template <typename Return> object_void_d_fn_t<Return (*)(core::Download*), Return>*
object_d_fn(Return (*func)(core::Download*)) {
return new object_void_d_fn_t<Return (*)(core::Download*), Return>(func);
}
template <typename Func> object_void_d_fn_t<Func>* object_void_d_fn(Func func) { return new object_void_d_fn_t<Func>(func); }
template <typename Func> object_value_d_fn1_t<Func>* object_value_d_fn(Func func) { return new object_value_d_fn1_t<Func>(func); }
template <typename Func> object_string_d_fn1_t<Func>* object_string_d_fn(Func func) { return new object_string_d_fn1_t<Func>(func); }
inline set_variable_d_fn_t*
set_variable_d_fn(const char* firstKey, const char* secondKey) { return new set_variable_d_fn_t(firstKey, secondKey); }
inline get_variable_d_fn_t*
get_variable_d_fn(const char* firstKey, const char* secondKey) { return new get_variable_d_fn_t(firstKey, secondKey); }
}
#endif
-123
View File
@@ -1,123 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <torrent/data/file.h>
#include "parse.h"
#include "command_file_itr_slot.h"
namespace rpc {
const torrent::Object
CommandFileItrSlot::call_unknown(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& rawArgs) {
CommandFileItrSlot* command = static_cast<CommandFileItrSlot*>(rawCommand);
return command->m_slot(file, rawArgs);
}
const torrent::Object
CommandFileItrSlot::call_list(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& rawArgs) {
CommandFileItrSlot* command = static_cast<CommandFileItrSlot*>(rawCommand);
switch (rawArgs.type()) {
case torrent::Object::TYPE_LIST:
return command->m_slot(file, rawArgs);
case torrent::Object::TYPE_VALUE:
case torrent::Object::TYPE_STRING:
{
torrent::Object tmpList(torrent::Object::TYPE_LIST);
tmpList.as_list().push_back(rawArgs);
return command->m_slot(file, tmpList);
}
default:
throw torrent::input_error("Not a list.");
}
}
const torrent::Object
CommandFileItrSlot::call_value_base(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& rawArgs, int base, int unit) {
CommandFileItrSlot* command = static_cast<CommandFileItrSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_VALUE:
// Should shift this one too, so it gives the right unit.
return command->m_slot(file, arg);
case torrent::Object::TYPE_STRING:
{
torrent::Object argValue(torrent::Object::TYPE_VALUE);
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
throw torrent::input_error("Not a value.");
return command->m_slot(file, argValue);
}
default:
throw torrent::input_error("Not a value.");
}
}
const torrent::Object
CommandFileItrSlot::call_string(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& rawArgs) {
CommandFileItrSlot* command = static_cast<CommandFileItrSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
return command->m_slot(file, arg);
// case torrent::Object::TYPE_NONE:
// throw torrent::input_error("CDS: void.");
// case torrent::Object::TYPE_VALUE:
// throw torrent::input_error("CDS: value.");
// case torrent::Object::TYPE_LIST:
// throw torrent::input_error("CDS: list.");
default:
throw torrent::input_error("Not a string.");
}
}
}
-176
View File
@@ -1,176 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_RPC_COMMAND_FILE_ITR_SLOT_H
#define RTORRENT_RPC_COMMAND_FILE_ITR_SLOT_H
#include <limits>
#include <inttypes.h>
#include <torrent/object.h>
#include <rak/functional_fun.h>
#include "command.h"
namespace torrent {
class FileListIterator;
}
namespace rpc {
class CommandFileItrSlot : public Command {
public:
typedef rak::function2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> slot_type;
CommandFileItrSlot() {}
CommandFileItrSlot(slot_type::base_type* s) {
m_slot.set(s);
}
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args);
static const torrent::Object call_list(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args);
static const torrent::Object call_string(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args);
static const torrent::Object call_value_base(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args, int base, int unit);
static const torrent::Object call_value(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args) { return call_value_base(rawCommand, file, args, 0, 1); }
static const torrent::Object call_value_kb(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args) { return call_value_base(rawCommand, file, args, 0, 1 << 10); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, torrent::FileListIterator* file, const torrent::Object& args) { return call_value_base(rawCommand, file, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
private:
slot_type m_slot;
};
// Some slots that convert torrent::Object arguments to proper
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_void_fi_fn_t : public rak::function_base2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> {
public:
object_void_fi_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::FileListIterator* file, const torrent::Object& arg1) { return torrent::Object(m_func(file)); }
private:
Func m_func;
};
template <typename Func>
class object_void_fi_fn_t<Func, void> : public rak::function_base2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> {
public:
object_void_fi_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::FileListIterator* file, const torrent::Object& arg1) {
m_func(file);
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_value_fi_fn1_t : public rak::function_base2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> {
public:
object_value_fi_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::FileListIterator* file, const torrent::Object& arg1) {
return torrent::Object((int64_t)m_func(file, arg1.as_value()));
}
private:
Func m_func;
};
template <typename Func>
class object_value_fi_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> {
public:
object_value_fi_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::FileListIterator* file, const torrent::Object& arg1) {
m_func(file, arg1.as_value());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_string_fi_fn1_t : public rak::function_base2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> {
public:
object_string_fi_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::FileListIterator* file, const torrent::Object& arg1) { return torrent::Object(m_func(file, arg1.as_string())); }
private:
Func m_func;
};
template <typename Func>
class object_string_fi_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::FileListIterator*, const torrent::Object&> {
public:
object_string_fi_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::FileListIterator* file, const torrent::Object& arg1) {
m_func(file, arg1.as_string());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Return> object_void_fi_fn_t<Return (*)(torrent::FileListIterator*), Return>*
object_fi_fn(Return (*func)(torrent::FileListIterator*)) {
return new object_void_fi_fn_t<Return (*)(torrent::FileListIterator*), Return>(func);
}
template <typename Func> object_void_fi_fn_t<Func>* object_void_fi_fn(Func func) { return new object_void_fi_fn_t<Func>(func); }
template <typename Func> object_value_fi_fn1_t<Func>* object_value_fi_fn(Func func) { return new object_value_fi_fn1_t<Func>(func); }
template <typename Func> object_string_fi_fn1_t<Func>* object_string_fi_fn(Func func) { return new object_string_fi_fn1_t<Func>(func); }
}
#endif
-123
View File
@@ -1,123 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <torrent/data/file.h>
#include "parse.h"
#include "command_file_slot.h"
namespace rpc {
const torrent::Object
CommandFileSlot::call_unknown(Command* rawCommand, torrent::File* file, const torrent::Object& rawArgs) {
CommandFileSlot* command = static_cast<CommandFileSlot*>(rawCommand);
return command->m_slot(file, rawArgs);
}
const torrent::Object
CommandFileSlot::call_list(Command* rawCommand, torrent::File* file, const torrent::Object& rawArgs) {
CommandFileSlot* command = static_cast<CommandFileSlot*>(rawCommand);
switch (rawArgs.type()) {
case torrent::Object::TYPE_LIST:
return command->m_slot(file, rawArgs);
case torrent::Object::TYPE_VALUE:
case torrent::Object::TYPE_STRING:
{
torrent::Object tmpList(torrent::Object::TYPE_LIST);
tmpList.as_list().push_back(rawArgs);
return command->m_slot(file, tmpList);
}
default:
throw torrent::input_error("Not a list.");
}
}
const torrent::Object
CommandFileSlot::call_value_base(Command* rawCommand, torrent::File* file, const torrent::Object& rawArgs, int base, int unit) {
CommandFileSlot* command = static_cast<CommandFileSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_VALUE:
// Should shift this one too, so it gives the right unit.
return command->m_slot(file, arg);
case torrent::Object::TYPE_STRING:
{
torrent::Object argValue(torrent::Object::TYPE_VALUE);
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
throw torrent::input_error("Not a value.");
return command->m_slot(file, argValue);
}
default:
throw torrent::input_error("Not a value.");
}
}
const torrent::Object
CommandFileSlot::call_string(Command* rawCommand, torrent::File* file, const torrent::Object& rawArgs) {
CommandFileSlot* command = static_cast<CommandFileSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
return command->m_slot(file, arg);
// case torrent::Object::TYPE_NONE:
// throw torrent::input_error("CDS: void.");
// case torrent::Object::TYPE_VALUE:
// throw torrent::input_error("CDS: value.");
// case torrent::Object::TYPE_LIST:
// throw torrent::input_error("CDS: list.");
default:
throw torrent::input_error("Not a string.");
}
}
}
-176
View File
@@ -1,176 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_RPC_COMMAND_FILE_SLOT_H
#define RTORRENT_RPC_COMMAND_FILE_SLOT_H
#include <limits>
#include <inttypes.h>
#include <torrent/object.h>
#include <rak/functional_fun.h>
#include "command.h"
namespace torrent {
class File;
}
namespace rpc {
class CommandFileSlot : public Command {
public:
typedef rak::function2<torrent::Object, torrent::File*, const torrent::Object&> slot_type;
CommandFileSlot() {}
CommandFileSlot(slot_type::base_type* s) {
m_slot.set(s);
}
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, torrent::File* file, const torrent::Object& args);
static const torrent::Object call_list(Command* rawCommand, torrent::File* file, const torrent::Object& args);
static const torrent::Object call_string(Command* rawCommand, torrent::File* file, const torrent::Object& args);
static const torrent::Object call_value_base(Command* rawCommand, torrent::File* file, const torrent::Object& args, int base, int unit);
static const torrent::Object call_value(Command* rawCommand, torrent::File* file, const torrent::Object& args) { return call_value_base(rawCommand, file, args, 0, 1); }
static const torrent::Object call_value_kb(Command* rawCommand, torrent::File* file, const torrent::Object& args) { return call_value_base(rawCommand, file, args, 0, 1 << 10); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, torrent::File* file, const torrent::Object& args) { return call_value_base(rawCommand, file, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
private:
slot_type m_slot;
};
// Some slots that convert torrent::Object arguments to proper
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_void_f_fn_t : public rak::function_base2<torrent::Object, torrent::File*, const torrent::Object&> {
public:
object_void_f_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::File* file, const torrent::Object& arg1) { return torrent::Object(m_func(file)); }
private:
Func m_func;
};
template <typename Func>
class object_void_f_fn_t<Func, void> : public rak::function_base2<torrent::Object, torrent::File*, const torrent::Object&> {
public:
object_void_f_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::File* file, const torrent::Object& arg1) {
m_func(file);
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_value_f_fn1_t : public rak::function_base2<torrent::Object, torrent::File*, const torrent::Object&> {
public:
object_value_f_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::File* file, const torrent::Object& arg1) {
return torrent::Object((int64_t)m_func(file, arg1.as_value()));
}
private:
Func m_func;
};
template <typename Func>
class object_value_f_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::File*, const torrent::Object&> {
public:
object_value_f_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::File* file, const torrent::Object& arg1) {
m_func(file, arg1.as_value());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_string_f_fn1_t : public rak::function_base2<torrent::Object, torrent::File*, const torrent::Object&> {
public:
object_string_f_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::File* file, const torrent::Object& arg1) { return torrent::Object(m_func(file, arg1.as_string())); }
private:
Func m_func;
};
template <typename Func>
class object_string_f_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::File*, const torrent::Object&> {
public:
object_string_f_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::File* file, const torrent::Object& arg1) {
m_func(file, arg1.as_string());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Return> object_void_f_fn_t<Return (*)(torrent::File*), Return>*
object_f_fn(Return (*func)(torrent::File*)) {
return new object_void_f_fn_t<Return (*)(torrent::File*), Return>(func);
}
template <typename Func> object_void_f_fn_t<Func>* object_void_f_fn(Func func) { return new object_void_f_fn_t<Func>(func); }
template <typename Func> object_value_f_fn1_t<Func>* object_value_f_fn(Func func) { return new object_value_f_fn1_t<Func>(func); }
template <typename Func> object_string_f_fn1_t<Func>* object_string_f_fn(Func func) { return new object_string_f_fn1_t<Func>(func); }
}
#endif
+4 -4
View File
@@ -147,8 +147,8 @@ CommandMap::call_command(key_type key, const mapped_type& arg, target_type targe
if (itr == base_type::end())
throw torrent::input_error("Command \"" + std::string(key) + "\" does not exist.");
if ((itr->second.m_target != target.first && itr->second.m_target != target_generic) ||
(itr->second.m_target != target_generic && target.second == NULL))
if ((itr->second.m_target != target.first && itr->second.m_target > target_any) ||
(target.second == NULL && itr->second.m_target != target_generic && !(itr->second.m_target == target_any && target.first == target_generic)))
throw torrent::input_error("Command type mis-match.");
// This _should_ be optimized int just two calls.
@@ -166,8 +166,8 @@ CommandMap::call_command(key_type key, const mapped_type& arg, target_type targe
const CommandMap::mapped_type
CommandMap::call_command(const_iterator itr, const mapped_type& arg, target_type target) {
if ((itr->second.m_target != target.first && itr->second.m_target != target_generic) ||
(itr->second.m_target != target_generic && target.second == NULL))
if ((itr->second.m_target != target.first && itr->second.m_target > target_any) ||
(target.second == NULL && itr->second.m_target != target_generic && !(itr->second.m_target == target_any && target.first == target_generic)))
throw torrent::input_error("Command type mis-match.");
// This _should_ be optimized int just two calls.
-123
View File
@@ -1,123 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <torrent/peer/peer.h>
#include "parse.h"
#include "command_peer_slot.h"
namespace rpc {
const torrent::Object
CommandPeerSlot::call_unknown(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs) {
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
return command->m_slot(peer, rawArgs);
}
const torrent::Object
CommandPeerSlot::call_list(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs) {
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
switch (rawArgs.type()) {
case torrent::Object::TYPE_LIST:
return command->m_slot(peer, rawArgs);
case torrent::Object::TYPE_VALUE:
case torrent::Object::TYPE_STRING:
{
torrent::Object tmpList(torrent::Object::TYPE_LIST);
tmpList.as_list().push_back(rawArgs);
return command->m_slot(peer, tmpList);
}
default:
throw torrent::input_error("Not a list.");
}
}
const torrent::Object
CommandPeerSlot::call_value_base(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs, int base, int unit) {
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_VALUE:
// Should shift this one too, so it gives the right unit.
return command->m_slot(peer, arg);
case torrent::Object::TYPE_STRING:
{
torrent::Object argValue(torrent::Object::TYPE_VALUE);
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
throw torrent::input_error("Not a value.");
return command->m_slot(peer, argValue);
}
default:
throw torrent::input_error("Not a value.");
}
}
const torrent::Object
CommandPeerSlot::call_string(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs) {
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
return command->m_slot(peer, arg);
// case torrent::Object::TYPE_NONE:
// throw torrent::input_error("CDS: void.");
// case torrent::Object::TYPE_VALUE:
// throw torrent::input_error("CDS: value.");
// case torrent::Object::TYPE_LIST:
// throw torrent::input_error("CDS: list.");
default:
throw torrent::input_error("Not a string.");
}
}
}
-176
View File
@@ -1,176 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_RPC_COMMAND_PEER_SLOT_H
#define RTORRENT_RPC_COMMAND_PEER_SLOT_H
#include <limits>
#include <inttypes.h>
#include <torrent/object.h>
#include <rak/functional_fun.h>
#include "command.h"
namespace torrent {
class Peer;
}
namespace rpc {
class CommandPeerSlot : public Command {
public:
typedef rak::function2<torrent::Object, torrent::Peer*, const torrent::Object&> slot_type;
CommandPeerSlot() {}
CommandPeerSlot(slot_type::base_type* s) {
m_slot.set(s);
}
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args);
static const torrent::Object call_list(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args);
static const torrent::Object call_string(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args);
static const torrent::Object call_value_base(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args, int base, int unit);
static const torrent::Object call_value(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args) { return call_value_base(rawCommand, peer, args, 0, 1); }
static const torrent::Object call_value_kb(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args) { return call_value_base(rawCommand, peer, args, 0, 1 << 10); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args) { return call_value_base(rawCommand, peer, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
private:
slot_type m_slot;
};
// Some slots that convert torrent::Object arguments to proper
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_void_p_fn_t : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
public:
object_void_p_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) { return torrent::Object(m_func(peer)); }
private:
Func m_func;
};
template <typename Func>
class object_void_p_fn_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
public:
object_void_p_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
m_func(peer);
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_value_p_fn1_t : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
public:
object_value_p_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
return torrent::Object((int64_t)m_func(peer, arg1.as_value()));
}
private:
Func m_func;
};
template <typename Func>
class object_value_p_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
public:
object_value_p_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
m_func(peer, arg1.as_value());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_string_p_fn1_t : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
public:
object_string_p_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) { return torrent::Object(m_func(peer, arg1.as_string())); }
private:
Func m_func;
};
template <typename Func>
class object_string_p_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
public:
object_string_p_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
m_func(peer, arg1.as_string());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Return> object_void_p_fn_t<Return (*)(torrent::Peer*), Return>*
object_p_fn(Return (*func)(torrent::Peer*)) {
return new object_void_p_fn_t<Return (*)(torrent::Peer*), Return>(func);
}
template <typename Func> object_void_p_fn_t<Func>* object_void_p_fn(Func func) { return new object_void_p_fn_t<Func>(func); }
template <typename Func> object_value_p_fn1_t<Func>* object_value_p_fn(Func func) { return new object_value_p_fn1_t<Func>(func); }
template <typename Func> object_string_p_fn1_t<Func>* object_string_p_fn(Func func) { return new object_string_p_fn1_t<Func>(func); }
}
#endif
+105 -4
View File
@@ -36,21 +36,51 @@
#include "config.h"
#include "core/download.h"
#include "parse.h"
#include "command_slot.h"
namespace rpc {
template <typename Target> const torrent::Object
CommandSlot<Target>::call_unknown(Command* rawCommand, Target target, const torrent::Object& rawArgs) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
return command->m_slot(target, rawArgs);
}
const torrent::Object
CommandSlot::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) {
CommandSlot<void>::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
return command->m_slot(rawArgs);
}
template <typename Target> const torrent::Object
CommandSlot<Target>::call_list(Command* rawCommand, Target target, const torrent::Object& rawArgs) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
switch (rawArgs.type()) {
case torrent::Object::TYPE_LIST:
return command->m_slot(target, rawArgs);
case torrent::Object::TYPE_VALUE:
case torrent::Object::TYPE_STRING:
case torrent::Object::TYPE_NONE:
{
torrent::Object tmpList(torrent::Object::TYPE_LIST);
tmpList.as_list().push_back(rawArgs);
return command->m_slot(target, tmpList);
}
default:
throw torrent::input_error("Not a list.");
}
}
const torrent::Object
CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs) {
CommandSlot<void>::call_list(Command* rawCommand, const torrent::Object& rawArgs) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
switch (rawArgs.type()) {
@@ -71,8 +101,33 @@ CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs) {
}
}
template <typename Target> const torrent::Object
CommandSlot<Target>::call_value_base(Command* rawCommand, Target target, const torrent::Object& rawArgs, int base, int unit) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_VALUE:
// Should shift this one too, so it gives the right unit.
return command->m_slot(target, arg);
case torrent::Object::TYPE_STRING:
{
torrent::Object argValue(torrent::Object::TYPE_VALUE);
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
throw torrent::input_error("Not a value.");
return command->m_slot(target, argValue);
}
default:
throw torrent::input_error("Not a value.");
}
}
const torrent::Object
CommandSlot::call_value_base(Command* rawCommand, const torrent::Object& rawArgs, int base, int unit) {
CommandSlot<void>::call_value_base(Command* rawCommand, const torrent::Object& rawArgs, int base, int unit) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
@@ -96,8 +151,27 @@ CommandSlot::call_value_base(Command* rawCommand, const torrent::Object& rawArgs
}
}
template <typename Target> const torrent::Object
CommandSlot<Target>::call_string(Command* rawCommand, Target target, const torrent::Object& rawArgs) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
// case torrent::Object::TYPE_VALUE:
// break;
case torrent::Object::TYPE_STRING:
return command->m_slot(target, arg);
break;
default:
throw torrent::input_error("Not a string.");
}
}
const torrent::Object
CommandSlot::call_string(Command* rawCommand, const torrent::Object& rawArgs) {
CommandSlot<void>::call_string(Command* rawCommand, const torrent::Object& rawArgs) {
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
@@ -115,4 +189,31 @@ CommandSlot::call_string(Command* rawCommand, const torrent::Object& rawArgs) {
}
}
torrent::Object
set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
if (m_firstKey == NULL)
download->bencode()->get_key(m_secondKey) = arg1;
else
download->bencode()->get_key(m_firstKey).get_key(m_secondKey) = arg1;
return torrent::Object();
}
torrent::Object
get_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
if (m_firstKey == NULL)
return download->bencode()->get_key(m_secondKey);
else
return download->bencode()->get_key(m_firstKey).get_key(m_secondKey);
}
// Initialize the necessary template classes.
template class CommandSlot<void>;
template class CommandSlot<target_type>;
template class CommandSlot<core::Download*>;
template class CommandSlot<torrent::File*>;
template class CommandSlot<torrent::FileListIterator*>;
template class CommandSlot<torrent::Peer*>;
template class CommandSlot<torrent::Tracker*>;
}
+165 -43
View File
@@ -45,24 +45,58 @@
#include "command.h"
namespace core {
class Download;
}
namespace torrent {
class File;
class FileListIterator;
class Peer;
class Tracker;
}
namespace rpc {
template <typename Target>
class CommandSlot : public Command {
public:
typedef rak::function2<torrent::Object, Target, const torrent::Object&> slot_type;
CommandSlot() {}
CommandSlot(typename slot_type::base_type* s) { m_slot.set(s); }
void set_slot(typename slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, Target target, const torrent::Object& args);
static const torrent::Object call_list(Command* rawCommand, Target target, const torrent::Object& args);
static const torrent::Object call_string(Command* rawCommand, Target target, const torrent::Object& args);
static const torrent::Object call_value_base(Command* rawCommand, Target target, const torrent::Object& args, int base, int unit);
static const torrent::Object call_value(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1); }
static const torrent::Object call_value_kb(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1 << 10); }
static const torrent::Object call_value_oct(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 8, 1); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
private:
slot_type m_slot;
};
template <>
class CommandSlot<void> : public Command {
public:
typedef rak::function1<torrent::Object, const torrent::Object&> slot_type;
// template <typename SlotSet>
// CommandSlot(SlotSet* slotSet) {
// m_slotSet.set(slotSet);
// }
CommandSlot() {}
CommandSlot(slot_type::base_type* s) { m_slot.set(s); }
CommandSlot(slot_type::base_type* s) {
m_slot.set(s);
}
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, const torrent::Object& args);
@@ -76,7 +110,7 @@ public:
static const torrent::Object call_value_oct(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, 8, 1); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, base, unit); }
static const torrent::Object call_value(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
@@ -87,8 +121,30 @@ private:
// Some slots that convert torrent::Object arguments to proper
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_void_fn_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
template <typename Target, typename Func, typename Result = typename Func::result_type>
class object_void_fn_t : public rak::function_base2<torrent::Object, Target, const torrent::Object&> {
public:
object_void_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { return torrent::Object(m_func(target)); }
private:
Func m_func;
};
template <typename Target, typename Func>
class object_void_fn_t<Target, Func, void> : public rak::function_base2<torrent::Object, Target, const torrent::Object&> {
public:
object_void_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { m_func(target); return torrent::Object(); }
private:
Func m_func;
};
template <typename Func, typename Result>
class object_void_fn_t<void, Func, Result> : public rak::function_base1<torrent::Object, const torrent::Object&> {
public:
object_void_fn_t(Func func) : m_func(func) {}
@@ -99,23 +155,42 @@ private:
};
template <typename Func>
class object_void_fn_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
class object_void_fn_t<void, Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
public:
object_void_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (const torrent::Object& arg1) {
m_func();
return torrent::Object();
}
virtual torrent::Object operator () (const torrent::Object& arg1) { m_func(); return torrent::Object(); }
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_value_fn1_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
template <typename Target, typename Func, typename Result = typename Func::result_type>
class object_value_fn_t : public rak::function_base2<torrent::Object, Target, const torrent::Object&> {
public:
object_value_fn1_t(Func func) : m_func(func) {}
object_value_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { return torrent::Object((int64_t)m_func(target, arg1.as_value())); }
private:
Func m_func;
};
template <typename Target, typename Func>
class object_value_fn_t<Target, Func, void> : public rak::function_base2<torrent::Object, Target, const torrent::Object&> {
public:
object_value_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { m_func(target, arg1.as_value()); return torrent::Object(); }
private:
Func m_func;
};
template <typename Func, typename Result>
class object_value_fn_t<void, Func, Result> : public rak::function_base1<torrent::Object, const torrent::Object&> {
public:
object_value_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object((int64_t)m_func(arg1.as_value())); }
@@ -124,24 +199,42 @@ private:
};
template <typename Func>
class object_value_fn1_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
class object_value_fn_t<void, Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
public:
object_value_fn1_t(Func func) : m_func(func) {}
object_value_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (const torrent::Object& arg1) {
m_func(arg1.as_value());
return torrent::Object();
}
virtual torrent::Object operator () (const torrent::Object& arg1) { m_func(arg1.as_value()); return torrent::Object(); }
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_string_fn1_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
template <typename Target, typename Func, typename Result = typename Func::result_type>
class object_string_fn_t : public rak::function_base2<torrent::Object, Target, const torrent::Object&> {
public:
object_string_fn1_t(Func func) : m_func(func) {}
object_string_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { return torrent::Object(m_func(target, arg1.as_string())); }
private:
Func m_func;
};
template <typename Target, typename Func>
class object_string_fn_t<Target, Func, void> : public rak::function_base2<torrent::Object, Target, const torrent::Object&> {
public:
object_string_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { m_func(target, arg1.as_string()); return torrent::Object(); }
private:
Func m_func;
};
template <typename Func, typename Result>
class object_string_fn_t<void, Func, Result> : public rak::function_base1<torrent::Object, const torrent::Object&> {
public:
object_string_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object(m_func(arg1.as_string())); }
@@ -150,26 +243,55 @@ private:
};
template <typename Func>
class object_string_fn1_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
class object_string_fn_t<void, Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
public:
object_string_fn1_t(Func func) : m_func(func) {}
object_string_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (const torrent::Object& arg1) {
m_func(arg1.as_string());
return torrent::Object();
}
virtual torrent::Object operator () (const torrent::Object& arg1) { m_func(arg1.as_string()); return torrent::Object(); }
private:
Func m_func;
};
template <typename Return> object_void_fn_t<Return (*)(void), Return>* object_fn(Return (*func)(void)) { return new object_void_fn_t<Return (*)(void), Return>(func); }
// Add more of these helpers.
template <typename Target, typename Return> object_void_fn_t<Target, Return (*)(Target), Return>*
object_fn(Return (*func)(Target)) { return new object_void_fn_t<Target, Return (*)(Target), Return>(func); }
template <typename Return> object_void_fn_t<void, Return (*)(), Return>*
object_fn(Return (*func)()) { return new object_void_fn_t<void, Return (*)(), Return>(func); }
template <typename Func> object_void_fn_t<Func>* object_void_fn(Func func) { return new object_void_fn_t<Func>(func); }
//template <typename Func> object_void_fn_t<Func>* object_void_value_fn(Func func) { return new object_void_fn_t<Func, int64_t>(func); }
template <typename Func> object_value_fn1_t<Func>* object_value_fn(Func func) { return new object_value_fn1_t<Func>(func); }
template <typename Func> object_string_fn1_t<Func>* object_string_fn(Func func) { return new object_string_fn1_t<Func>(func); }
template <typename Func> object_void_fn_t<void, Func>* object_void_fn(Func func) { return new object_void_fn_t<void, Func>(func); }
template <typename Target, typename Func> object_void_fn_t<Target, Func>* object_void_fn(Func func) { return new object_void_fn_t<Target, Func>(func); }
template <typename Func> object_value_fn_t<void, Func>* object_value_fn(Func func) { return new object_value_fn_t<void, Func>(func); }
template <typename Target, typename Func> object_value_fn_t<Target, Func>* object_value_fn(Func func) { return new object_value_fn_t<Target, Func>(func); }
template <typename Func> object_string_fn_t<void, Func>* object_string_fn(Func func) { return new object_string_fn_t<void, Func>(func); }
template <typename Target, typename Func> object_string_fn_t<Target, Func>* object_string_fn(Func func) { return new object_string_fn_t<Target, Func>(func); }
class set_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
set_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1);
private:
const char* m_firstKey;
const char* m_secondKey;
};
class get_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
get_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1);
private:
const char* m_firstKey;
const char* m_secondKey;
};
inline set_variable_d_fn_t*
set_variable_d_fn(const char* firstKey, const char* secondKey) { return new set_variable_d_fn_t(firstKey, secondKey); }
inline get_variable_d_fn_t*
get_variable_d_fn(const char* firstKey, const char* secondKey) { return new get_variable_d_fn_t(firstKey, secondKey); }
}
-123
View File
@@ -1,123 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <torrent/tracker.h>
#include "parse.h"
#include "command_tracker_slot.h"
namespace rpc {
const torrent::Object
CommandTrackerSlot::call_unknown(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& rawArgs) {
CommandTrackerSlot* command = static_cast<CommandTrackerSlot*>(rawCommand);
return command->m_slot(tracker, rawArgs);
}
const torrent::Object
CommandTrackerSlot::call_list(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& rawArgs) {
CommandTrackerSlot* command = static_cast<CommandTrackerSlot*>(rawCommand);
switch (rawArgs.type()) {
case torrent::Object::TYPE_LIST:
return command->m_slot(tracker, rawArgs);
case torrent::Object::TYPE_VALUE:
case torrent::Object::TYPE_STRING:
{
torrent::Object tmpList(torrent::Object::TYPE_LIST);
tmpList.as_list().push_back(rawArgs);
return command->m_slot(tracker, tmpList);
}
default:
throw torrent::input_error("Not a list.");
}
}
const torrent::Object
CommandTrackerSlot::call_value_base(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& rawArgs, int base, int unit) {
CommandTrackerSlot* command = static_cast<CommandTrackerSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_VALUE:
// Should shift this one too, so it gives the right unit.
return command->m_slot(tracker, arg);
case torrent::Object::TYPE_STRING:
{
torrent::Object argValue(torrent::Object::TYPE_VALUE);
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
throw torrent::input_error("Not a value.");
return command->m_slot(tracker, argValue);
}
default:
throw torrent::input_error("Not a value.");
}
}
const torrent::Object
CommandTrackerSlot::call_string(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& rawArgs) {
CommandTrackerSlot* command = static_cast<CommandTrackerSlot*>(rawCommand);
const torrent::Object& arg = convert_to_single_argument(rawArgs);
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
return command->m_slot(tracker, arg);
// case torrent::Object::TYPE_NONE:
// throw torrent::input_error("CDS: void.");
// case torrent::Object::TYPE_VALUE:
// throw torrent::input_error("CDS: value.");
// case torrent::Object::TYPE_LIST:
// throw torrent::input_error("CDS: list.");
default:
throw torrent::input_error("Not a string.");
}
}
}
-176
View File
@@ -1,176 +0,0 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_RPC_COMMAND_TRACKER_SLOT_H
#define RTORRENT_RPC_COMMAND_TRACKER_SLOT_H
#include <limits>
#include <inttypes.h>
#include <torrent/object.h>
#include <rak/functional_fun.h>
#include "command.h"
namespace torrent {
class Tracker;
}
namespace rpc {
class CommandTrackerSlot : public Command {
public:
typedef rak::function2<torrent::Object, torrent::Tracker*, const torrent::Object&> slot_type;
CommandTrackerSlot() {}
CommandTrackerSlot(slot_type::base_type* s) {
m_slot.set(s);
}
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
static const torrent::Object call_unknown(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args);
static const torrent::Object call_list(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args);
static const torrent::Object call_string(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args);
static const torrent::Object call_value_base(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args, int base, int unit);
static const torrent::Object call_value(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args) { return call_value_base(rawCommand, tracker, args, 0, 1); }
static const torrent::Object call_value_kb(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args) { return call_value_base(rawCommand, tracker, args, 0, 1 << 10); }
template <int base, int unit>
static const torrent::Object call_value(Command* rawCommand, torrent::Tracker* tracker, const torrent::Object& args) { return call_value_base(rawCommand, tracker, args, base, unit); }
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
private:
slot_type m_slot;
};
// Some slots that convert torrent::Object arguments to proper
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_void_t_fn_t : public rak::function_base2<torrent::Object, torrent::Tracker*, const torrent::Object&> {
public:
object_void_t_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Tracker* tracker, const torrent::Object& arg1) { return torrent::Object(m_func(tracker)); }
private:
Func m_func;
};
template <typename Func>
class object_void_t_fn_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Tracker*, const torrent::Object&> {
public:
object_void_t_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Tracker* tracker, const torrent::Object& arg1) {
m_func(tracker);
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_value_t_fn1_t : public rak::function_base2<torrent::Object, torrent::Tracker*, const torrent::Object&> {
public:
object_value_t_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Tracker* tracker, const torrent::Object& arg1) {
return torrent::Object((int64_t)m_func(tracker, arg1.as_value()));
}
private:
Func m_func;
};
template <typename Func>
class object_value_t_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Tracker*, const torrent::Object&> {
public:
object_value_t_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Tracker* tracker, const torrent::Object& arg1) {
m_func(tracker, arg1.as_value());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Func, typename Result = typename Func::result_type>
class object_string_t_fn1_t : public rak::function_base2<torrent::Object, torrent::Tracker*, const torrent::Object&> {
public:
object_string_t_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Tracker* tracker, const torrent::Object& arg1) { return torrent::Object(m_func(tracker, arg1.as_string())); }
private:
Func m_func;
};
template <typename Func>
class object_string_t_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Tracker*, const torrent::Object&> {
public:
object_string_t_fn1_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (torrent::Tracker* tracker, const torrent::Object& arg1) {
m_func(tracker, arg1.as_string());
return torrent::Object();
}
private:
Func m_func;
};
template <typename Return> object_void_t_fn_t<Return (*)(torrent::Tracker*), Return>*
object_t_fn(Return (*func)(torrent::Tracker*)) {
return new object_void_t_fn_t<Return (*)(torrent::Tracker*), Return>(func);
}
template <typename Func> object_void_t_fn_t<Func>* object_void_t_fn(Func func) { return new object_void_t_fn_t<Func>(func); }
template <typename Func> object_value_t_fn1_t<Func>* object_value_t_fn(Func func) { return new object_value_t_fn1_t<Func>(func); }
template <typename Func> object_string_t_fn1_t<Func>* object_string_t_fn(Func func) { return new object_string_t_fn1_t<Func>(func); }
}
#endif