[Spice-devel] [RFC] client: --help should not need X
Alon Levy
alevy at redhat.com
Tue Jan 25 15:55:33 PST 2011
separate initialization into before command line parsing and after,
call later only if command line parsing succeeds (in particular, it
"fails" if --help is given).
Not tested on windows.
---
client/application.cpp | 75 ++++++++++++++++++++++++++++++++---------------
client/application.h | 3 ++
2 files changed, 54 insertions(+), 24 deletions(-)
diff --git a/client/application.cpp b/client/application.cpp
index d1aef1a..eff0495 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -362,14 +362,6 @@ Application::Application()
#endif
{
DBG(0, "");
- Platform::set_process_loop(*this);
- init_monitors();
- memset(_keyboard_state, 0, sizeof(_keyboard_state));
- init_menu();
- _main_screen = get_screen(0);
-
- Platform::set_event_listener(this);
- Platform::set_display_mode_listner(this);
_commands_map["toggle-fullscreen"] = APP_CMD_TOGGLE_FULL_SCREEN;
_commands_map["release-cursor"] = APP_CMD_RELEASE_CAPTURE;
@@ -420,15 +412,6 @@ Application::Application()
_sticky_info.key = REDKEY_INVALID;
_sticky_info.timer.reset(new StickyKeyTimer());
-#ifdef USE_GUI
- _gui.reset(new GUI(*this, DISCONNECTED));
- _gui_timer.reset(new GUITimer(*_gui.get()));
- activate_interval_timer(*_gui_timer, 1000 / 30);
-#ifdef GUI_DEMO
- _gui_test_timer.reset(new TestTimer(*this));
- activate_interval_timer(*_gui_test_timer, 1000 * 30);
-#endif
-#endif // USE_GUI
for (int i = SPICE_CHANNEL_MAIN; i < SPICE_END_CHANNEL; i++) {
_peer_con_opt[i] = RedPeer::ConnectionOptions::CON_OP_BOTH;
}
@@ -437,20 +420,28 @@ Application::Application()
Application::~Application()
{
#ifdef USE_GUI
- deactivate_interval_timer(*_gui_timer);
+ if (*_gui_timer != NULL) {
+ deactivate_interval_timer(*_gui_timer);
+ }
#ifdef GUI_DEMO
- deactivate_interval_timer(*_gui_test_timer);
+ if (*_gui_test_timer != NULL) {
+ deactivate_interval_timer(*_gui_test_timer);
+ }
#endif
destroyed_gui_barriers();
- _gui->set_screen(NULL);
+ if (_gui.get() != NULL) {
+ _gui->set_screen(NULL);
+ }
#endif // USE_GUI
if (_info_layer->screen()) {
_main_screen->detach_layer(*_info_layer);
}
- _main_screen->unref();
- destroy_monitors();
+ if (_main_screen != NULL) {
+ _main_screen->unref();
+ destroy_monitors();
+ }
#ifdef USE_SMARTCARD
delete _smartcard_options;
#endif
@@ -2221,7 +2212,6 @@ bool Application::process_cmd_line(int argc, char** argv)
if (argc == 1) {
_gui_mode = GUI_MODE_FULL;
register_channels();
- _main_screen->show(true, NULL);
return true;
}
#endif // USE_GUI
@@ -2545,16 +2535,48 @@ void Application::init_globals()
#ifdef WIN32
gdi_canvas_init();
#endif
+}
+/* seperated from init_globals to allow --help to work
+ * without an X display, and without opening window when run
+ * from console on windows. */
+void Application::init_platform_globals()
+{
Platform::init();
RedWindow::init();
}
-void Application::cleanup_globals()
+void Application::init_second_half()
+{
+ Platform::set_process_loop(*this);
+ init_monitors();
+ memset(_keyboard_state, 0, sizeof(_keyboard_state));
+ init_menu();
+ _main_screen = get_screen(0);
+
+ Platform::set_event_listener(this);
+ Platform::set_display_mode_listner(this);
+
+#ifdef USE_GUI
+ _gui.reset(new GUI(*this, DISCONNECTED));
+ _gui_timer.reset(new GUITimer(*_gui.get()));
+ activate_interval_timer(*_gui_timer, 1000 / 30);
+#ifdef GUI_DEMO
+ _gui_test_timer.reset(new TestTimer(*this));
+ activate_interval_timer(*_gui_test_timer, 1000 * 30);
+#endif
+#endif // USE_GUI
+}
+
+void Application::cleanup_platform_globals()
{
RedWindow::cleanup();
}
+void Application::cleanup_globals()
+{
+}
+
int Application::main(int argc, char** argv, const char* version_str)
{
int ret;
@@ -2564,6 +2586,11 @@ int Application::main(int argc, char** argv, const char* version_str)
std::auto_ptr<Application> app(new Application());
AutoAbort auto_abort(*app.get());
if (app->process_cmd_line(argc, argv)) {
+ init_platform_globals();
+ app->init_second_half();
+ if (app->_gui_mode == GUI_MODE_FULL) {
+ app->_main_screen->show(true, NULL);
+ }
ret = app->run();
} else {
ret = app->_exit_code;
diff --git a/client/application.h b/client/application.h
index f9bbd53..de72454 100644
--- a/client/application.h
+++ b/client/application.h
@@ -343,7 +343,10 @@ private:
static void init_logger();
static void init_globals();
+ static void init_platform_globals();
+ static void cleanup_platform_globals();
static void cleanup_globals();
+ void init_second_half();
friend class DisconnectedEvent;
friend class ConnectionErrorEvent;
--
1.7.3.5
More information about the Spice-devel
mailing list