~serge-hallyn/ubuntu/raring/spice/spice-fixed2

« back to all changes in this revision

Viewing changes to client/application.h

  • Committer: Package Import Robot
  • Author(s): Liang Guo
  • Date: 2011-07-23 12:21:04 UTC
  • Revision ID: package-import@ubuntu.com-20110723122104-gvv70gd6ui6213qd
Tags: upstream-0.8.2
ImportĀ upstreamĀ versionĀ 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2009 Red Hat, Inc.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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/>.
 
16
*/
 
17
 
 
18
#ifndef _H_APPLICATION
 
19
#define _H_APPLICATION
 
20
 
 
21
#include "common.h"
 
22
#include "threads.h"
 
23
#include "red_client.h"
 
24
#include "red_key.h"
 
25
#include "platform.h"
 
26
#include "menu.h"
 
27
#include "hot_keys.h"
 
28
#include "process_loop.h"
 
29
#include "foreign_menu.h"
 
30
#include "controller.h"
 
31
 
 
32
#ifdef USE_SMARTCARD
 
33
struct SmartcardOptions;
 
34
#endif
 
35
class RedScreen;
 
36
class Application;
 
37
class ScreenLayer;
 
38
class InfoLayer;
 
39
class InputsHandler;
 
40
class Monitor;
 
41
class CmdLineParser;
 
42
class Menu;
 
43
 
 
44
#ifdef USE_GUI
 
45
class GUI;
 
46
class GUITimer;
 
47
class GUIBarrier;
 
48
 
 
49
#ifdef GUI_DEMO
 
50
class TestTimer;
 
51
#endif
 
52
#endif // USE_GUI
 
53
 
 
54
 
 
55
class ConnectedEvent: public Event {
 
56
public:
 
57
    virtual void response(AbstractProcessLoop& events_loop);
 
58
};
 
59
 
 
60
class DisconnectedEvent: public Event {
 
61
public:
 
62
    DisconnectedEvent() : _error_code (SPICEC_ERROR_CODE_SUCCESS) {}
 
63
    DisconnectedEvent(int error_code) : _error_code (error_code) {}
 
64
    virtual void response(AbstractProcessLoop& events_loop);
 
65
 
 
66
private:
 
67
    int _error_code;
 
68
};
 
69
 
 
70
class VisibilityEvent: public Event {
 
71
public:
 
72
    VisibilityEvent(int screen_id) : _screen_id (screen_id) {}
 
73
 
 
74
    virtual void response(AbstractProcessLoop& events_loop);
 
75
 
 
76
private:
 
77
    int _screen_id;
 
78
};
 
79
 
 
80
struct MonitorInfo {
 
81
    int depth;
 
82
    SpicePoint size;
 
83
    SpicePoint position;
 
84
};
 
85
 
 
86
class MonitorsQuery: public SyncEvent {
 
87
public:
 
88
    MonitorsQuery() {}
 
89
 
 
90
    virtual void do_response(AbstractProcessLoop& events_loop);
 
91
    std::vector<MonitorInfo>& get_monitors() {return _monitors;}
 
92
 
 
93
private:
 
94
    std::vector<MonitorInfo> _monitors;
 
95
};
 
96
 
 
97
class SwitchHostEvent: public Event {
 
98
public:
 
99
    SwitchHostEvent(const char* host, int port, int sport, const char* cert_subject);
 
100
    virtual void response(AbstractProcessLoop& events_loop);
 
101
 
 
102
private:
 
103
    std::string _host;
 
104
    int _port;
 
105
    int _sport;
 
106
    std::string _cert_subject;
 
107
};
 
108
 
 
109
enum CanvasOption {
 
110
    CANVAS_OPTION_INVALID,
 
111
    CANVAS_OPTION_SW,
 
112
#ifdef WIN32
 
113
    CANVAS_OPTION_GDI,
 
114
#endif
 
115
#ifdef USE_OGL
 
116
    CANVAS_OPTION_OGL_FBO,
 
117
    CANVAS_OPTION_OGL_PBUFF,
 
118
#endif
 
119
};
 
120
 
 
121
class StickyKeyTimer: public Timer {
 
122
public:
 
123
    virtual void response(AbstractProcessLoop& events_loop);
 
124
};
 
125
 
 
126
typedef struct StickyInfo {
 
127
    bool trace_is_on;
 
128
    bool sticky_mode;
 
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;
 
138
} StickyInfo;
 
139
 
 
140
 
 
141
typedef std::list<KeyHandler*> KeyHandlersStack;
 
142
#ifdef USE_GUI
 
143
typedef std::list<GUIBarrier*> GUIBarriers;
 
144
#endif // USE_GUI
 
145
 
 
146
enum AppMenuItemType {
 
147
    APP_MENU_ITEM_TYPE_INVALID,
 
148
    APP_MENU_ITEM_TYPE_FOREIGN,
 
149
    APP_MENU_ITEM_TYPE_CONTROLLER,
 
150
};
 
151
 
 
152
typedef struct AppMenuItem {
 
153
    AppMenuItemType type;
 
154
    int32_t conn_ref;
 
155
    uint32_t ext_id;
 
156
} AppMenuItem;
 
