Mir
async_server_runner.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014-2017 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 2 or 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: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_TESTS_INCLUDE_MIR_TEST_FRAMEWORK_ASYNC_SERVER_RUNNER_H_
20 #define MIR_TESTS_INCLUDE_MIR_TEST_FRAMEWORK_ASYNC_SERVER_RUNNER_H_
21 
24 
25 #include "mir/server.h"
27 
28 #include <condition_variable>
29 #include <list>
30 #include <mutex>
31 #include <thread>
32 
33 namespace mir_test_framework
34 {
36 {
37 public:
39  ~AsyncServerRunner() noexcept;
40 
41  void add_to_environment(char const* key, char const* value);
42 
44  void start_server();
45 
47  void stop_server();
48 
50  void wait_for_server_exit();
51 
53  auto new_connection() -> std::string;
54 
56  auto connection(int fd) -> std::string;
57 
58  mir::Server server;
59 
60  template<typename Policy, typename ...Args>
61  void override_window_management_policy(Args& ... args)
62  {
63  set_window_management_policy =
64  miral::set_window_management_policy<Policy>(args...);
65  }
66 
67 private:
68  std::list<TemporaryEnvironmentValue> env;
69  mir::test::AutoJoinThread server_thread;
70 
71  // Once we migrate away from "legacy" window management stubs this can become
72  // SetWindowManagementPolicy set_window_management_policy;
73  std::function<void(mir::Server&)> set_window_management_policy;
74 
75  std::mutex mutex;
76  std::condition_variable started;
77  bool server_running{false};
78 };
79 }
80 
81 #endif /* MIR_TESTS_INCLUDE_MIR_TEST_FRAMEWORK_ASYNC_SERVER_RUNNER_H_ */
void stop_server()
Stops the server and joins thread.
mir::Server server
Definition: async_server_runner.h:58
Definition: async_server_runner.h:35
Definition: auto_unblock_thread.h:37
void wait_for_server_exit()
Wait for the server to exit and joins thread.
void override_window_management_policy(Args &... args)
Definition: async_server_runner.h:61
auto connection(int fd) -> std::string
Definition: any_surface.h:25
void start_server()
Starts the server on a new thread.
void add_to_environment(char const *key, char const *value)
auto new_connection() -> std::string

Copyright © 2012-2018 Canonical Ltd.
Generated on Thu Apr 5 15:26:05 UTC 2018