Planeshift

remotedebug.h

Go to the documentation of this file.
00001 /*
00002  * remotedebug.h by Anders Reggestad <[email protected]>
00003  *
00004  * Copyright (C) 2013 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 #ifndef __REMOTEDEBUG_H__
00020 #define __REMOTEDEBUG_H__
00021 //=============================================================================
00022 // Crystal Space Includes
00023 //=============================================================================
00024 
00025 //=============================================================================
00026 // Library Includes
00027 //=============================================================================
00028 #include "psstdint.h"
00029 
00030 //=============================================================================
00031 // Local Includes
00032 //=============================================================================
00033 
00038 // Forward declarations
00039 
00048 #define RDebug(debugEntity,debugLevel,...) \
00049     { if (debugEntity->IsDebugging()) { debugEntity->Printf(debugLevel, __VA_ARGS__); }}
00050 
00051 
00058 class RemoteDebug
00059 {
00060 public:
00064     RemoteDebug();
00065 
00069     virtual ~RemoteDebug();
00070     
00074     inline bool IsDebugging()
00075     {
00076         return (highestActiveDebugLevel > 0);
00077     };
00078     
00084     bool IsDebugging(int debugLevel)
00085     {
00086         return (highestActiveDebugLevel > 0 && debugLevel <= highestActiveDebugLevel);
00087     };
00088 
00092     bool SwitchDebugging();
00093 
00099     void SetDebugging(int debugLevel);
00100 
00104     int GetDebugging() const;
00105 
00112     void AddDebugClient(uint clientNum, int debugLevel);
00113 
00119     void RemoveDebugClient(uint clientNum);
00120 
00124     csString GetRemoteDebugClientsString() const;
00125     
00132     void Printf(int debugLevel, const char* msg,...);
00133     
00134 protected:
00138     virtual void LocalDebugReport(const csString& debugString) = 0;
00139     
00143     virtual void RemoteDebugReport(uint32_t clientNum, const csString& debugString) = 0;
00144     
00145 private:
00149     struct DebugClient
00150     {
00154         DebugClient(uint32_t clientNum, int debugLevel):clientNum(clientNum),debugLevel(debugLevel) {};
00155 
00159         bool operator==(const DebugClient& other) const { return clientNum == other.clientNum; }
00160             
00161         
00162         uint32_t clientNum; 
00163         int debugLevel;     
00164     };
00165     
00169     void VPrintf(int debugLevel, const char* msg, va_list args);
00170 
00176     void CalculateHighestActiveDebugLevel();
00177 
00178     int                  localDebugLevel;         
00179     csArray<DebugClient> debugClients;            
00180     int                  highestActiveDebugLevel; 
00181 
00182 protected:
00183     csArray<csString>    debugLog;                
00184     int                  nextDebugLogEntry;       
00185 };
00186 
00189 #endif