123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #pragma once
- #include <memory>
- #include <string>
- #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 <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, 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 _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 <IOEventCenter> EventCenter;
- protected:
- std::unique_ptr <Detail::IODeviceDetail> 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 <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;
- };
- }
|