settingAPI.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "settingAPI.h"
  2. #include <QLibrary>
  3. #include <QCoreApplication>
  4. #include <QDebug>
  5. using funcInit = int (*)(const stInitData* pData);
  6. using funcCreateWindow = int (*)(int nSkinType, QWidget* parent);
  7. using funcShowWindow = int (*)(int nSkinType, int nServiceID, bool bShowWindow);
  8. using funcGetChangedData = int (*)(QString& data);
  9. using funcSave = int (*)(const int);
  10. using funcRelease = int (*)();
  11. funcInit g_pFuncInit = nullptr;
  12. funcCreateWindow g_pFuncCreateWindow = nullptr;
  13. funcShowWindow g_pFuncShowWindow = nullptr;
  14. funcGetChangedData g_pFuncGetChangedData = nullptr;
  15. funcSave g_pFuncSaveData = nullptr;
  16. funcRelease g_pFuncRelease = nullptr;
  17. bool g_isLoaded = false;
  18. /**
  19. * @brief 加载设置动态库
  20. *
  21. * @return true
  22. * @return false
  23. */
  24. bool loadSettingLibrary()
  25. {
  26. if(g_isLoaded)
  27. {
  28. return true; // 已经加载过
  29. }
  30. QString strLibPath = QCoreApplication::applicationDirPath() + "/libACAServerSetting.dll";
  31. QLibrary lib(strLibPath);
  32. if(!lib.load())
  33. {
  34. qWarning() << "Failed to load library:" << strLibPath << lib.errorString();
  35. return false;
  36. }
  37. g_pFuncInit = reinterpret_cast<funcInit>(lib.resolve("DoInit"));
  38. g_pFuncCreateWindow = reinterpret_cast<funcCreateWindow>(lib.resolve("DoCreateWindow"));
  39. g_pFuncShowWindow = reinterpret_cast<funcShowWindow>(lib.resolve("DoShowWindow"));
  40. g_pFuncGetChangedData = reinterpret_cast<funcGetChangedData>(lib.resolve("DoGetChangedData"));
  41. g_pFuncSaveData = reinterpret_cast<funcSave>(lib.resolve("DoSave"));
  42. g_pFuncRelease = reinterpret_cast<funcRelease>(lib.resolve("DoRelease"));
  43. if(!g_pFuncInit || !g_pFuncCreateWindow || !g_pFuncShowWindow || !g_pFuncGetChangedData || !g_pFuncSaveData || !g_pFuncRelease)
  44. {
  45. qWarning() << "Failed to resolve functions in library:" << strLibPath;
  46. return false;
  47. }
  48. g_isLoaded = true;
  49. qDebug() << "Library loaded successfully:" << strLibPath;
  50. return true;
  51. }
  52. int DoInit(const stInitData* pData)
  53. {
  54. if(g_pFuncInit == nullptr)
  55. {
  56. qDebug() << "Function DoInit is not resolved.";
  57. return -1; // 函数未解析
  58. }
  59. return g_pFuncInit(pData);
  60. }
  61. int DoCreateWindow(int nSkinType, QWidget* parent)
  62. {
  63. if(g_pFuncCreateWindow == nullptr)
  64. {
  65. qDebug() << "Function DoCreateWindow is not resolved.";
  66. return -1; // 函数未解析
  67. }
  68. return g_pFuncCreateWindow(nSkinType, parent);
  69. }
  70. int DoShowWindow(int nSkinType, int nServiceID, bool bShowWindow)
  71. {
  72. if(g_pFuncShowWindow == nullptr)
  73. {
  74. qDebug() << "Function DoShowWindow is not resolved.";
  75. return -1; // 函数未解析
  76. }
  77. return g_pFuncShowWindow(nSkinType, nServiceID, bShowWindow);
  78. }
  79. int DoGetChangedData(QString& strData)
  80. {
  81. if(g_pFuncGetChangedData == nullptr)
  82. {
  83. qDebug() << "Function DoGetChangedData is not resolved.";
  84. return -1; // 函数未解析
  85. }
  86. return g_pFuncGetChangedData(strData);
  87. }
  88. int DoSave(const int nServiceID)
  89. {
  90. if(g_pFuncSaveData == nullptr)
  91. {
  92. qDebug() << "Function DoSaveData is not resolved.";
  93. return -1; // 函数未解析
  94. }
  95. return g_pFuncSaveData(nServiceID);
  96. }
  97. int DoRelease()
  98. {
  99. if(g_pFuncRelease == nullptr)
  100. {
  101. qDebug() << "Function DoRelease is not resolved.";
  102. return -1; // 函数未解析
  103. }
  104. return g_pFuncRelease();
  105. }