run_loop.h 1016 Bytes
Newer Older
1 2
#ifndef RUNNER_RUN_LOOP_H_
#define RUNNER_RUN_LOOP_H_
3

4
#include <flutter/flutter_engine.h>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

#include <chrono>
#include <set>

// A runloop that will service events for Flutter instances as well
// as native messages.
class RunLoop {
 public:
  RunLoop();
  ~RunLoop();

  // Prevent copying
  RunLoop(RunLoop const&) = delete;
  RunLoop& operator=(RunLoop const&) = delete;

  // Runs the run loop until the application quits.
  void Run();

  // Registers the given Flutter instance for event servicing.
  void RegisterFlutterInstance(
25
      flutter::FlutterEngine* flutter_instance);
26 27 28

  // Unregisters the given Flutter instance from event servicing.
  void UnregisterFlutterInstance(
29
      flutter::FlutterEngine* flutter_instance);
30 31 32 33 34 35 36

 private:
  using TimePoint = std::chrono::steady_clock::time_point;

  // Processes all currently pending messages for registered Flutter instances.
  TimePoint ProcessFlutterMessages();

37
  std::set<flutter::FlutterEngine*> flutter_instances_;
38 39
};

40
#endif  // RUNNER_RUN_LOOP_H_