123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- #pragma once
- #include <map>
- #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<Notify_Thread*, LogicDriver*> 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<DriverHandle*> m_hSubDriverList; //子驱动列表
- MsgVector<DriverHandle*> m_DynSubDriverList; //动态驱动列表
- map<string, LogicDevice*> m_RootDeviceMap; //DevShortPath : LogicDevice 逻辑设备映射string 设备路径
- map<string, LogicDevice*> m_DynRootDeviceMap; //DevShortPath : LogicDevice 动态逻辑设备映射 设备路径
- //map<UINT64, ServerSysIF*> m_AddressMap;// DeviceSysIF : RealSysIF 64位数字地址和SysIF指针的 映射
- //map<UINT64, ServerSysIF*> m_DynAddressMap;// DeviceSysIF : RealSysIF 64位数字地址和动态地址指针的 映射
- //map<Dual_Driver_Thread*, vector<UINT64>> m_ThreadMap;// thread : DeviceSysIF[]
- //map<Dual_Driver_Thread*, vector<UINT64>> m_DynThreadMap;// thread : DeviceSysIF[]
- void MakeShortPaths(string stackpath, DevTree *pDevTree, map<string, vector<LogicDevice*>> &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<string, UINT64> m_DeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
- map<string, UINT64> m_DynDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
- map<string, UINT64> m_CcosDeviceFullPathMap; //fulldevpath : LogicDeviceSysIF
- map<string, UINT64> 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<UINT64> &ifList);
- void DynGetSysIFList(vector<UINT64> &ifList);
- bool IsDPCMatch(LogicDriver*pDriver);
- bool IsMDPCHANDLE();
- };
- class DriverManager : public CcosLock
- {
- friend class DriverHandle;
- DriverHandle* m_pRootDrvHandle;
- vector<DriverHandle*> m_SubDriverList;
- //map<UINT64, ServerSysIF*> m_AddressMap;// DeviceSysIF : RealSysIF
- void DynAddDriver(DriverHandle *pDrv);
- void AddDriver(DriverHandle *pDrv);
- //void UpdateSysIF(vector<UINT64> &SysIFList, bool del = false);
- void AddDevice(const char* devUri, LogicDevice* pDevice);
- std::map<string, LogicDevice*> 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();
- };*/
|