* Changed element_peer_list.cc to te_command.

* Added several Peer commands.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@993 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-10-23 15:56:58 +00:00
parent 61098513c6
commit 4038e78665
6 changed files with 100 additions and 211 deletions
-135
View File
@@ -61,141 +61,6 @@ te_command(const char* command, int flags = TextElementCommand::flag_normal, int
// End All we're ever going to need.
typedef TextElementStringBase string_base;
typedef TextElementValueBase value_base;
// String stuff:
inline TextElementStringBase*
te_string(const char* str) {
return new TextElementCString(str);
}
// template <typename Object, typename Return>
// inline TextElementStringBase*
// te_string(Return (Object::*fptr)() const, const Object* object, int attributes = Attributes::a_invalid) {
// return text_element_string_void(rak::make_mem_fun(object, fptr), attributes);
// }
template <typename Return, typename Arg1>
inline TextElementStringBase*
te_string(Return (*fptr)(Arg1), int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_string_slot(std::ptr_fun(fptr), flags, attributes);
}
template <typename Return>
inline TextElementStringBase*
te_string(Return (core::Download::*fptr)() const, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_string_slot(std::mem_fun(fptr), flags, attributes);
}
template <typename Return>
inline TextElementStringBase*
te_string(Return (torrent::Download::*fptr)() const, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_string_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(fptr)), flags, attributes);
}
template <typename Return>
inline TextElementStringBase*
te_string(Return (torrent::FileList::*fptr)() const, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_string_slot(rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(fptr)), flags, attributes);
}
// TMP HACK
inline std::string te_call_command_d_string(const char* key, core::Download* download) { return rpc::commands.call_command(key, torrent::Object(), rpc::make_target(download)).as_string(); }
inline int64_t te_call_command_d_value(const char* key, core::Download* download) { return rpc::commands.call_command(key, torrent::Object(), rpc::make_target(download)).as_value(); }
inline TextElementStringBase*
te_variable_string(const char* variable, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_string_slot(rak::bind1st(std::ptr_fun(&te_call_command_d_string), variable), flags, attributes);
}
// Value stuff:
template <typename Return>
inline TextElementValueBase*
te_value(Return (torrent::Download::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(fptr)), flags, attributes);
}
template <typename Return>
inline TextElementValueBase*
te_value(Return (torrent::FileList::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_file_list), std::mem_fun(fptr)), flags, attributes);
}
template <typename Return>
inline TextElementValueBase*
te_value(Return (torrent::File::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_value_slot(rak::on(std::mem_fun(&torrent::FileListIterator::file), std::mem_fun(fptr)), flags, attributes);
}
inline TextElementValueBase*
te_variable_value(const char* variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_value_slot(rak::bind1st(std::ptr_fun(&te_call_command_d_value), variable), flags, attributes);
}
template <typename Return>
inline TextElementValueBase*
te_value(Return (torrent::ChunkManager::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_value_void(rak::make_mem_fun(torrent::chunk_manager(), fptr), flags, attributes);
}
template <typename Return>
inline TextElementValueBase*
te_value(Return (torrent::ConnectionManager::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
return text_element_value_void(rak::make_mem_fun(torrent::connection_manager(), fptr), flags, attributes);
}
// Various:
inline unsigned int
te_bitfield_percentage(const torrent::Bitfield* bitfield) {
return bitfield != NULL ? (100 * bitfield->size_set()) / bitfield->size_bits() : 0;
}
inline std::string
te_address(const ::sockaddr* address) {
return rak::socket_address::cast_from(address)->address_str();
}
inline unsigned int
te_port(const ::sockaddr* address) {
return rak::socket_address::cast_from(address)->port();
}
// Lambda
template <typename Return>
inline TextElement*
te_branch(Return (*fptr)(), TextElement* branch1, TextElement* branch2) {
return text_element_branch_void(std::mem_fun(fptr), branch1, branch2);
}
template <typename Return, typename Arg1>
inline TextElement*
te_branch(Return (*fptr)(Arg1), TextElement* branch1, TextElement* branch2) {
return text_element_branch(std::mem_fun(fptr), branch1, branch2);
}
template <typename Return, typename Object>
inline TextElement*
te_branch(Return (Object::*fptr)() const, TextElement* branch1, TextElement* branch2) {
return text_element_branch(std::mem_fun(fptr), branch1, branch2);
}
template <typename Return, typename Object>
inline TextElement*
te_branch(Return (Object::*fptr)() const, const Object* object, TextElement* branch1, TextElement* branch2) {
return text_element_branch_void(rak::make_mem_fun(object, fptr), branch1, branch2);
}
template <typename Return1, typename Return2, typename Object1, typename Object2>
inline TextElement*
te_branch(Return1 (Object1::*fptr1)() const, Return2 (Object2::*fptr2)() const, TextElement* branch1, TextElement* branch2) {
return text_element_branch(rak::on(std::mem_fun(fptr1), std::mem_fun(fptr2)), branch1, branch2);
}
} }
#endif
+19
View File
@@ -48,6 +48,7 @@ namespace display {
WindowText::WindowText(rpc::target_type target, extent_type margin) :
Window(new Canvas, 0, 0, 0, extent_static, extent_static),
m_target(target),
m_errorHandler(NULL),
m_margin(margin),
m_interval(0) {
}
@@ -56,6 +57,9 @@ void
WindowText::clear() {
std::for_each(begin(), end(), rak::call_delete<TextElement>());
base_type::clear();
delete m_errorHandler;
m_errorHandler = NULL;
}
void
@@ -86,6 +90,21 @@ WindowText::redraw() {
unsigned int position = 0;
if (m_canvas->height() == 0)
return;
if (m_errorHandler != NULL && m_target.second == NULL) {
char buffer[m_canvas->width() + 1];
Canvas::attributes_list attributes;
attributes.push_back(Attributes(buffer, Attributes::a_normal, Attributes::color_default));
char* last = m_errorHandler->print(buffer, buffer + m_canvas->width(), &attributes, m_target);
m_canvas->print_attributes(0, position, buffer, last, &attributes);
return;
}
for (iterator itr = begin(); itr != end() && position < m_canvas->height(); ++itr, ++position) {
if (*itr == NULL)
continue;
+5
View File
@@ -75,10 +75,15 @@ public:
void push_back(TextElement* element);
// Set an error handler if targets pointing to NULL elements should
// be handled separately to avoid throwing errors.
void set_error_handler(TextElement* element) { m_errorHandler = element; }
virtual void redraw();
private:
rpc::target_type m_target;
TextElement* m_errorHandler;
extent_type m_margin;
uint32_t m_interval;