Changeset 1041
- Timestamp:
- 03/13/08 14:28:17 (2 years ago)
- Location:
- trunk/rtorrent/src
- Files:
-
- 12 modified
-
command_download.cc (modified) (1 diff)
-
command_file.cc (modified) (2 diffs)
-
command_helpers.cc (modified) (1 diff)
-
command_helpers.h (modified) (2 diffs)
-
command_peer.cc (modified) (1 diff)
-
command_tracker.cc (modified) (1 diff)
-
core/view.h (modified) (2 diffs)
-
display/window_tracker_list.cc (modified) (4 diffs)
-
rpc/command.h (modified) (3 diffs)
-
rpc/command_map.cc (modified) (5 diffs)
-
rpc/command_map.h (modified) (7 diffs)
-
rpc/command_slot.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rtorrent/src/command_download.cc
r1026 r1041 332 332 #define ADD_CD_SLOT(key, function, slot, parm, doc) \ 333 333 commandDownloadSlotsItr->set_slot(slot); \ 334 rpc::commands.insert_ download(key, commandDownloadSlotsItr++, &rpc::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);334 rpc::commands.insert_type(key, commandDownloadSlotsItr++, &rpc::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete, parm, doc); 335 335 336 336 #define ADD_CD_SLOT_PUBLIC(key, function, slot, parm, doc) \ 337 337 commandDownloadSlotsItr->set_slot(slot); \ 338 rpc::commands.insert_ download(key, commandDownloadSlotsItr++, &rpc::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);338 rpc::commands.insert_type(key, commandDownloadSlotsItr++, &rpc::CommandSlot<core::Download*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 339 339 340 340 #define ADD_CD_VOID(key, slot) \ -
trunk/rtorrent/src/command_file.cc
r1030 r1041 100 100 #define ADD_CF_SLOT(key, function, slot, parm, doc) \ 101 101 commandFileSlotsItr->set_slot(slot); \ 102 rpc::commands.insert_ file(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);102 rpc::commands.insert_type(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete, parm, doc); 103 103 104 104 #define ADD_CF_SLOT_PUBLIC(key, function, slot, parm, doc) \ 105 105 commandFileSlotsItr->set_slot(slot); \ 106 rpc::commands.insert_ file(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);106 rpc::commands.insert_type(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 107 107 108 108 #define ADD_CF_VOID(key, slot) \ … … 124 124 #define ADD_CFI_SLOT_PUBLIC(key, function, slot, parm, doc) \ 125 125 commandFileItrSlotsItr->set_slot(slot); \ 126 rpc::commands.insert_ file_itr(key, commandFileItrSlotsItr++, &rpc::CommandSlot<torrent::FileListIterator*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);126 rpc::commands.insert_type(key, commandFileItrSlotsItr++, &rpc::CommandSlot<torrent::FileListIterator*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 127 127 128 128 #define ADD_CFI_VOID(key, slot) \ -
trunk/rtorrent/src/command_helpers.cc
r971 r1041 105 105 void 106 106 add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, 107 rpc::Command Map::generic_slot getSlot, rpc::CommandMap::generic_slot setSlot,107 rpc::Command::generic_slot getSlot, rpc::Command::generic_slot setSlot, 108 108 const torrent::Object& defaultObject) { 109 109 rpc::CommandVariable* variable = commandVariablesItr++; 110 110 variable->set_variable(defaultObject); 111 111 112 rpc::commands.insert_ generic(getKey, variable, getSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", "");112 rpc::commands.insert_type(getKey, variable, getSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); 113 113 114 114 if (setKey) 115 rpc::commands.insert_ generic(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", "");115 rpc::commands.insert_type(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); 116 116 117 117 if (defaultSetKey) 118 rpc::commands.insert_ generic(defaultSetKey, variable, setSlot, rpc::CommandMap::flag_dont_delete, "i:", "");118 rpc::commands.insert_type(defaultSetKey, variable, setSlot, rpc::CommandMap::flag_dont_delete, "i:", ""); 119 119 } -
trunk/rtorrent/src/command_helpers.h
r1030 r1041 79 79 void 80 80 add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, 81 rpc::Command Map::generic_slot getSlot, rpc::CommandMap::generic_slot setSlot,81 rpc::Command::generic_slot getSlot, rpc::Command::generic_slot setSlot, 82 82 const torrent::Object& defaultObject); 83 83 … … 96 96 #define ADD_COMMAND_SLOT(key, function, slot, parm, doc) \ 97 97 commandSlotsItr->set_slot(slot); \ 98 rpc::commands.insert_ generic(key, commandSlotsItr++, &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);98 rpc::commands.insert_type(key, commandSlotsItr++, &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 99 99 100 100 #define ADD_ANY_SLOT(key, function, slot, parm, doc) \ 101 101 commandAnySlotsItr->set_slot(slot); \ 102 rpc::commands.insert_ any(key, commandAnySlotsItr++, &rpc::CommandSlot<rpc::target_type>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);102 rpc::commands.insert_type(key, commandAnySlotsItr++, &rpc::CommandSlot<rpc::target_type>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 103 103 104 104 #define ADD_COMMAND_SLOT_PRIVATE(key, function, slot) \ 105 105 commandSlotsItr->set_slot(slot); \ 106 rpc::commands.insert_ generic(key, commandSlotsItr++, &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);106 rpc::commands.insert_type(key, commandSlotsItr++, &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL); 107 107 108 108 #define ADD_COMMAND_COPY(key, function, parm, doc) \ 109 rpc::commands.insert_ generic(key, (commandSlotsItr - 1), &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);109 rpc::commands.insert_type(key, (commandSlotsItr - 1), &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 110 110 111 111 #define ADD_COMMAND_COPY_PRIVATE(key, function) \ 112 rpc::commands.insert_ generic(key, (commandSlotsItr - 1), &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL);112 rpc::commands.insert_type(key, (commandSlotsItr - 1), &rpc::CommandSlot<void>::function, rpc::CommandMap::flag_dont_delete, NULL, NULL); 113 113 114 114 #define ADD_COMMAND_VALUE_TRI(key, set, get) \ -
trunk/rtorrent/src/command_peer.cc
r1032 r1041 97 97 #define ADD_CP_SLOT(key, function, slot, parm, doc) \ 98 98 commandPeerSlotsItr->set_slot(slot); \ 99 rpc::commands.insert_ peer(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);99 rpc::commands.insert_type(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete, parm, doc); 100 100 101 101 #define ADD_CP_SLOT_PUBLIC(key, function, slot, parm, doc) \ 102 102 commandPeerSlotsItr->set_slot(slot); \ 103 rpc::commands.insert_ peer(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);103 rpc::commands.insert_type(key, commandPeerSlotsItr++, &rpc::CommandSlot<torrent::Peer*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 104 104 105 105 #define ADD_CP_VOID(key, slot) \ -
trunk/rtorrent/src/command_tracker.cc
r1002 r1041 56 56 #define ADD_CT_SLOT(key, function, slot, parm, doc) \ 57 57 commandTrackerSlotsItr->set_slot(slot); \ 58 rpc::commands.insert_t racker(key, commandTrackerSlotsItr++, &rpc::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete, parm, doc);58 rpc::commands.insert_type(key, commandTrackerSlotsItr++, &rpc::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete, parm, doc); 59 59 60 60 #define ADD_CT_SLOT_PUBLIC(key, function, slot, parm, doc) \ 61 61 commandTrackerSlotsItr->set_slot(slot); \ 62 rpc::commands.insert_t racker(key, commandTrackerSlotsItr++, &rpc::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);62 rpc::commands.insert_type(key, commandTrackerSlotsItr++, &rpc::CommandSlot<torrent::Tracker*>::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); 63 63 64 64 #define ADD_CT_VOID(key, slot) \ -
trunk/rtorrent/src/core/view.h
r938 r1041 121 121 void set_filter_on(int event); 122 122 123 void set_cfilter(const std::string& s) { m_cfilter = s; } 124 123 125 void clear_filter_on(); 124 126 … … 163 165 filter_list m_filter; 164 166 167 std::string m_cfilter; 168 165 169 rak::timer m_lastChanged; 166 170 signal_type m_signalChanged; -
trunk/rtorrent/src/display/window_tracker_list.cc
r1013 r1041 61 61 m_canvas->erase(); 62 62 63 int pos = 0;63 unsigned int pos = 0; 64 64 torrent::TrackerList* tl = m_download->tracker_list(); 65 65 … … 72 72 typedef std::pair<unsigned int, unsigned int> Range; 73 73 74 unsigned int group = 0;75 Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, tl->size(), (m_canvas->height() + 1) / 2);74 Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, tl->size(), (m_canvas->height() - 1) / 2); 75 unsigned int group = tl->at(range.first)->group(); 76 76 77 77 while (range.first != range.second) { … … 89 89 tracker->url().c_str()); 90 90 91 m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s S/L: %u/%u", 92 rak::copy_escape_html(tracker->tracker_id()).c_str(), 93 range.first == tl->focus_index() ? "yes" : " no", 94 tracker->is_usable() ? "yes" : tracker->is_enabled() ? "off" : " no", 95 tracker->is_busy() ? "yes" : " no", 96 tracker->scrape_complete(), 97 tracker->scrape_incomplete()); 91 if (pos < m_canvas->height()) 92 m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s S/L: %u/%u", 93 rak::copy_escape_html(tracker->tracker_id()).c_str(), 94 range.first == tl->focus_index() ? "yes" : " no", 95 tracker->is_usable() ? "yes" : tracker->is_enabled() ? "off" : " no", 96 tracker->is_busy() ? "yes" : " no", 97 tracker->scrape_complete(), 98 tracker->scrape_incomplete()); 98 99 99 100 // m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s Timer: %u/%u", … … 111 112 112 113 range.first++; 114 115 // If we're at the end of the range, check if we can 116 // show one more line for the following tracker. 117 if (range.first == range.second && pos < m_canvas->height() && range.first < tl->size()) 118 range.second++; 113 119 } 114 120 } -
trunk/rtorrent/src/rpc/command.h
r970 r1041 40 40 #include <torrent/object.h> 41 41 42 namespace core { 43 class Download; 44 } 45 46 namespace torrent { 47 class File; 48 class FileListIterator; 49 class Peer; 50 class Tracker; 51 } 52 42 53 namespace rpc { 54 55 // Since c++0x isn't out yet... 56 template <typename T1, typename T2, typename T3> 57 struct rt_triple : private std::pair<T1, T2> { 58 typedef std::pair<T1, T2> base_type; 59 typedef T3 third_type; 60 61 using base_type::first; 62 using base_type::second; 63 using base_type::first_type; 64 using base_type::second_type; 65 66 T3 third; 67 68 rt_triple() : base_type(), third() {} 69 70 rt_triple(const T1& a, const T2& b) : 71 base_type(a, b), third() {} 72 73 rt_triple(const T1& a, const T2& b, const T3& c) : 74 base_type(a, b), third(c) {} 75 76 template <typename U1, typename U2> 77 rt_triple(const std::pair<U1, U2>& b) : base_type(b), third() {} 78 79 template <typename U1, typename U2, typename U3> 80 rt_triple(const rt_triple& src) : 81 base_type(src.first, src.second), third(src.third) {} 82 }; 43 83 44 84 // Since it gets used so many places we might as well put it in the 45 85 // rpc namespace. 46 typedef std::pair<int, void*> target_type; 86 //typedef std::pair<int, void*> target_type; 87 typedef rt_triple<int, void*, void*> target_type; 47 88 48 89 class Command { … … 54 95 typedef torrent::Object::key_type key_type; 55 96 97 typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&); 98 typedef const torrent::Object (*any_slot) (Command*, target_type, const torrent::Object&); 99 typedef const torrent::Object (*download_slot) (Command*, core::Download*, const torrent::Object&); 100 typedef const torrent::Object (*file_slot) (Command*, torrent::File*, const torrent::Object&); 101 typedef const torrent::Object (*file_itr_slot) (Command*, torrent::FileListIterator*, const torrent::Object&); 102 typedef const torrent::Object (*peer_slot) (Command*, torrent::Peer*, const torrent::Object&); 103 typedef const torrent::Object (*tracker_slot) (Command*, torrent::Tracker*, const torrent::Object&); 104 105 static const int target_generic = 0; 106 static const int target_any = 1; 107 static const int target_download = 2; 108 static const int target_peer = 3; 109 static const int target_tracker = 4; 110 static const int target_file = 5; 111 static const int target_file_itr = 6; 112 56 113 Command() {} 57 114 virtual ~Command() {} … … 62 119 }; 63 120 121 template <typename T> 122 struct target_type_id { 123 // Nothing here, so we cause an error. 124 }; 125 126 template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; }; 127 template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; }; 128 template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; }; 129 template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; }; 130 template <> struct target_type_id<Command::tracker_slot> { static const int value = Command::target_tracker; }; 131 template <> struct target_type_id<Command::file_slot> { static const int value = Command::target_file; }; 132 template <> struct target_type_id<Command::file_itr_slot> { static const int value = Command::target_file_itr; }; 133 64 134 } 65 135 -
trunk/rtorrent/src/rpc/command_map.cc
r1006 r1041 62 62 } 63 63 64 // The functions below should be reduced to just one.65 void66 CommandMap::insert_generic(key_type key, Command* variable, generic_slot targetSlot, int flags, const char* parm, const char* doc) {67 iterator itr = insert(key, variable, flags, parm, doc);68 69 itr->second.m_target = target_generic;70 itr->second.m_genericSlot = targetSlot;71 }72 73 void74 CommandMap::insert_any(key_type key, Command* variable, any_slot targetSlot, int flags, const char* parm, const char* doc) {75 iterator itr = insert(key, variable, flags, parm, doc);76 77 itr->second.m_target = target_any;78 itr->second.m_anySlot = targetSlot;79 }80 81 void82 CommandMap::insert_download(key_type key, Command* variable, download_slot targetSlot, int flags, const char* parm, const char* doc) {83 iterator itr = insert(key, variable, flags, parm, doc);84 85 itr->second.m_target = target_download;86 itr->second.m_downloadSlot = targetSlot;87 }88 89 void90 CommandMap::insert_peer(key_type key, Command* variable, peer_slot targetSlot, int flags, const char* parm, const char* doc) {91 iterator itr = insert(key, variable, flags, parm, doc);92 93 itr->second.m_target = target_peer;94 itr->second.m_peerSlot = targetSlot;95 }96 97 void98 CommandMap::insert_tracker(key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc) {99 iterator itr = insert(key, variable, flags, parm, doc);100 101 itr->second.m_target = target_tracker;102 itr->second.m_trackerSlot = targetSlot;103 }104 105 void106 CommandMap::insert_file(key_type key, Command* variable, file_slot targetSlot, int flags, const char* parm, const char* doc) {107 iterator itr = insert(key, variable, flags, parm, doc);108 109 itr->second.m_target = target_file;110 itr->second.m_fileSlot = targetSlot;111 }112 113 void114 CommandMap::insert_file_itr(key_type key, Command* variable, file_itr_slot targetSlot, int flags, const char* parm, const char* doc) {115 iterator itr = insert(key, variable, flags, parm, doc);116 117 itr->second.m_target = target_file_itr;118 itr->second.m_fileItrSlot = targetSlot;119 }120 121 64 void 122 65 CommandMap::insert(key_type key, const command_map_data_type src) { … … 132 75 // This _should_ be optimized int just one assignment. 133 76 switch (itr->second.m_target) { 134 case target_generic: itr->second.m_genericSlot = src.m_genericSlot; break;135 case target_any: itr->second.m_anySlot = src.m_anySlot; break;136 case target_download: itr->second.m_downloadSlot = src.m_downloadSlot; break;137 case target_file: itr->second.m_fileSlot = src.m_fileSlot; break;138 case target_file_itr: itr->second.m_fileItrSlot = src.m_fileItrSlot; break;139 case target_peer: itr->second.m_peerSlot = src.m_peerSlot; break;140 case target_tracker: itr->second.m_trackerSlot = src.m_trackerSlot; break;77 case Command::target_generic: itr->second.m_genericSlot = src.m_genericSlot; break; 78 case Command::target_any: itr->second.m_anySlot = src.m_anySlot; break; 79 case Command::target_download: itr->second.m_downloadSlot = src.m_downloadSlot; break; 80 case Command::target_file: itr->second.m_fileSlot = src.m_fileSlot; break; 81 case Command::target_file_itr: itr->second.m_fileItrSlot = src.m_fileItrSlot; break; 82 case Command::target_peer: itr->second.m_peerSlot = src.m_peerSlot; break; 83 case Command::target_tracker: itr->second.m_trackerSlot = src.m_trackerSlot; break; 141 84 default: throw torrent::internal_error("CommandMap::insert(...) Invalid target."); 142 85 } … … 150 93 throw torrent::input_error("Command \"" + std::string(key) + "\" does not exist."); 151 94 152 if (target.first != target_generic && target.second == NULL) {95 if (target.first != Command::target_generic && target.second == NULL) { 153 96 // We received a target that is NULL, so throw an exception unless 154 97 // we can convert it to a void target. 155 if (itr->second.m_target > target_any)98 if (itr->second.m_target > Command::target_any) 156 99 throw torrent::input_error("Command type mis-match."); 157 100 158 target.first = target_generic;101 target.first = Command::target_generic; 159 102 } 160 103 161 if (itr->second.m_target != target.first && itr->second.m_target > target_any) {104 if (itr->second.m_target != target.first && itr->second.m_target > Command::target_any) { 162 105 // Mismatch between the target and command type. If it is not 163 106 // possible to convert, then throw an input error. 164 if (target.first == target_file_itr && itr->second.m_target ==target_file)165 target = target_type((int) target_file, static_cast<torrent::FileListIterator*>(target.second)->file());107 if (target.first == Command::target_file_itr && itr->second.m_target == Command::target_file) 108 target = target_type((int)Command::target_file, static_cast<torrent::FileListIterator*>(target.second)->file()); 166 109 else 167 110 throw torrent::input_error("Command type mis-match."); … … 170 113 // This _should_ be optimized int just two calls. 171 114 switch (itr->second.m_target) { 172 case target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg);173 case target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg);174 case target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);175 case target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);176 case target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);177 case target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);178 case target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);115 case Command::target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg); 116 case Command::target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg); 117 case Command::target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg); 118 case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg); 119 case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg); 120 case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg); 121 case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg); 179 122 default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target."); 180 123 } … … 183 126 const CommandMap::mapped_type 184 127 CommandMap::call_command(const_iterator itr, const mapped_type& arg, target_type target) { 185 if (target.first != target_generic && target.second == NULL) {128 if (target.first != Command::target_generic && target.second == NULL) { 186 129 // We received a target that is NULL, so throw an exception unless 187 130 // we can convert it to a void target. 188 if (itr->second.m_target > target_any)131 if (itr->second.m_target > Command::target_any) 189 132 throw torrent::input_error("Command type mis-match."); 190 133 191 target.first = target_generic;134 target.first = Command::target_generic; 192 135 } 193 136 194 if (itr->second.m_target != target.first && itr->second.m_target > target_any)137 if (itr->second.m_target != target.first && itr->second.m_target > Command::target_any) 195 138 throw torrent::input_error("Command type mis-match."); 196 139 197 140 // This _should_ be optimized int just two calls. 198 141 switch (itr->second.m_target) { 199 case target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg);200 case target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg);201 case target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);202 case target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);203 case target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);204 case target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);205 case target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);142 case Command::target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg); 143 case Command::target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg); 144 case Command::target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg); 145 case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg); 146 case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg); 147 case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg); 148 case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg); 206 149 default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target."); 207 150 } -
trunk/rtorrent/src/rpc/command_map.h
r970 r1041 45 45 #include "command.h" 46 46 47 namespace core {48 class Download;49 }50 51 namespace torrent {52 class File;53 class FileListIterator;54 class Peer;55 class Tracker;56 }57 58 47 namespace rpc { 59 48 … … 68 57 // 69 58 // The any_slot should perhaps replace generic_slot? 70 typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&);71 typedef const torrent::Object (*any_slot) (Command*, target_type, const torrent::Object&);72 typedef const torrent::Object (*download_slot) (Command*, core::Download*, const torrent::Object&);73 typedef const torrent::Object (*file_slot) (Command*, torrent::File*, const torrent::Object&);74 typedef const torrent::Object (*file_itr_slot) (Command*, torrent::FileListIterator*, const torrent::Object&);75 typedef const torrent::Object (*peer_slot) (Command*, torrent::Peer*, const torrent::Object&);76 typedef const torrent::Object (*tracker_slot) (Command*, torrent::Tracker*, const torrent::Object&);77 59 78 60 command_map_data_type(Command* variable, int flags, const char* parm, const char* doc) : … … 84 66 85 67 union { 86 generic_slot m_genericSlot;87 any_slot m_anySlot;88 download_slot m_downloadSlot;89 file_slot m_fileSlot;90 file_itr_slot m_fileItrSlot;91 peer_slot m_peerSlot;92 tracker_slot m_trackerSlot;68 Command::generic_slot m_genericSlot; 69 Command::any_slot m_anySlot; 70 Command::download_slot m_downloadSlot; 71 Command::file_slot m_fileSlot; 72 Command::file_itr_slot m_fileItrSlot; 73 Command::peer_slot m_peerSlot; 74 Command::tracker_slot m_trackerSlot; 93 75 }; 94 76 … … 104 86 typedef std::map<const char*, command_map_data_type, command_map_comp> base_type; 105 87 106 typedef command_map_data_type::generic_slot generic_slot;107 typedef command_map_data_type::any_slot any_slot;108 typedef command_map_data_type::download_slot download_slot;109 typedef command_map_data_type::file_slot file_slot;110 typedef command_map_data_type::file_itr_slot file_itr_slot;111 typedef command_map_data_type::peer_slot peer_slot;112 typedef command_map_data_type::tracker_slot tracker_slot;113 114 88 typedef torrent::Object mapped_type; 115 89 typedef mapped_type::value_type mapped_value_type; … … 124 98 using base_type::find; 125 99 126 static const int target_generic = 0;127 static const int target_any = 1;128 static const int target_download = 2;129 static const int target_peer = 3;130 static const int target_tracker = 4;131 static const int target_file = 5;132 static const int target_file_itr = 6;133 134 100 static const int flag_dont_delete = 0x1; 135 101 static const int flag_public_xmlrpc = 0x2; … … 143 109 iterator insert(key_type key, Command* variable, int flags, const char* parm, const char* doc); 144 110 145 void insert_generic (key_type key, Command* variable, generic_slot targetSlot, int flags, const char* parm, const char* doc);146 void insert_ any (key_type key, Command* variable, any_slot targetSlot, int flags, const char* parm, const char* doc);147 void insert_download(key_type key, Command* variable, download_slot targetSlot, int flags, const char* parm, const char*doc);148 void insert_peer (key_type key, Command* variable, peer_slot targetSlot, int flags, const char* parm, const char* doc); 149 void insert_tracker (key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc);150 void insert_file (key_type key, Command* variable, file_slot targetSlot, int flags, const char* parm, const char* doc);151 void insert_file_itr(key_type key, Command* variable, file_itr_slot targetSlot, int flags, const char* parm, const char* doc);111 template <typename T> 112 void insert_type(key_type key, Command* variable, T targetSlot, int flags, const char* parm, const char* doc) { 113 iterator itr = insert(key, variable, flags, parm, doc); 114 115 itr->second.m_target = target_type_id<T>::value; 116 itr->second.m_genericSlot = (Command::generic_slot)targetSlot; 117 } 152 118 153 119 void insert(key_type key, const command_map_data_type src); 154 120 155 const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int) target_generic, NULL));156 const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int) target_generic, NULL));121 const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)Command::target_generic, NULL)); 122 const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int)Command::target_generic, NULL)); 157 123 158 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)); }159 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)); }160 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)); }161 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)); }124 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)); } 125 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)); } 126 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)); } 127 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)); } 162 128 163 129 private: … … 166 132 }; 167 133 168 inline target_type make_target() { return target_type((int)Command Map::target_generic, NULL); }169 inline target_type make_target(core::Download* target) { return target_type((int)Command Map::target_download, target); }170 inline target_type make_target(torrent::Peer* target) { return target_type((int)Command Map::target_peer, target); }171 inline target_type make_target(torrent::Tracker* target) { return target_type((int)Command Map::target_tracker, target); }172 inline target_type make_target(torrent::File* target) { return target_type((int)Command Map::target_file, target); }173 inline target_type make_target(torrent::FileListIterator* target) { return target_type((int)Command Map::target_file_itr, target); }134 inline target_type make_target() { return target_type((int)Command::target_generic, NULL); } 135 inline target_type make_target(core::Download* target) { return target_type((int)Command::target_download, target); } 136 inline target_type make_target(torrent::Peer* target) { return target_type((int)Command::target_peer, target); } 137 inline target_type make_target(torrent::Tracker* target) { return target_type((int)Command::target_tracker, target); } 138 inline target_type make_target(torrent::File* target) { return target_type((int)Command::target_file, target); } 139 inline target_type make_target(torrent::FileListIterator* target) { return target_type((int)Command::target_file_itr, target); } 174 140 inline target_type make_target(int type, void* target) { return target_type(type, target); } 175 141 -
trunk/rtorrent/src/rpc/command_slot.h
r976 r1041 81 81 82 82 template <int base, int unit> 83 static const torrent::Object call_value (Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, base, unit); }83 static const torrent::Object call_value_tmpl(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, base, unit); } 84 84 85 85 // static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args); … … 111 111 112 112 template <int base, int unit> 113 static const torrent::Object call_value (Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, base, unit); }113 static const torrent::Object call_value_tmpl(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, base, unit); } 114 114 115 115 // static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
