CkLog.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // CkLog.cpp: implementation of the CkLog class.
  2. #include "CkLog.h"
  3. #if defined(CKLOG)
  4. extern CTraceManager *pLOG;
  5. #endif
  6. //获取完整路径中的文件名称
  7. std::string GetFileName(char* pstrFullPath)
  8. {
  9. std::string strRet = "";
  10. if(nullptr == pstrFullPath) return strRet;
  11. char* pLastSlash = strrchr(pstrFullPath, '/'); //find last slash
  12. if(nullptr == pLastSlash)
  13. strRet = pstrFullPath;
  14. else
  15. strRet = pLastSlash + 1;
  16. return strRet;
  17. }
  18. bool GetCurModulePath(char* pstrLibPath, char* pstrLibName)
  19. {
  20. Dl_info path_info;
  21. char sPath[256];
  22. memset(sPath, 0x00, sizeof(sPath));
  23. dladdr((void*)GetCurModulePath, &path_info); //根据内存空间所在地址 获取当前模块完整路径
  24. strcpy(sPath, path_info.dli_fname);
  25. char *pLastSlash=strrchr(sPath, '/'); //find last slash
  26. if(nullptr != pLastSlash)
  27. {
  28. *pLastSlash=0;
  29. if(nullptr != pstrLibPath)
  30. strcpy(pstrLibPath, sPath);
  31. if(nullptr != pstrLibName)
  32. strcpy(pstrLibName, pLastSlash + 1);
  33. return true;
  34. }
  35. return false;
  36. }
  37. //加载SO
  38. void* LoadSO(char* pstrSOName)
  39. {
  40. void* pSO = nullptr;
  41. char sPath[256];
  42. char sFullPath[256];
  43. memset(sPath, 0x00, sizeof(sPath));
  44. memset(sFullPath, 0x00, sizeof(sFullPath));
  45. bool bRet = GetCurModulePath(sPath, nullptr);
  46. if(bRet)
  47. {
  48. sprintf(sFullPath, "%s/%s", sPath, pstrSOName); //拼出so完整路径
  49. pSO = dlopen(sFullPath, RTLD_LAZY); //RTLD_NOW
  50. if (nullptr == pSO)
  51. printf("LoadSO()->dlopen(%s, RTLD_LAZY) fail, dlerror=[%s]", sFullPath, dlerror());
  52. else
  53. printf("LoadSO()->dlopen(%s, RTLD_LAZY) OK!!!", sFullPath);
  54. }
  55. return pSO;
  56. }
  57. void* GetPtr(void* pVoid)
  58. {
  59. void* ptrTmp = pVoid;
  60. return ptrTmp;
  61. }
  62. bool CkLog_FuncTracer::m_bCkLogExtendInf = false;
  63. //==> Enter {GetEncryptFunc}, file: {PinPadClassImpl_ZT598M.cpp}, line: {1001}.
  64. //根据整型变量占空间的大小判断类型
  65. CkLog_FuncTracer::CkLog_FuncTracer(const char* pszFunc, const char* pszFile, int nLine, void* pfRet, int iSize)
  66. {
  67. memset(m_pszFunc, 0x00, sizeof(m_pszFunc));
  68. memset(m_pszFile, 0x00, sizeof(m_pszFile));
  69. snprintf(m_pszFunc,sizeof(m_pszFunc), "%s", pszFunc);
  70. snprintf(m_pszFile,sizeof(m_pszFile), "%s", pszFile);
  71. m_nLine = nLine;
  72. m_psfRet = nullptr; //INT16
  73. m_pifRet = nullptr; //INT32
  74. m_plfRet = nullptr; //INT64
  75. if(sizeof(short) == iSize)
  76. m_psfRet =(short*)pfRet;
  77. else if(sizeof(int) == iSize)
  78. m_pifRet =(int*)pfRet;
  79. else if(sizeof(long) == iSize)
  80. m_plfRet =(long*)pfRet;
  81. #if defined(CKLOG)
  82. pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "==> Enter {%s}, file: {%s}, line: {%d}.", m_pszFunc, m_pszFile, m_nLine);
  83. #endif
  84. }
  85. //<== Leave {DevOpen}, file: {PinPadClassImpl_ZT598M.cpp}, line: {171}.
  86. CkLog_FuncTracer::~CkLog_FuncTracer()
  87. {
  88. #if defined(CKLOG)
  89. if(nullptr != m_psfRet)
  90. pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d} , short RetCode=[%d].", m_pszFunc, m_pszFile, m_nLine, *m_psfRet);
  91. else if(nullptr != m_pifRet)
  92. pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d} , int RetCode=[%d].", m_pszFunc, m_pszFile, m_nLine, *m_pifRet);
  93. else if(nullptr != m_plfRet)
  94. pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d} , long RetCode=[%ld].", m_pszFunc, m_pszFile, m_nLine, *m_plfRet);
  95. else
  96. pLOG->TraceInFormat(TRM_INT, TRM_LV_COMMN, "<== Leave {%s}, file: {%s}, line: {%d}.", m_pszFunc, m_pszFile, m_nLine);
  97. #endif
  98. }