Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
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.

lfr_socket.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include <iostream>
  3. #include <functional>
  4. #include <vector>
  5. #include <memory>
  6. #include <mutex>
  7. #include <thread>
  8. #include <sys/socket.h>
  9. #include <netinet/in.h>
  10. #include <poll.h>
  11. #include <string>
  12. #include <algorithm>
  13. #include <exception>
  14. class LFR_Socket
  15. {
  16. public:
  17. using LFR_Telegram = char[1024];
  18. using ListenerKey = void const*;
  19. using ExceptionCallback = std::function<bool(std::exception const &ex)>;
  20. using ListenerCallback = std::function<void(LFR_Telegram)>;
  21. private:
  22. using ListenerPair = std::pair<ListenerKey, ListenerCallback>;
  23. using ListenerVector = std::vector<ListenerPair>;
  24. ListenerVector listeners;
  25. ExceptionCallback cb;
  26. bool stop;
  27. std::unique_ptr<std::thread> thread;
  28. mutable std::mutex mutex;
  29. int server_fd, new_socket, bytes_received;
  30. struct sockaddr_in address;
  31. int opt = 1;
  32. int addrlen = sizeof(address);
  33. char buffer[1024] = {0};
  34. //void provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);
  35. void createThread();
  36. void setStop(bool val);
  37. public:
  38. LFR_Socket() = delete;
  39. LFR_Socket(ExceptionCallback cb);
  40. ~LFR_Socket();
  41. void startLoop();
  42. void endLoop();
  43. void addListener(ListenerCallback cv, ListenerKey key);
  44. void removeListener(ListenerKey key);
  45. void isStopped() const noexcept;
  46. //const bool interpretMessage(co)
  47. };