Skip to content

Commit

Permalink
Merge pull request #44 from ComradeKeys/master
Browse files Browse the repository at this point in the history
The location of the log file can now be specified
  • Loading branch information
r4stl1n authored Aug 15, 2016
2 parents 3b9fd6e + 2a790c3 commit 207352a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 41 deletions.
3 changes: 3 additions & 0 deletions cAudio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ else()
target_link_libraries(cAudio ${OPENAL_LIBRARIES})
endif()

set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY VERSION "2.3.0")
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY SOVERSION 2 )

if (APPLE AND CAUDIO_IOS_BUILD)
set_target_properties(cAudio PROPERTIES XCODE_ATTRIBUTE_GCC_THUMB_SUPPORT "NO")
set_target_properties(cAudio PROPERTIES XCODE_ATTRIBUTE_GCC_UNROLL_LOOPS "YES")
Expand Down
6 changes: 3 additions & 3 deletions cAudio/Headers/cFileLogReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace cAudio
class cFileLogReceiver : public ILogReceiver
{
public:
cFileLogReceiver();
cFileLogReceiver(const char *lFilePath);
~cFileLogReceiver();

bool OnLogMessage(const char* sender, const char* message, LogLevel level, float time);

private:

bool firsttime;

const char *logFilePath;
};
};
#endif
#endif
3 changes: 2 additions & 1 deletion cAudio/include/cAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ namespace 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.
\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.
*/
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.
/**
Expand Down
75 changes: 41 additions & 34 deletions cAudio/src/cAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,37 @@
namespace cAudio
{

//---------------------------------------------------------------------------------------
// Audio manager section
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
// 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;
}

//---------------------------------------------------------------------------------------
// Audio manager section
//---------------------------------------------------------------------------------------

#if CAUDIO_COMPILE_WITH_OGG_DECODER == 1
static cOggAudioDecoderFactory OggDecoderFactory;
Expand All @@ -46,10 +74,14 @@ namespace cAudio
#if CAUDIO_COMPILE_WITH_FILE_SOURCE == 1
static cFileSourceFactory FileSourceFactory;
#endif

CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault)
CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault, const char *lFilePath)
{
cAudioManager* manager = CAUDIO_NEW cAudioManager;
#if CAUDIO_COMPILE_WITH_FILE_LOG_RECEIVER == 1
if(FileLog == nullptr)

FileLog = new cFileLogReceiver(lFilePath);
#endif
if(manager)
{
if(initializeDefault)
Expand Down Expand Up @@ -81,6 +113,10 @@ namespace cAudio

CAUDIO_API void destroyAudioManager(IAudioManager* manager)
{
#if CAUDIO_COMPILE_WITH_FILE_LOG_RECEIVER == 1
if(FileLog not_eq nullptr)
delete FileLog;
#endif
if(manager)
{
#ifdef CAUDIO_COMPILE_WITH_PLUGIN_SUPPORT
Expand Down Expand Up @@ -137,35 +173,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
//---------------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions cAudio/src/cFileLogReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace cAudio
{
cFileLogReceiver::cFileLogReceiver()
cFileLogReceiver::cFileLogReceiver(const char *lFilePath) :
logFilePath(lFilePath)
{
firsttime = false;
}
Expand All @@ -31,7 +32,7 @@ namespace cAudio
// Reset log file
outf.setf( std::ios::fixed );
outf.precision( 3 );
outf.open( "cAudioEngineLog.html", std::ios::out );
outf.open( logFilePath, std::ios::out );

if( !outf ){
return false;
Expand Down Expand Up @@ -108,7 +109,7 @@ namespace cAudio
}
else
{
outf.open( "cAudioEngineLog.html", std::ios::out | std::ios::app );
outf.open( logFilePath, std::ios::out | std::ios::app );

if( !outf ){
return false;
Expand Down

0 comments on commit 207352a

Please sign in to comment.