| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMLOG_H_ |
| 28 |
#define MEDIADRIVER_AGNOSTIC_COMMON_CM_CMLOG_H_ |
| 29 |
|
| 30 |
#include <fstream> |
| 31 |
#include <ostream> |
| 32 |
#include <string> |
| 33 |
#include <sstream> |
| 34 |
|
| 35 |
#include "cm_hal.h" |
| 36 |
|
| 37 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 38 |
#define CM_LOG_ON 1 |
| 39 |
#endif |
| 40 |
|
| 41 |
#if !(CM_LOG_ON) |
| 42 |
#define INSERT_API_CALL_LOG(halState) |
| 43 |
#define TASK_LOG(_pTask) |
| 44 |
#define DEVICE_LOG(_pDev) |
| 45 |
#define EVENT_LOG(_pEvt) |
| 46 |
|
| 47 |
#else |
| 48 |
|
| 49 |
#include "cm_perf.h" |
| 50 |
|
| 51 |
typedef enum _CM_LOG_LEVEL{ |
| 52 |
CM_LOG_LEVEL_NONE = 0, |
| 53 |
CM_LOG_LEVEL_ERROR = 1, |
| 54 |
CM_LOG_LEVEL_WARN = 2, |
| 55 |
CM_LOG_LEVEL_DEBUG = 3, |
| 56 |
CM_LOG_LEVEL_INFO = 4 |
| 57 |
}CM_LOG_LEVEL; |
| 58 |
|
| 59 |
#define _CM_LOG(priority, msg, halState) \ |
| 60 |
CmLogPrint(priority, msg, halState) |
| 61 |
|
| 62 |
#define CM_DEBUG(msg, halState) _CM_LOG(CM_LOG_LEVEL_DEBUG, msg, halState) |
| 63 |
#define INSERT_API_CALL_LOG(halState) CmLogTimer _LogTimer(__FUNCTION__, halState) |
| 64 |
#define TASK_LOG(_pTask) CM_DEBUG(_pTask->Log(), _pTask->GetHalState()); |
| 65 |
#define DEVICE_LOG(_pDev) CM_DEBUG(_pDev->Log(), _pDev->GetHalState()); |
| 66 |
#define EVENT_LOG(_pEvt) CM_DEBUG(_pEvt->Log(__FUNCTION__), _pEvt->GetHalState()); |
| 67 |
|
| 68 |
class CmLogger |
| 69 |
{ |
| 70 |
public: |
| 71 |
static CmLogger* GetInstance(CM_HAL_STATE *halState); |
| 72 |
|
| 73 |
static void LogDataArrayHex(std::ostringstream &oss, |
| 74 |
unsigned char *data, |
| 75 |
unsigned int size); |
| 76 |
|
| 77 |
virtual void Print(const unsigned int verbosityLevel, |
| 78 |
const std::string &sourceFile, |
| 79 |
const int codeLine, |
| 80 |
const std::string &message); |
| 81 |
|
| 82 |
private: |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
std::string m_logFile; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
std::ofstream m_streamOut; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
unsigned int m_verbosityLevel; |
| 98 |
|
| 99 |
CmLogger(CM_HAL_STATE *halState); |
| 100 |
|
| 101 |
~CmLogger(); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
inline static void Lock(); |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
inline static void Unlock(); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
void GetVerbosityLevel(CM_HAL_STATE *halState); |
| 117 |
}; |
| 118 |
|
| 119 |
inline void CmLogPrint(CM_LOG_LEVEL priority, std::string msg, CM_HAL_STATE *halState) |
| 120 |
{ |
| 121 |
std::ostringstream __debug_stream__; |
| 122 |
__debug_stream__ << msg; |
| 123 |
CmLogger* logTmp = CmLogger::GetInstance(halState); |
| 124 |
if (logTmp != nullptr) |
| 125 |
{ |
| 126 |
logTmp->Print(priority, __FILE__, __LINE__, |
| 127 |
__debug_stream__.str()); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
class CmLogTimer |
| 132 |
{ |
| 133 |
|
| 134 |
public: |
| 135 |
CmLogTimer(const std::string &str, CM_HAL_STATE *halState) |
| 136 |
: m_string(str), |
| 137 |
m_timer(str), |
| 138 |
m_halState(halState) {} |
| 139 |
|
| 140 |
~CmLogTimer() |
| 141 |
{ |
| 142 |
m_timer.Stop(); |
| 143 |
m_string = m_timer.ToString(); |
| 144 |
_CM_LOG(CM_LOG_LEVEL_INFO, m_string, m_halState); |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
void Stop() |
| 149 |
{ |
| 150 |
m_timer.Stop(); |
| 151 |
} |
| 152 |
|
| 153 |
private: |
| 154 |
std::string m_string; |
| 155 |
|
| 156 |
CmTimer m_timer; |
| 157 |
|
| 158 |
CM_HAL_STATE *m_halState; |
| 159 |
}; |
| 160 |
|
| 161 |
#endif |
| 162 |
|
| 163 |
#endif |