1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007, 2010 Licq developers
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef LICQDAEMON_LOGDISTRIBUTOR_H
21 #define LICQDAEMON_LOGDISTRIBUTOR_H
22 
23 #include <licq/logging/logsink.h>
24 #include <licq/thread/mutex.h>
25 
26 #include <list>
27 
28 namespace LicqDaemon
29 {
30 
31 /**
32  * Distributes log messages to all registered sinks.
33  */
34 class LogDistributor : public Licq::LogSink
35 {
36 public:
37   /**
38    * Registers a sink that will receive a copy of future log messages.
39    *
40    * @param sink Sink to register.
41    */
42   void registerSink(LogSink::Ptr sink);
43 
44   /**
45    * Unregisters a previous registered log sink.
46    *
47    * @param sink Sink to unregister.
48    */
49   void unregisterSink(LogSink::Ptr sink);
50 
51   // From Licq::LogSink
52   bool isLogging(Licq::Log::Level level) const;
53   bool isLoggingPackets() const;
54   void log(Message::Ptr message);
55 
56 private:
57   mutable Licq::Mutex myMutex;
58 
59   typedef std::list<LogSink::Ptr> LogSinkList;
60   LogSinkList mySinks;
61 };
62 
63 } // namespace LicqDaemon
64 
65 #endif
66