Add set_alert_notify to python bindings (#3066)
This commit is contained in:
parent
6c4869f044
commit
c2ea38fdfe
|
@ -388,6 +388,20 @@ namespace
|
||||||
}
|
}
|
||||||
#endif // TORRENT_ABI_VERSION
|
#endif // TORRENT_ABI_VERSION
|
||||||
|
|
||||||
|
void alert_notify(object cb)
|
||||||
|
{
|
||||||
|
lock_gil lock;
|
||||||
|
if (cb)
|
||||||
|
{
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_alert_notify(lt::session& s, object cb)
|
||||||
|
{
|
||||||
|
s.set_alert_notify(std::bind(&alert_notify, cb));
|
||||||
|
}
|
||||||
|
|
||||||
alert const*
|
alert const*
|
||||||
wait_for_alert(lt::session& s, int ms)
|
wait_for_alert(lt::session& s, int ms)
|
||||||
{
|
{
|
||||||
|
@ -987,6 +1001,7 @@ void bind_session()
|
||||||
.def("save_state", &save_state, (arg("entry"), arg("flags") = 0xffffffff))
|
.def("save_state", &save_state, (arg("entry"), arg("flags") = 0xffffffff))
|
||||||
.def("pop_alerts", &pop_alerts)
|
.def("pop_alerts", &pop_alerts)
|
||||||
.def("wait_for_alert", &wait_for_alert, return_internal_reference<>())
|
.def("wait_for_alert", &wait_for_alert, return_internal_reference<>())
|
||||||
|
.def("set_alert_notify", &set_alert_notify)
|
||||||
.def("add_extension", &add_extension)
|
.def("add_extension", &add_extension)
|
||||||
#if TORRENT_ABI_VERSION == 1
|
#if TORRENT_ABI_VERSION == 1
|
||||||
#if TORRENT_USE_I2P
|
#if TORRENT_USE_I2P
|
||||||
|
|
|
@ -15,6 +15,7 @@ import subprocess as sub
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
import inspect
|
||||||
import pickle
|
import pickle
|
||||||
|
import threading
|
||||||
|
|
||||||
# include terminal interface for travis parallel executions of scripts which use
|
# include terminal interface for travis parallel executions of scripts which use
|
||||||
# terminal features: fix multiple stdin assignment at termios.tcgetattr
|
# terminal features: fix multiple stdin assignment at termios.tcgetattr
|
||||||
|
@ -398,6 +399,18 @@ class test_alerts(unittest.TestCase):
|
||||||
print(a.message())
|
print(a.message())
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
def test_alert_notify(self):
|
||||||
|
ses = lt.session(settings)
|
||||||
|
event = threading.Event()
|
||||||
|
|
||||||
|
def callback():
|
||||||
|
event.set()
|
||||||
|
|
||||||
|
ses.set_alert_notify(callback)
|
||||||
|
ses.async_add_torrent(
|
||||||
|
{"ti": lt.torrent_info("base.torrent"), "save_path": "."})
|
||||||
|
event.wait()
|
||||||
|
|
||||||
|
|
||||||
class test_bencoder(unittest.TestCase):
|
class test_bencoder(unittest.TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue