source: trunk/src/halEvent.cpp @ 503

Revision 503, 2.2 KB checked in by Eoin, 11 years ago (diff)

Cleaned up trunk alert handler code.

Line 
1
2//         Copyright Eóin O'Callaghan 2006 - 2008.
3// Distributed under the Boost Software License, Version 1.0.
4//    (See accompanying file LICENSE_1_0.txt or copy at
5//          http://www.boost.org/LICENSE_1_0.txt)
6
7#include "stdAfx.hpp"
8#include "Halite.hpp"
9
10#include <iostream>
11#include <fstream>
12#include <iterator>
13#include <iomanip>
14#include <map>
15#include <algorithm>
16#include <string>
17#include <vector>
18
19#include <libtorrent/file.hpp>
20#include <libtorrent/hasher.hpp>
21#include <libtorrent/entry.hpp>
22#include <libtorrent/bencode.hpp>
23#include <libtorrent/session.hpp>
24#include <libtorrent/ip_filter.hpp>
25#include <libtorrent/torrent_handle.hpp>
26#include <libtorrent/peer_connection.hpp>
27
28#define HAL_EVENT_IMPL_UNIT
29#include "halEvent.hpp"
30
31namespace hal
32{
33
34static boost::shared_ptr<event_impl> s_event_impl;
35
36struct event_impl
37{
38        mutable mutex_t mutex_;
39        boost::signal<void (boost::shared_ptr<EventDetail>)> event_signal_;
40};
41
42event_logger::event_logger()
43{
44        init();
45}
46
47void event_logger::init()
48{
49        if (!s_event_impl)
50                s_event_impl.reset(new event_impl());
51
52        pimpl_ = s_event_impl;
53}
54
55event_logger::~event_logger()
56{}
57
58boost::signals::connection event_logger::attach(boost::function<void (boost::shared_ptr<EventDetail>)> fn)
59{
60        mutex_t::scoped_lock l(pimpl_->mutex_);
61        return pimpl_->event_signal_.connect(fn);
62}
63
64void event_logger::dettach(const boost::signals::connection& c)
65{
66        mutex_t::scoped_lock l(pimpl_->mutex_);
67        pimpl_->event_signal_.disconnect(c);
68}
69
70void event_logger::post(boost::shared_ptr<EventDetail> e)
71{
72        mutex_t::scoped_lock l(pimpl_->mutex_);
73        if (e->level() != hal::event_logger::debug || halite().logDebug())
74                pimpl_->event_signal_(e);
75}
76       
77std::wstring event_logger::eventLevelToStr(eventLevel event)
78{
79        switch (event)
80        {
81        case debug:
82                return hal::app().res_wstr(HAL_EVENTDEBUG);
83        case info:
84                return hal::app().res_wstr(HAL_EVENTINFO);
85        case warning:
86                return hal::app().res_wstr(HAL_EVENTWARNING);
87        case critical:
88                return hal::app().res_wstr(HAL_EVENTCRITICAL);
89        case fatal:
90                return hal::app().res_wstr(HAL_EVENTCRITICAL);
91        default:
92                return hal::app().res_wstr(HAL_EVENTNONE);
93        }
94}
95
96} // namespace hal
Note: See TracBrowser for help on using the repository browser.