#pragma once #include #include #include "TmplEvent.tlh" #ifndef DIOSLOGICDEVICE_EXPORTS #ifdef _WIN64 #ifdef _DEBUG #pragma comment(lib, "DIOS.Device.IODevice64D.lib") #else #pragma comment(lib, "DIOS.Device.IODevice64.lib") #endif #else #ifdef _DEBUG #pragma comment(lib, "DIOS.Device.IODeviceD.lib") #else #pragma comment(lib, "DIOS.Device.IODevice.lib") #endif #endif #endif #ifdef DIOSLOGICDEVICE_EXPORTS #define _DIOSLogicDevice_API __declspec(dllexport) #else #define _DIOSLogicDevice_API __declspec(dllimport) #endif #pragma warning (disable:4251) // warning C4251: class“std::unique_ptr>”需要有 dll 接口由 class“DIOS::Dev::IODevice”的客户端使用 namespace DIOS::Dev { using JSONString = std::string; namespace Detail { class IODeviceDetail; } //----------------------------------------------------------------------------- // IOEventCenter //----------------------------------------------------------------------------- class _DIOSLogicDevice_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 _DIOSLogicDevice_API IODevice { private: IODevice (const IODevice &) = delete; IODevice (IODevice &&) = delete; IODevice & operator = (const IODevice &) = delete; IODevice & operator = (IODevice &&) = delete; public: IODevice (Detail::IODeviceDetail * detal); // 由内部类来构造 virtual ~IODevice (); 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 _DIOSLogicDevice_API IODriver { 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 (); //< DIOS 运行环境将调用如下 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 int Connect (); 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; }; }