formatting fixes in client test, and made the test build when resolve countries is...
[libtorrent-kjk.git] / src / alert.cpp
blobb990db7e18e02dcf591cdf35b38982683c6acabc
1 /*
3 Copyright (c) 2003, Arvid Norberg, Daniel Wallin
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #include "libtorrent/pch.hpp"
35 #include "libtorrent/alert.hpp"
37 namespace libtorrent {
39 alert::alert(severity_t severity, const std::string& msg)
40 : m_msg(msg)
41 , m_severity(severity)
42 , m_timestamp(time_now())
46 alert::~alert()
50 ptime alert::timestamp() const
52 return m_timestamp;
55 const std::string& alert::msg() const
57 return m_msg;
60 alert::severity_t alert::severity() const
62 return m_severity;
67 alert_manager::alert_manager()
68 : m_severity(alert::none)
71 alert_manager::~alert_manager()
73 while (!m_alerts.empty())
75 delete m_alerts.front();
76 m_alerts.pop();
80 void alert_manager::post_alert(const alert& alert_)
82 boost::mutex::scoped_lock lock(m_mutex);
83 if (m_severity > alert_.severity()) return;
85 // the internal limit is 100 alerts
86 if (m_alerts.size() == 100)
88 alert* result = m_alerts.front();
89 m_alerts.pop();
90 delete result;
92 m_alerts.push(alert_.clone().release());
95 std::auto_ptr<alert> alert_manager::get()
97 boost::mutex::scoped_lock lock(m_mutex);
99 assert(!m_alerts.empty());
101 alert* result = m_alerts.front();
102 m_alerts.pop();
103 return std::auto_ptr<alert>(result);
106 bool alert_manager::pending() const
108 boost::mutex::scoped_lock lock(m_mutex);
110 return !m_alerts.empty();
113 void alert_manager::set_severity(alert::severity_t severity)
115 boost::mutex::scoped_lock lock(m_mutex);
117 m_severity = severity;
120 bool alert_manager::should_post(alert::severity_t severity) const
122 return severity >= m_severity;
125 } // namespace libtorrent