DriverManager.h 6.8 KB

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