Skip to content

Commit

Permalink
Fix no existing alert types if disabled logging for consistency.
Browse files Browse the repository at this point in the history
Fix num_alert_types.
  • Loading branch information
aldenml committed Dec 4, 2015
1 parent 595125d commit 26e8c83
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 30 deletions.
97 changes: 69 additions & 28 deletions include/libtorrent/alert_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,6 @@ namespace libtorrent
int map_type;
};

#ifndef TORRENT_DISABLE_LOGGING

// This alert is generated to log informational events related to either
// UPnP or NAT-PMP. They contain a log line and the type (0 = NAT-PMP
// and 1 = UPnP). Displaying these messages to an end user is only useful
Expand All @@ -1411,12 +1409,21 @@ namespace libtorrent
struct TORRENT_EXPORT portmap_log_alert TORRENT_FINAL : alert
{
// internal
#ifndef TORRENT_DISABLE_LOGGING
portmap_log_alert(aux::stack_allocator& alloc, int t, const char* m);
virtual std::string message() const TORRENT_OVERRIDE;
#else
portmap_log_alert() {}
virtual std::string message() const TORRENT_OVERRIDE
{
return "";
}
#endif // TORRENT_DISABLE_LOGGING

TORRENT_DEFINE_ALERT(portmap_log_alert, 52)

static const int static_category = alert::port_mapping_log_notification;
virtual std::string message() const TORRENT_OVERRIDE;
#ifndef TORRENT_DISABLE_LOGGING

int map_type;

Expand All @@ -1433,10 +1440,9 @@ namespace libtorrent
aux::stack_allocator const& m_alloc;

int m_log_idx;
#endif // TORRENT_DISABLE_LOGGING
};

#endif

// This alert is generated when a fastresume file has been passed to
// add_torrent() but the files on disk did not match the fastresume file.
// The error_code explains the reason why the resume file was rejected.
Expand Down Expand Up @@ -2119,27 +2125,36 @@ namespace libtorrent
udp::endpoint ip;
};

#ifndef TORRENT_DISABLE_LOGGING
// This alert is posted by some session wide event. Its main purpose is
// trouble shooting and debugging. It's not enabled by the default alert
// mask and is enabled by the ``alert::session_log_notification`` bit.
// Furhtermore, it's by default disabled as a build configuration.
// Furthermore, it's by default disabled as a build configuration.
struct TORRENT_EXPORT log_alert TORRENT_FINAL : alert
{
// internal
#ifndef TORRENT_DISABLE_LOGGING
log_alert(aux::stack_allocator& alloc, char const* log);
virtual std::string message() const TORRENT_OVERRIDE;
#else
log_alert() {}
virtual std::string message() const TORRENT_OVERRIDE
{
return "";
}
#endif // TORRENT_DISABLE_LOGGING

TORRENT_DEFINE_ALERT(log_alert, 79)

static const int static_category = alert::session_log_notification;
virtual std::string message() const TORRENT_OVERRIDE;
#ifndef TORRENT_DISABLE_LOGGING

// returns the log message
char const* msg() const;

private:
aux::stack_allocator const& m_alloc;
int m_str_idx;
#endif // TORRENT_DISABLE_LOGGING
};

// This alert is posted by torrent wide events. It's meant to be used for
Expand All @@ -2149,19 +2164,30 @@ namespace libtorrent
struct TORRENT_EXPORT torrent_log_alert TORRENT_FINAL : torrent_alert
{
// internal
torrent_log_alert(aux::stack_allocator& alloc, torrent_handle h
#ifndef TORRENT_DISABLE_LOGGING
torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, char const* log);
virtual std::string message() const TORRENT_OVERRIDE;
#else
torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h)
: torrent_alert(alloc, h) {}
virtual std::string message() const TORRENT_OVERRIDE
{
return "";
}
#endif // TORRENT_DISABLE_LOGGING

TORRENT_DEFINE_ALERT(torrent_log_alert, 80)

static const int static_category = alert::torrent_log_notification;
virtual std::string message() const TORRENT_OVERRIDE;
#ifndef TORRENT_DISABLE_LOGGING

