refactor log methods in public peer_connection_handle for stable ABI (#1180)

expose log functions in peer_connection_handle with empty bodies when logging is disabled
This commit is contained in:
Alden Torres 2016-10-04 00:35:40 -04:00 committed by Arvid Norberg
parent 2d7378ddcd
commit be70afa4b8
2 changed files with 12 additions and 13 deletions

View File

@ -38,20 +38,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/operations.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/peer_connection.hpp" // for connection_type
#include "libtorrent/error_code.hpp"
namespace libtorrent
{
class peer_connection;
class bt_peer_connection;
struct torrent_handle;
struct peer_plugin;
struct peer_info;
struct crypto_plugin;
typedef boost::system::error_code error_code;
// hidden
struct TORRENT_EXPORT peer_connection_handle
{
peer_connection_handle(std::weak_ptr<peer_connection> impl)
@ -95,14 +92,10 @@ struct TORRENT_EXPORT peer_connection_handle
bool failed() const;
#ifndef TORRENT_DISABLE_LOGGING
bool should_log(peer_log_alert::direction_t direction) const;
void peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt = "", ...) const TORRENT_FORMAT(4,5);
#endif // TORRENT_DISABLE_LOGGING
bool can_disconnect(error_code const& ec) const;
bool has_metadata() const;

View File

@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/bt_peer_connection.hpp"
#ifndef TORRENT_DISABLE_LOGGING
@ -208,19 +207,23 @@ bool peer_connection_handle::failed() const
return pc->failed();
}
#ifndef TORRENT_DISABLE_LOGGING
bool peer_connection_handle::should_log(peer_log_alert::direction_t direction) const
{
#ifndef TORRENT_DISABLE_LOGGING
std::shared_ptr<peer_connection> pc = native_handle();
TORRENT_ASSERT(pc);
return pc->should_log(direction);
#else
TORRENT_UNUSED(direction);
return false;
#endif
}
TORRENT_FORMAT(4,5)
void peer_connection_handle::peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt, ...) const
{
#ifndef TORRENT_DISABLE_LOGGING
std::shared_ptr<peer_connection> pc = native_handle();
TORRENT_ASSERT(pc);
va_list v;
@ -235,10 +238,13 @@ void peer_connection_handle::peer_log(peer_log_alert::direction_t direction
#pragma clang diagnostic pop
#endif
va_end(v);
#else // TORRENT_DISABLE_LOGGING
TORRENT_UNUSED(direction);
TORRENT_UNUSED(event);
TORRENT_UNUSED(fmt);
#endif
}
#endif // TORRENT_DISABLE_LOGGING
bool peer_connection_handle::can_disconnect(error_code const& ec) const
{
std::shared_ptr<peer_connection> pc = native_handle();