connectionManager.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. Worker* createWorker(Module mod, size_t numberOfJobs);
  33. Worker* getWorker(size_t i) const {return &(*workers.at(i));}
  34. size_t getWorkerCount() const {return workers.size();}
  35. void setSendDelay(microseconds us) {sendDelay = us;}
  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. microseconds sendDelay = microseconds(50);
  43. };
  44. #endif