Browse Source

Move plLoggable into NucleusLib/inc.

Also add deprecation warnings to non-plString uses. This will be very
noisy, but that should make it easy to track down places that should now
be using plFormat.
Darryl Pogue 10 years ago committed by Michael Hansen
parent
commit
1adce68d0d
  1. 1
      Sources/Plasma/NucleusLib/inc/CMakeLists.txt
  2. 259
      Sources/Plasma/NucleusLib/inc/plLoggable.h
  3. 1
      Sources/Plasma/NucleusLib/pnNetCommon/CMakeLists.txt
  4. 54
      Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.cpp
  5. 26
      Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.h
  6. 4
      Sources/Plasma/NucleusLib/pnNetCommon/plNetResManager.cpp
  7. 16
      Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp
  8. 36
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
  9. 4
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h
  10. 2
      Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.h
  11. 7
      Sources/Plasma/PubUtilLib/plStatusLog/CMakeLists.txt
  12. 181
      Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.cpp
  13. 86
      Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.h
  14. 17
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  15. 6
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h

1
Sources/Plasma/NucleusLib/inc/CMakeLists.txt

@ -14,6 +14,7 @@ set(pnNucleusInc_HEADERS
plCreatableStrings.h plCreatableStrings.h
plDrawable.h plDrawable.h
plgDispatch.h plgDispatch.h
plLoggable.h
plPhysical.h plPhysical.h
plPipeline.h plPipeline.h
plPipeResReq.h plPipeResReq.h

259
Sources/Plasma/NucleusLib/inc/plLoggable.h

@ -0,0 +1,259 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plLoggable_inc
#define plLoggable_inc
#include "HeadSpin.h"
#include "plString.h"
#include "plFormat.h"
// Stub interface implemented by plStatusLog
class plLog
{
public:
virtual ~plLog() { }
virtual bool AddLine(const plString& line) = 0;
};
// An abstract base class which contains a status log and simple functions
// for writing Debug and Error msgs to the log
class plLoggable
{
protected:
mutable plLog* fStatusLog;
mutable bool fWeCreatedLog;
mutable bool fComplainAboutMissingLog;
// call plStatusLogMgr::CreateStatusLog with the options you want
virtual void ICreateStatusLog() const { };
void IDeleteLog()
{
if (fWeCreatedLog) {
delete fStatusLog;
}
fWeCreatedLog = false;
fStatusLog = nullptr;
}
public:
plLoggable()
: fStatusLog(nullptr), fWeCreatedLog(false),
fComplainAboutMissingLog(true)
{ }
virtual ~plLoggable()
{
IDeleteLog();
}
plLog* GetLog() const
{
// create status log if necessary
if (fStatusLog == nullptr) {
ICreateStatusLog(); // Usually overridden by derived class
if (fStatusLog) {
fWeCreatedLog = true;
}
}
#ifdef HS_DEBUGGING
if (fComplainAboutMissingLog) {
hsAssert(fStatusLog, "null log: override ICreateStatusLog()");
}
#endif
return fStatusLog;
}
void SetLog(plLog* log, bool deleteOnDestruct=false)
{
IDeleteLog();
fStatusLog = log;
fWeCreatedLog = deleteOnDestruct;
}
// logging
virtual bool Log(const plString& str) const
{
if (str.IsNull() || str.IsEmpty()) {
return true;
}
GetLog();
if (fStatusLog) {
return fStatusLog->AddLine(str);
}
return true;
}
virtual bool ErrorMsg(const plString& msg) const
{
return Log(plFormat("ERR: {}", msg));
}
virtual bool WarningMsg(const plString& msg) const
{
return Log(plFormat("WRN: {}", msg));
}
virtual bool AppMsg(const plString& msg) const
{
return Log(plFormat("APP: {}", msg));
}
virtual bool DebugMsg(const plString& msg) const
{
return Log(plFormat("DBG: {}", msg));
}
/////////////////////////////////////////////////////////////////////////
// DEPRECATED Log methods
/////////////////////////////////////////////////////////////////////////
hsDeprecated("plLoggable::Log is deprecated -- use plFormat instead")
virtual bool Log( const char * str ) const
{
return Log(plString::FromUtf8(str));
}
hsDeprecated("plLoggable::LogF is deprecated -- use plFormat instead")
virtual bool LogF( const char * fmt, ... ) const
{
va_list args;
va_start(args, fmt);
bool ret = Log(plString::IFormat(fmt, args));
va_end(args);
return ret;
}
hsDeprecated("plLoggable::LogV is deprecated -- use plFormat instead")
virtual bool LogV( const char * fmt, va_list args ) const
{
return Log(plString::IFormat(fmt, args));
}
hsDeprecated("plLoggable::ErrorMsgV is deprecated -- use plFormat instead")
virtual bool ErrorMsgV(const char* fmt, va_list args) const
{
return ErrorMsg(plString::IFormat(fmt, args));
}
hsDeprecated("plLoggable::DebugMsgV is deprecated -- use plFormat instead")
virtual bool DebugMsgV(const char* fmt, va_list args) const
{
return DebugMsg(plString::IFormat(fmt, args));
}
hsDeprecated("plLoggable::WarningMsgV is deprecated -- use plFormat instead")
virtual bool WarningMsgV(const char* fmt, va_list args) const
{
return WarningMsg(plString::IFormat(fmt, args));
}
hsDeprecated("plLoggable::AppMsgV is deprecated -- use plFormat instead")
virtual bool AppMsgV(const char* fmt, va_list args) const
{
return AppMsg(plString::IFormat(fmt, args));
}
hsDeprecated("plLoggable::ErrorMsg with format is deprecated -- use plFormat instead")
virtual bool ErrorMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = ErrorMsgV(fmt, args);
va_end(args);
return ret;
}
hsDeprecated("plLoggable::DebugMsg with format is deprecated -- use plFormat instead")
virtual bool DebugMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = DebugMsgV(fmt, args);
va_end(args);
return ret;
}
hsDeprecated("plLoggable::WarningMsg with format is deprecated -- use plFormat instead")
virtual bool WarningMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = WarningMsgV(fmt, args);
va_end(args);
return ret;
}
hsDeprecated("plLoggable::AppMsg with format is deprecated -- use plFormat instead")
virtual bool AppMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = AppMsgV(fmt, args);
va_end(args);
return ret;
}
};
#endif // plLoggable_inc

