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

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