Skip to content

Commit 322007b

Browse files
committed
make save_state_flags a strong type
1 parent 69bd298 commit 322007b

28 files changed

+226
-148
lines changed

bindings/python/src/converters.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "libtorrent/aux_/noexcept_movable.hpp"
1616
#include "libtorrent/peer_info.hpp"
1717
#include "libtorrent/alert_types.hpp" // for picker_flags_t
18+
#include "libtorrent/session_types.hpp" // for save_state_flags_t
1819
#include "libtorrent/alert.hpp"
1920
#include <vector>
2021

@@ -304,6 +305,9 @@ void bind_converters()
304305
to_python_converter<lt::add_piece_flags_t, from_bitfield_flag<lt::add_piece_flags_t>>();
305306
to_python_converter<lt::pause_flags_t, from_bitfield_flag<lt::pause_flags_t>>();
306307
to_python_converter<lt::deadline_flags_t, from_bitfield_flag<lt::deadline_flags_t>>();
308+
to_python_converter<lt::save_state_flags_t, from_bitfield_flag<lt::save_state_flags_t>>();
309+
to_python_converter<lt::session_flags_t, from_bitfield_flag<lt::session_flags_t>>();
310+
to_python_converter<lt::remove_flags_t, from_bitfield_flag<lt::remove_flags_t>>();
307311

308312
// work-around types
309313
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
@@ -358,4 +362,7 @@ void bind_converters()
358362
to_bitfield_flag<lt::add_piece_flags_t>();
359363
to_bitfield_flag<lt::pause_flags_t>();
360364
to_bitfield_flag<lt::deadline_flags_t>();
365+
to_bitfield_flag<lt::save_state_flags_t>();
366+
to_bitfield_flag<lt::session_flags_t>();
367+
to_bitfield_flag<lt::remove_flags_t>();
361368
}

bindings/python/src/session.cpp

+33-29
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace
163163
return ret;
164164
}
165165

166-
std::shared_ptr<lt::session> make_session(boost::python::dict sett, int flags)
166+
std::shared_ptr<lt::session> make_session(boost::python::dict sett, session_flags_t flags)
167167
{
168168
settings_pack p;
169169
make_settings_pack(p, sett);
@@ -471,11 +471,11 @@ namespace
471471
}
472472
#endif
473473

474-
entry save_state(lt::session const& s, std::uint32_t flags)
474+
entry save_state(lt::session const& s, std::uint32_t const flags)
475475
{
476476
allow_threading_guard guard;
477477
entry e;
478-
s.save_state(e, flags);
478+
s.save_state(e, save_state_flags_t(flags));
479479
return e;
480480
}
481481

@@ -495,7 +495,7 @@ namespace
495495
return ret;
496496
}
497497

498-
void load_state(lt::session& ses, entry const& st, std::uint32_t flags)
498+
void load_state(lt::session& ses, entry const& st, std::uint32_t const flags)
499499
{
500500
allow_threading_guard guard;
501501

@@ -505,7 +505,7 @@ namespace
505505
error_code ec;
506506
bdecode(&buf[0], &buf[0] + buf.size(), e, ec);
507507
TORRENT_ASSERT(!ec);
508-
ses.load_state(e, flags);
508+
ses.load_state(e, save_state_flags_t(flags));
509509
}
510510

511511
#ifndef TORRENT_DISABLE_DHT
@@ -564,6 +564,9 @@ struct dummy1 {};
564564
#ifndef TORRENT_NO_DEPRECATE
565565
struct dummy2 {};
566566
#endif
567+
struct dummy9 {};
568+
struct dummy10 {};
569+
struct dummy11 {};
567570