1
Sources/Plasma/NucleusLib/pnNetCommon/CMakeLists.txt

@ -39,7 +39,6 @@ target_link_libraries(pnNetCommon pnDispatch)
target_link_libraries(pnNetCommon pnFactory) target_link_libraries(pnNetCommon pnFactory)
target_link_libraries(pnNetCommon pnKeyedObject) target_link_libraries(pnNetCommon pnKeyedObject)
target_link_libraries(pnNetCommon pnUUID) target_link_libraries(pnNetCommon pnUUID)
target_link_libraries(pnNetCommon plStatusLog)
if(WIN32) if(WIN32)
target_link_libraries(pnNetCommon ws2_32) target_link_libraries(pnNetCommon ws2_32)
endif(WIN32) endif(WIN32)

54
Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.cpp

@ -58,40 +58,70 @@ void plNetApp::SetInstance(plNetApp* app)
fInstance = app; fInstance = app;
} }
bool plNetApp::StaticErrorMsg(const char* fmt, ...)
bool plNetApp::StaticErrorMsg(const plString& msg)
{
if (!GetInstance()) {
return true;
}
return GetInstance()->ErrorMsg(msg);
}
bool plNetApp::StaticWarningMsg(const plString& msg)
{
if (!GetInstance()) {
return true;
}
return GetInstance()->WarningMsg(msg);
}
bool plNetApp::StaticAppMsg(const plString& msg)
{
if (!GetInstance()) {
return true;
}
return GetInstance()->AppMsg(msg);
}
bool plNetApp::StaticDebugMsg(const plString& msg)
{ {
if ( !GetInstance() ) if (!GetInstance()) {
return true; return true;
}
return GetInstance()->DebugMsg(msg);
}
bool plNetApp::StaticErrorMsg(const char* fmt, ...)
{
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
return GetInstance()->ErrorMsgV(fmt, args); return StaticErrorMsg(plString::IFormat(fmt, args));
} }
bool plNetApp::StaticDebugMsg(const char* fmt, ...) bool plNetApp::StaticDebugMsg(const char* fmt, ...)
{ {
if ( !GetInstance() )
return true;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
return GetInstance()->DebugMsgV(fmt, args); return StaticDebugMsg(plString::IFormat(fmt, args));
} }
bool plNetApp::StaticWarningMsg(const char* fmt, ...) bool plNetApp::StaticWarningMsg(const char* fmt, ...)
{ {
if ( !GetInstance() )
return true;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
return GetInstance()->WarningMsgV(fmt, args); return StaticWarningMsg(plString::IFormat(fmt, args));
} }
bool plNetApp::StaticAppMsg(const char* fmt, ...) bool plNetApp::StaticAppMsg(const char* fmt, ...)
{ {
if ( !GetInstance() )
return true;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
return GetInstance()->AppMsgV(fmt, args); return StaticAppMsg(plString::IFormat(fmt, args));
} }

