singletonwork.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "singletonwork.h"
  2. QMutex singletonWork::m_Mutex;
  3. singletonWork* singletonWork::m_pInstance = nullptr;
  4. CLHQLogApi* singletonWork::m_pLHQLogApi = nullptr;
  5. lhhttpapi* singletonWork::m_pLhHttpAPI = nullptr;
  6. QString singletonWork::sm_ServerID = nullptr;
  7. QString singletonWork::sm_ServerDBID = nullptr;
  8. QString singletonWork::sm_ServerUrl = nullptr;
  9. QString singletonWork::sm_ServerToken = nullptr;
  10. singletonWork::singletonWork()
  11. {
  12. if(m_pLHQLogApi == nullptr)
  13. {
  14. m_pLHQLogApi = new CLHQLogApi();
  15. #ifdef WIN32
  16. #ifdef QT_NO_DEBUG
  17. QString strDllPath ="LHQLog.dll";
  18. #else
  19. QString strDllPath = "LHQLogd.dll";
  20. #endif
  21. #else
  22. QString strDllPath = QDir::current().path()+"/LHQLog.so";
  23. #endif
  24. bool isSuccess = m_pLHQLogApi->Load(strDllPath);
  25. qDebug() << (isSuccess?"加载成功13:":"缺少文件:") << strDllPath;
  26. m_pLHQLogApi->DoInitial("CAS_Dante_Driver");
  27. }
  28. if(m_pLhHttpAPI == nullptr)
  29. {
  30. qDebug() << "Load LHSqlWebInterface.dll begin";
  31. m_pLhHttpAPI = new lhhttpapi();
  32. #ifdef WIN32
  33. #ifdef QT_NO_DEBUG
  34. QString strDllPath = "LHSqlWebInterface.dll";
  35. #else
  36. QString strDllPath = "LHSqlWebInterfaced.dll";
  37. #endif
  38. #else
  39. QString strDllPath = QDir::current().path()+"/LHSqlWebInterface.so";
  40. #endif
  41. bool isSuccess = m_pLhHttpAPI->Load(strDllPath);
  42. qDebug() << (isSuccess?"加载成功12:":"缺少文件:") << strDllPath;
  43. }
  44. }
  45. singletonWork::~singletonWork()
  46. {
  47. if(m_pLHQLogApi != nullptr)
  48. {
  49. delete m_pLHQLogApi;
  50. m_pLHQLogApi = nullptr;
  51. }
  52. if(m_pLhHttpAPI != nullptr)
  53. {
  54. delete m_pLhHttpAPI;
  55. m_pLhHttpAPI = nullptr;
  56. }
  57. if(m_pInstance != nullptr)
  58. {
  59. delete m_pInstance;
  60. m_pInstance = nullptr;
  61. }
  62. }
  63. void singletonWork::SetServerID(QString strserid)
  64. {
  65. sm_ServerID = strserid;
  66. }
  67. void singletonWork::SetServerDBID(QString strserdbid)
  68. {
  69. sm_ServerDBID = strserdbid;
  70. }
  71. void singletonWork::SetServerUrl(QString strserurl)
  72. {
  73. sm_ServerUrl = strserurl;
  74. }
  75. void singletonWork::SetServerToken(QString strsertoken)
  76. {
  77. sm_ServerToken = strsertoken;
  78. }
  79. QString singletonWork::GetServerID()
  80. {
  81. return sm_ServerID;
  82. }
  83. QString singletonWork::GetServerDBID()
  84. {
  85. return sm_ServerDBID;
  86. }
  87. QString singletonWork::GetServerUrl()
  88. {
  89. return sm_ServerUrl;
  90. }
  91. QString singletonWork::GetServerToken()
  92. {
  93. return sm_ServerToken;
  94. }
  95. CLHQLogApi *singletonWork::LHQLogAPI()
  96. {
  97. return m_pLHQLogApi;
  98. }
  99. lhhttpapi *singletonWork::LhHttpAPI()
  100. {
  101. return m_pLhHttpAPI;
  102. }
  103. singletonWork *singletonWork::instance()
  104. {
  105. //单例对象
  106. if (m_pInstance== nullptr)
  107. {
  108. QMutexLocker mutexLocker(&m_Mutex);
  109. if (m_pInstance == nullptr)
  110. {
  111. m_pInstance = new singletonWork();
  112. }
  113. }
  114. return m_pInstance;
  115. }