Mir
glib_main_loop.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014-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: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17  */
18 
19 #ifndef MIR_GLIB_MAIN_LOOP_H_
20 #define MIR_GLIB_MAIN_LOOP_H_
21 
22 #include "mir/main_loop.h"
24 
25 #include <atomic>
26 #include <vector>
27 #include <mutex>
28 #include <exception>
29 
30 #include <glib.h>
31 
32 namespace mir
33 {
34 
35 namespace detail
36 {
37 
39 {
40 public:
43  operator GMainContext*() const;
44 private:
45  GMainContext* const main_context;
46 };
47 
48 }
49 
50 class GLibMainLoop : public MainLoop
51 {
52 public:
53  GLibMainLoop(std::shared_ptr<time::Clock> const& clock);
54 
55  void run() override;
56  void stop() override;
57 
58  void register_signal_handler(
59  std::initializer_list<int> signals,
60  std::function<void(int)> const& handler) override;
61 
62  void register_signal_handler(
63  std::initializer_list<int> signals,
64  mir::UniqueModulePtr<std::function<void(int)>> handler) override;
65 
66  void register_fd_handler(
67  std::initializer_list<int> fds,
68  void const* owner,
69  std::function<void(int)> const& handler) override;
70 
71  void register_fd_handler(
72  std::initializer_list<int> fds,
73  void const* owner,
74  mir::UniqueModulePtr<std::function<void(int)>> handler) override;
75 
76  void unregister_fd_handler(void const* owner) override;
77 
78  void enqueue(void const* owner, ServerAction const& action) override;
79  void pause_processing_for(void const* owner) override;
80  void resume_processing_for(void const* owner) override;
81 
82  std::unique_ptr<mir::time::Alarm> create_alarm(
83  std::function<void()> const& callback) override;
84 
85  std::unique_ptr<mir::time::Alarm> create_alarm(
86  std::shared_ptr<LockableCallback> const& callback) override;
87 
88  void reprocess_all_sources();
89 
90 private:
91  bool should_process_actions_for(void const* owner);
92  void handle_exception(std::exception_ptr const& e);
93 
94  std::shared_ptr<time::Clock> const clock;
95  detail::GMainContextHandle const main_context;
96  std::atomic<bool> running;
97  detail::FdSources fd_sources;
98  detail::SignalSources signal_sources;
99  std::mutex do_not_process_mutex;
100  std::vector<void const*> do_not_process;
101  std::function<void()> before_iteration_hook;
102  std::exception_ptr main_loop_exception;
103 };
104 
105 }
106 
107 #endif
All things Mir.
Definition: atomic_callback.h:25
Definition: glib_main_loop.h:38
GMainContextHandle()
Definition: glib_main_loop.cpp:108
std::unique_ptr< T, ModuleDeleter< T >> UniqueModulePtr
Use UniqueModulePtr to ensure that your loadable libray outlives instances created within it...
Definition: module_deleter.h:83
Definition: glib_main_loop.h:50
std::function< void()> ServerAction
Definition: server_action_queue.h:27
Definition: main_loop.h:29
Definition: glib_main_loop_sources.h:83
Definition: glib_main_loop_sources.h:101
std::promise< bool > stop
Definition: in.cpp:28
~GMainContextHandle()
Definition: glib_main_loop.cpp:115

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016