connectionManager.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef myCONNMANAGE_H
  2. #define myCONNMANAGE_H
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <thread>
  7. #include <future>
  8. #include <mutex>
  9. #include <condition_variable>
  10. #include "commFPGA.hpp"
  11. #include "worker.hpp"
  12. /*
  13. worker thread:
  14. takes jobs
  15. assigns free fpga
  16. queue response
  17. cb on overwrite + delete old resp
  18. fills send buffer
  19. send thread:
  20. cycle fd
  21. send 1 packet if available
  22. recv thread:
  23. select(readFD)
  24. recv data into response
  25. cb on success + delete response
  26. response thread:
  27. search old responses
  28. cb on timeout + delete response
  29. */
  30. class ConnectionManager {
  31. public:
  32. ConnectionManager();
  33. ~ConnectionManager();
  34. void addFPGA(const char* ip, const uint port);
  35. void start();
  36. //send many Jobs and wait for all responses
  37. int sendJobListSync(JobList &jobList);
  38. //send many Jobs and call back
  39. int sendJobListAsync(JobList &jobList);
  40. private:
  41. std::vector<std::reference_wrapper<commFPGA>> fpgas;
  42. std::vector<std::reference_wrapper<Worker>> workers;
  43. void sendThread();
  44. std::future<void> sendResult;
  45. bool running = true;
  46. };
  47. #endif