2
Copyright (C) 2009 Red Hat, Inc.
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public
15
License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
#ifndef _H_APPLICATION
19
#define _H_APPLICATION
23
#include "red_client.h"
28
#include "process_loop.h"
29
#include "foreign_menu.h"
30
#include "controller.h"
33
struct SmartcardOptions;
55
class ConnectedEvent: public Event {
57
virtual void response(AbstractProcessLoop& events_loop);
60
class DisconnectedEvent: public Event {
62
DisconnectedEvent() : _error_code (SPICEC_ERROR_CODE_SUCCESS) {}
63
DisconnectedEvent(int error_code) : _error_code (error_code) {}
64
virtual void response(AbstractProcessLoop& events_loop);
70
class VisibilityEvent: public Event {
72
VisibilityEvent(int screen_id) : _screen_id (screen_id) {}
74
virtual void response(AbstractProcessLoop& events_loop);
86
class MonitorsQuery: public SyncEvent {
90
virtual void do_response(AbstractProcessLoop& events_loop);
91
std::vector<MonitorInfo>& get_monitors() {return _monitors;}
94
std::vector<MonitorInfo> _monitors;
97
class SwitchHostEvent: public Event {
99
SwitchHostEvent(const char* host, int port, int sport, const char* cert_subject);
100
virtual void response(AbstractProcessLoop& events_loop);
106
std::string _cert_subject;
110
CANVAS_OPTION_INVALID,
116
CANVAS_OPTION_OGL_FBO,
117
CANVAS_OPTION_OGL_PBUFF,
121
class StickyKeyTimer: public Timer {
123
virtual void response(AbstractProcessLoop& events_loop);
126
typedef struct StickyInfo {
129
bool key_first_down; // True when (1) a potential sticky key is pressed,
130
// and none of the other keys are pressed and (2) in the moment
131
// of pressing, _sticky_mode is false. When the key is up
132
// for the first time, it is set to false.
133
bool key_down; // The physical state of the sticky key. Valid only till
134
// stickiness is removed.
135
RedKey key; // the key that is currently being traced, or,
136
// if _sticky mode is on, the sticky key
137
AutoRef<StickyKeyTimer> timer;
141
typedef std::list<KeyHandler*> KeyHandlersStack;
143
typedef std::list<GUIBarrier*> GUIBarriers;
146
enum AppMenuItemType {
147
APP_MENU_ITEM_TYPE_INVALID,
148
APP_MENU_ITEM_TYPE_FOREIGN,
149
APP_MENU_ITEM_TYPE_CONTROLLER,
152
typedef struct AppMenuItem {
153
AppMenuItemType type;
158
typedef std::map<int, AppMenuItem> AppMenuItemMap;
160
class Application : public ProcessLoop,
161
public Platform::EventListener,
162
public Platform::DisplayModeListener,
163
public ForeignMenuInterface,
164
public ControllerInterface {
178
GUI_MODE_ACTIVE_SESSION,
184
virtual ~Application();
188
void set_key_handler(KeyHandler& handler);
189
void remove_key_handler(KeyHandler& handler);
190
void set_mouse_handler(MouseHandler& handler);
191
void remove_mouse_handler(MouseHandler& handler);
192
void capture_mouse();
193
void release_mouse_capture();
194
RedScreen* find_screen(int id);
195
RedScreen* get_screen(int id);
197
void on_screen_unlocked(RedScreen& screen);
198
void on_screen_destroyed(int id, bool was_captured);
199
void on_mouse_motion(int dx, int dy, int buttons_state);
200
void on_mouse_down(int button, int buttons_state);
201
void on_mouse_up(int button, int buttons_state);
202
void on_key_down(RedKey key);
203
void on_key_up(RedKey key);
204
void on_char(uint32_t ch);
205
void on_deactivate_screen(RedScreen* screen);
206
void on_activate_screen(RedScreen* screen);
207
void on_start_screen_key_interception(RedScreen* screen);
208
void on_stop_screen_key_interception(RedScreen* screen);
209
virtual void on_start_running();
210
virtual void on_app_activated();
211
virtual void on_app_deactivated();
212
virtual void on_monitors_change();
213
virtual void on_display_mode_change();
215
void on_disconnected(int spice_error_code);
216
void on_disconnecting();
217
void on_visibility_start(int screen_id);
219
void enter_full_screen();
220
void exit_full_screen();
221
bool toggle_full_screen();
222
void resize_screen(RedScreen *screen, int width, int height);
224
void set_title(const std::string& title);
227
void external_show();
229
void switch_host(const std::string& host, int port, int sport, const std::string& cert_subject);
231
const PeerConnectionOptMap& get_con_opt_map() {return _peer_con_opt;}
232
const RedPeer::HostAuthOptions& get_host_auth_opt() { return _host_auth_opt;}
233
const std::string& get_connection_ciphers() { return _con_ciphers;}
234
uint32_t get_mouse_mode();
235
const std::vector<int>& get_canvas_types() { return _canvas_types;}
237
Menu* get_app_menu();
238
virtual void do_command(int command);
240
int get_foreign_menu_item_id(int32_t opaque_conn_ref, uint32_t msg_id);
241
void clear_menu_items(int32_t opaque_conn_ref);
242
void remove_menu_item(int item_id);
245
//controller interface begin
246
void set_auto_display_res(bool auto_display_res);
247
bool connect(const std::string& host, int port, int sport, const std::string& password);
250
void show_me(bool full_screen);
252
void set_hotkeys(const std::string& hotkeys);
253
int get_controller_menu_item_id(int32_t opaque_conn_ref, uint32_t msg_id);
254
void set_menu(Menu* menu);
259
bool is_disconnect_allowed();
263
const std::string& get_host();
266
const std::string& get_password();
267
//controller interface end
270
void message_box_test();
274
const SmartcardOptions* get_smartcard_options() const {
275
return _smartcard_options;
279
static int main(int argc, char** argv, const char* version_str);
282
bool set_channels_security(CmdLineParser& parser, bool on, char *val, const char* arg0);
283
bool set_channels_security(int port, int sport);
284
bool set_connection_ciphers(const char* ciphers, const char* arg0);
285
bool set_ca_file(const char* ca_file, const char* arg0);
286
bool set_host_cert_subject(const char* subject, const char* arg0);
287
bool set_enable_channels(CmdLineParser& parser, bool enable, char *val, const char* arg0);
288
bool set_canvas_option(CmdLineParser& parser, char *val, const char* arg0);
289
bool set_disabled_display_effects(CmdLineParser& parser, char *val, const char* arg0,
290
DisplaySetting& disp_setting);
291
void on_cmd_line_invalid_arg(const char* arg0, const char* what, const char* val);
292
bool process_cmd_line(int argc, char** argv, bool& full_screen);
293
void register_channels();
297
bool release_capture();
299
bool do_disconnect();
300
void set_state(State);
302
void restore_screens_size();
303
Monitor* find_monitor(int id);
304
Monitor* get_monitor(int id);
305
void init_monitors();
306
void destroy_monitors();
307
void assign_monitors();
308
void restore_monitors();
309
void prepare_monitors();
310
void rearrange_monitors(bool force_capture,
311
bool enter_full_screen,
312
RedScreen* screen = NULL);
313
void position_screens();
314
void show_full_screen();
315
void send_key_down(RedKey key);
316
void send_key_up(RedKey key);
317
void send_alt_ctl_del();
318
void send_ctrl_alt_end();
319
void send_command_hotkey(int command);
320
void send_hotkey_key_set(const HotkeySet& key_set);
321
void menu_item_callback(unsigned int item_id);
322
int get_menu_item_id(AppMenuItemType type, int32_t conn_ref, uint32_t ext_id);
323
int get_hotkeys_commnad();
324
bool is_key_set_pressed(const HotkeySet& key_set);
325
void do_on_key_up(RedKey key);
326
void __remove_key_handler(KeyHandler& handler);
328
void show_info_layer();
329
void hide_info_layer();
331
void attach_gui_barriers();
332
void detach_gui_barriers();
334
void create_gui_barrier(RedScreen& screen, int id);
335
void destroyed_gui_barrier(int id);
336
void destroyed_gui_barriers();
339
// returns the press value before operation (i.e., if it was already pressed)
340
bool press_key(RedKey key);
341
bool unpress_key(RedKey key);
343
static bool is_sticky_trace_key(RedKey key);
344
void sync_keyboard_modifiers();
346
static void init_logger();
347
static void init_globals();
348
static void init_platform_globals();
349
static void cleanup_platform_globals();
350
static void cleanup_globals();
351
void init_remainder();
353
friend class DisconnectedEvent;
354
friend class ConnectionErrorEvent;
355
friend class MonitorsQuery;
356
friend class AutoAbort;
357
friend class StickyKeyTimer;
361
PeerConnectionOptMap _peer_con_opt;
362
RedPeer::HostAuthOptions _host_auth_opt;
363
std::string _con_ciphers;
364
std::vector<bool> _enabled_channels;
365
std::vector<RedScreen*> _screens;
366
RedScreen* _main_screen;
369
bool _changing_screens;
372
RedScreen* _active_screen;
373
bool _keyboard_state[REDKEY_NUM_KEYS];
374
int _num_keys_pressed;
376
CommandsMap _commands_map;
377
std::auto_ptr<InfoLayer> _info_layer;
378
KeyHandler* _key_handler;
379
KeyHandlersStack _key_handlers;
380
MouseHandler* _mouse_handler;
381
const MonitorsList* _monitors;
383
bool _sys_key_intercept_mode;
384
StickyInfo _sticky_info;
385
std::vector<int> _canvas_types;
386
AutoRef<Menu> _app_menu;
387
AutoRef<ForeignMenu> _foreign_menu;
388
bool _enable_controller;
389
AutoRef<Controller> _controller;
390
AppMenuItemMap _app_menu_items;
392
std::auto_ptr<GUI> _gui;
393
AutoRef<GUITimer> _gui_timer;
394
GUIBarriers _gui_barriers;
397
AutoRef<TestTimer> _gui_test_timer;
400
bool _during_host_switch;
404
SmartcardOptions* _smartcard_options;