connectionManager.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 <algorithm>
  11. #include "commFPGA.hpp"
  12. #include "worker.hpp"
  13. /*
  14. worker thread:
  15. takes jobs
  16. assigns free fpga
  17. queue response
  18. cb on overwrite + delete old resp
  19. fills send buffer
  20. retransmit job
  21. send thread:
  22. send 1 packet per fpga if available
  23. recv thread:
  24. recv data into response
  25. cb on success
  26. */
  27. class ConnectionManager {
  28. public:
  29. ConnectionManager();
  30. ~ConnectionManager();
  31. void addFPGA(const char* ip, const uint port, bool bindSelf=false);
  32. void start();
  33. Worker* createWorker(Module mod, size_t numberOfJobs = 1);
  34. Worker* getWorker(size_t i) const {return &(*workers.at(i));}
  35. size_t getWorkerCount() const {return workers.size();}
  36. void removeFinishedWorkers();
  37. void setSendDelay(microseconds us) {sendDelay = us;}
  38. bool isRunning() const {return running;}
  39. private:
  40. std::vector<std::unique_ptr<commFPGA>> fpgas;
  41. std::vector<std::unique_ptr<Worker>> workers;
  42. void sendThread();
  43. std::future<void> sendResult;
  44. bool running = false;
  45. microseconds sendDelay = microseconds(50);
  46. };
  47. #endif