| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // CkLog.cpp: implementation of the CkLog class.
- #include "CkLog.h"
- #if defined(CKLOG)
- extern CTraceManager *pLOG;
- #endif
- //获取完整路径中的文件名称
- std::string GetFileName(char* pstrFullPath)
- {
- std::string strRet = "";
- if(nullptr == pstrFullPath) return strRet;
- char* pLastSlash = strrchr(pstrFullPath, '/'); //find last slash
- if(nullptr == pLastSlash)
- strRet = pstrFullPath;
- else
- strRet = pLastSlash + 1;
- return strRet;
- }
- bool GetCurModulePath(char* pstrLibPath, char* pstrLibName)
- {
- Dl_info path_info;
- char sPath[256];
- memset(sPath, 0x00, sizeof(sPath));
- dladdr((void*)GetCurModulePath, &path_info); //根据内存空间所在地址 获取当前模块完整路径
- strcpy(sPath, path_info.dli_fname);
- char *pLastSlash=strrchr(sPath, '/'); //find last slash
- if(nullptr != pLastSlash)
- {
- *pLastSlash=0;
- if(nullptr != pstrLibPath)
- strcpy(pstrLibPath, sPath);
- if(nullptr != pstrLibName)
- strcpy(pstrLibName, pLastSlash + 1);
- return true;
- }
- return false;
- }
- //加载SO
- void* LoadSO(char* pstrSOName)
- {
- void* pSO = nullptr;
- char sPath[256];
- char sFullPath[256];
- memset(sPath, 0x00, sizeof(sPath));
- memset(sFullPath, 0x00, sizeof(sFullPath));
- bool bRet = GetCurModulePath(sPath, nullptr);
- if(bRet)
- {
- sprintf(sFullPath, "%s/%s", sPath, pstrSOName); //拼出so完整路径
- pSO = dlopen(sFullPath, RTLD_LAZY); //RTLD_NOW
- if (nullptr == pSO)
- printf("LoadSO()->dlopen(%s, RTLD_LAZY) fail, dlerror=[%s]", sFullPath, dlerror());
- else
- printf("LoadSO()->dlopen(%s, RTLD_LAZY) OK!!!", sFullPath);
- }
- return pSO;
- }
- void* GetPtr(void* pVoid)
- {
- void* ptrTmp = pVoid;
- return ptrTmp;
- }
- bool CkLog_FuncTracer::m_bCkLogExtendInf = false;
- //==> Enter {GetEncryptFunc}, file: {PinPadClassImpl_ZT598M.cpp}, line: {1001}.
- //根据整型变量占空间的大小判断类型
- CkLog_FuncTracer::CkLog_FuncTracer(const char* pszFunc, const char* pszFile, int nLine, void* pfRet, int iSize)
- {
- memset(m_pszFunc, 0x00, sizeof(m_pszFunc));
- memset(m_pszFile, 0x00, sizeof(m_pszFile));
- snprintf(m_pszFunc,sizeof(m_pszFunc), "%s", pszFunc);
- snprintf(m_pszFile,sizeof(m_pszFile), "%s", pszFile);
- m_nLine = nLine;
- m_psfRet = nullptr; //INT16
- m_pifRet = nullptr; //INT32
- m_plfRet = nullptr; //INT64
- if(sizeof(short) == iSize)
- m_psfRet =(short*)pfRet;
- else if(sizeof(int) == iSize)
- m_pifRet =(int*)pfRet;
- else if(sizeof(long) == iSize)
- m_plfRet =(long*)pfRet;
- #if defined(CKLOG)
- pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "==> Enter {%s}, file: {%s}, line: {%d}.", m_pszFunc, m_pszFile, m_nLine);
- #endif
- }
- //<== Leave {DevOpen}, file: {PinPadClassImpl_ZT598M.cpp}, line: {171}.
- CkLog_FuncTracer::~CkLog_FuncTracer()
- {
- #if defined(CKLOG)
- if(nullptr != m_psfRet)
- pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d} , short RetCode=[%d].", m_pszFunc, m_pszFile, m_nLine, *m_psfRet);
- else if(nullptr != m_pifRet)
- pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d} , int RetCode=[%d].", m_pszFunc, m_pszFile, m_nLine, *m_pifRet);
- else if(nullptr != m_plfRet)
- pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d} , long RetCode=[%ld].", m_pszFunc, m_pszFile, m_nLine, *m_plfRet);
- else
- pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d}.", m_pszFunc, m_pszFile, m_nLine);
- #endif
- }
|