Modified the audiomanager so that it can configure where it is going to place the log files

This commit is contained in:
Brigham Keys, Esq 2016-08-01 17:03:52 -05:00
parent 9b6b2f4853
commit 87f3aff423
4 changed files with 45 additions and 38 deletions

View File

@ -14,7 +14,7 @@ namespace cAudio
class cFileLogReceiver : public ILogReceiver class cFileLogReceiver : public ILogReceiver
{ {
public: public:
cFileLogReceiver(); cFileLogReceiver(const char *lFilePath);
~cFileLogReceiver(); ~cFileLogReceiver();
bool OnLogMessage(const char* sender, const char* message, LogLevel level, float time); bool OnLogMessage(const char* sender, const char* message, LogLevel level, float time);
@ -22,7 +22,7 @@ namespace cAudio
private: private:
bool firsttime; bool firsttime;
const char *logFilePath;
}; };
}; };
#endif #endif

View File

@ -108,9 +108,10 @@ namespace cAudio {
/** Note: This is the only way to get access to the audio playback capabilities of cAudio. /** Note: This is the only way to get access to the audio playback capabilities of cAudio.
You must delete this interface using destroyAudioManager() once you are done with it. You must delete this interface using destroyAudioManager() once you are done with it.
\param initializeDefault: Whether to return an object initialized with the default settings. If set to false, you must make a call to initialize before you can create audio sources. \param initializeDefault: Whether to return an object initialized with the default settings. If set to false, you must make a call to initialize before you can create audio sources.
\param lFilePath Where the log file is going to be placed
\return A pointer to the created object, NULL if the object could not be allocated. \return A pointer to the created object, NULL if the object could not be allocated.
*/ */
CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault = true); CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault = true, const char *lFilePath = "cAudioEngineLog.html");
//! Destroys an interface to a previously created Audio Manager and frees the memory allocated for it. //! Destroys an interface to a previously created Audio Manager and frees the memory allocated for it.
/** /**

View File

@ -30,6 +30,19 @@
namespace cAudio namespace cAudio
{ {
//---------------------------------------------------------------------------------------
// Logger section
//---------------------------------------------------------------------------------------
#if CAUDIO_COMPILE_WITH_CONSOLE_LOG_RECEIVER == 1
static cConsoleLogReceiver ConsoleLog;
#endif
#if CAUDIO_COMPILE_WITH_FILE_LOG_RECEIVER == 1
// static cFileLogReceiver *FileLog = new cFileLogReceiver();
static cFileLogReceiver *FileLog;
#endif
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Audio manager section // Audio manager section
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
@ -46,10 +59,11 @@ namespace cAudio
#if CAUDIO_COMPILE_WITH_FILE_SOURCE == 1 #if CAUDIO_COMPILE_WITH_FILE_SOURCE == 1
static cFileSourceFactory FileSourceFactory; static cFileSourceFactory FileSourceFactory;
#endif #endif
CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault, const char *lFilePath)
CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault)
{ {
cAudioManager* manager = CAUDIO_NEW cAudioManager; cAudioManager* manager = CAUDIO_NEW cAudioManager;
if(FileLog == nullptr)
FileLog = new cFileLogReceiver(lFilePath);
if(manager) if(manager)
{ {
if(initializeDefault) if(initializeDefault)
@ -98,6 +112,26 @@ namespace cAudio
} }
} }
//////////////////////////////////////////
CAUDIO_API ILogger* getLogger()
{
static cLogger* Logger = NULL;
if(!Logger)
{
Logger = new cLogger;
#if CAUDIO_COMPILE_WITH_CONSOLE_LOG_RECEIVER == 1
Logger->registerLogReceiver(&ConsoleLog, "Console");
#endif
#if CAUDIO_COMPILE_WITH_FILE_LOG_RECEIVER == 1
Logger->registerLogReceiver(FileLog,"File");
#endif
}
return Logger;
}
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// Audio capture section // Audio capture section
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
@ -137,35 +171,6 @@ namespace cAudio
} }
} }
//---------------------------------------------------------------------------------------
// Logger section
//---------------------------------------------------------------------------------------
#if CAUDIO_COMPILE_WITH_CONSOLE_LOG_RECEIVER == 1
static cConsoleLogReceiver ConsoleLog;
#endif
#if CAUDIO_COMPILE_WITH_FILE_LOG_RECEIVER == 1
static cFileLogReceiver FileLog;
#endif
CAUDIO_API ILogger* getLogger()
{
static cLogger* Logger = NULL;
if(!Logger)
{
Logger = new cLogger;
#if CAUDIO_COMPILE_WITH_CONSOLE_LOG_RECEIVER == 1
Logger->registerLogReceiver(&ConsoleLog, "Console");
#endif
#if CAUDIO_COMPILE_WITH_FILE_LOG_RECEIVER == 1
Logger->registerLogReceiver(&FileLog,"File");
#endif
}
return Logger;
}
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// IAudioDeviceList section // IAudioDeviceList section
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------

View File

@ -10,7 +10,8 @@
namespace cAudio namespace cAudio
{ {
cFileLogReceiver::cFileLogReceiver() cFileLogReceiver::cFileLogReceiver(const char *lFilePath) :
logFilePath(lFilePath)
{ {
firsttime = false; firsttime = false;
} }
@ -31,7 +32,7 @@ namespace cAudio
// Reset log file // Reset log file
outf.setf( std::ios::fixed ); outf.setf( std::ios::fixed );
outf.precision( 3 ); outf.precision( 3 );
outf.open( "cAudioEngineLog.html", std::ios::out ); outf.open( logFilePath, std::ios::out );
if( !outf ){ if( !outf ){
return false; return false;
@ -108,7 +109,7 @@ namespace cAudio
} }
else else
{ {
outf.open( "cAudioEngineLog.html", std::ios::out | std::ios::app ); outf.open( logFilePath, std::ios::out | std::ios::app );
if( !outf ){ if( !outf ){
return false; return false;