Added basic logger logged cAudioManager.cpp

This commit is contained in:
Raynaldo Rivera 2009-09-12 05:59:28 +00:00
parent e3baec7932
commit 973bd33e5a
8 changed files with 133 additions and 9 deletions

View File

@ -9,6 +9,7 @@
#include "../include/IAudio.h"
#include "../Include/cVector3.h"
#include "../Headers/cMutex.h"
#include "../include/ILogger.h"
namespace cAudio
{

View File

@ -9,6 +9,8 @@
#include "cAudioCapture.h"
#include "../include/IAudioManager.h"
#include "../Headers/cMutex.h"
#include "../include/ILogger.h"
#include "../Headers/cLogger.h"
namespace cAudio
{
@ -17,6 +19,7 @@ namespace cAudio
class cAudioManager : public IAudioManager
{
public:
//!Inits the audio manager calling the alut/etc start ups
virtual void init(int argc,char* argv[]);
//!Shuts everything down
@ -59,16 +62,21 @@ namespace cAudio
{
return &m_cAudioManager;
}
virtual ~cAudioManager(){
delete log;
}
protected:
cAudioManager() : RunThread(false){ }
cAudioManager() : RunThread(false){
log = new cLogger();}
private:
//Mutex for thread syncronization
cAudioMutex Mutex;
bool RunThread;
//Logger Object
ILogger *log;
//!Global cAudioManager
static cAudioManager m_cAudioManager;
//!The map that holds the cAudio objects

26
Headers/cLogger.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef CLOGGERR_H_INCLUDED
#define CLOGGER_H_INCLUDED
#include <iostream>
#include "../Include/ILogger.h"
#include "../Headers/cMutex.h"
namespace cAudio{
class cLogger : public ILogger{
public:
cLogger();
virtual ~cLogger();
void setLogLevel(E_LOGLEVEL level);
void log(E_LOGLEVEL loglevel,const char* text,...);
private:
E_LOGLEVEL logLevel;
//Mutex for thread syncronization
cAudioMutex Mutex;
};
}
#endif

View File

@ -52,8 +52,11 @@ namespace cAudio
ALint attribs[4] = { 0 };
//Check if device can be created
if (Device == NULL)
log->log(E_LOGLEVEL_4,"cAudio Failed to Initalized:");
exit(-1);
log->log(E_LOGLEVEL_4,"cAudio Initalized:");
//Setup attributes to request 4 slots per a sound source
attribs[0] = ALC_MAX_AUXILIARY_SENDS;
attribs[1] = 4;
@ -61,9 +64,11 @@ namespace cAudio
//Create context with eax effects for windows
#ifdef CAUDIO_EAX_ENABLED
if(alcIsExtensionPresent(Device, "ALC_EXT_EFX") == AL_FALSE)
log->log(E_LOGLEVEL_4,"cAudio: EFX isnt supported");
return;
Context=alcCreateContext(Device, attribs);
log->log(E_LOGLEVEL_4,"cAudio: EFX Supported and Enabled.");
#else
Context=alcCreateContext(Device, NULL);
#endif
@ -106,12 +111,14 @@ namespace cAudio
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
IAudio* audio = new cAudio(decoder);
audiomap[identifier] = audio;
Mutex.unlock();
return audio;
log->log(E_LOGLEVEL_4,"cAudio: Streaming IAudio Object %s created from %s", identifier.c_str(),file.c_str());
Mutex.unlock();
return audio;
}
else
{
delete source;
log->log(E_LOGLEVEL_4,"cAudio: Failed to create IAudio Object %s from %s", identifier.c_str(),file.c_str());
Mutex.unlock();
return NULL;
}
@ -148,12 +155,14 @@ namespace cAudio
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
IAudio* audio = new cAudio(decoder);
audiomap[identifier] = audio;
log->log(E_LOGLEVEL_4,"cAudio: IAudio Object %s created from memory", identifier.c_str());
Mutex.unlock();
return audio;
}
else
{
delete source;
log->log(E_LOGLEVEL_4,"cAudio: Failed to create IAudio Object %s from memory", identifier.c_str());
Mutex.unlock();
return NULL;
}
@ -175,12 +184,14 @@ namespace cAudio
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
IAudio* audio = new cAudio(decoder);
audiomap[identifier] = audio;
log->log(E_LOGLEVEL_4,"cAudio: IAudio Object %s created from memory", identifier.c_str());
Mutex.unlock();
return audio;
}
else
{
delete source;
log->log(E_LOGLEVEL_4,"cAudio: Failed to create IAudio Object %s from memory", identifier.c_str());
Mutex.unlock();
return NULL;
}
@ -190,6 +201,7 @@ namespace cAudio
{
Mutex.lock();
decodermap[extension] = factory;
log->log(E_LOGLEVEL_4,"cAudio: Audio Decoder %s loaded", extension.c_str());
Mutex.unlock();
return true;
}
@ -202,6 +214,7 @@ namespace cAudio
{
delete it->second;
decodermap.erase(it);
log->log(E_LOGLEVEL_4,"cAudio: Audio Decoder %s unloaded", extension.c_str());
}
Mutex.unlock();
}
@ -310,7 +323,7 @@ namespace cAudio
alcDestroyContext(Context);
//Close the device
alcCloseDevice(Device);
log->log(E_LOGLEVEL_4,"cAudio ShutDown");
Mutex.unlock();
RunThread = false;
}