157
 
 
158
typedef std::map<int, AppMenuItem> AppMenuItemMap;
 
159
 
 
160
class Application : public ProcessLoop,
 
161
                    public Platform::EventListener,
 
162
                    public Platform::DisplayModeListener,
 
163
                    public ForeignMenuInterface,
 
164
                    public ControllerInterface {
 
165
public:
 
166
 
 
167
    enum State {
 
168
        DISCONNECTED,
 
169
        CONNECTING,
 
170
        CONNECTED,
 
171
        VISIBILITY,
 
172
        DISCONECTING,
 
173
    };
 
174
 
 
175
#ifdef USE_GUI
 
176
    enum GuiMode {
 
177
        GUI_MODE_FULL,
 
178
        GUI_MODE_ACTIVE_SESSION,
 
179
        GUI_MODE_MINIMAL,
 
180
    };
 
181
#endif // USE_GUI
 
182
 
 
183
    Application();
 
184
    virtual ~Application();
 
185
 
 
186
    int run();
 
187
 
 
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);
 
196
 
 
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();
 
214
    void on_connected();
 
215
    void on_disconnected(int spice_error_code);
 
216
    void on_disconnecting();
 
217
    void on_visibility_start(int screen_id);
 
218
 
 
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);
 
223
    void minimize();
 
224
    void set_title(const std::string& title);
 
225
    void hide();
 
226
    void show();
 
227
    void external_show();
 
228
    void connect();
 
229
    void switch_host(const std::string& host, int port, int sport, const std::string& cert_subject);
 
230
 
 
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;}
 
236
 
 
237
    Menu* get_app_menu();
 
238
    virtual void do_command(int command);
 
239
 
 
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);
 
243
    void update_menu();
 
244
 
 
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);
 
248
    void disconnect();
 
249
    void quit();
 
250
    void show_me(bool full_screen);
 
251
    void hide_me();
 
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);
 
255
    void delete_menu();
 
256
    void beep();
 
257
 
 
258
#ifdef USE_GUI
 
259
    bool is_disconnect_allowed();
 
260
    void hide_gui();
 
261
#endif
 
262
 
 
263
    const std::string& get_host();
 
264
    int get_port();
 
265
    int get_sport();
 
266
    const std::string& get_password();
 
267
    //controller interface end
 
268
 
 
269
#ifdef GUI_DEMO
 
270
    void message_box_test();
 
271
#endif
 
272
 
 
273
#ifdef USE_SMARTCARD
 
274
    const SmartcardOptions* get_smartcard_options() const {
 
275
        return _smartcard_options;
 
276
    }
 
277
#endif
 
278
 
 
279
    static int main(int argc, char** argv, const char* version_str);
 
280
 
 
281
private:
 
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();
 
294
    void abort();
 
295
    void init_menu();
 
296
    void unpress_all();
 
297
    bool release_capture();
 
298
    bool do_connect();
 
299
    bool do_disconnect();
 
300
    void set_state(State);
 
301
 
 
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);
 
327
 
 
328
    void show_info_layer();
 
329
    void hide_info_layer();
 
330
#ifdef USE_GUI
 
331
    void attach_gui_barriers();
 
332
    void detach_gui_barriers();
 
333
    void show_gui();
 
334
    void create_gui_barrier(RedScreen& screen, int id);
 
335
    void destroyed_gui_barrier(int id);
 
336
    void destroyed_gui_barriers();
 
337
#endif // USE_GUI
 
338
 
 
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);
 
342
    void reset_sticky();
 
343
    static bool is_sticky_trace_key(RedKey key);
 
344
    void sync_keyboard_modifiers();
 
345
 
 
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();
 
352
 
 
353
    friend class DisconnectedEvent;
 
354
    friend class ConnectionErrorEvent;
 
355
    friend class MonitorsQuery;
 
356
    friend class AutoAbort;
 
357
    friend class StickyKeyTimer;
 
358
 
 
359
private:
 
360
    RedClient _client;
 
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;
 
367
    bool _active;
 
368
    bool _full_screen;
 
369
    bool _changing_screens;
 
370
    bool _out_of_sync;
 
371
    int _exit_code;
 
372
    RedScreen* _active_screen;
 
373
    bool _keyboard_state[REDKEY_NUM_KEYS];
 
374
    int _num_keys_pressed;
 
375
    HotKeys _hot_keys;
 
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;
 
382
    std::string _title;
 
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;
 
391
#ifdef USE_GUI
 
392
    std::auto_ptr<GUI> _gui;
 
393
    AutoRef<GUITimer> _gui_timer;
 
394
    GUIBarriers _gui_barriers;
 
395
    GuiMode _gui_mode;
 
396
#ifdef GUI_DEMO
 
397
    AutoRef<TestTimer> _gui_test_timer;
 
398
#endif
 
399
#endif // USE_GUI
 
400
    bool _during_host_switch;
 
401
 
 
402
    State _state;
 
403
#ifdef USE_SMARTCARD
 
404
    SmartcardOptions* _smartcard_options;
 
405
#endif
 
406
};
 
407
 
 
408
#endif
 
409