Planeshift
remotedebug.h
Go to the documentation of this file.
1 /*
2  * remotedebug.h by Anders Reggestad <andersr@pvv.org>
3  *
4  * Copyright (C) 2013 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program 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  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef __REMOTEDEBUG_H__
20 #define __REMOTEDEBUG_H__
21 //=============================================================================
22 // Crystal Space Includes
23 //=============================================================================
24 
25 //=============================================================================
26 // Library Includes
27 //=============================================================================
28 #include "psstdint.h"
29 
30 //=============================================================================
31 // Local Includes
32 //=============================================================================
33 
38 // Forward declarations
39 
48 #define RDebug(debugEntity,debugLevel,...) \
49  { if (debugEntity->IsDebugging()) { debugEntity->Printf(debugLevel, __VA_ARGS__); }}
50 
51 
59 {
60 public:
64  RemoteDebug();
65 
69  virtual ~RemoteDebug();
70 
74  inline bool IsDebugging()
75  {
76  return (highestActiveDebugLevel > 0);
77  };
78 
84  bool IsDebugging(int debugLevel)
85  {
86  return (highestActiveDebugLevel > 0 && debugLevel <= highestActiveDebugLevel);
87  };
88 
92  bool SwitchDebugging();
93 
99  void SetDebugging(int debugLevel);
100 
104  int GetDebugging() const;
105 
112  void AddDebugClient(uint clientNum, int debugLevel);
113 
119  void RemoveDebugClient(uint clientNum);
120 
124  csString GetRemoteDebugClientsString() const;
125 
132  void Printf(int debugLevel, const char* msg,...);
133 
134 protected:
138  virtual void LocalDebugReport(const csString& debugString) = 0;
139 
143  virtual void RemoteDebugReport(uint32_t clientNum, const csString& debugString) = 0;
144 
145 private:
149  struct DebugClient
150  {
154  DebugClient(uint32_t clientNum, int debugLevel):clientNum(clientNum),debugLevel(debugLevel) {};
155 
159  bool operator==(const DebugClient& other) const { return clientNum == other.clientNum; }
160 
161 
162  uint32_t clientNum;
163  int debugLevel;
164  };
165 
169  void VPrintf(int debugLevel, const char* msg, va_list args);
170 
176  void CalculateHighestActiveDebugLevel();
177 
178  int localDebugLevel;
179  csArray<DebugClient> debugClients;
180  int highestActiveDebugLevel;
181 
182 protected:
183  csArray<csString> debugLog;
185 };
186 
189 #endif
virtual ~RemoteDebug()
Destructor.
void AddDebugClient(uint clientNum, int debugLevel)
Add a client to receive debug information.
bool IsDebugging()
Check if debugging is enabled.
Definition: remotedebug.h:74
void Printf(int debugLevel, const char *msg,...)
Function to generate a debug print.
int GetDebugging() const
Get the local debugging level.
csArray< csString > debugLog
Local debug log of last n print statments.
Definition: remotedebug.h:183
int nextDebugLogEntry
The next entry to use.
Definition: remotedebug.h:184
RemoteDebug()
Constructor.
bool IsDebugging(int debugLevel)
Check if this NPC is debugging at the given level.
Definition: remotedebug.h:84
csString GetRemoteDebugClientsString() const
Utility function to retrive a string with all remote debugging clients for debug outputs.
void SetDebugging(int debugLevel)
Set a new debug level.
void RemoveDebugClient(uint clientNum)
Remove client from list of debug receivers.
virtual void LocalDebugReport(const csString &debugString)=0
Callback function to report local debug.
virtual void RemoteDebugReport(uint32_t clientNum, const csString &debugString)=0
Callback function to report remote debug.
Keep track of remote debugging.
Definition: remotedebug.h:58
bool operator==(T *p, const scoped_ptr< T > &b)
Definition: scoped_ptr.h:134
bool SwitchDebugging()
Switch the local debuging state.