connectionManager.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. retransmit job
  20. send thread:
  21. send 1 packet per fpga if available
  22. recv thread:
  23. recv data into response
  24. cb on success
  25. */
  26. class ConnectionManager {
  27. public:
  28. ConnectionManager();
  29. ~ConnectionManager();
  30. void addFPGA(const char* ip, const uint port, bool bindSelf=false);
  31. void start();
  32. //send many Jobs and wait for all responses
  33. int sendJobListSync(std::shared_ptr<JobList> &jobList);
  34. //send many Jobs and call back
  35. int sendJobListAsync(std::shared_ptr<JobList> &jobList);
  36. private:
  37. std::vector<std::unique_ptr<commFPGA>> fpgas;
  38. std::vector<std::unique_ptr<Worker>> workers;
  39. void sendThread();
  40. std::future<void> sendResult;
  41. bool running = true;
  42. };
  43. #endif