123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #pragma once
- #include <memory>
- #include <string>
- #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<DIOS::Dev::Detail::IODeviceDetail,std::default_delete<_Ty>>”需要有 dll 接口由 class“DIOS::Dev::IODevice”的客户端使用
- namespace DIOS::Dev
- {
- using JSONString = std::string;
- namespace Detail
- {
- class IODeviceDetail;
- }
- //-----------------------------------------------------------------------------
- // IOEventCenter
- //-----------------------------------------------------------------------------
- class _DIOSLogicDevice_API IOEventCenter
- {
- public:
- CXXHelper::Event <int, std::string, std::string> OnNotify;
- CXXHelper::Event <int, std::string, JSONString, JSONString, char*, int> OnDataNotify;
- CXXHelper::Event <std::string, DWORD, DWORD, DWORD, DWORD> OnMaxBlockSize;
- CXXHelper::Event <int, std::string, std::string> OnSystemLog;
- CXXHelper::Event <int, std::string> 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 <IOEventCenter> EventCenter;
- protected:
- std::unique_ptr <Detail::IODeviceDetail> 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 <IODevice> = 0;
- virtual bool GetDeviceConfig(std::string & Cfg);
- virtual bool SetDeviceConfig(std::string Cfg);
- protected:
- std::string m_ConfigFileName;
- public:
- std::shared_ptr <IOEventCenter> EventCenter;
- };
- }
|