DriverManager.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #pragma once
  2. #include <map>
  3. #include "DPC.h"
  4. //#include "SysIF.h"
  5. //#include "ebus.h"
  6. //#include "logger.h"
  7. #include "CcosLock.h"
  8. #include "MsgVector.h"
  9. #include "DevTree.h"
  10. #include "LogicDriver.h"
  11. //#include "MultiDPC.h"
  12. #include "DriverThread.h"
  13. #include "Notify_Thread.h"
  14. using namespace std;
  15. class DriverHandle
  16. {
  17. bool m_IsRootHandle;//is the first?
  18. bool m_HandleStatus;
  19. void* m_DllFileHandle;
  20. DevTree *m_pRootDevice;
  21. DevTree *m_pDynRootDevice;
  22. //MultiDPC *m_pParent;
  23. //DriverDPC *m_pDPC;
  24. LogicDriver *m_pDPC;
  25. bool m_bCommonDPC;
  26. Notify_Thread m_NotifyThread;
  27. //map<Notify_Thread*, LogicDriver*> m_NotifyThreadMap;
  28. ResDataObject m_Probe;
  29. ResDataObject m_DynProbe;
  30. ResDataObject m_Connection;
  31. ResDataObject m_DrvConfig;
  32. string m_DriverConfigFilePath;
  33. string m_DllFileTitle;
  34. string m_DynWorkPath;
  35. string m_DynLogPath;
  36. string m_WorkPath;
  37. string m_LogPath;
  38. //Logger *m_pLog;
  39. //Logger *m_pDynLog;
  40. //Thread_Base *m_pNotifyThread;
  41. MsgVector<DriverHandle*> m_hSubDriverList; //子驱动列表
  42. MsgVector<DriverHandle*> m_DynSubDriverList; //动态驱动列表
  43. map<string, LogicDevice*> m_RootDeviceMap; //DevShortPath : LogicDevice 逻辑设备映射string 设备路径
  44. map<string, LogicDevice*> m_DynRootDeviceMap; //DevShortPath : LogicDevice 动态逻辑设备映射 设备路径
  45. //map<UINT64, ServerSysIF*> m_AddressMap;// DeviceSysIF : RealSysIF 64位数字地址和SysIF指针的 映射
  46. //map<UINT64, ServerSysIF*> m_DynAddressMap;// DeviceSysIF : RealSysIF 64位数字地址和动态地址指针的 映射
  47. //map<Dual_Driver_Thread*, vector<UINT64>> m_ThreadMap;// thread : DeviceSysIF[]
  48. //map<Dual_Driver_Thread*, vector<UINT64>> m_DynThreadMap;// thread : DeviceSysIF[]
  49. void MakeShortPaths(string stackpath, DevTree *pDevTree, map<string, vector<LogicDevice*>> &ShortpathMap);
  50. bool MakeDevicePaths();//with m_pRootDevice
  51. bool DynMakeDevicePaths();//with m_pDynRootDevice
  52. bool MakeDriverPaths();//do nothing
  53. bool DynMakeDriverPaths();
  54. bool MakeDeviceSysIFsAndThreads();
  55. bool DynMakeDeviceSysIFsAndThreads();
  56. bool MakeDriverSysIFsAndThreads();
  57. bool DynMakeDriverSysIFsAndThreads();
  58. void InitLogForDPC(DriverHandle *pParent);
  59. void InitDynLogForDPC(DriverHandle *pParent);
  60. public:
  61. DriverHandle();
  62. virtual ~DriverHandle();
  63. bool m_AsRootDriver;
  64. LogicDriver* GetDpcDriver() { return m_pDPC; }
  65. string m_DriverFullPathMap; //driver fulldevpath
  66. map<string, UINT64> m_DeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
  67. map<string, UINT64> m_DynDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
  68. map<string, UINT64> m_CcosDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
  69. map<string, UINT64> m_CcosDynDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
  70. //Process:x64,x32
  71. //StartType:ignore
  72. //LoadType:module, or new
  73. //drvtype:lead,standalone,subsystem,device
  74. //driver:dpcpath
  75. //entrysource:xxx(it must load to memory)
  76. //connection:connections
  77. bool LoadDriver(ResDataObject &config);
  78. bool LoadDriver(const char *pConfigFilepath, bool bCommDPC);
  79. //bool LoadDPC(MultiDPC *pParent, DriverDPC *pDriver, ResDataObject &config);
  80. bool UnloadDriver();
  81. //bool CallUnloadDriver_forMDPC();
  82. //after connect succeed,mainT call into this
  83. bool LoadDynDriver();
  84. //before disconnect,main T call into this,and call disconnect
  85. bool UnloadDynDriver();
  86. bool DynInitHandle(DriverHandle *pSubHandle, LogicDriver*pDPC);
  87. bool InitHandle(DriverHandle *Handle, LogicDriver*pDPC);
  88. bool InitSubDriverObject();
  89. bool InitDynSubDriverObject();
  90. void RegistToDrvObject(bool dyn = true, bool regist = true);//regist or unregist devices to drvobject
  91. bool DynRegistToRoot(const char* RootPath, DWORD timeout = INFINITE);
  92. bool RegistToRoot(const char* RootPath,DWORD timeout = INFINITE);
  93. bool DynUnRegistFromRoot();
  94. bool UnRegistFromRoot();
  95. void CompleteStaticInit(bool Init);
  96. void CompleteDynInit(bool Init);
  97. bool StartWork();
  98. void StopWork();
  99. bool DynStartWork();
  100. void DynStopWork();
  101. bool InitLoadDynDriver();
  102. bool ClearDriverHandles();
  103. bool DynClearDriverHandles();
  104. bool GetThreadsLogger(DWORD ThreadId, PVOID &pLogger);
  105. void GetSysIFList(vector<UINT64> &ifList);
  106. void DynGetSysIFList(vector<UINT64> &ifList);
  107. bool IsDPCMatch(LogicDriver*pDriver);
  108. bool IsMDPCHANDLE();
  109. };
  110. class DriverManager : public CcosLock
  111. {
  112. friend class DriverHandle;
  113. DriverHandle* m_pRootDrvHandle;
  114. vector<DriverHandle*> m_SubDriverList;
  115. //map<UINT64, ServerSysIF*> m_AddressMap;// DeviceSysIF : RealSysIF
  116. void DynAddDriver(DriverHandle *pDrv);
  117. void AddDriver(DriverHandle *pDrv);
  118. //void UpdateSysIF(vector<UINT64> &SysIFList, bool del = false);
  119. void AddDevice(const char* devUri, LogicDevice* pDevice);
  120. std::map<string, LogicDevice*> m_CcosDeviceMap;
  121. string m_strAllDeviceUri;
  122. public:
  123. DriverManager();
  124. virtual ~DriverManager();
  125. bool LoadRootDrv();
  126. bool UnRegistFromChannel(DWORD timeout = 2000);
  127. bool DynLoadDriver(DriverHandle *pDrv);
  128. bool DynDriverInitLoadAll();
  129. bool LoadDrv(ResDataObject &ConfigContext);
  130. bool LoadDriver(const char *pConfigFilepath);
  131. //bool LoadDPC(MultiDPC *pParent, DriverDPC *pDriver, ResDataObject &config);
  132. //bool UnLoadDPC(MultiDPC *pParent, DriverDPC *pDriver);
  133. const char* GetAllDevice(void** pDevices, int& nDevNums);
  134. void UnloadDrivers();
  135. void UnloadRootDriver();
  136. bool GetThreadsLogger(DWORD Tid, PVOID &pLogger);
  137. bool UpdateRootDrvStatus(int Status);
  138. //int RequestToDevice(ResDataObject &Req, UINT64 pServerSysIF);
  139. bool UnloadDynDrvHandle(DriverHandle *pHandle);
  140. bool UnloadDrvHandle(DriverHandle *pHandle);
  141. };
  142. extern DriverManager g_DrvManager;
  143. /*
  144. class DPC_Driver_Thread : public Driver_Thread
  145. {
  146. DriverHandle *m_pDrvHandle;
  147. DWORD m_TimeOut;
  148. bool m_FirstHeart;
  149. bool m_FirstAction;
  150. public:
  151. DPC_Driver_Thread(void);
  152. virtual ~DPC_Driver_Thread(void);
  153. void InitDPCDriverThread(DriverHandle *pHandle);
  154. protected:
  155. virtual bool Exec();
  156. bool HandleConnectionReq(LogicDriver *pDrv);
  157. bool HandleDisConnectionReq(LogicDriver *pDrv);
  158. bool HandleAutomaticConnection(int Idx);
  159. int GetTimeoutConnectionIndex(DWORD &NextTimeout);
  160. DWORD GetDriverHeartBeatTimePeriod();
  161. bool HandleClientRequestEx();
  162. int WaitForInQueEx(DWORD Timeout);
  163. bool CleanupPassiveDisconnect(int DrvIdx);
  164. void FirstAction();
  165. };
  166. */
  167. /*
  168. class MDPC_Driver_Thread : public Driver_Thread
  169. {
  170. DriverHandle *m_pDrvHandle;
  171. DWORD m_TimeOut;
  172. bool m_FirstHeart;
  173. bool m_FirstAction;
  174. public:
  175. MDPC_Driver_Thread(void);
  176. virtual ~MDPC_Driver_Thread(void);
  177. void InitDPCDriverThread(DriverHandle *pHandle);
  178. protected:
  179. virtual bool Exec();
  180. bool HandleConnectionReq(LogicDriver *pDrv);
  181. bool HandleDisConnectionReq(LogicDriver *pDrv);
  182. bool HandleAutomaticConnection(int Idx);
  183. int GetTimeoutConnectionIndex(DWORD &NextTimeout);
  184. DWORD GetDriverHeartBeatTimePeriod();
  185. bool HandleClientRequestEx();
  186. bool SubDPCConnection(bool Connect, LogicDriver *pDrv);
  187. int WaitForInQueEx(DWORD Timeout);
  188. bool CleanupPassiveDisconnect(int DrvIdx);
  189. void FirstAction();
  190. };*/