DeviceBaseClass.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 __cplusplus
  49. extern "C"
  50. {
  51. #endif
  52. const int MAX_DEV_TYPE_LEN = 256;
  53. const int MAX_DEV_MODEL_LEN = 256;
  54. const int MAX_DEV_VENDOR_LEN = 256;
  55. const int MAX_DEV_ERROR_MSG_LEN = 256;
  56. #ifndef RVC_VENDOE_BUILDIN_TYPE
  57. #if (defined(_WIN32) || defined(_WIN64))
  58. typedef unsigned char BYTE;
  59. typedef BYTE *LPBYTE;
  60. typedef unsigned short WORD;
  61. typedef unsigned long DWORD;
  62. typedef unsigned long* PDWORD;
  63. #else
  64. typedef uint8_t BYTE;
  65. typedef uint8_t* LPBYTE;
  66. typedef uint16_t WORD;
  67. typedef uint32_t DWORD;
  68. typedef uint32_t* PDWORD;
  69. typedef char CHAR;
  70. #endif
  71. #define RVC_VENDOE_BUILDIN_TYPE
  72. #endif // !RVC_VENDOE_BUILDIN_TYPE
  73. //version info of device software
  74. struct DevSoftVersion
  75. {
  76. WORD wMajor; //release major version
  77. WORD wMinor; //release minor version
  78. WORD wRevision; //bug repair version with the major and minor version remains the same
  79. WORD wBuild; //compile version
  80. };
  81. enum DevStateEnum
  82. {
  83. DEVICE_STATUS_NOT_READY, //uninit
  84. DEVICE_STATUS_NORMAL, //normal
  85. DEVICE_STATUS_MAINTAINCE, //need to maintaince
  86. //ex:paper tray is empty,retain bin is full
  87. DEVICE_STATUS_FAULT, //cannot work
  88. DEVICE_STATUS_CONNECTING, //device connecting
  89. DEVICE_STATUS_NOCFG, //the vtm has no such device
  90. DEVICE_STATUS_CROSS_USING, //the device is in cross calling
  91. };
  92. struct DevCategoryInfo
  93. {
  94. char szType[MAX_DEV_TYPE_LEN]; //device type sth like "CMB.Printer.HP1234"
  95. char szModel[MAX_DEV_MODEL_LEN]; //device model
  96. char szVendor[MAX_DEV_VENDOR_LEN]; //device vendor
  97. DevStateEnum eState; //device status
  98. DevSoftVersion version; //software version
  99. };
  100. struct DevErrorInfo
  101. {
  102. DWORD dwErrMsgLen;
  103. char szErrMsg[MAX_DEV_ERROR_MSG_LEN];
  104. };
  105. class DeviceBaseClass
  106. {
  107. public:
  108. virtual ~DeviceBaseClass() {}
  109. //
  110. // Get category infomation about device.
  111. //
  112. virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory) = 0;
  113. //
  114. // Reset device.
  115. // Do the cleaning work and initialize device again in order to return to
  116. // the normal condition.
  117. virtual ErrorCodeEnum Reset() = 0;
  118. //
  119. // Close device and do the cleaning work.
  120. // ex. close connection,close port,release memery and so on
  121. virtual ErrorCodeEnum DevClose() = 0;
  122. //
  123. // Get last error the device issued.
  124. // Error message must include explanatory memorandum ,the original error
  125. // code and anything in favour of location problem.
  126. virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo) = 0;
  127. };
  128. DEVICEBASE_API ErrorCodeEnum CreateDevComponent(DeviceBaseClass*& baseObj);
  129. DEVICEBASE_API ErrorCodeEnum ReleaseDevComponent(DeviceBaseClass*& pBaseObj);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif // __DEVICE_BASE_CLASS_H