run_loop.h 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef RUNNER_RUN_LOOP_H_
  2. #define RUNNER_RUN_LOOP_H_
  3. #include <flutter/flutter_engine.h>
  4. #include <chrono>
  5. #include <set>
  6. // A runloop that will service events for Flutter instances as well
  7. // as native messages.
  8. class RunLoop {
  9. public:
  10. RunLoop();
  11. ~RunLoop();
  12. // Prevent copying
  13. RunLoop(RunLoop const&) = delete;
  14. RunLoop& operator=(RunLoop const&) = delete;
  15. // Runs the run loop until the application quits.
  16. void Run();
  17. // Registers the given Flutter instance for event servicing.
  18. void RegisterFlutterInstance(
  19. flutter::FlutterEngine* flutter_instance);
  20. // Unregisters the given Flutter instance from event servicing.
  21. void UnregisterFlutterInstance(
  22. flutter::FlutterEngine* flutter_instance);
  23. private:
  24. using TimePoint = std::chrono::steady_clock::time_point;
  25. // Processes all currently pending messages for registered Flutter instances.
  26. TimePoint ProcessFlutterMessages();
  27. std::set<flutter::FlutterEngine*> flutter_instances_;
  28. };
  29. #endif // RUNNER_RUN_LOOP_H_