~ubuntu-branches/ubuntu/trusty/miro/trusty

« back to all changes in this revision

Viewing changes to portable/libtorrent/bindings/python/src/extensions.cpp

  • Committer: Daniel Hahler
  • Date: 2010-04-13 18:51:35 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: ubuntu-launchpad@thequod.de-20100413185135-xi24v1diqg8w406x
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright Daniel Wallin, Arvid Norberg 2007. Use, modification and distribution is
2
 
// subject to the Boost Software License, Version 1.0. (See accompanying
3
 
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
 
 
5
 
#include <libtorrent/extensions.hpp>
6
 
#include <libtorrent/entry.hpp>
7
 
#include <libtorrent/peer_request.hpp>
8
 
#include <libtorrent/peer_connection.hpp>
9
 
#include <libtorrent/extensions/ut_pex.hpp>
10
 
#include <libtorrent/extensions/metadata_transfer.hpp>
11
 
#include <libtorrent/extensions/ut_metadata.hpp>
12
 
#include <libtorrent/extensions/smart_ban.hpp>
13
 
#include <boost/python.hpp>
14
 
#include "gil.hpp"
15
 
 
16
 
using namespace boost::python;
17
 
using namespace libtorrent;
18
 
 
19
 
namespace 
20
 
{
21
 
 
22
 
  struct torrent_plugin_wrap : torrent_plugin, wrapper<torrent_plugin>
23
 
  {
24
 
      boost::shared_ptr<peer_plugin> new_connection(peer_connection* p)
25
 
      {
26
 
          lock_gil lock;
27
 
 
28
 
          if (override f = this->get_override("new_connection"))
29
 
              return f(ptr(p));
30
 
          return torrent_plugin::new_connection(p);
31
 
      }
32
 
 
33
 
      boost::shared_ptr<peer_plugin> default_new_connection(peer_connection* p)
34
 
      {
35
 
          return this->torrent_plugin::new_connection(p);
36
 
      }
37
 
 
38
 
      void on_piece_pass(int index)
39
 
      {
40
 
          lock_gil lock;
41
 
 
42
 
          if (override f = this->get_override("on_piece_pass"))
43
 
              f(index);
44
 
          else
45
 
            torrent_plugin::on_piece_pass(index);
46
 
      }
47
 
 
48
 
      void default_on_piece_pass(int index)
49
 
      {
50
 
          this->torrent_plugin::on_piece_pass(index);
51
 
      }
52
 
 
53
 
      void on_piece_failed(int index)
54
 
      {
55
 
          lock_gil lock;
56
 
 
57
 
          if (override f = this->get_override("on_piece_failed"))
58
 
              f(index);
59
 
          else
60
 
              torrent_plugin::on_piece_failed(index);
61
 
      }
62
 
 
63
 
      void default_on_piece_failed(int index)
64
 
      {
65
 
          return this->torrent_plugin::on_piece_failed(index);
66
 
      }
67
 
 
68
 
      void tick()
69
 
      {
70
 
          lock_gil lock;
71
 
 
72
 
          if (override f = this->get_override("tick"))
73
 
              f();
74
 
          else
75
 
              torrent_plugin::tick();
76
 
      }
77
 
 
78
 
      void default_tick()
79
 
      {
80
 
          return this->torrent_plugin::tick();
81
 
      }
82
 
 
83
 
      bool on_pause()
84
 
      {
85
 
          lock_gil lock;
86
 
 
87
 
          if (override f = this->get_override("on_pause"))
88
 
              return f();
89
 
          return torrent_plugin::on_pause();
90
 
      }
91
 
 
92
 
      bool default_on_pause()
93
 
      {
94
 
          return this->torrent_plugin::on_pause();
95
 
      }
96
 
 
97
 
      bool on_resume()
98
 
      {
99
 
          lock_gil lock;
100
 
 
101
 
          if (override f = this->get_override("on_resume"))
102
 
              return f();
103
 
          return torrent_plugin::on_resume();
104
 
      }
105
 
 
106
 
      bool default_on_resume()
107
 
      {
108
 
          return this->torrent_plugin::on_resume();
109
 
      }
110
 
  };
111
 
 
112
 
} // namespace unnamed
113
 
 
114
 
 
115
 
boost::shared_ptr<torrent_plugin> create_metadata_plugin_wrapper(torrent* t) {
116
 
    return create_metadata_plugin(t, NULL);
117
 
}
118
 
 
119
 
boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin_wrapper(torrent *t) {
120
 
    return create_ut_metadata_plugin(t, NULL);
121
 
}
122
 
 
123
 
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
124
 
    return create_ut_pex_plugin(t, NULL);
125
 
}
126
 
 
127
 
boost::shared_ptr<torrent_plugin> create_smart_ban_plugin_wrapper(torrent* t) {
128
 
    return create_smart_ban_plugin(t, NULL);
129
 
}
130
 
 
131
 
void bind_extensions()
132
 
{
133
 
    class_<
134
 
        torrent_plugin_wrap, boost::shared_ptr<torrent_plugin_wrap>, boost::noncopyable
135
 
    >("torrent_plugin")
136
 
        .def(
137
 
            "new_connection"
138
 
          , &torrent_plugin::new_connection, &torrent_plugin_wrap::default_new_connection
139
 
        )
140
 
        .def(
141
 
            "on_piece_pass"
142
 
          , &torrent_plugin::on_piece_pass, &torrent_plugin_wrap::default_on_piece_pass
143
 
        )
144
 
        .def(
145
 
            "on_piece_failed"
146
 
          , &torrent_plugin::on_piece_failed, &torrent_plugin_wrap::default_on_piece_failed
147
 
        )
148
 
        .def(
149
 
            "tick"
150
 
          , &torrent_plugin::tick, &torrent_plugin_wrap::default_tick
151
 
        )
152
 
        .def(
153
 
            "on_pause"
154
 
          , &torrent_plugin::on_pause, &torrent_plugin_wrap::default_on_pause
155
 
        )
156
 
        .def(
157
 
            "on_resume"
158
 
          , &torrent_plugin::on_resume, &torrent_plugin_wrap::default_on_resume
159
 
        );
160
 
 
161
 
    // TODO move to it's own file
162
 
    class_<peer_connection, boost::noncopyable>("peer_connection", no_init);
163
 
 
164
 
    class_<torrent_plugin, boost::shared_ptr<torrent_plugin> >("torrent_plugin", no_init);
165
 
    def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
166
 
    def("create_metadata_plugin", create_metadata_plugin_wrapper);
167
 
    def("create_ut_metadata_plugin", create_ut_metadata_plugin_wrapper);
168
 
    def("create_smart_ban_plugin", create_smart_ban_plugin_wrapper);
169
 
}
170
 
 
171