1
// rTorrent - BitTorrent client
2
// Copyright (C) 2005-2007, Jari Sundell
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// In addition, as a special exception, the copyright holders give
19
// permission to link the code of portions of this program with the
20
// OpenSSL library under certain conditions as described in each
21
// individual source file, and distribute linked combinations
24
// You must obey the GNU General Public License in all respects for
25
// all of the code used other than OpenSSL. If you modify file(s)
26
// with this exception, you may extend this exception to your version
27
// of the file(s), but you are not obligated to do so. If you do not
28
// wish to do so, delete this exception statement from your version.
29
// If you delete this exception statement from all source files in the
30
// program, then also delete it here.
32
// Contact: Jari Sundell <jaris@ifi.uio.no>
35
// 3185 Skoppum, NORWAY
37
#ifndef RTORRENT_RPC_VARIABLE_H
38
#define RTORRENT_RPC_VARIABLE_H
40
#include <torrent/object.h>
48
class FileListIterator;
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;
61
using base_type::first;
62
using base_type::second;
63
using base_type::first_type;
64
using base_type::second_type;
68
rt_triple() : base_type(), third() {}
70
rt_triple(const T1& a, const T2& b) :
71
base_type(a, b), third() {}
73
rt_triple(const T1& a, const T2& b, const T3& c) :
74
base_type(a, b), third(c) {}
76
template <typename U1, typename U2>
77
rt_triple(const std::pair<U1, U2>& b) : base_type(b), third() {}
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) {}
84
// Since it gets used so many places we might as well put it in the
86
//typedef std::pair<int, void*> target_type;
87
typedef rt_triple<int, void*, void*> target_type;
91
typedef torrent::Object::value_type value_type;
92
typedef torrent::Object::string_type string_type;
93
typedef torrent::Object::list_type list_type;
94
typedef torrent::Object::map_type map_type;
95
typedef torrent::Object::key_type key_type;
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&);
105
typedef const torrent::Object (*download_pair_slot) (Command*, core::Download*, core::Download*, const torrent::Object&);
107
static const int target_generic = 0;
108
static const int target_any = 1;
109
static const int target_download = 2;
110
static const int target_peer = 3;
111
static const int target_tracker = 4;
112
static const int target_file = 5;
113
static const int target_file_itr = 6;
115
static const int target_download_pair = 7;
118
virtual ~Command() {}
121
Command(const Command&);
122
void operator = (const Command&);
125
template <typename T1 = void, typename T2 = void>
126
struct target_type_id {
127
// Nothing here, so we cause an error.
130
template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; };
131
template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; };
132
template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; };
133
template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; };
134
template <> struct target_type_id<Command::tracker_slot> { static const int value = Command::target_tracker; };
135
template <> struct target_type_id<Command::file_slot> { static const int value = Command::target_file; };
136
template <> struct target_type_id<Command::file_itr_slot> { static const int value = Command::target_file_itr; };
138
template <> struct target_type_id<Command::download_pair_slot> { static const int value = Command::target_download_pair; };
140
template <> struct target_type_id<> { static const int value = Command::target_generic; };
141
template <> struct target_type_id<target_type> { static const int value = Command::target_any; };
142
template <> struct target_type_id<core::Download*> { static const int value = Command::target_download; };
143
template <> struct target_type_id<torrent::Peer*> { static const int value = Command::target_peer; };
144
template <> struct target_type_id<torrent::Tracker*> { static const int value = Command::target_tracker; };
145
template <> struct target_type_id<torrent::File*> { static const int value = Command::target_file; };
146
template <> struct target_type_id<torrent::FileListIterator*> { static const int value = Command::target_file_itr; };
148
template <> struct target_type_id<core::Download*, core::Download*> { static const int value = Command::target_download_pair; };
150
// Splitting pairs into separate targets.
151
inline bool is_target_pair(const target_type& target) { return target.first >= Command::target_download_pair; }
153
inline target_type get_target_left(const target_type& target) { return target_type(target.first - 5, target.second); }
154
inline target_type get_target_right(const target_type& target) { return target_type(target.first - 5, target.third); }