26
Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.h

@ -46,11 +46,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsBitVector.h" #include "hsBitVector.h"
#include "plNetGroup.h" #include "plNetGroup.h"
#include "plLoggable.h"
#include "pnKeyedObject/hsKeyedObject.h" #include "pnKeyedObject/hsKeyedObject.h"
#include "pnKeyedObject/plUoid.h" #include "pnKeyedObject/plUoid.h"
#include "plStatusLog/plLoggable.h"
#define plVerifyConditionRet(NetApp,cond,ret,str) \ #define plVerifyConditionRet(NetApp,cond,ret,str) \
do { \ do { \
if (!(cond)) { \ if (!(cond)) { \
@ -98,18 +98,32 @@ public:
plNetApp() {} plNetApp() {}
virtual ~plNetApp() {} virtual ~plNetApp() {}
CLASSNAME_REGISTER( plNetApp ); CLASSNAME_REGISTER(plNetApp);
GETINTERFACE_ANY( plNetApp, hsKeyedObject); GETINTERFACE_ANY(plNetApp, hsKeyedObject);
virtual void Shutdown() {} virtual void Shutdown() {}
void SetFlagsBit(int b, bool on=true) { fFlagsVec.SetBit(b, on); } void SetFlagsBit(int b, bool on=true) { fFlagsVec.SetBit(b, on); }
bool GetFlagsBit(int b) const { return fFlagsVec.IsBitSet(b) ? true : false; } bool GetFlagsBit(int b) const { return fFlagsVec.IsBitSet(b) ? true : false; }
static bool StaticWarningMsg(const char* fmt, ...); static bool StaticErrorMsg(const plString& msg);
static bool StaticWarningMsg(const plString& msg);
static bool StaticAppMsg(const plString& msg);
static bool StaticDebugMsg(const plString& msg);
// Deprecated
hsDeprecated("StaticErrorMsg with format is deprecated -- use plFormat instead")
static bool StaticErrorMsg(const char* fmt, ...); static bool StaticErrorMsg(const char* fmt, ...);
static bool StaticDebugMsg(const char* fmt, ...);
hsDeprecated("StaticWarningMsg with format is deprecated -- use plFormat instead")
static bool StaticWarningMsg(const char* fmt, ...);
hsDeprecated("StaticAppMsg with format is deprecated -- use plFormat instead")
static bool StaticAppMsg(const char* fmt, ...); static bool StaticAppMsg(const char* fmt, ...);
hsDeprecated("StaticDebugMsg with format is deprecated -- use plFormat instead")
static bool StaticDebugMsg(const char* fmt, ...);
}; };
// //

4
Sources/Plasma/NucleusLib/pnNetCommon/plNetResManager.cpp

@ -83,12 +83,12 @@ plCreatable* plNetResManager::IReadCreatable(hsStream* s) const
{ {
plCreatable *pCre = plFactory::Create(hClass); plCreatable *pCre = plFactory::Create(hClass);
if (!pCre) if (!pCre)
hsAssert( hClass == 0x8000, "Invalid creatable index" ); hsAssert(hClass == 0x8000, "Invalid creatable index");
return pCre; return pCre;
} }
plNetApp::StaticWarningMsg("NetResMgr::Can't create class %s", plFactory::GetNameOfClass(hClass)); plNetApp::StaticWarningMsg(plFormat("NetResMgr::Can't create class {}", plFactory::GetNameOfClass(hClass)));
return nil; return nil;
} }

16
Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp

