1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  */
16 
17 #pragma once
18 
19 #include "Singleton.h"
20 #include "TimerManager.h"
21 
22 namespace dcpp {
23 
24 class DebugManagerListener {
25 public:
26 template<int I> struct X { enum { TYPE = I };  };
27 
28     typedef X<0> DebugCommand;
29     typedef X<1> DebugDetection;
30 
on(DebugDetection,const string &)31     virtual void on(DebugDetection, const string&) noexcept { }
on(DebugCommand,const string &,int,const string &)32     virtual void on(DebugCommand, const string&, int, const string&) noexcept { }
33 };
34 
35 class DebugManager : public Singleton<DebugManager>, public Speaker<DebugManagerListener> {
36 public:
SendCommandMessage(const string & mess,int typeDir,const string & ip)37     void SendCommandMessage(const string& mess, int typeDir, const string& ip) {
38         fire(DebugManagerListener::DebugCommand(), mess, typeDir, ip);
39     }
SendDetectionMessage(const string & mess)40     void SendDetectionMessage(const string& mess) {
41         fire(DebugManagerListener::DebugDetection(), mess);
42     }
43     enum {
44         HUB_IN, HUB_OUT, CLIENT_IN, CLIENT_OUT
45     };
46 
47 private:
48     friend class Singleton<DebugManager>;
DebugManager()49     DebugManager() noexcept { };
~DebugManager()50     ~DebugManager() noexcept { };
51 };
52 #define COMMAND_DEBUG(a,b,c) if (DebugManager::getInstance()) DebugManager::getInstance()->SendCommandMessage(a,b,c);
53 #define DETECTION_DEBUG(m) if (DebugManager::getInstance()) DebugManager::getInstance()->SendDetectionMessage(m);
54 
55 } // namespace dcpp
56