#pragma once #include #include #include "TmplEvent.h" #include "LogicDevice.h" #include "LogicDriver.h" #define _CCOSLogicDevice_API namespace CCOS::Dev { using JSONString = std::string; namespace Detail { class IODeviceDetail; } //----------------------------------------------------------------------------- // IOEventCenter //----------------------------------------------------------------------------- class _CCOSLogicDevice_API IOEventCenter { public: CXXHelper::Event OnNotify; CXXHelper::Event OnDataNotify; CXXHelper::Event OnMaxBlockSize; CXXHelper::Event OnSystemLog; CXXHelper::Event OnLog; CXXHelper::Event <> OnPassiveDisconnected; }; //----------------------------------------------------------------------------- // IODevice // The root / base class for any IODevice //----------------------------------------------------------------------------- /* enum class RET_STATUS { RET_THREAD_INVALID = -4,//the calling thread is not owner RET_INVALID = -3,//the handle is invalid RET_NOSUPPORT = -2,//device not support RET_TIMEOUT = -1,//超时(无接收命令) RET_FAILED = 0,//执行命令失败 RET_PENDING,//设备有接收命令,但无反馈(在一定时间内无反馈情况) RET_SUCCEED,//设备执行命令成功 RET_ONGOING,//设备执行命令已经完成,但是没有达成目标. RET_FINISHED,//设备执行命令已经完成,且有达成目标. RET_WARNING };*/ class _CCOSLogicDevice_API IODevice : public LogicDevice { private: IODevice (const IODevice &) = delete; IODevice (IODevice &&) = delete; IODevice & operator = (const IODevice &) = delete; IODevice & operator = (IODevice &&) = delete; public: IODevice (Detail::IODeviceDetail * detal); // 由内部类来构造 virtual ~IODevice (); virtual bool SYSTEM_CALL GetDeviceType(GUID& DevType) override; virtual RET_STATUS SYSTEM_CALL CmdToLogicDev(ResDataObject PARAM_IN* pCmd) override; virtual RET_STATUS SYSTEM_CALL Request(ResDataObject PARAM_IN* pRequest, ResDataObject PARAM_OUT* pResponse) override; void SubscribeSelf() override; void SYSTEM_CALL CompleteInit() override; void SYSTEM_CALL CompleteUnInit() override; public: std::string GetGUID () const; std::string GetResource () const; bool Prepare(); RET_STATUS Add (const std::string funcName, JSONString In, JSONString & Out); RET_STATUS Delete (const std::string funcName, JSONString In, JSONString & Out); RET_STATUS Update (const std::string funcName, JSONString In, JSONString & Out); RET_STATUS Action (const std::string funcName, JSONString In, JSONString & Out); RET_STATUS Get (const std::string funcName, JSONString& Out); RET_STATUS Set (const std::string funcName, JSONString In); public: std::shared_ptr EventCenter; protected: std::unique_ptr m_Detail; }; //----------------------------------------------------------------------------- // IODriver // The manager for IODevice //----------------------------------------------------------------------------- class _CCOSLogicDevice_API IODriver : public LogicDriver { private: IODriver (const IODriver &) = delete; IODriver (IODriver &&) = delete; IODriver & operator = (const IODriver &) = delete; IODriver & operator = (IODriver &&) = delete; public: IODriver (); virtual ~IODriver (); public: virtual void Prepare (); //< CCOS 运行环境将调用如下 API virtual bool DriverEntry (std::string CfgFileName); virtual std::string DriverProbe () = 0; virtual std::string GetGUID () const = 0; virtual std::string GetResource () = 0; virtual std::string DeviceProbe () = 0; virtual bool OnHeartBeat (); //> // Connect () 返回值的定义, 待定 !!! virtual bool DATA_ACTION Connect () override; virtual void Disconnect (); virtual bool isConnected () const; virtual auto CreateDevice (int index) -> std::unique_ptr = 0; virtual bool GetDeviceConfig(std::string & Cfg); virtual bool SetDeviceConfig(std::string Cfg); protected: std::string m_ConfigFileName; public: std::shared_ptr EventCenter; }; }