* Fixed minor bugs in the display of tracker groups. Patch by Josef

Drexler.

* Cleanup of the CommandMap class.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1041 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2008-03-13 14:28:17 +00:00
parent b21f465969
commit 8cc7c8430d
12 changed files with 169 additions and 180 deletions
+2 -2
View File
@@ -331,11 +331,11 @@ p_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::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_type(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::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(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_fn(slot), "i:", "")
+3 -3
View File
@@ -99,11 +99,11 @@ apply_fi_filename_last(torrent::FileListIterator* itr) {
#define ADD_CF_SLOT(key, function, slot, parm, doc) \
commandFileSlotsItr->set_slot(slot); \
rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_type(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::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(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." key, call_unknown, rpc::object_fn(slot), "i:", "")
@@ -123,7 +123,7 @@ apply_fi_filename_last(torrent::FileListIterator* itr) {
#define ADD_CFI_SLOT_PUBLIC(key, function, slot, parm, doc) \
commandFileItrSlotsItr->set_slot(slot); \
rpc::commands.insert_file_itr(key, commandFileItrSlotsItr++, &rpc::CommandSlot<torrent::FileListIterator*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(key, commandFileItrSlotsItr++, &rpc::CommandSlot<torrent::FileListIterator*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_CFI_VOID(key, slot) \
ADD_CFI_SLOT_PUBLIC("fi." key, call_unknown, rpc::object_fn(slot), "i:", "")
+4 -4
View File
@@ -104,16 +104,16 @@ initialize_commands() {
void
add_variable(const char* getKey, const char* setKey, const char* defaultSetKey,
rpc::CommandMap::generic_slot getSlot, rpc::CommandMap::generic_slot setSlot,
rpc::Command::generic_slot getSlot, rpc::Command::generic_slot setSlot,
const torrent::Object& defaultObject) {
rpc::CommandVariable* variable = commandVariablesItr++;
variable->set_variable(defaultObject);
rpc::commands.insert_generic(getKey, variable, getSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", "");
rpc::commands.insert_type(getKey, variable, getSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", "");
if (setKey)
rpc::commands.insert_generic(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", "");
rpc::commands.insert_type(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", "");
if (defaultSetKey)
rpc::commands.insert_generic(defaultSetKey, variable, setSlot, rpc::CommandMap::flag_dont_delete, "i:", "");
rpc::commands.insert_type(defaultSetKey, variable, setSlot, rpc::CommandMap::flag_dont_delete, "i:", "");
}
+6 -6
View File
@@ -78,7 +78,7 @@ void initialize_commands();
void
add_variable(const char* getKey, const char* setKey, const char* defaultSetKey,
rpc::CommandMap::generic_slot getSlot, rpc::CommandMap::generic_slot setSlot,
rpc::Command::generic_slot getSlot, rpc::Command::generic_slot setSlot,
const torrent::Object& defaultObject);
#define ADD_VARIABLE_BOOL(key, defaultValue) \
@@ -95,21 +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<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(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);
rpc::commands.insert_type(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<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);
rpc::commands.insert_type(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<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(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<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);
rpc::commands.insert_type(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)) \
+2 -2
View File
@@ -96,11 +96,11 @@ retrieve_p_completed_percent(torrent::Peer* peer) {
#define ADD_CP_SLOT(key, function, slot, parm, doc) \
commandPeerSlotsItr->set_slot(slot); \
rpc::commands.insert_peer(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_type(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::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(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_fn(slot), "i:", "")
+2 -2
View File
@@ -55,11 +55,11 @@ 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::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);
rpc::commands.insert_type(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::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
rpc::commands.insert_type(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." key, call_unknown, rpc::object_void_fn<torrent::Tracker*>(slot), "i:", "")
+4
View File
@@ -120,6 +120,8 @@ public:
void set_filter(const filter_list& s) { m_filter = s; }
void set_filter_on(int event);
void set_cfilter(const std::string& s) { m_cfilter = s; }
void clear_filter_on();
// The time of the last change to the view, semantics of this is
@@ -162,6 +164,8 @@ private:
filter_list m_filter;
std::string m_cfilter;
rak::timer m_lastChanged;
signal_type m_signalChanged;
};
+16 -10
View File
@@ -60,7 +60,7 @@ WindowTrackerList::redraw() {
m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(10)).round_seconds());
m_canvas->erase();
int pos = 0;
unsigned int pos = 0;
torrent::TrackerList* tl = m_download->tracker_list();
m_canvas->print(2, pos, "Trackers: [Key: %08x]", tl->key());
@@ -71,8 +71,8 @@ WindowTrackerList::redraw() {
typedef std::pair<unsigned int, unsigned int> Range;
unsigned int group = 0;
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, tl->size(), (m_canvas->height() + 1) / 2);
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, tl->size(), (m_canvas->height() - 1) / 2);
unsigned int group = tl->at(range.first)->group();
while (range.first != range.second) {
torrent::Tracker* tracker = tl->at(range.first);
@@ -88,13 +88,14 @@ WindowTrackerList::redraw() {
m_canvas->print(4, pos++, "%s",
tracker->url().c_str());
m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s S/L: %u/%u",
rak::copy_escape_html(tracker->tracker_id()).c_str(),
range.first == tl->focus_index() ? "yes" : " no",
tracker->is_usable() ? "yes" : tracker->is_enabled() ? "off" : " no",
tracker->is_busy() ? "yes" : " no",
tracker->scrape_complete(),
tracker->scrape_incomplete());
if (pos < m_canvas->height())
m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s S/L: %u/%u",
rak::copy_escape_html(tracker->tracker_id()).c_str(),
range.first == tl->focus_index() ? "yes" : " no",
tracker->is_usable() ? "yes" : tracker->is_enabled() ? "off" : " no",
tracker->is_busy() ? "yes" : " no",
tracker->scrape_complete(),
tracker->scrape_incomplete());
// m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s Timer: %u/%u",
// rak::copy_escape_html(tracker->tracker_id()).c_str(),
@@ -110,6 +111,11 @@ WindowTrackerList::redraw() {
}
range.first++;
// If we're at the end of the range, check if we can
// show one more line for the following tracker.
if (range.first == range.second && pos < m_canvas->height() && range.first < tl->size())
range.second++;
}
}
+71 -1
View File
@@ -39,11 +39,52 @@
#include <torrent/object.h>
namespace core {
class Download;
}
namespace torrent {
class File;
class FileListIterator;
class Peer;
class Tracker;
}
namespace rpc {
// Since c++0x isn't out yet...
template <typename T1, typename T2, typename T3>
struct rt_triple : private std::pair<T1, T2> {
typedef std::pair<T1, T2> base_type;
typedef T3 third_type;
using base_type::first;
using base_type::second;
using base_type::first_type;
using base_type::second_type;
T3 third;
rt_triple() : base_type(), third() {}
rt_triple(const T1& a, const T2& b) :
base_type(a, b), third() {}
rt_triple(const T1& a, const T2& b, const T3& c) :
base_type(a, b), third(c) {}
template <typename U1, typename U2>
rt_triple(const std::pair<U1, U2>& b) : base_type(b), third() {}
template <typename U1, typename U2, typename U3>
rt_triple(const rt_triple& src) :
base_type(src.first, src.second), third(src.third) {}
};
// Since it gets used so many places we might as well put it in the
// rpc namespace.
typedef std::pair<int, void*> target_type;
//typedef std::pair<int, void*> target_type;
typedef rt_triple<int, void*, void*> target_type;
class Command {
public:
@@ -53,6 +94,22 @@ public:
typedef torrent::Object::map_type map_type;
typedef torrent::Object::key_type key_type;
typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&);
typedef const torrent::Object (*any_slot) (Command*, target_type, const torrent::Object&);
typedef const torrent::Object (*download_slot) (Command*, core::Download*, const torrent::Object&);
typedef const torrent::Object (*file_slot) (Command*, torrent::File*, const torrent::Object&);
typedef const torrent::Object (*file_itr_slot) (Command*, torrent::FileListIterator*, const torrent::Object&);
typedef const torrent::Object (*peer_slot) (Command*, torrent::Peer*, const torrent::Object&);
typedef const torrent::Object (*tracker_slot) (Command*, torrent::Tracker*, const torrent::Object&);
static const int target_generic = 0;
static const int target_any = 1;
static const int target_download = 2;
static const int target_peer = 3;
static const int target_tracker = 4;
static const int target_file = 5;
static const int target_file_itr = 6;
Command() {}
virtual ~Command() {}
@@ -61,6 +118,19 @@ protected:
void operator = (const Command&);
};
template <typename T>
struct target_type_id {
// Nothing here, so we cause an error.
};
template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; };
template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; };
template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; };
template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; };
template <> struct target_type_id<Command::tracker_slot> { static const int value = Command::target_tracker; };
template <> struct target_type_id<Command::file_slot> { static const int value = Command::target_file; };
template <> struct target_type_id<Command::file_itr_slot> { static const int value = Command::target_file_itr; };
}
#endif
+31 -88
View File
@@ -61,63 +61,6 @@ CommandMap::insert(key_type key, Command* variable, int flags, const char* parm,
return base_type::insert(itr, value_type(key, command_map_data_type(variable, flags, parm, doc)));
}
// The functions below should be reduced to just one.
void
CommandMap::insert_generic(key_type key, Command* variable, generic_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_generic;
itr->second.m_genericSlot = targetSlot;
}
void
CommandMap::insert_any(key_type key, Command* variable, any_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_any;
itr->second.m_anySlot = targetSlot;
}
void
CommandMap::insert_download(key_type key, Command* variable, download_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_download;
itr->second.m_downloadSlot = targetSlot;
}
void
CommandMap::insert_peer(key_type key, Command* variable, peer_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_peer;
itr->second.m_peerSlot = targetSlot;
}
void
CommandMap::insert_tracker(key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_tracker;
itr->second.m_trackerSlot = targetSlot;
}
void
CommandMap::insert_file(key_type key, Command* variable, file_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_file;
itr->second.m_fileSlot = targetSlot;
}
void
CommandMap::insert_file_itr(key_type key, Command* variable, file_itr_slot targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_file_itr;
itr->second.m_fileItrSlot = targetSlot;
}
void
CommandMap::insert(key_type key, const command_map_data_type src) {
iterator itr = base_type::find(key);
@@ -131,13 +74,13 @@ CommandMap::insert(key_type key, const command_map_data_type src) {
// This _should_ be optimized int just one assignment.
switch (itr->second.m_target) {
case target_generic: itr->second.m_genericSlot = src.m_genericSlot; break;
case target_any: itr->second.m_anySlot = src.m_anySlot; break;
case target_download: itr->second.m_downloadSlot = src.m_downloadSlot; break;
case target_file: itr->second.m_fileSlot = src.m_fileSlot; break;
case target_file_itr: itr->second.m_fileItrSlot = src.m_fileItrSlot; break;
case target_peer: itr->second.m_peerSlot = src.m_peerSlot; break;
case target_tracker: itr->second.m_trackerSlot = src.m_trackerSlot; break;
case Command::target_generic: itr->second.m_genericSlot = src.m_genericSlot; break;
case Command::target_any: itr->second.m_anySlot = src.m_anySlot; break;
case Command::target_download: itr->second.m_downloadSlot = src.m_downloadSlot; break;
case Command::target_file: itr->second.m_fileSlot = src.m_fileSlot; break;
case Command::target_file_itr: itr->second.m_fileItrSlot = src.m_fileItrSlot; break;
case Command::target_peer: itr->second.m_peerSlot = src.m_peerSlot; break;
case Command::target_tracker: itr->second.m_trackerSlot = src.m_trackerSlot; break;
default: throw torrent::internal_error("CommandMap::insert(...) Invalid target.");
}
}
@@ -149,60 +92,60 @@ 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 (target.first != target_generic && target.second == NULL) {
if (target.first != Command::target_generic && target.second == NULL) {
// We received a target that is NULL, so throw an exception unless
// we can convert it to a void target.
if (itr->second.m_target > target_any)
if (itr->second.m_target > Command::target_any)
throw torrent::input_error("Command type mis-match.");
target.first = target_generic;
target.first = Command::target_generic;
}
if (itr->second.m_target != target.first && itr->second.m_target > target_any) {
if (itr->second.m_target != target.first && itr->second.m_target > Command::target_any) {
// Mismatch between the target and command type. If it is not
// possible to convert, then throw an input error.
if (target.first == target_file_itr && itr->second.m_target == target_file)
target = target_type((int)target_file, static_cast<torrent::FileListIterator*>(target.second)->file());
if (target.first == Command::target_file_itr && itr->second.m_target == Command::target_file)
target = target_type((int)Command::target_file, static_cast<torrent::FileListIterator*>(target.second)->file());
else
throw torrent::input_error("Command type mis-match.");
}
// This _should_ be optimized int just two calls.
switch (itr->second.m_target) {
case target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg);
case target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg);
case target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);
case target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);
case target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);
case target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);
case target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);
case Command::target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg);
case Command::target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg);
case Command::target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);
case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);
case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);
case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);
case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);
default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target.");
}
}
const CommandMap::mapped_type
CommandMap::call_command(const_iterator itr, const mapped_type& arg, target_type target) {
if (target.first != target_generic && target.second == NULL) {
if (target.first != Command::target_generic && target.second == NULL) {
// We received a target that is NULL, so throw an exception unless
// we can convert it to a void target.
if (itr->second.m_target > target_any)
if (itr->second.m_target > Command::target_any)
throw torrent::input_error("Command type mis-match.");
target.first = target_generic;
target.first = Command::target_generic;
}
if (itr->second.m_target != target.first && itr->second.m_target > target_any)
if (itr->second.m_target != target.first && itr->second.m_target > Command::target_any)
throw torrent::input_error("Command type mis-match.");
// This _should_ be optimized int just two calls.
switch (itr->second.m_target) {
case target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg);
case target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg);
case target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);
case target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);
case target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);
case target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);
case target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);
case Command::target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg);
case Command::target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg);
case Command::target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);
case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);
case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);
case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);
case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);
default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target.");
}
}
+26 -60
View File
@@ -44,17 +44,6 @@
#include "command.h"
namespace core {
class Download;
}
namespace torrent {
class File;
class FileListIterator;
class Peer;
class Tracker;
}
namespace rpc {
struct command_map_comp : public std::binary_function<const char*, const char*, bool> {
@@ -67,13 +56,6 @@ struct command_map_data_type {
// will register a member function pointer to be used instead.
//
// The any_slot should perhaps replace generic_slot?
typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&);
typedef const torrent::Object (*any_slot) (Command*, target_type, const torrent::Object&);
typedef const torrent::Object (*download_slot) (Command*, core::Download*, const torrent::Object&);
typedef const torrent::Object (*file_slot) (Command*, torrent::File*, const torrent::Object&);
typedef const torrent::Object (*file_itr_slot) (Command*, torrent::FileListIterator*, const torrent::Object&);
typedef const torrent::Object (*peer_slot) (Command*, torrent::Peer*, const torrent::Object&);
typedef const torrent::Object (*tracker_slot) (Command*, torrent::Tracker*, const torrent::Object&);
command_map_data_type(Command* variable, int flags, const char* parm, const char* doc) :
m_variable(variable), m_flags(flags), m_parm(parm), m_doc(doc) {}
@@ -83,13 +65,13 @@ struct command_map_data_type {
Command* m_variable;
union {
generic_slot m_genericSlot;
any_slot m_anySlot;
download_slot m_downloadSlot;
file_slot m_fileSlot;
file_itr_slot m_fileItrSlot;
peer_slot m_peerSlot;
tracker_slot m_trackerSlot;
Command::generic_slot m_genericSlot;
Command::any_slot m_anySlot;
Command::download_slot m_downloadSlot;
Command::file_slot m_fileSlot;
Command::file_itr_slot m_fileItrSlot;
Command::peer_slot m_peerSlot;
Command::tracker_slot m_trackerSlot;
};
int m_flags;
@@ -103,14 +85,6 @@ class CommandMap : public std::map<const char*, command_map_data_type, command_m
public:
typedef std::map<const char*, command_map_data_type, command_map_comp> base_type;
typedef command_map_data_type::generic_slot generic_slot;
typedef command_map_data_type::any_slot any_slot;
typedef command_map_data_type::download_slot download_slot;
typedef command_map_data_type::file_slot file_slot;
typedef command_map_data_type::file_itr_slot file_itr_slot;
typedef command_map_data_type::peer_slot peer_slot;
typedef command_map_data_type::tracker_slot tracker_slot;
typedef torrent::Object mapped_type;
typedef mapped_type::value_type mapped_value_type;
@@ -123,14 +97,6 @@ public:
using base_type::end;
using base_type::find;
static const int target_generic = 0;
static const int target_any = 1;
static const int target_download = 2;
static const int target_peer = 3;
static const int target_tracker = 4;
static const int target_file = 5;
static const int target_file_itr = 6;
static const int flag_dont_delete = 0x1;
static const int flag_public_xmlrpc = 0x2;
@@ -142,35 +108,35 @@ public:
iterator insert(key_type key, Command* variable, int flags, const char* parm, const char* doc);
void insert_generic (key_type key, Command* variable, generic_slot targetSlot, int flags, const char* parm, const char* doc);
void insert_any (key_type key, Command* variable, any_slot targetSlot, int flags, const char* parm, const char* doc);
void insert_download(key_type key, Command* variable, download_slot targetSlot, int flags, const char* parm, const char* doc);
void insert_peer (key_type key, Command* variable, peer_slot targetSlot, int flags, const char* parm, const char* doc);
void insert_tracker (key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc);
void insert_file (key_type key, Command* variable, file_slot targetSlot, int flags, const char* parm, const char* doc);
void insert_file_itr(key_type key, Command* variable, file_itr_slot targetSlot, int flags, const char* parm, const char* doc);
template <typename T>
void insert_type(key_type key, Command* variable, T targetSlot, int flags, const char* parm, const char* doc) {
iterator itr = insert(key, variable, flags, parm, doc);
itr->second.m_target = target_type_id<T>::value;
itr->second.m_genericSlot = (Command::generic_slot)targetSlot;
}
void insert(key_type key, const command_map_data_type src);
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)target_generic, NULL));
const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int)target_generic, NULL));
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)Command::target_generic, NULL));
const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int)Command::target_generic, NULL));
const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_download, download)); }
const mapped_type call_command_p(key_type key, torrent::Peer* peer, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_peer, peer)); }
const mapped_type call_command_t(key_type key, torrent::Tracker* tracker, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_tracker, tracker)); }
const mapped_type call_command_f(key_type key, torrent::File* file, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_file, file)); }
const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg) { return call_command(key, arg, target_type((int)Command::target_download, download)); }
const mapped_type call_command_p(key_type key, torrent::Peer* peer, const mapped_type& arg) { return call_command(key, arg, target_type((int)Command::target_peer, peer)); }
const mapped_type call_command_t(key_type key, torrent::Tracker* tracker, const mapped_type& arg) { return call_command(key, arg, target_type((int)Command::target_tracker, tracker)); }
const mapped_type call_command_f(key_type key, torrent::File* file, const mapped_type& arg) { return call_command(key, arg, target_type((int)Command::target_file, file)); }
private:
CommandMap(const CommandMap&);
void operator = (const CommandMap&);
};
inline target_type make_target() { return target_type((int)CommandMap::target_generic, NULL); }
inline target_type make_target(core::Download* target) { return target_type((int)CommandMap::target_download, target); }
inline target_type make_target(torrent::Peer* target) { return target_type((int)CommandMap::target_peer, target); }
inline target_type make_target(torrent::Tracker* target) { return target_type((int)CommandMap::target_tracker, target); }
inline target_type make_target(torrent::File* target) { return target_type((int)CommandMap::target_file, target); }
inline target_type make_target(torrent::FileListIterator* target) { return target_type((int)CommandMap::target_file_itr, target); }
inline target_type make_target() { return target_type((int)Command::target_generic, NULL); }
inline target_type make_target(core::Download* target) { return target_type((int)Command::target_download, target); }
inline target_type make_target(torrent::Peer* target) { return target_type((int)Command::target_peer, target); }
inline target_type make_target(torrent::Tracker* target) { return target_type((int)Command::target_tracker, target); }
inline target_type make_target(torrent::File* target) { return target_type((int)Command::target_file, target); }
inline target_type make_target(torrent::FileListIterator* target) { return target_type((int)Command::target_file_itr, target); }
inline target_type make_target(int type, void* target) { return target_type(type, target); }
}
+2 -2
View File
@@ -80,7 +80,7 @@ public:
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 call_value_tmpl(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);
@@ -110,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_tmpl(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);