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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <unistd.h>
  11. #include <poll.h>
  12. #include <string>
  13. #include <algorithm>
  14. #include <exception>
  15. #include <cstring>
  16. class LFR_Socket
  17. {
  18. public:
  19. using LFR_Telegram = char[1024];
  20. using ListenerKey = void const*;
  21. using ExceptionCallback = std::function<bool(std::exception const &ex)>;
  22. using ListenerCallback = std::function<void(LFR_Telegram)>;
  23. private:
  24. using ListenerPair = std::pair<ListenerKey, ListenerCallback>;
  25. using ListenerVector = std::vector<ListenerPair>;
  26. ListenerVector listeners;
  27. ExceptionCallback cb;
  28. bool stop;
  29. std::unique_ptr<std::thread> thread;
  30. mutable std::mutex mutex;
  31. int server_fd, new_socket, bytesReceived;
  32. struct sockaddr_in address;
  33. int opt = 1;
  34. int addrlen = sizeof(address);
  35. char buffer[1024] = {0};
  36. char* bufferIterator;
  37. //void provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);
  38. void createThread();
  39. void setStop(bool val);
  40. public:
  41. LFR_Socket() = delete;
  42. LFR_Socket(ExceptionCallback cb);
  43. ~LFR_Socket();
  44. void startLoop();
  45. void endLoop();
  46. void addListener(ListenerCallback cv, ListenerKey key);
  47. void removeListener(ListenerKey key);
  48. void isStopped() const noexcept;
  49. //const bool interpretMessage(co)
  50. };