AMPS:Trace模块源码解读 (二)
int Trace_Init(void* r_pvAMPSContext, char* r_pchFileName, unsigned int r_unTraceLevel, unsigned int r_unTraceMode);
void Trace_Cleanup(void* r_pvAMPSContext);
int Trace_OpenFileForTracing(void* r_pvAMPSTrace, char* r_pchFileName);
void Trace_SetTraceForTraceID(void* r_pvAMPSContext, unsigned int r_unTraceID);
void Trace_ClearTraceForTraceID(void* r_pvAMPSContext, unsigned int r_unTraceID);
void Trace_SetTraceLevel(void* r_pvAMPSContext, unsigned int r_unTraceLevel);
void Trace_ClearTraceLevel(void* r_pvAMPSContext, unsigned int r_unTraceLevel);
void Trace_SetTraceMode(void* r_pvAMPSContext, unsigned int r_unTraceMode);
void Trace_ClearTraceMode(void* r_pvAMPSContext, unsigned int r_unTraceMode);
int Trace_GetTraceID(void* r_pvAMPSContext);
#ifdef __cplusplus
}
#endif
#endif /*#ifndef __HEADER_AMPS_TRACE_H__*/
AMPS_Trace.c
[cpp]
#include "AMPS_Defines.h"
#include "AMPS_LinkList.h"
#include "AMPS_SystemAPI.h"
#include "AMPS_Core.h"
#include "AMPS_MemMgt.h"
#include "AMPS_Trace.h"
#include "AMPS_Core.h"
#include "AMPS_API.h"
/*全局跟踪句柄*/
t_AMPSTrace* g_poAMPSTrace;
/*跟踪级别*/
char ppchTraceStr[5][20] =
{
"ERROR",
"WARNING",
"DEBUG",
"DEBUG_2",
"INFO"
};
/*****************************************************************
函数名称: Trace_Init
功能描述: 初始化跟踪模块,由AMPS核心模块初始函数Core_Init调用
入参::
void* r_pvAMPSContext AMPS应用上下文数据结构
char* r_pchFilePath 跟踪文件路径
char ppchTraceStr[5][20] =
{
"ERROR",
"WARNING",
"DEBUG",
"DEBUG_2",
"INFO"
};
unsigned int r_unTraceLevel 跟踪记录模式,取值为:
typedef enum
{
AMPS_TRACE_MODE_DISPLAY = 1,
AMPS_TRACE_MODE_FILE = 2,
AMPS_TRACE_MODE_BOTH = 3
}e_AMPSTraceMode;
出参:
--
返回值:
AMPS_SUCCESS: success
AMPS_ERROR_FAILURE: fail
*****************************************************************/
int Trace_Init(void* r_pvAMPSContext, char* r_pchFilePath, unsigned int r_unTraceLevel, unsigned int r_unTraceMode)
{
t_AMPSTrace* poAMPSTrace = NULL;
printf("Trace_Init : Entering %s with mode %d .\n", r_pchFilePath, r_unTraceMode);
poAMPSTrace = (t_AMPSTrace*)AMPS_InternalMalloc(sizeof(t_AMPSTrace));
if(NULL == poAMPSTrace)
{
printf("Trace_Init : AMPS_InternalMalloc failed.\n");
return AMPS_ERROR_FAILURE;
}
poAMPSTrace->pvAMPSContext = r_pvAMPSContext;
poAMPSTrace->unTraceLevel = r_unTraceLevel ;
poAMPSTrace->unModuleId = 0;
poAMPSTrace->unTraceMode = r_unTraceMode;
poAMPSTrace->nTraceID = 1;
memcpy(poAMPSTrace->pchTraceFilePath, r_pchFilePath, strlen(r_pchFilePath));
if((AMPS_TRACE_MODE_FILE == poAMPSTrace->unTraceMode) || (AMPS_TRACE_MODE_BOTH == poAMPSTrace->unTraceMode))
{
printf("Opening File from Init \n");
if(AMPS_SUCCE