@ -209,8 +209,8 @@ bool plSynchedObject::DirtySynchState(const plString& SDLStateName, uint32_t syn
{ {
#if 0 #if 0
if (plNetClientApp::GetInstance()) if (plNetClientApp::GetInstance())
plNetClientApp::GetInstance()->DebugMsg("NotOKToDirty - Not queueing SDL state, obj %s, sdl %s", plNetClientApp::GetInstance()->DebugMsg(plFormat("NotOKToDirty - Not queueing SDL state, obj {}, sdl {}",
GetKeyName().c_str(), SDLStateName.c_str()); GetKeyName(), SDLStateName));
#endif #endif
return false; return false;
} }
@ -219,8 +219,8 @@ bool plSynchedObject::DirtySynchState(const plString& SDLStateName, uint32_t syn
{ {
#if 0 #if 0
if (plNetClientApp::GetInstance()) if (plNetClientApp::GetInstance())
plNetClientApp::GetInstance()->DebugMsg("LocalOnly Object - Not queueing SDL msg, obj %s, sdl %s", plNetClientApp::GetInstance()->DebugMsg(plFormat("LocalOnly Object - Not queueing SDL msg, obj {}, sdl {}",
GetKeyName().c_str(), SDLStateName.c_str()); GetKeyName(), SDLStateName));
#endif #endif
return false; return false;
} }
@ -235,8 +235,8 @@ bool plSynchedObject::DirtySynchState(const plString& SDLStateName, uint32_t syn
else else
{ {
if (plNetClientApp::GetInstance()) if (plNetClientApp::GetInstance())
plNetClientApp::GetInstance()->DebugMsg("Queueing SDL state with 'maybe' ownership, obj %s, sdl %s", plNetClientApp::GetInstance()->DebugMsg(plFormat("Queueing SDL state with 'maybe' ownership, obj {}, sdl {}",
GetKeyName().c_str(), SDLStateName.c_str()); GetKeyName(), SDLStateName));
} }
} }
@ -281,8 +281,8 @@ void plSynchedObject::IAddDirtyState(plKey objKey, const plString& sdlName, uint
else else
{ {
#if 0 #if 0
plNetClientApp::GetInstance()->DebugMsg("Not queueing diplicate request for SDL state, obj %s, sdl %s", plNetClientApp::GetInstance()->DebugMsg(plFormat("Not queueing diplicate request for SDL state, obj {}, sdl {}",
objKey->GetName().c_str(), sdlName.c_str()); objKey->GetName(), sdlName));
#endif #endif
} }
} }

36
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp

@ -274,31 +274,43 @@ const char* ProcessTab(const char* fmt)
return fmt; return fmt;
} }
//
// create StatusLog if necessary
//
void plNetClientMgr::ICreateStatusLog() const
{
if (!fStatusLog)
{
fStatusLog = plStatusLogMgr::GetInstance().CreateStatusLog(40, "network.log",
plStatusLog::kTimestamp | plStatusLog::kFilledBackground | plStatusLog::kAlignToTop |
plStatusLog::kServerTimestamp);
}
}
// //
// override for plLoggable // override for plLoggable
// //
bool plNetClientMgr::Log(const char* str) const bool plNetClientMgr::Log(const plString& str) const
{ {
if (strlen(str) == 0) if (str.IsNull() || str.IsEmpty()) {
return true; return true;
}
// prepend raw time // prepend raw time
plString buf2 = plFormat("{.2f} {}", hsTimer::GetSeconds(), ProcessTab(str)); plString buf2 = plFormat("{.2f} {}", hsTimer::GetSeconds(), ProcessTab(str.c_str()));
if ( GetConsoleOutput() ) if ( GetConsoleOutput() )
hsStatusMessage(buf2.c_str()); hsStatusMessage(buf2.c_str());
// create status log if necessary GetLog();
if(fStatusLog==nil)
{
fStatusLog = plStatusLogMgr::GetInstance().CreateStatusLog(40, "network.log",
plStatusLog::kTimestamp | plStatusLog::kFilledBackground | plStatusLog::kAlignToTop |
plStatusLog::kServerTimestamp);
fWeCreatedLog = true;
}
plNetObjectDebugger::GetInstance()->LogMsgIfMatch(buf2.c_str()); plNetObjectDebugger::GetInstance()->LogMsgIfMatch(buf2.c_str());
return fStatusLog->AddLine(buf2.c_str());
if (fStatusLog) {
return fStatusLog->AddLine(buf2);
}
return true;
} }
// //

4
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h

