lhtransmitterswitchapi.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #include "lhtransmitterswitchapi.h"
  2. #include <QLibrary>
  3. #include <QApplication>
  4. #include <QDebug>
  5. OnePlanItemInfo::OnePlanItemInfo()
  6. {
  7. ChannelID = -1;
  8. ChannelName = "";
  9. onWeekDay = enum_WeekDay::WeekDay_Mon;
  10. onDateTime = QDateTime::fromString("1970-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
  11. offWeekDay = enum_WeekDay::WeekDay_Mon;
  12. offDateTime = QDateTime::fromString("1970-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
  13. }
  14. OnePlanItemInfo::OnePlanItemInfo(const OnePlanItemInfo& item)
  15. {
  16. ChannelID = item.ChannelID;
  17. ChannelName = item.ChannelName;
  18. onWeekDay = item.onWeekDay;
  19. onDateTime = item.onDateTime;
  20. offWeekDay = item.offWeekDay;
  21. offDateTime = item.offDateTime;
  22. }
  23. OnePlanItemInfo& OnePlanItemInfo::operator=(const OnePlanItemInfo& item)
  24. {
  25. if(this == &item)
  26. return *this;
  27. ChannelID = item.ChannelID;
  28. ChannelName = item.ChannelName;
  29. onWeekDay = item.onWeekDay;
  30. onDateTime = item.onDateTime;
  31. offWeekDay = item.offWeekDay;
  32. offDateTime = item.offDateTime;
  33. return *this;
  34. }
  35. LHTransmitterSwitchAPI::LHTransmitterSwitchAPI()
  36. {
  37. }
  38. LHTransmitterSwitchAPI::~LHTransmitterSwitchAPI()
  39. {
  40. }
  41. /* 加载动态库 */
  42. bool LHTransmitterSwitchAPI::loadLibrary()
  43. {
  44. #ifdef Q_OS_WIN
  45. QString libPath = QApplication::applicationDirPath() + "/libLHTransmitterSwitch.dll";
  46. #elif defined(Q_OS_LINUX)
  47. QString libPath = QApplication::applicationDirPath() + "/libLHTransmitterSwitch.so";
  48. #endif
  49. QLibrary lib(libPath);
  50. if(!lib.load())
  51. {
  52. qDebug() << "load 《LHTransmitterSwitch》 library failed, path: " << libPath;
  53. return false;
  54. }
  55. m_pInit = (pInit)lib.resolve("DoInit");
  56. m_pCreateWindow = (pCreateWindow)lib.resolve("DoCreateWindow");
  57. m_pShowWindow = (pShowWindow)lib.resolve("DoShowWindow");
  58. m_pGetExecPlanFromEQM = (pGetExecPlanFromEQM)lib.resolve("DoGetExecPlanFromEQM");
  59. m_pSaveExecPlanToEQM = (pSaveExecPlanToEQM)lib.resolve("DoSaveExecPlanToEQM");
  60. m_pRelease = (pRelease)lib.resolve("DoRelease");
  61. m_pSetCallBack = (pSetCallBack)lib.resolve("DoSetCallBack");
  62. m_pSetUserPermission = (pSetUserPermission)lib.resolve("DoSetUserPermission");
  63. if(m_pInit == nullptr || m_pCreateWindow == nullptr || m_pShowWindow == nullptr ||
  64. m_pGetExecPlanFromEQM == nullptr || m_pSaveExecPlanToEQM == nullptr ||
  65. m_pRelease == nullptr || m_pSetCallBack == nullptr || m_pSetUserPermission == nullptr)
  66. {
  67. return false;
  68. }
  69. m_pDoInitLibrary = (pDoInitLibrary)lib.resolve("DoInitLibrary");
  70. m_pCreateOneWindow = (pCreateOneWindow)lib.resolve("DoCreateOneWindow");
  71. m_pSetWebAPIInfo = (pSetWebAPIInfo)lib.resolve("DoSetWebAPIInfo");
  72. m_pSetChannelInfo = (pSetChannelInfo)lib.resolve("DoSetChannelInfo");
  73. m_pSetOnePageCardNum = (pSetOnePageCardNum)lib.resolve("DoSetOnePageCardNum");
  74. m_pGetPlanData = (pGetPlanData)lib.resolve("DoGetPlanData");
  75. m_pSetPlanData = (pSetPlanData)lib.resolve("DoSetPlanData");
  76. m_pClearAll = (pClearAll)lib.resolve("DoClearAll");
  77. if( m_pDoInitLibrary == nullptr || m_pCreateOneWindow == nullptr ||
  78. m_pSetWebAPIInfo == nullptr || m_pSetChannelInfo == nullptr ||
  79. m_pSetOnePageCardNum == nullptr || m_pGetPlanData == nullptr ||
  80. m_pSetPlanData == nullptr || m_pClearAll == nullptr)
  81. {
  82. return false;
  83. }
  84. return true;
  85. }
  86. int LHTransmitterSwitchAPI::DoInit(const InitData* pData)
  87. {
  88. if(pData == nullptr)
  89. {
  90. return -1;
  91. }
  92. return m_pInit(pData);
  93. }
  94. int LHTransmitterSwitchAPI::DoCreateWindow(int skintype, QWidget* parent)
  95. {
  96. if(parent == nullptr)
  97. {
  98. return -1;
  99. }
  100. return m_pCreateWindow(skintype, parent);
  101. }
  102. int LHTransmitterSwitchAPI::DoShowWindow(int skintype, bool showWindow)
  103. {
  104. if(m_pShowWindow == nullptr)
  105. {
  106. return -1;
  107. }
  108. return m_pShowWindow(skintype, showWindow);
  109. }
  110. int LHTransmitterSwitchAPI::DoGetExecPlanFromEQM()
  111. {
  112. if(m_pGetExecPlanFromEQM == nullptr)
  113. {
  114. return -1;
  115. }
  116. return m_pGetExecPlanFromEQM();
  117. }
  118. int LHTransmitterSwitchAPI::DoSaveExecPlanToEQM()
  119. {
  120. if(m_pSaveExecPlanToEQM == nullptr)
  121. {
  122. return -1;
  123. }
  124. return m_pSaveExecPlanToEQM();
  125. }
  126. int LHTransmitterSwitchAPI::DoRelease()
  127. {
  128. if(m_pRelease == nullptr)
  129. {
  130. return -1;
  131. }
  132. return m_pRelease();
  133. }
  134. int LHTransmitterSwitchAPI::DoSetCallBack(trackCallBack cb)
  135. {
  136. if(cb == nullptr)
  137. {
  138. return -1;
  139. }
  140. return m_pSetCallBack(cb);
  141. }
  142. int LHTransmitterSwitchAPI::DoSetUserPermission(int userPermission)
  143. {
  144. if(m_pSetUserPermission == nullptr)
  145. {
  146. return -1;
  147. }
  148. return m_pSetUserPermission(userPermission);
  149. }
  150. int LHTransmitterSwitchAPI::DoInitLibrary()
  151. {
  152. if(m_pDoInitLibrary == nullptr)
  153. {
  154. return -1;
  155. }
  156. return m_pDoInitLibrary();
  157. }
  158. int LHTransmitterSwitchAPI::DoCreateOneWindow(int skintype, QWidget* parent)
  159. {
  160. if(parent == nullptr)
  161. {
  162. return -1;
  163. }
  164. return m_pCreateOneWindow(skintype, parent);
  165. }
  166. int LHTransmitterSwitchAPI::DoSetWebAPIInfo(InitData* pData)
  167. {
  168. if(pData == nullptr)
  169. {
  170. return -1;
  171. }
  172. return m_pSetWebAPIInfo(pData);
  173. }
  174. int LHTransmitterSwitchAPI::DoSetChannelInfo(ExecPlanInfo* info, bool useOnlineDB)
  175. {
  176. if(m_pSetChannelInfo == nullptr)
  177. {
  178. return -1;
  179. }
  180. return m_pSetChannelInfo(info, useOnlineDB);
  181. }
  182. int LHTransmitterSwitchAPI::DoSetOnePageCardNum(int horNum, int verNum)
  183. {
  184. if(m_pSetOnePageCardNum == nullptr)
  185. {
  186. return -1;
  187. }
  188. return m_pSetOnePageCardNum(horNum, verNum);
  189. }
  190. int LHTransmitterSwitchAPI::DoGetPlanData(QList<OnePlanItemInfo>* listPlan, ExecPlanConfig* config, int channelID)
  191. {
  192. if(m_pGetPlanData == nullptr)
  193. {
  194. return -1;
  195. }
  196. if(listPlan == nullptr)
  197. {
  198. return -1;
  199. }
  200. return m_pGetPlanData(listPlan, config, channelID);
  201. }
  202. int LHTransmitterSwitchAPI::DoSetPlanData(QList<OnePlanItemInfo>* listPlan, ExecPlanConfig* config, int channelID)
  203. {
  204. if(m_pSetPlanData == nullptr)
  205. {
  206. return -1;
  207. }
  208. return m_pSetPlanData(listPlan, config, channelID);
  209. }
  210. int LHTransmitterSwitchAPI::DoClearAll()
  211. {
  212. if(m_pClearAll == nullptr)
  213. {
  214. return -1;
  215. }
  216. return m_pClearAll();
  217. }