Mir
mir_prompt_session.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
17  */
18 
19 #ifndef MIR_CLIENT_MIR_PROMPT_SESSION_H_
20 #define MIR_CLIENT_MIR_PROMPT_SESSION_H_
21 
23 
24 #include "mir_wait_handle.h"
25 
26 #include <mutex>
27 #include <memory>
28 #include <atomic>
29 
30 namespace mir
31 {
32 namespace protobuf
33 {
34 class PromptSessionParameters;
35 class SocketFD;
36 class Void;
37 }
39 namespace client
40 {
41 class EventHandlerRegister;
42 namespace rpc
43 {
44 class DisplayServer;
45 }
46 }
47 }
48 
50 {
51 public:
53  std::shared_ptr<mir::client::EventHandlerRegister> const& event_handler_register);
54 
56 
57  MirWaitHandle* start(pid_t application_pid, mir_prompt_session_callback callback, void* context);
58  MirWaitHandle* stop(mir_prompt_session_callback callback, void* context);
59 
60  MirWaitHandle* new_fds_for_prompt_providers(
61  unsigned int no_of_fds,
62  mir_client_fd_callback callback,
63  void * context);
64 
65  void register_prompt_session_state_change_callback(mir_prompt_session_state_change_callback callback, void* context);
66 
67  char const* get_error_message();
68 
69 private:
70  std::mutex mutable mutex; // Protects parameters, wait_handles & results
72  std::unique_ptr<mir::protobuf::PromptSessionParameters> parameters;
73  std::unique_ptr<mir::protobuf::Void> add_result;
74  std::unique_ptr<mir::protobuf::Void> protobuf_void;
75  std::unique_ptr<mir::protobuf::SocketFD> socket_fd_response;
76  std::shared_ptr<mir::client::EventHandlerRegister> const event_handler_register;
77  int const event_handler_register_id;
78 
79  MirWaitHandle start_wait_handle;
80  MirWaitHandle stop_wait_handle;
81  MirWaitHandle fds_for_prompt_providers_wait_handle;
82  std::atomic<MirPromptSessionState> state;
83 
84  std::mutex mutable session_mutex; // Protects session
85  std::unique_ptr<mir::protobuf::Void> session;
86 
87  std::mutex mutable event_handler_mutex; // Need another mutex for callback access to members
88  std::function<void(MirPromptSessionState)> handle_prompt_session_state_change;
89 
90  void set_state(MirPromptSessionState new_state);
91  void done_start(mir_prompt_session_callback callback, void* context);
92  void done_stop(mir_prompt_session_callback callback, void* context);
93  void done_fds_for_prompt_providers(mir_client_fd_callback callback, void* context);
94  MirPromptSession(MirPromptSession const&) = delete;
95  MirPromptSession& operator=(MirPromptSession const&) = delete;
96 };
97 
98 #endif /* MIR_CLIENT_MIR_PROMPT_SESSION_H_ */
99 
All things Mir.
Definition: atomic_callback.h:25
Definition: mir_wait_handle.h:31
MirPromptSessionState
Definition: common.h:109
struct MirPromptSession MirPromptSession
Definition: client_types.h:44
void(* mir_client_fd_callback)(MirPromptSession *prompt_session, size_t count, int const *fds, void *context)
Callback called when a request for client file descriptors completes.
Definition: client_types.h:144
Definition: mir_prompt_session.h:49
void(* mir_prompt_session_callback)(MirPromptSession *prompt_provider, void *context)
Callback member of MirPromptSession for handling of prompt sessions.
Definition: client_types.h:412
std::promise< bool > stop
Definition: in.cpp:28
Definition: mir_display_server.h:33
void(* mir_prompt_session_state_change_callback)(MirPromptSession *prompt_provider, MirPromptSessionState state, void *context)
Callback member of MirPromptSession for handling of prompt sessions events.
Definition: client_types.h:420

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