DeviceBaseClass.h 4.3 KB

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