Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scenario_manager.hpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d158c1fdc42f3e0a2c19d59ee278d46f3cbd8c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once

#include "drape_frontend/frontend_renderer.hpp"

#include "drape/drape_diagnostics.hpp"

#include "geometry/point2d.hpp"

#include "base/stl_helpers.hpp"
#include "base/thread.hpp"

#include <chrono>
#include <functional>
#include <memory>
#include <mutex>
#include <vector>

namespace df
{

class ScenarioManager
{
public:
  enum class ActionType
  {
    CenterViewport,
    WaitForTime
  };

  class Action
  {
  public:
    virtual ~Action() {}
    virtual ActionType GetType() = 0;
  };

  class CenterViewportAction : public Action
  {
  public:
    CenterViewportAction(m2::PointD const & pt, int zoomLevel)
      : m_center(pt), m_zoomLevel(zoomLevel) {}

    ActionType GetType() override { return ActionType::CenterViewport; }

    m2::PointD const & GetCenter() const { return m_center; }
    int GetZoomLevel() const { return m_zoomLevel; }
  private:
    m2::PointD const m_center;
    int const m_zoomLevel;
  };

  class WaitForTimeAction : public Action
  {
  public:
    using Duration = std::chrono::steady_clock::duration;

    WaitForTimeAction(Duration const & duration)
      : m_duration(duration) {}

    ActionType GetType() override { return ActionType::WaitForTime; }

    Duration const & GetDuration() const { return m_duration; }
  private:
    Duration m_duration;
  };

  using Scenario = std::vector<std::unique_ptr<Action>>;
  using ScenarioCallback = std::function<void(std::string const & name)>;

  struct ScenarioData
  {
    std::string m_name;
    Scenario m_scenario;
  };

  ScenarioManager(FrontendRenderer * frontendRenderer);
  ~ScenarioManager();

  bool RunScenario(ScenarioData && scenarioData,
                   ScenarioCallback const & startHandler, ScenarioCallback const & finishHandler);
  void Interrupt();
  bool IsRunning();

private:
  void ThreadRoutine();
  void InterruptImpl();

  FrontendRenderer * m_frontendRenderer;

  std::mutex m_mutex;
  ScenarioData m_scenarioData;
  bool m_needInterrupt;
  bool m_isFinished;
  ScenarioCallback m_onStartHandler;
  ScenarioCallback m_onFinishHandler;
#ifdef DEBUG
  std::thread::id m_threadId;
#endif
  std::unique_ptr<threads::SimpleThread> m_thread;
};

} //  namespace df