@ -237,6 +237,8 @@ private:
int ISendGameMessage(plMessage* msg); int ISendGameMessage(plMessage* msg);
void IDisableNet (); void IDisableNet ();
void ICreateStatusLog() const override;
public: public:
plNetClientMgr(); plNetClientMgr();
~plNetClientMgr(); ~plNetClientMgr();
@ -263,7 +265,7 @@ public:
void SendApplyAvatarCustomizationsMsg(const plKey msgReceiver, bool netPropagate=true, bool localPropagate=true); void SendApplyAvatarCustomizationsMsg(const plKey msgReceiver, bool netPropagate=true, bool localPropagate=true);
// plLoggable // plLoggable
bool Log(const char* str) const; bool Log(const plString& str) const override;
// setters // setters
void SetIniAuthServer(const char * value) { fIniAuthServer=value;} void SetIniAuthServer(const char * value) { fIniAuthServer=value;}

2
Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.h

@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plNetMsgScreener_h #define plNetMsgScreener_h
#include "pnKeyedObject/plKey.h" #include "pnKeyedObject/plKey.h"
#include "plStatusLog/plLoggable.h" #include "plLoggable.h"
// //
// Class which decides what game messages are allowed to be sent to the server. // Class which decides what game messages are allowed to be sent to the server.

7
Sources/Plasma/PubUtilLib/plStatusLog/CMakeLists.txt

@ -5,18 +5,19 @@ include_directories("../../PubUtilLib")
set(plStatusLog_SOURCES set(plStatusLog_SOURCES
plEncryptLogLine.cpp plEncryptLogLine.cpp
plLoggable.cpp
plStatusLog.cpp plStatusLog.cpp
) )
set(plStatusLog_HEADERS set(plStatusLog_HEADERS
plEncryptLogLine.h plEncryptLogLine.h
plLoggable.h
plStatusLog.h plStatusLog.h
) )
add_library(plStatusLog STATIC ${plStatusLog_SOURCES} ${plStatusLog_HEADERS}) add_library(plStatusLog STATIC ${plStatusLog_SOURCES} ${plStatusLog_HEADERS})
target_link_libraries(plStatusLog CoreLib plFile plUnifiedTime) target_link_libraries(plStatusLog CoreLib)
target_link_libraries(plStatusLog pnNucleusInc)
target_link_libraries(plStatusLog plFile)
target_link_libraries(plStatusLog plUnifiedTime)
source_group("Source Files" FILES ${plStatusLog_SOURCES}) source_group("Source Files" FILES ${plStatusLog_SOURCES})
source_group("Header Files" FILES ${plStatusLog_HEADERS}) source_group("Header Files" FILES ${plStatusLog_HEADERS})

181
Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.cpp

@ -1,181 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "plLoggable.h"
#include "plStatusLog.h"
#include "hsTemplates.h"
plLoggable::~plLoggable()
{
IDeleteLog();
}
void plLoggable::IDeleteLog()
{
if ( fWeCreatedLog )
delete fStatusLog;
fWeCreatedLog = false;
fStatusLog = nil;
}
plStatusLog* plLoggable::GetLog() const
{
// create status log if necessary
if(fStatusLog==nil)
{
ICreateStatusLog(); // Usually overridden by derived class
if ( fStatusLog )
fWeCreatedLog = true;
}
#ifdef HS_DEBUGGING
if ( fComplainAboutMissingLog )
{
hsAssert(fStatusLog, "nil fStatusLog. Should override ICreateStatusLog()");
}
#endif
return fStatusLog;
}
void plLoggable::SetLog( plStatusLog * log, bool deleteOnDestruct/*=false */)
{
IDeleteLog();
fStatusLog = log;
fWeCreatedLog = deleteOnDestruct;
}
bool plLoggable::Log( const char * str ) const
{
return Log(plString::FromUtf8(str));
}
bool plLoggable::Log(const plString& str) const
{
if (str.IsNull() || str.IsEmpty()) {
return true;
}
GetLog();
if (fStatusLog) {
return fStatusLog->AddLine(str.c_str());
}
return true;
}
bool plLoggable::LogF( const char * fmt, ... ) const
{
va_list args;
va_start(args, fmt);
bool ret = Log(plString::IFormat(fmt, args));
va_end(args);
return ret;
}
bool plLoggable::LogV( const char * fmt, va_list args ) const
{
return Log(plString::IFormat(fmt, args));
}
bool plLoggable::DebugMsgV(const char* fmt, va_list args) const
{
return Log(plString("DBG: ") + plString::IFormat(fmt, args));
}
bool plLoggable::ErrorMsgV(const char* fmt, va_list args) const
{
return Log(plString("ERR: ") + plString::IFormat(fmt, args));
}
bool plLoggable::WarningMsgV(const char* fmt, va_list args) const
{
return Log(plString("WRN: ") + plString::IFormat(fmt, args));
}
bool plLoggable::AppMsgV(const char* fmt, va_list args) const
{
return Log(plString("APP: ") + plString::IFormat(fmt, args));
}
///////////////////////////////////////////////////////////////
bool plLoggable::DebugMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = DebugMsgV(fmt, args);
va_end(args);
return ret;
}
bool plLoggable::ErrorMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = ErrorMsgV(fmt, args);
va_end(args);
return ret;
}
bool plLoggable::WarningMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = WarningMsgV(fmt, args);
va_end(args);
return ret;
}
bool plLoggable::AppMsg(const char* fmt, ...) const
{
va_list args;
va_start(args, fmt);
bool ret = AppMsgV(fmt, args);
va_end(args);
return ret;
}

