Mir
internal_client.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016-2020 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 as
6  * 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 
17 #ifndef MIRAL_INTERNAL_CLIENT_H
18 #define MIRAL_INTERNAL_CLIENT_H
19 
20 #include <functional>
21 #include <memory>
22 #include <string>
23 
24 namespace mir { class Server; namespace scene { class Session; }}
25 
26 struct wl_display;
27 
28 namespace miral
29 {
30 /** Wrapper for running an internal Mir client at startup
31  * \note client_code will be executed on its own thread, this must exit
32  * \note connection_notification will be called on a worker thread and must not block
33  *
34  * \param client_code code implementing the internal client
35  * \param connection_notification handler for registering the server-side application
36  */
38 {
39 public:
41  std::function<void(struct ::wl_display* display)> client_code,
42  std::function<void(std::weak_ptr<mir::scene::Session> const session)> connect_notification);
43 
44  template <typename ClientObject>
45  explicit StartupInternalClient(ClientObject const& client_object) :
46  StartupInternalClient(client_object, client_object) {}
47 
49 
50  void operator()(mir::Server& server);
51 
52 private:
53  class Self;
54  std::shared_ptr<Self> internal_client;
55 };
56 
58 {
59 public:
62 
63  void operator()(mir::Server& server);
64 
65  void launch(
66  std::function<void(struct ::wl_display* display)> const& wayland_fd,
67  std::function<void(std::weak_ptr<mir::scene::Session> const session)> const& connect_notification) const;
68 
69  template <typename ClientObject>
70  void launch(ClientObject& client_object) const
71  {
72  launch(
73  [&](struct ::wl_display* display) { client_object(display); },
74  [&](std::weak_ptr<mir::scene::Session> const session) { client_object(session); });
75  }
76 
77 private:
78  struct Self;
79  std::shared_ptr<Self> self;
80 };
81 }
82 
83 #endif //MIRAL_INTERNAL_CLIENT_H

Copyright © 2012-2022 Canonical Ltd.
Generated on Fri Aug 26 13:27:37 UTC 2022
This documentation is licensed under the GPL version 2 or 3.