35
Source/cLogger.cpp Normal file
View File

@ -0,0 +1,35 @@
#include "../Headers/cLogger.h"
namespace cAudio{
cLogger::cLogger()
{
Mutex.lock();
logLevel = E_LOGLEVEL_4;
Mutex.unlock();
}
cLogger::~cLogger()
{
Mutex.lock();
Mutex.unlock();
}
void cLogger::setLogLevel(E_LOGLEVEL level)
{
Mutex.lock();
logLevel = level;
Mutex.unlock();
}
void cLogger::log(E_LOGLEVEL loglevel,const char* text,...)
{
Mutex.lock();
if(logLevel <= loglevel){
std::cout<<text<<std::endl;
}
Mutex.unlock();
}
}

View File

@ -196,6 +196,10 @@
RelativePath=".\Headers\cListener.h"
>
</File>
<File
RelativePath=".\Headers\cLogger.h"
>
</File>
<File
RelativePath=".\Headers\cMemorySource.h"
>
@ -268,6 +272,10 @@
RelativePath=".\Source\cListener.cpp"
>
</File>
<File
RelativePath=".\Source\cLogger.cpp"
>
</File>
<File
RelativePath=".\Source\cMemorySource.cpp"
>
@ -344,6 +352,10 @@
RelativePath=".\include\IListener.h"
>
</File>
<File
RelativePath=".\include\ILogger.h"
>
</File>
</Filter>
<Filter
Name="Util"

View File

@ -13,6 +13,7 @@ namespace cAudio
class IAudioManager
{
public:
//!Inits the audio manager calling the alut/etc start ups
virtual void init(int argc,char* argv[]) = 0;
//!Shuts everything down
@ -52,7 +53,8 @@ namespace cAudio
virtual IAudioCapture* getAudioCapture() = 0;
virtual bool IsThreadRunning() = 0;
IAudioManager(){}
virtual ~IAudioManager() {}
protected:
private:

27
include/ILogger.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef ICAUDIOLOGGER_H_INCLUDED
#define ICAUDIOLOGGER_H_INCLUDED
#include <iostream>
#include <string>
namespace cAudio{
enum E_LOGLEVEL{
E_LOGLEVEL_1,
E_LOGLEVEL_2,
E_LOGLEVEL_3,
E_LOGLEVEL_4,
};
class ILogger{
public:
ILogger(){}
virtual ~ILogger(){}
virtual void setLogLevel(E_LOGLEVEL level) = 0;
virtual void log(E_LOGLEVEL loglevel,const char* text,...) = 0;
};
}
#endif