///////////////////////////////////////////////////////////////////////////////// /// Copyright (c) 2012 China Merchants Bank, all rights reserved /// /// /// /// Base defination for device adapter. /// /// DeviceBaseClass.h: Interface for the DeviceBaseClass class. /// /// /// ///////////////////////////////////////////////////////////////////////////////// // Return code(ErrorCodeEnum): // Error code that adapters returned mainly in the following list: // Error_Hardware=0x800, // Error_DevLoadFileFailed, //load dll or config file failed // Error_DevNotAvailable, //device not connected // Error_DevAlreadyConnected, //device already connected // Error_DevConnFailed, //connect to device failed // Error_DevCommFailed, //Communication failed between HOST and Device // Error_DevMedia, //Media error(Data lack,unrecognized and so on) // Adapters can also return error code which included in the file ErrorCode.h // The "Optional." in front of method's comment means this method to implement depends on device. // If the device don't have the function ,just return Error_Succeed simply,but must declare in the // implementation document. #ifndef __DEVICE_BASE_CLASS_H #define __DEVICE_BASE_CLASS_H /** define device interface file version*/ #define DEVICE_BASE_INTERFACE_FILE_VERSION 1 #define DEVICE_STRINGIFY_HELPER(v) #v #define DEVICE_ADAPTER_CLASS_STRINGFY(m, n) \ DEVICE_STRINGIFY_HELPER(DEVICE_BASE_INTERFACE_FILE_VERSION) "." \ DEVICE_STRINGIFY_HELPER(m) "." DEVICE_STRINGIFY_HELPER(n) #define DEVICE_ADAPTER_CLASS_COMBINE(v) \ ((DEVICE_BASE_INTERFACE_FILE_VERSION << 16) | (v << 8) | (0)) #include "ErrorCode.h" #if (!defined(_WIN32) && !defined(_WIN64)) #include #else #include #endif //NOT _WIN32 #if (defined(_WIN32) || defined(_WIN64)) # ifdef DEVICEBASE_EXPORTS # define DEVICEBASE_API __declspec(dllexport) # else # define DEVICEBASE_API __declspec(dllimport) # endif #elif ( defined(__GNUC__) && __GNUC__ >= 4 ) # define DEVICEBASE_API __attribute__((visibility("default"))) #else # define DEVICEBASE_API #endif //#ifdef _MSC_VER //# if _MSC_VER >= 1920 //# define NEWER_COMPILER_WORKAROUNDS //# endif //#endif #ifdef __cplusplus extern "C" { #endif const int MAX_DEV_TYPE_LEN = 256; const int MAX_DEV_MODEL_LEN = 256; const int MAX_DEV_VENDOR_LEN = 256; const int MAX_DEV_ERROR_MSG_LEN = 256; #ifndef RVC_VENDOE_BUILDIN_TYPE #if (defined(_WIN32) || defined(_WIN64)) typedef unsigned char BYTE; typedef BYTE *LPBYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef unsigned long* PDWORD; #else typedef uint8_t BYTE; typedef uint8_t* LPBYTE; typedef uint16_t WORD; typedef uint32_t DWORD; typedef uint32_t* PDWORD; typedef char CHAR; #endif #define RVC_VENDOE_BUILDIN_TYPE #endif // !RVC_VENDOE_BUILDIN_TYPE //version info of device software struct DevSoftVersion { WORD wMajor; //release major version WORD wMinor; //release minor version WORD wRevision; //bug repair version with the major and minor version remains the same WORD wBuild; //compile version }; enum DevStateEnum { DEVICE_STATUS_NOT_READY, //uninit DEVICE_STATUS_NORMAL, //normal DEVICE_STATUS_MAINTAINCE, //need to maintaince //ex:paper tray is empty,retain bin is full DEVICE_STATUS_FAULT, //cannot work DEVICE_STATUS_CONNECTING, //device connecting DEVICE_STATUS_NOCFG, //the vtm has no such device DEVICE_STATUS_CROSS_USING, //the device is in cross calling }; struct DevCategoryInfo { char szType[MAX_DEV_TYPE_LEN]; //device type sth like "CMB.Printer.HP1234" char szModel[MAX_DEV_MODEL_LEN]; //device model char szVendor[MAX_DEV_VENDOR_LEN]; //device vendor DevStateEnum eState; //device status DevSoftVersion version; //software version }; struct DevErrorInfo { DWORD dwErrMsgLen; char szErrMsg[MAX_DEV_ERROR_MSG_LEN]; }; class DeviceBaseClass { public: virtual ~DeviceBaseClass() {} // // Get category infomation about device. // virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory) = 0; // // Reset device. // Do the cleaning work and initialize device again in order to return to // the normal condition. virtual ErrorCodeEnum Reset() = 0; // // Close device and do the cleaning work. // ex. close connection,close port,release memery and so on virtual ErrorCodeEnum DevClose() = 0; // // Get last error the device issued. // Error message must include explanatory memorandum ,the original error // code and anything in favour of location problem. virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo) = 0; }; DEVICEBASE_API ErrorCodeEnum CreateDevComponent(DeviceBaseClass*& baseObj); DEVICEBASE_API ErrorCodeEnum ReleaseDevComponent(DeviceBaseClass*& pBaseObj); #ifdef NEWER_COMPILER_WORKAROUNDS DEVICEBASE_API ErrorCodeEnum GetDevAdapterVersion(DevSoftVersion& retVesion); #endif // NEWER_COMPILER_WORKAROUNDS #ifdef __cplusplus } #endif #endif // __DEVICE_BASE_CLASS_H