#pragma once #include #include "DPC.h" //#include "SysIF.h" //#include "ebus.h" //#include "logger.h" #include "CcosLock.h" #include "MsgVector.h" #include "DevTree.h" #include "LogicDriver.h" //#include "MultiDPC.h" #include "DriverThread.h" #include "Notify_Thread.h" using namespace std; class DriverHandle { bool m_IsRootHandle;//is the first? bool m_HandleStatus; void* m_DllFileHandle; DevTree *m_pRootDevice; DevTree *m_pDynRootDevice; //MultiDPC *m_pParent; //DriverDPC *m_pDPC; LogicDriver *m_pDPC; bool m_bCommonDPC; Notify_Thread m_NotifyThread; //map m_NotifyThreadMap; ResDataObject m_Probe; ResDataObject m_DynProbe; ResDataObject m_Connection; ResDataObject m_DrvConfig; string m_DriverConfigFilePath; string m_DllFileTitle; string m_DynWorkPath; string m_DynLogPath; string m_WorkPath; string m_LogPath; //Logger *m_pLog; //Logger *m_pDynLog; //Thread_Base *m_pNotifyThread; MsgVector m_hSubDriverList; //子驱动列表 MsgVector m_DynSubDriverList; //动态驱动列表 map m_RootDeviceMap; //DevShortPath : LogicDevice 逻辑设备映射string 设备路径 map m_DynRootDeviceMap; //DevShortPath : LogicDevice 动态逻辑设备映射 设备路径 //map m_AddressMap;// DeviceSysIF : RealSysIF 64位数字地址和SysIF指针的 映射 //map m_DynAddressMap;// DeviceSysIF : RealSysIF 64位数字地址和动态地址指针的 映射 //map> m_ThreadMap;// thread : DeviceSysIF[] //map> m_DynThreadMap;// thread : DeviceSysIF[] void MakeShortPaths(string stackpath, DevTree *pDevTree, map> &ShortpathMap); bool MakeDevicePaths();//with m_pRootDevice bool DynMakeDevicePaths();//with m_pDynRootDevice bool MakeDriverPaths();//do nothing bool DynMakeDriverPaths(); bool MakeDeviceSysIFsAndThreads(); bool DynMakeDeviceSysIFsAndThreads(); bool MakeDriverSysIFsAndThreads(); bool DynMakeDriverSysIFsAndThreads(); void InitLogForDPC(DriverHandle *pParent); void InitDynLogForDPC(DriverHandle *pParent); public: DriverHandle(); virtual ~DriverHandle(); bool m_AsRootDriver; LogicDriver* GetDpcDriver() { return m_pDPC; } string m_DriverFullPathMap; //driver fulldevpath map m_DeviceFullPathMap; //fulldevpath : LogicDeviceSysIF map m_DynDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF map m_CcosDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF map m_CcosDynDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF //Process:x64,x32 //StartType:ignore //LoadType:module, or new //drvtype:lead,standalone,subsystem,device //driver:dpcpath //entrysource:xxx(it must load to memory) //connection:connections bool LoadDriver(ResDataObject &config); bool LoadDriver(const char *pConfigFilepath, bool bCommDPC); //bool LoadDPC(MultiDPC *pParent, DriverDPC *pDriver, ResDataObject &config); bool UnloadDriver(); //bool CallUnloadDriver_forMDPC(); //after connect succeed,mainT call into this bool LoadDynDriver(); //before disconnect,main T call into this,and call disconnect bool UnloadDynDriver(); bool DynInitHandle(DriverHandle *pSubHandle, LogicDriver*pDPC); bool InitHandle(DriverHandle *Handle, LogicDriver*pDPC); bool InitSubDriverObject(); bool InitDynSubDriverObject(); void RegistToDrvObject(bool dyn = true, bool regist = true);//regist or unregist devices to drvobject bool DynRegistToRoot(const char* RootPath, DWORD timeout = INFINITE); bool RegistToRoot(const char* RootPath,DWORD timeout = INFINITE); bool DynUnRegistFromRoot(); bool UnRegistFromRoot(); void CompleteStaticInit(bool Init); void CompleteDynInit(bool Init); bool StartWork(); void StopWork(); bool DynStartWork(); void DynStopWork(); bool InitLoadDynDriver(); bool ClearDriverHandles(); bool DynClearDriverHandles(); bool GetThreadsLogger(DWORD ThreadId, PVOID &pLogger); void GetSysIFList(vector &ifList); void DynGetSysIFList(vector &ifList); bool IsDPCMatch(LogicDriver*pDriver); bool IsMDPCHANDLE(); }; class DriverManager : public CcosLock { friend class DriverHandle; DriverHandle* m_pRootDrvHandle; vector m_SubDriverList; //map m_AddressMap;// DeviceSysIF : RealSysIF void DynAddDriver(DriverHandle *pDrv); void AddDriver(DriverHandle *pDrv); //void UpdateSysIF(vector &SysIFList, bool del = false); void AddDevice(const char* devUri, LogicDevice* pDevice); std::map m_CcosDeviceMap; string m_strAllDeviceUri; public: DriverManager(); virtual ~DriverManager(); bool LoadRootDrv(); bool UnRegistFromChannel(DWORD timeout = 2000); bool DynLoadDriver(DriverHandle *pDrv); bool DynDriverInitLoadAll(); bool LoadDrv(ResDataObject &ConfigContext); bool LoadDriver(const char *pConfigFilepath); //bool LoadDPC(MultiDPC *pParent, DriverDPC *pDriver, ResDataObject &config); //bool UnLoadDPC(MultiDPC *pParent, DriverDPC *pDriver); const char* GetAllDevice(void** pDevices, int& nDevNums); void UnloadDrivers(); void UnloadRootDriver(); bool GetThreadsLogger(DWORD Tid, PVOID &pLogger); bool UpdateRootDrvStatus(int Status); //int RequestToDevice(ResDataObject &Req, UINT64 pServerSysIF); bool UnloadDynDrvHandle(DriverHandle *pHandle); bool UnloadDrvHandle(DriverHandle *pHandle); }; extern DriverManager g_DrvManager; /* class DPC_Driver_Thread : public Driver_Thread { DriverHandle *m_pDrvHandle; DWORD m_TimeOut; bool m_FirstHeart; bool m_FirstAction; public: DPC_Driver_Thread(void); virtual ~DPC_Driver_Thread(void); void InitDPCDriverThread(DriverHandle *pHandle); protected: virtual bool Exec(); bool HandleConnectionReq(LogicDriver *pDrv); bool HandleDisConnectionReq(LogicDriver *pDrv); bool HandleAutomaticConnection(int Idx); int GetTimeoutConnectionIndex(DWORD &NextTimeout); DWORD GetDriverHeartBeatTimePeriod(); bool HandleClientRequestEx(); int WaitForInQueEx(DWORD Timeout); bool CleanupPassiveDisconnect(int DrvIdx); void FirstAction(); }; */ /* class MDPC_Driver_Thread : public Driver_Thread { DriverHandle *m_pDrvHandle; DWORD m_TimeOut; bool m_FirstHeart; bool m_FirstAction; public: MDPC_Driver_Thread(void); virtual ~MDPC_Driver_Thread(void); void InitDPCDriverThread(DriverHandle *pHandle); protected: virtual bool Exec(); bool HandleConnectionReq(LogicDriver *pDrv); bool HandleDisConnectionReq(LogicDriver *pDrv); bool HandleAutomaticConnection(int Idx); int GetTimeoutConnectionIndex(DWORD &NextTimeout); DWORD GetDriverHeartBeatTimePeriod(); bool HandleClientRequestEx(); bool SubDPCConnection(bool Connect, LogicDriver *pDrv); int WaitForInQueEx(DWORD Timeout); bool CleanupPassiveDisconnect(int DrvIdx); void FirstAction(); };*/