568571
void bind_session()
569572
{
@@ -695,21 +698,21 @@ void bind_session()
695698
#endif
696699
;
697700

698-
699701
enum_<storage_mode_t>("storage_mode_t")
700702
.value("storage_mode_allocate", storage_mode_allocate)
701703
.value("storage_mode_sparse", storage_mode_sparse)
702704
;
703705

704-
enum_<lt::session::options_t>("options_t")
705-
.value("delete_files", lt::session::delete_files)
706-
;
707-
708-
enum_<lt::session::session_flags_t>("session_flags_t")
709-
.value("add_default_plugins", lt::session::add_default_plugins)
710-
.value("start_default_features", lt::session::start_default_features)
711-
;
706+
{
707+
scope s = class_<dummy11>("options_t");
708+
s.attr("delete_files") = lt::session::delete_files;
709+
}
712710

711+
{
712+
scope s = class_<dummy10>("session_flags_t");
713+
s.attr("add_default_plugins") = lt::session::add_default_plugins;
714+
s.attr("start_default_features") = lt::session::start_default_features;
715+
}
713716

714717
{
715718
scope s = class_<dummy1>("torrent_flags");
@@ -799,10 +802,10 @@ void bind_session()
799802
)
800803
#ifndef TORRENT_NO_DEPRECATE
801804
.def(
802-
init<fingerprint, int, std::uint32_t>((
805+
init<fingerprint, session_flags_t, alert_category_t>((
803806
arg("fingerprint")=fingerprint("LT",0,1,0,0)
804807
, arg("flags")=lt::session::start_default_features | lt::session::add_default_plugins
805-
, arg("alert_mask")=int(alert::error_notification)))
808+
, arg("alert_mask")=alert::error_notification))
806809
)
807810
.def("outgoing_ports", &outgoing_ports)
808811
#endif
@@ -933,21 +936,22 @@ void bind_session()
933936
.value("tcp", lt::session::tcp)
934937
;
935938

936-
enum_<lt::session::save_state_flags_t>("save_state_flags_t")
937-
.value("save_settings", lt::session::save_settings)
938-
.value("save_dht_settings", lt::session::save_dht_settings)
939-
.value("save_dht_state", lt::session::save_dht_state)
940-
.value("save_encryption_settings", lt::session:: save_encryption_settings)
939+
{
940+
scope s = class_<dummy9>("save_state_flags_t");
941+
s.attr("save_settings") = lt::session::save_settings;
942+
s.attr("save_dht_settings") = lt::session::save_dht_settings;
943+
s.attr("save_dht_state") = lt::session::save_dht_state;
944+
s.attr("save_encryption_settings") = lt::session:: save_encryption_settings;
941945
#ifndef TORRENT_NO_DEPRECATE
942-
.value("save_as_map", lt::session::save_as_map)
943-
.value("save_i2p_proxy", lt::session::save_i2p_proxy)
944-
.value("save_proxy", lt::session::save_proxy)
945-
.value("save_dht_proxy", lt::session::save_dht_proxy)
946-
.value("save_peer_proxy", lt::session::save_peer_proxy)
947-
.value("save_web_proxy", lt::session::save_web_proxy)
948-
.value("save_tracker_proxy", lt::session::save_tracker_proxy)
946+
s.attr("save_as_map") = lt::session::save_as_map;
947+
s.attr("save_i2p_proxy") = lt::session::save_i2p_proxy;
948+
s.attr("save_proxy") = lt::session::save_proxy;
949+
s.attr("save_dht_proxy") = lt::session::save_dht_proxy;
950+
s.attr("save_peer_proxy") = lt::session::save_peer_proxy;
951+
s.attr("save_web_proxy") = lt::session::save_web_proxy;
952+
s.attr("save_tracker_proxy") = lt::session::save_tracker_proxy;
949953
#endif
950-
;
954+
}
951955

952956
#ifndef TORRENT_NO_DEPRECATE
953957
enum_<lt::session::listen_on_flags_t>("listen_on_flags_t")

docs/hunspell/libtorrent.dic

+3
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,6 @@ Hellman
208208
html
209209
namespace
210210
dn
211+
pe
212+
lt
213+
tex

include/libtorrent/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ nobase_include_HEADERS = \
116116
session_settings.hpp \
117117
session_stats.hpp \
118118
session_status.hpp \
119+
session_types.hpp \
119120
settings_pack.hpp \
120121
sha1.hpp \
121122
sha512.hpp \

include/libtorrent/aux_/session_impl.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ namespace aux {
499499
void on_async_load_torrent(add_torrent_params* params, error_code ec);
500500
#endif
501501

502-
void remove_torrent(torrent_handle const& h, int options) override;
503-
void remove_torrent_impl(std::shared_ptr<torrent> tptr, int options) override;
502+
void remove_torrent(torrent_handle const& h, remove_flags_t options) override;
503+
void remove_torrent_impl(std::shared_ptr<torrent> tptr, remove_flags_t options) override;
504504

505505
void get_torrent_status(std::vector<torrent_status>* ret
506506
, std::function<bool(torrent_status const&)> const& pred
@@ -600,8 +600,8 @@ namespace aux {
600600

601601
void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false) override;
602602

603-
void save_state(entry* e, std::uint32_t flags) const;
604-
void load_state(bdecode_node const* e, std::uint32_t flags);
603+
void save_state(entry* e, save_state_flags_t flags) const;
604+
void load_state(bdecode_node const* e, save_state_flags_t flags);
605605

606606
bool has_connection(peer_connection* p) const override;
607607
void insert_peer(std::shared_ptr<peer_connection> const& c) override;

include/libtorrent/aux_/session_interface.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
4343
#include "libtorrent/socket.hpp" // for tcp::endpoint
4444
#include "libtorrent/aux_/vector.hpp"
4545
#include "libtorrent/aux_/listen_socket_handle.hpp"
46+
#include "libtorrent/session_types.hpp"
4647

4748
#include <functional>
4849
#include <memory>
@@ -155,8 +156,8 @@ namespace libtorrent { namespace aux {
155156
virtual bool has_connection(peer_connection* p) const = 0;
156157
virtual void insert_peer(std::shared_ptr<peer_connection> const& c) = 0;
157158

158-
virtual void remove_torrent(torrent_handle const& h, int options = 0) = 0;
159-
virtual void remove_torrent_impl(std::shared_ptr<torrent> tptr, int options) = 0;
159+
virtual void remove_torrent(torrent_handle const& h, remove_flags_t options = {}) = 0;
160+
virtual void remove_torrent_impl(std::shared_ptr<torrent> tptr, remove_flags_t options) = 0;
160161

161162
// port filter
162163
virtual port_filter const& get_port_filter() const = 0;

include/libtorrent/aux_/storage_utils.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
4040
#include "libtorrent/aux_/typed_span.hpp"
4141
#include "libtorrent/units.hpp"
4242
#include "libtorrent/storage_defs.hpp" // for status_t
43+
#include "libtorrent/session_types.hpp"
4344

4445
namespace libtorrent {
4546

@@ -85,7 +86,7 @@ namespace aux {
8586
// opt to only delete the partfile
8687
TORRENT_EXTRA_EXPORT void
8788
delete_files(file_storage const& fs, std::string const& save_path
88-
, std::string const& part_file_name, int const options, storage_error& ec);
89+
, std::string const& part_file_name, remove_flags_t const options, storage_error& ec);
8990

9091
TORRENT_EXTRA_EXPORT bool
9192
verify_resume_data(add_torrent_params const& rd

include/libtorrent/disk_interface.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
4646
#include "libtorrent/time.hpp"
4747
#include "libtorrent/sha1_hash.hpp"
4848
#include "libtorrent/flags.hpp"
49+
#include "libtorrent/session_types.hpp"
4950

5051
namespace libtorrent {
5152

@@ -164,7 +165,7 @@ namespace libtorrent {
164165
virtual void async_rename_file(storage_index_t storage
165166
, file_index_t index, std::string name
166167
, std::function<void(std::string const&, file_index_t, storage_error const&)> handler) = 0;
167-
virtual void async_delete_files(storage_index_t storage, int options
168+
virtual void async_delete_files(storage_index_t storage, remove_flags_t options
168169
, std::function<void(storage_error const&)> handler) = 0;
169170
virtual void async_set_file_priority(storage_index_t storage
170171
, aux::vector<std::uint8_t, file_index_t> prio

include/libtorrent/disk_io_job.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
4141
#include "libtorrent/disk_interface.hpp"
4242
#include "libtorrent/aux_/vector.hpp"
4343
#include "libtorrent/units.hpp"
44+
#include "libtorrent/session_types.hpp"
4445

4546
#include "libtorrent/aux_/disable_warnings_push.hpp"
4647
#include <boost/variant/variant.hpp>
@@ -127,7 +128,8 @@ namespace libtorrent {
127128
, std::string
128129
, add_torrent_params const*
129130
, aux::vector<std::uint8_t, file_index_t>
130-
, int> argument;
131+
, remove_flags_t
132+
> argument;
131133

132134
// the disk storage this job applies to (if applicable)
133135
std::shared_ptr<storage_interface> storage;

include/libtorrent/disk_io_thread.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ namespace aux {
311311
, std::function<void(status_t, std::string const&, storage_error const&)> handler) override;
312312
void async_release_files(storage_index_t storage
313313
, std::function<void()> handler = std::function<void()>()) override;
314-
void async_delete_files(storage_index_t storage, int options
314+
void async_delete_files(storage_index_t storage, remove_flags_t options
315315
, std::function<void(storage_error const&)> handler) override;
316316
void async_check_files(storage_index_t storage
317317
, add_torrent_params const* resume_data

include/libtorrent/session.hpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace aux {
163163
// This function helps to construct a ``session_params`` from a
164164
// bencoded data generated by ``session_handle::save_state``
165165
TORRENT_EXPORT session_params read_session_params(bdecode_node const& e
166-
, std::uint32_t flags = 0xffffffff);
166+
, save_state_flags_t flags = save_state_flags_t{0xffffffff});
167167

168168
// The session holds all state that spans multiple torrents. Among other
169169
// things it runs the network loop and manages all torrents. Once it's
@@ -222,7 +222,7 @@ namespace aux {
222222
// default is to start those features. If you do not want them to start,
223223
// pass 0 as the flags parameter.
224224
session(settings_pack pack
225-
, int flags = start_default_features | add_default_plugins)
225+
, session_flags_t const flags = start_default_features | add_default_plugins)
226226
{
227227
TORRENT_CFG();
228228
start(flags, std::move(pack), nullptr);
@@ -251,7 +251,7 @@ namespace aux {
251251
// destruct the session_proxy object.
252252
session(settings_pack pack
253253
, io_service& ios
254-
, int flags = start_default_features | add_default_plugins)
254+
, session_flags_t const flags = start_default_features | add_default_plugins)
255255
{
256256
TORRENT_CFG();
257257
start(flags, std::move(pack), &ios);
@@ -272,14 +272,14 @@ namespace aux {
272272
#endif
273273
TORRENT_DEPRECATED
274274
session(fingerprint const& print
275-
, int flags = start_default_features | add_default_plugins
276-
, std::uint32_t alert_mask = alert::error_notification)
275+
, session_flags_t const flags = start_default_features | add_default_plugins
276+
, alert_category_t const alert_mask = alert::error_notification)
277277
{
278278
TORRENT_CFG();
279279
settings_pack pack;
280280
pack.set_int(settings_pack::alert_mask, int(alert_mask));
281281
pack.set_str(settings_pack::peer_fingerprint, print.to_string());
282-
if ((flags & start_default_features) == 0)
282+
if (!(flags & start_default_features))
283283
{
284284
pack.set_bool(settings_pack::enable_upnp, false);
285285
pack.set_bool(settings_pack::enable_natpmp, false);
@@ -294,8 +294,8 @@ namespace aux {
294294
session(fingerprint const& print
295295
, std::pair<int, int> listen_port_range
296296
, char const* listen_interface = "0.0.0.0"
297-
, int flags = start_default_features | add_default_plugins
298-
, int alert_mask = alert::error_notification)
297+
, session_flags_t const flags = start_default_features | add_default_plugins
298+
, alert_category_t const alert_mask = alert::error_notification)
299299
{
300300
TORRENT_CFG();
301301
TORRENT_ASSERT(listen_port_range.first > 0);
@@ -311,7 +311,7 @@ namespace aux {
311311
std::snprintf(if_string, sizeof(if_string), "%s:%d", listen_interface, listen_port_range.first);
312312
pack.set_str(settings_pack::listen_interfaces, if_string);
313313

314-
if ((flags & start_default_features) == 0)
314+
if (!(flags & start_default_features))
315315
{
316316
pack.set_bool(settings_pack::enable_upnp, false);
317317
pack.set_bool(settings_pack::enable_natpmp, false);
@@ -362,7 +362,7 @@ namespace aux {
362362
private:
363363

364364
void start(session_params params, io_service* ios);
365-
void start(int flags, settings_pack sp, io_service* ios);
365+
void start(session_flags_t flags, settings_pack sp, io_service* ios);
366366

367367
// data shared between the main thread
368368
// and the working thread

0 commit comments

Comments
 (0)