PlainConnection.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef PLAINCONNECTION_H
  2. #define PLAINCONNECTION_H
  3. #ifdef _WIN32
  4. #include <winsock2.h>
  5. #include <ws2tcpip.h>
  6. #include "win32shim.h"
  7. #else
  8. #include <unistd.h> // for size_t
  9. #endif
  10. #include <cstdint> // for uint8_t
  11. #include <functional> // for function
  12. #include <string> // for string
  13. #include <vector> // for vector
  14. typedef std::function<bool()> timeoutCallback;
  15. namespace cspot {
  16. class PlainConnection {
  17. public:
  18. PlainConnection();
  19. ~PlainConnection();
  20. /**
  21. * @brief Connect to the given AP address
  22. *
  23. * @param apAddress The AP url to connect to
  24. */
  25. void connect(const std::string& apAddress);
  26. void close();
  27. timeoutCallback timeoutHandler;
  28. std::vector<uint8_t> sendPrefixPacket(const std::vector<uint8_t>& prefix,
  29. const std::vector<uint8_t>& data);
  30. std::vector<uint8_t> recvPacket();
  31. void readBlock(const uint8_t* dst, size_t size);
  32. size_t writeBlock(const std::vector<uint8_t>& data);
  33. private:
  34. int apSock;
  35. };
  36. } // namespace cspot
  37. #endif