source: trunk/src/halEvent.cpp @ 539

Revision 539, 2.3 KB checked in by Eoin, 11 years ago (diff)

Fixed problem with log singleton (there were 2 of 'em!)

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#define HAL_EVENT_IMPL_UNIT
8
9#include "stdAfx.hpp"
10#include "halEvent.hpp"
11#include "Halite.hpp"
12
13#include <iostream>
14#include <fstream>
15#include <iterator>
16#include <iomanip>
17#include <map>
18#include <algorithm>
19#include <string>
20#include <vector>
21
22#include <libtorrent/file.hpp>
23#include <libtorrent/hasher.hpp>
24#include <libtorrent/entry.hpp>
25#include <libtorrent/bencode.hpp>
26#include <libtorrent/session.hpp>
27#include <libtorrent/ip_filter.hpp>
28#include <libtorrent/torrent_handle.hpp>
29#include <libtorrent/peer_connection.hpp>
30
31
32namespace hal
33{
34
35struct event_impl
36{
37        mutable mutex_t mutex_;
38        boost::signal<void (boost::shared_ptr<EventDetail>)> event_signal_;
39};
40
41event_logger::event_logger()
42{
43        init();
44}
45
46void event_logger::init()
47{
48        static boost::shared_ptr<event_impl> s_event_impl;
49
50        if (!s_event_impl)
51                s_event_impl.reset(new event_impl());
52
53        pimpl_ = s_event_impl;
54}
55
56event_logger::~event_logger()
57{}
58
59boost::signals::connection event_logger::attach(boost::function<void (boost::shared_ptr<EventDetail>)> fn)
60{
61        if (pimpl_)
62        {
63        mutex_t::scoped_lock l(pimpl_->mutex_);
64        return pimpl_->event_signal_.connect(fn);
65        }
66}
67
68void event_logger::dettach(const boost::signals::connection& c)
69{
70        if (pimpl_)
71        {
72        mutex_t::scoped_lock l(pimpl_->mutex_);
73        pimpl_->event_signal_.disconnect(c);
74        }
75}
76
77void event_logger::post(boost::shared_ptr<EventDetail> e)
78{
79        if (pimpl_)
80        {
81        mutex_t::scoped_lock l(pimpl_->mutex_);
82        if (e->level() != hal::event_logger::debug || halite().logDebug() || true)
83                pimpl_->event_signal_(e);
84        }
85}
86       
87std::wstring event_logger::eventLevelToStr(eventLevel event)
88{
89        switch (event)
90        {
91        case debug:
92                return hal::app().res_wstr(HAL_EVENTDEBUG);
93        case info:
94                return hal::app().res_wstr(HAL_EVENTINFO);
95        case warning:
96                return hal::app().res_wstr(HAL_EVENTWARNING);
97        case critical:
98                return hal::app().res_wstr(HAL_EVENTCRITICAL);
99        case fatal:
100                return hal::app().res_wstr(HAL_EVENTCRITICAL);
101        case xml_dev:
102                return L"XML Dev";
103        default:
104                return hal::app().res_wstr(HAL_EVENTNONE);
105        }
106}
107
108} // namespace hal
Note: See TracBrowser for help on using the repository browser.