86
Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.h

@ -1,86 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plLoggable_inc
#define plLoggable_inc
#include "HeadSpin.h"
#include "plString.h"
//
// An abstract base class which contains a status log and simple functions
// for writing Debug and Error msgs to the log
//
class plStatusLog;
class plLoggable
{
protected:
mutable plStatusLog* fStatusLog;
mutable bool fWeCreatedLog;
mutable bool fComplainAboutMissingLog;
virtual void ICreateStatusLog() const { }; // call plStatusLogMgr::CreateStatusLog with the options you want
void IDeleteLog();
public:
plLoggable() : fStatusLog(nil), fWeCreatedLog(false),fComplainAboutMissingLog(true) { }
virtual ~plLoggable();
plStatusLog* GetLog() const;
void SetLog( plStatusLog * log, bool deleteOnDestruct=false );
// logging
virtual bool Log( const char * str ) const;
virtual bool Log(const plString& str) const;
virtual bool LogF( const char * fmt, ... ) const;
virtual bool LogV( const char * fmt, va_list args ) const;
virtual bool ErrorMsgV(const char* fmt, va_list args) const ;
virtual bool DebugMsgV(const char* fmt, va_list args) const ;
virtual bool WarningMsgV(const char* fmt, va_list args) const ;
virtual bool AppMsgV(const char* fmt, va_list args) const ;
virtual bool ErrorMsg(const char* fmt, ...) const ;
virtual bool DebugMsg(const char* fmt, ...) const ;
virtual bool WarningMsg(const char* fmt, ...) const ;
virtual bool AppMsg(const char* fmt, ...) const ;
};
#endif // plLoggable_inc

17
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

@ -495,6 +495,23 @@ bool plStatusLog::IAddLine( const char *line, int32_t count, uint32_t color )
//// AddLine ///////////////////////////////////////////////////////////////// //// AddLine /////////////////////////////////////////////////////////////////
bool plStatusLog::AddLine(const plString& line)
{
if (fLoggingOff && !fForceLog) {
return true;
}
bool ret = true;
std::vector<plString> lines = line.Split("\n");
for (plString& str : lines)
{
ret &= IAddLine(str.c_str(), -1, kWhite);
}
return ret;
}
bool plStatusLog::AddLine( const char *line, uint32_t color ) bool plStatusLog::AddLine( const char *line, uint32_t color )
{ {
char *c, *str; char *c, *str;

6
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h

@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "hsThread.h" #include "hsThread.h"
#include "plFileSystem.h" #include "plFileSystem.h"
#include "plLoggable.h"
#include <string> #include <string>
@ -70,7 +71,8 @@ class plPipeline;
class plStatusLogMgr; class plStatusLogMgr;
class plStatusLogDrawerStub; class plStatusLogDrawerStub;
class plStatusLog
class plStatusLog : public plLog
{ {
friend class plStatusLogMgr; friend class plStatusLogMgr;
friend class plStatusLogDrawerStub; friend class plStatusLogDrawerStub;
@ -157,6 +159,8 @@ class plStatusLog
~plStatusLog(); ~plStatusLog();
bool AddLine(const plString& line) override;
bool AddLine( const char *line, uint32_t color = kWhite ); bool AddLine( const char *line, uint32_t color = kWhite );
/// printf-like functions /// printf-like functions

Loading…
Cancel
Save