You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
1.9 KiB

​
​
​
​
​
​
​
4 months ago
​
4 months ago
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASIC_TNSPORT_HEADERS__
  2. #define __BASIC_TNSPORT_HEADERS__
  3. #include "basicLogCollection.h"
  4. #include "basicMutex.h"
  5. #include <algorithm>
  6. #include <vector>
  7. #include <queue>
  8. #ifdef DEBUG
  9. // #ifndef DUBUG_COMMUNICATION
  10. // #define DUBUG_COMMUNICATION
  11. // #endif
  12. #endif
  13. #define SERIAL_PING_PONG
  14. #ifdef SERIAL_PING_PONG
  15. class protocolParser;
  16. #endif
  17. #ifndef MAXIMAL_SERIAL_IO_BUFFER_LENGTH
  18. #define MAXIMAL_SERIAL_IO_BUFFER_LENGTH 102400
  19. #endif
  20. typedef struct S_SIO_TZ {
  21. bool wReplay;
  22. bool finished;
  23. bool success;
  24. int inp_size;
  25. int out_size;
  26. #ifdef SERIAL_PING_PONG
  27. protocolParser * boundParser;
  28. #endif
  29. uint8_t out_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  30. uint8_t inp_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  31. } SIO_TZ;
  32. typedef std::queue<SIO_TZ *> Q_SIO_TZ;
  33. class protocolParser;
  34. typedef std::vector<protocolParser *> parseQueue;
  35. class basicTransport
  36. {
  37. private:
  38. basicLogCollection * m_pLog;
  39. protected:
  40. parseQueue m_vParsers;
  41. basicMutex m_mQueueProtectorMutex;
  42. basicMutex m_mBufferProtectorMutex;
  43. CONNECTION_STATUS m_eConnectionStatus;
  44. public:
  45. basicTransport();
  46. ~basicTransport();
  47. #ifdef SERIAL_PING_PONG
  48. virtual bool sendData(unsigned char * Data, int DataSize, protocolParser *src = NULL )
  49. #else
  50. virtual bool sendData(unsigned char * Data, int DataSize )
  51. #endif
  52. {
  53. if ( !Data ) return false;
  54. if ( !DataSize ) return false;
  55. return true;
  56. }
  57. virtual bool reconnect(void)
  58. {
  59. return false;
  60. }
  61. bool addRecipient(protocolParser * ProtoParser);
  62. bool removeRecipient(protocolParser * ProtoParser);
  63. bool getStatus(void)
  64. {
  65. return m_eConnectionStatus == CS_CONNECTED;
  66. }
  67. void setConnectionStatus(CONNECTION_STATUS ES);
  68. CONNECTION_STATUS getConnectionStatus(void);
  69. virtual int getRawHandle(void)
  70. {
  71. return -1;
  72. }
  73. };
  74. #endif