1 /*
2  * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include "typedefs.h"
22 #include "CriticalSection.h"
23 #include "Singleton.h"
24 #include "Speaker.h"
25 #include "LogManagerListener.h"
26 
27 namespace dcpp {
28 
29 class LogManager : public Singleton<LogManager>, public Speaker<LogManagerListener>
30 {
31 public:
32     typedef pair<time_t, string> Pair;
33     typedef deque<Pair> List;
34 
35     enum Area { CHAT, PM, DOWNLOAD, FINISHED_DOWNLOAD, UPLOAD, SYSTEM, STATUS, SPY, LAST };
36     enum { FILE, FORMAT };
37 
38     void log(Area area, StringMap& params) noexcept;
39     void message(const string& msg);
40 
41     List getLastLogs();
42     string getPath(Area area, StringMap& params) const;
43     string getPath(Area area) const;
44 
45     const string& getSetting(int area, int sel) const;
46     void saveSetting(int area, int sel, const string& setting);
47 
48 private:
49     void log(const string& area, const string& msg) noexcept;
50 
51     friend class Singleton<LogManager>;
52     CriticalSection cs;
53     List lastLogs;
54 
55     int options[LAST][2];
56 
57     LogManager();
58     virtual ~LogManager();
59 };
60 
61 #define LOG(area, msg) LogManager::getInstance()->log(area, msg)
62 
63 } // namespace dcpp
64