// returns the log message
char const* msg() const;

private:
int m_str_idx;
#endif // TORRENT_DISABLE_LOGGING
};

// This alert is posted by events specific to a peer. It's meant to be used
Expand All @@ -2182,15 +2208,26 @@ namespace libtorrent
};

// internal
#ifndef TORRENT_DISABLE_LOGGING
peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& i, peer_id const& pi
, peer_log_alert::direction_t dir
, char const* event, char const* log);
virtual std::string message() const TORRENT_OVERRIDE;
#else
peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& i, peer_id const& pi)
: peer_alert(alloc, h, i, pi) {}
virtual std::string message() const TORRENT_OVERRIDE
{
return "";
}
#endif // TORRENT_DISABLE_LOGGING

TORRENT_DEFINE_ALERT(peer_log_alert, 81)

static const int static_category = alert::peer_log_notification;
virtual std::string message() const TORRENT_OVERRIDE;
#ifndef TORRENT_DISABLE_LOGGING

// string literal indicating the kind of event. For messages, this is the
// message name.
Expand All @@ -2203,10 +2240,9 @@ namespace libtorrent

private:
int m_str_idx;
#endif // TORRENT_DISABLE_LOGGING
};

#endif

// posted if the local service discovery socket fails to start properly.
// it's categorized as ``error_notification``.
struct TORRENT_EXPORT lsd_error_alert TORRENT_FINAL : alert
Expand Down Expand Up @@ -2441,20 +2477,6 @@ namespace libtorrent
// picker_log_notification).
struct TORRENT_EXPORT picker_log_alert : peer_alert
{
#ifndef TORRENT_DISABLE_LOGGING

// internal
picker_log_alert(aux::stack_allocator& alloc, torrent_handle h
, tcp::endpoint const& ep, peer_id const& peer_id, boost::uint32_t flags
, piece_block const* blocks, int num_blocks);

TORRENT_DEFINE_ALERT(picker_log_alert, 89)

static const int static_category = alert::picker_log_notification;
virtual std::string message() const TORRENT_OVERRIDE;

#endif // TORRENT_DISABLE_LOGGING

enum picker_flags_t
{
// the ratio of partial pieces is too high. This forces a preference
Expand All @@ -2477,6 +2499,25 @@ namespace libtorrent
end_game = 0x8000
};

// internal
#ifndef TORRENT_DISABLE_LOGGING
picker_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& ep, peer_id const& peer_id, boost::uint32_t flags
, piece_block const* blocks, int num_blocks);
virtual std::string message() const TORRENT_OVERRIDE;
#else
picker_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& i, peer_id const& pi)
: peer_alert(alloc, h, i, pi) {}
virtual std::string message() const TORRENT_OVERRIDE
{
return "";
}
#endif // TORRENT_DISABLE_LOGGING

TORRENT_DEFINE_ALERT(picker_log_alert, 89)

static const int static_category = alert::picker_log_notification;
#ifndef TORRENT_DISABLE_LOGGING

// this is a bitmask of which features were enabled for this particular
Expand All @@ -2496,7 +2537,7 @@ namespace libtorrent
#undef TORRENT_DEFINE_ALERT_PRIO
#undef TORRENT_CLONE

enum { num_alert_types = 89 };
enum { num_alert_types = 90 };
}


Expand Down
4 changes: 2 additions & 2 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ namespace libtorrent {
return msg();
}

torrent_log_alert::torrent_log_alert(aux::stack_allocator& alloc, torrent_handle h
torrent_log_alert::torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, char const* log)
: torrent_alert(alloc, h)
, m_str_idx(alloc.copy_string(log))
Expand Down Expand Up @@ -1898,7 +1898,7 @@ namespace libtorrent {

#ifndef TORRENT_DISABLE_LOGGING

picker_log_alert::picker_log_alert(aux::stack_allocator& alloc, torrent_handle h
picker_log_alert::picker_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& ep, peer_id const& peer_id, boost::uint32_t flags
, piece_block const* blocks, int num_blocks)
: peer_alert(alloc, h, ep, peer_id)
Expand Down

0 comments on commit 26e8c83

Please sign in to comment.