DeviceBaseClass.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /////////////////////////////////////////////////////////////////////////////////
  2. /// Copyright (c) 2012 China Merchants Bank, all rights reserved ///
  3. /// ///
  4. /// Base defination for device adapter. ///
  5. /// DeviceBaseClass.h: Interface for the DeviceBaseClass class. ///
  6. /// ///
  7. /////////////////////////////////////////////////////////////////////////////////
  8. // Return code(ErrorCodeEnum):
  9. // Error code that adapters returned mainly in the following list:
  10. // Error_Hardware=0x800,
  11. // Error_DevLoadFileFailed, //load dll or config file failed
  12. // Error_DevNotAvailable, //device not connected
  13. // Error_DevAlreadyConnected, //device already connected
  14. // Error_DevConnFailed, //connect to device failed
  15. // Error_DevCommFailed, //Communication failed between HOST and Device
  16. // Error_DevMedia, //Media error(Data lack,unrecognized and so on)
  17. // Adapters can also return error code which included in the file ErrorCode.h
  18. // The "Optional." in front of method's comment means this method to implement depends on device.
  19. // If the device don't have the function ,just return Error_Succeed simply,but must declare in the
  20. // implementation document.
  21. #ifndef __DEVICE_BASE_CLASS_H
  22. #define __DEVICE_BASE_CLASS_H
  23. /** define device interface file version*/
  24. #define DEVICE_BASE_INTERFACE_FILE_VERSION 1
  25. #define DEVICE_STRINGIFY_HELPER(v) #v
  26. #define DEVICE_ADAPTER_CLASS_STRINGFY(m, n) \
  27. DEVICE_STRINGIFY_HELPER(DEVICE_BASE_INTERFACE_FILE_VERSION) "." \
  28. DEVICE_STRINGIFY_HELPER(m) "." DEVICE_STRINGIFY_HELPER(n)
  29. #define DEVICE_ADAPTER_CLASS_COMBINE(v) \
  30. ((DEVICE_BASE_INTERFACE_FILE_VERSION << 16) | (v << 8) | (0))
  31. #include "ErrorCode.h"
  32. #if (!defined(_WIN32) && !defined(_WIN64))
  33. #include <stdint.h>
  34. #else
  35. #include <wtypes.h>
  36. #endif //NOT _WIN32
  37. #if (defined(_WIN32) || defined(_WIN64))
  38. # ifdef DEVICEBASE_EXPORTS
  39. # define DEVICEBASE_API __declspec(dllexport)
  40. # else
  41. # define DEVICEBASE_API __declspec(dllimport)
  42. # endif
  43. #elif ( defined(__GNUC__) && __GNUC__ >= 4 )
  44. # define DEVICEBASE_API __attribute__((visibility("default")))
  45. #else
  46. # define DEVICEBASE_API
  47. #endif
  48. //#ifdef _MSC_VER
  49. //# if _MSC_VER >= 1920
  50. //# define NEWER_COMPILER_WORKAROUNDS
  51. //# endif
  52. //#endif
  53. #ifdef __cplusplus
  54. extern "C"
  55. {
  56. #endif
  57. const int MAX_DEV_TYPE_LEN = 256;
  58. const int MAX_DEV_MODEL_LEN = 256;
  59. const int MAX_DEV_VENDOR_LEN = 256;
  60. const int MAX_DEV_ERROR_MSG_LEN = 256;
  61. #ifndef RVC_VENDOE_BUILDIN_TYPE
  62. #if (defined(_WIN32) || defined(_WIN64))
  63. typedef unsigned char BYTE;
  64. typedef BYTE *LPBYTE;
  65. typedef unsigned short WORD;
  66. typedef unsigned long DWORD;
  67. typedef unsigned long* PDWORD;
  68. #else
  69. typedef uint8_t BYTE;
  70. typedef uint8_t* LPBYTE;
  71. typedef uint16_t WORD;
  72. typedef uint32_t DWORD;
  73. typedef uint32_t* PDWORD;
  74. typedef char CHAR;
  75. #endif
  76. #define RVC_VENDOE_BUILDIN_TYPE
  77. #endif // !RVC_VENDOE_BUILDIN_TYPE
  78. //version info of device software
  79. struct DevSoftVersion
  80. {
  81. WORD wMajor; //release major version
  82. WORD wMinor; //release minor version
  83. WORD wRevision; //bug repair version with the major and minor version remains the same
  84. WORD wBuild; //compile version
  85. };
  86. enum DevStateEnum
  87. {
  88. DEVICE_STATUS_NOT_READY, //uninit
  89. DEVICE_STATUS_NORMAL, //normal
  90. DEVICE_STATUS_MAINTAINCE, //need to maintaince
  91. //ex:paper tray is empty,retain bin is full
  92. DEVICE_STATUS_FAULT, //cannot work
  93. DEVICE_STATUS_CONNECTING, //device connecting
  94. DEVICE_STATUS_NOCFG, //the vtm has no such device
  95. DEVICE_STATUS_CROSS_USING, //the device is in cross calling
  96. };
  97. struct DevCategoryInfo
  98. {
  99. char szType[MAX_DEV_TYPE_LEN]; //device type sth like "CMB.Printer.HP1234"
  100. char szModel[MAX_DEV_MODEL_LEN]; //device model
  101. char szVendor[MAX_DEV_VENDOR_LEN]; //device vendor
  102. DevStateEnum eState; //device status
  103. DevSoftVersion version; //software version
  104. };
  105. struct DevErrorInfo
  106. {
  107. DWORD dwErrMsgLen;
  108. char szErrMsg[MAX_DEV_ERROR_MSG_LEN];
  109. };
  110. class DeviceBaseClass
  111. {
  112. public:
  113. virtual ~DeviceBaseClass() {}
  114. //
  115. // Get category infomation about device.
  116. //
  117. virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory) = 0;
  118. //
  119. // Reset device.
  120. // Do the cleaning work and initialize device again in order to return to
  121. // the normal condition.
  122. virtual ErrorCodeEnum Reset() = 0;
  123. //
  124. // Close device and do the cleaning work.
  125. // ex. close connection,close port,release memery and so on
  126. virtual ErrorCodeEnum DevClose() = 0;
  127. //
  128. // Get last error the device issued.
  129. // Error message must include explanatory memorandum ,the original error
  130. // code and anything in favour of location problem.
  131. virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo) = 0;
  132. };
  133. DEVICEBASE_API ErrorCodeEnum CreateDevComponent(DeviceBaseClass*& baseObj);
  134. DEVICEBASE_API ErrorCodeEnum ReleaseDevComponent(DeviceBaseClass*& pBaseObj);
  135. #ifdef NEWER_COMPILER_WORKAROUNDS
  136. DEVICEBASE_API ErrorCodeEnum GetDevAdapterVersion(DevSoftVersion& retVesion);
  137. #endif // NEWER_COMPILER_WORKAROUNDS
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif // __DEVICE_BASE_CLASS_H