Mir
timeout_application_not_responding_detector.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored By: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17  */
18 
19 #ifndef MIR_SCENE_TIMOUT_APPLICATION_NOT_RESPONDING_DETECTOR_
20 #define MIR_SCENE_TIMOUT_APPLICATION_NOT_RESPONDING_DETECTOR_
21 
23 #include "mir/basic_observers.h"
24 
25 #include <chrono>
26 #include <unordered_map>
27 #include <functional>
28 
29 namespace mir
30 {
31 namespace time
32 {
33 class Alarm;
34 class AlarmFactory;
35 }
36 
37 namespace scene
38 {
40 {
41 public:
43  time::AlarmFactory& alarms,
44  std::chrono::milliseconds period);
45 
46  template<typename Rep, typename Period>
48  time::AlarmFactory& alarms,
49  std::chrono::duration<Rep, Period> period)
51  std::chrono::duration_cast<std::chrono::milliseconds>(period))
52  {
53  }
54 
56 
57  void register_session(frontend::Session const* session,
58  std::function<void()> const& pinger) override;
59 
60  void unregister_session(frontend::Session const* session) override;
61 
62  void pong_received(frontend::Session const* received_for) override;
63 
64  void register_observer(std::shared_ptr<Observer> const& observer) override;
65  void unregister_observer(std::shared_ptr<Observer> const& observer) override;
66 private:
67  void handle_ping_cycle();
68 
69  struct ANRContext;
70 
71  class ANRObservers : public Observer, private BasicObservers<Observer>
72  {
73  public:
76 
77  void session_unresponsive(Session const* session) override;
78  void session_now_responsive(Session const* session) override;
79  } observers;
80 
81  std::mutex session_mutex;
82  std::unordered_map<Session const*, std::unique_ptr<ANRContext>> sessions;
83  std::vector<Session const*> unresponsive_sessions_temporary;
84 
85  std::chrono::milliseconds const period;
86  std::unique_ptr<time::Alarm> const alarm;
87 };
88 }
89 }
90 
91 #endif // MIR_SCENE_TIMOUT_APPLICATION_NOT_RESPONDING_DETECTOR_
Definition: session.h:44
All things Mir.
Definition: atomic_callback.h:25
Definition: session.h:38
STL namespace.
Definition: timeout_application_not_responding_detector.h:39
Definition: alarm_factory.h:38
Definition: application_not_responding_detector.h:36
Definition: basic_observers.h:28
TimeoutApplicationNotRespondingDetector(time::AlarmFactory &alarms, std::chrono::duration< Rep, Period > period)
Definition: timeout_application_not_responding_detector.h:47
Notification object for application-not-responsive signals.
Definition: application_not_responding_detector.h:49

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016