~ubuntu-branches/ubuntu/raring/rtorrent/raring

« back to all changes in this revision

Viewing changes to src/rpc/command.h

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2009-08-16 09:12:32 UTC
  • mfrom: (1.1.12 upstream) (5.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090816091232-fkf317r620hqsrz1
Tags: 0.8.5-2
* Add patch to fix crash by SCGI, closes: 541487, thanks for jdrexler.
* Standards-Version was bumped to 3.8.3 (no changes required).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// rTorrent - BitTorrent client
2
 
// Copyright (C) 2005-2007, Jari Sundell
3
 
//
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.
8
 
// 
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.
13
 
// 
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
17
 
//
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
22
 
// including the two.
23
 
//
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.
31
 
//
32
 
// Contact:  Jari Sundell <jaris@ifi.uio.no>
33
 
//
34
 
//           Skomakerveien 33
35
 
//           3185 Skoppum, NORWAY
36
 
 
37
 
#ifndef RTORRENT_RPC_VARIABLE_H
38
 
#define RTORRENT_RPC_VARIABLE_H
39
 
 
40
 
#include <torrent/object.h>
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
 
 
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
 
};
83
 
 
84
 
// Since it gets used so many places we might as well put it in the
85
 
// rpc namespace.
86
 
//typedef std::pair<int, void*> target_type;
87
 
typedef rt_triple<int, void*, void*> target_type;
88
 
 
89
 
class Command {
90
 
public:
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;
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
 
  typedef const torrent::Object (*download_pair_slot) (Command*, core::Download*, core::Download*, const torrent::Object&);
106
 
 
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;
114
 
 
115
 
  static const int target_download_pair = 7;
116
 
 
117
 
  Command() {}
118
 
  virtual ~Command() {}
119
 
 
120
 
protected:
121
 
  Command(const Command&);
122
 
  void operator = (const Command&);
123
 
};
124
 
 
125
 
template <typename T1 = void, typename T2 = void>
126
 
struct target_type_id {
127
 
  // Nothing here, so we cause an error.
128
 
};
129
 
 
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; };
137
 
 
138
 
template <> struct target_type_id<Command::download_pair_slot> { static const int value = Command::target_download_pair; };
139
 
 
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; };
147
 
 
148
 
template <> struct target_type_id<core::Download*, core::Download*> { static const int value = Command::target_download_pair; };
149
 
 
150
 
// Splitting pairs into separate targets.
151
 
inline bool is_target_pair(const target_type& target) { return target.first >= Command::target_download_pair; }
152
 
 
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); }
155
 
 
156
 
}
157
 
 
158
 
#endif