[Spice-commits] 3 commits - client/application.cpp client/application.h client/common.h client/process_loop.cpp client/red_client.cpp client/windows

Alon Levy alon at kemper.freedesktop.org
Thu Jan 27 07:19:26 PST 2011


 client/application.cpp      |   92 +++++++++++++++++++++++++++-----------------
 client/application.h        |    5 +-
 client/common.h             |   11 ++++-
 client/process_loop.cpp     |    2 
 client/red_client.cpp       |    4 +
 client/windows/platform.cpp |   36 ++++++++++++-----
 6 files changed, 104 insertions(+), 46 deletions(-)

New commits:
commit 42f83d18b50009c2aaa6913a0f305d33c04c5bba
Author: Alon Levy <alevy at redhat.com>
Date:   Thu Jan 27 12:13:20 2011 +0200

    client/windows: don't allocate console unless required

diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index c41c39a..f57413d 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -1121,6 +1121,7 @@ void Platform::on_clipboard_release()
 }
 
 static bool has_console = false;
+static BOOL parent_console;
 
 static void create_console()
 {
@@ -1132,27 +1133,44 @@ static void create_console()
         return;
     }
 
-    AllocConsole();
+    parent_console = AttachConsole(-1 /* parent */);
+
+    if (!parent_console) {
+        AllocConsole();
+    }
+
     HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
     int hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
-    FILE * fp = _fdopen(hConHandle, "w");
-    *stdout = *fp;
+    FILE * fp;
+    /* _open_osfhandle can fail, for instance this will fail:
+        start /wait spicec.exe --help | more
+       however this actually works:
+        cmd /c spicec --help | more
+       */
+    if (hConHandle != -1) {
+        fp = _fdopen(hConHandle, "w");
+        *stdout = *fp;
+    }
 
     h = GetStdHandle(STD_INPUT_HANDLE);
     hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
-    fp = _fdopen(hConHandle, "r");
-    *stdin = *fp;
+    if (hConHandle != -1) {
+        fp = _fdopen(hConHandle, "r");
+        *stdin = *fp;
+    }
 
     h = GetStdHandle(STD_ERROR_HANDLE);
     hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
-    fp = _fdopen(hConHandle, "w");
-    *stderr = *fp;
+    if (hConHandle != -1) {
+        fp = _fdopen(hConHandle, "w");
+        *stderr = *fp;
+    }
 
     has_console = true;
 
     HWND consol_window = GetConsoleWindow();
 
-    if (consol_window) {
+    if (consol_window && !parent_console) {
         SetForegroundWindow(consol_window);
     }
 }
@@ -1161,7 +1179,7 @@ class ConsoleWait {
 public:
     ~ConsoleWait()
     {
-        if (has_console) {
+        if (has_console && !parent_console) {
             Platform::term_printf("\n\nPress any key to exit...");
             _getch();
         }
commit 645236df2bc908de7abcd6b3d8aab0467ee2d401
Author: Alon Levy <alevy at redhat.com>
Date:   Thu Jan 27 12:12:41 2011 +0200

    client: fix broken vs2008 build

diff --git a/client/application.cpp b/client/application.cpp
index 3205098..3333b0c 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -15,8 +15,6 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
 #include "common.h"
 #ifdef WIN32
 #include <io.h>
diff --git a/client/common.h b/client/common.h
index bda7a19..80911d2 100644
--- a/client/common.h
+++ b/client/common.h
@@ -26,7 +26,11 @@
 #include <errno.h>
 #endif
 
-#include <spice/types.h>
+#define __STDC_FORMAT_MACROS
+#ifndef _WIN32
+#include <inttypes.h>
+#endif
+
 #include <stdio.h>
 #include <string>
 #include <vector>
@@ -74,6 +78,11 @@
 #define RED64
 #endif
 
+#if defined(_WIN32) && !defined(PRIu64)
+#define PRIu64 "I64u"
+#endif
+
+#include <spice/types.h>
 #include "red_types.h"
 
 #endif
diff --git a/client/process_loop.cpp b/client/process_loop.cpp
index d7e6744..9a0dadc 100644
--- a/client/process_loop.cpp
+++ b/client/process_loop.cpp
@@ -236,7 +236,7 @@ unsigned int TimersQueue::get_soonest_timeout()
     if (next_time <= now) {
         return 0;
     }
-    return (next_time - now);
+    return (int)(next_time - now);
 }
 
 
diff --git a/client/red_client.cpp b/client/red_client.cpp
index 1810593..ac04555 100644
--- a/client/red_client.cpp
+++ b/client/red_client.cpp
@@ -24,6 +24,10 @@
 #include "debug.h"
 #include "marshallers.h"
 
+#ifndef INFINITY
+#define INFINITY HUGE
+#endif
+
 #ifdef __GNUC__
 typedef struct __attribute__ ((__packed__)) OldRedMigrationBegin {
 #else
commit 9394b2c50e8b5d7b336c6603166709ed0637bb81
Author: Alon Levy <alevy at redhat.com>
Date:   Wed Jan 26 01:52:45 2011 +0200

    client: --help should not need platform initialization
    
    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).

diff --git a/client/application.cpp b/client/application.cpp
index d1aef1a..3205098 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,37 +412,37 @@ 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;
     }
+    memset(_keyboard_state, 0, sizeof(_keyboard_state));
 }
 
 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
@@ -2181,13 +2173,12 @@ void Application::register_channels()
 #endif
 }
 
-bool Application::process_cmd_line(int argc, char** argv)
+bool Application::process_cmd_line(int argc, char** argv, bool &full_screen)
 {
     std::string host = "";
     int sport = -1;
     int port = -1;
     bool auto_display_res = false;
-    bool full_screen = false;
     std::string password;
     DisplaySetting display_setting;
 
@@ -2217,11 +2208,12 @@ bool Application::process_cmd_line(int argc, char** argv)
 #endif
     };
 
+    full_screen = false;
+
 #ifdef USE_GUI
     if (argc == 1) {
         _gui_mode = GUI_MODE_FULL;
         register_channels();
-        _main_screen->show(true, NULL);
         return true;
     }
 #endif // USE_GUI
@@ -2439,11 +2431,6 @@ bool Application::process_cmd_line(int argc, char** argv)
     _client.set_auto_display_res(auto_display_res);
     _client.set_display_setting(display_setting);
 
-    if (full_screen) {
-        enter_full_screen();
-    } else {
-        _main_screen->show(true, NULL);
-    }
     return true;
 }
 
@@ -2545,26 +2532,65 @@ void Application::init_globals()
 #ifdef WIN32
     gdi_canvas_init();
 #endif
+}
 
+/* seperated from init_globals to allow --help to work
+ * faster and not require X on linux. */
+void Application::init_platform_globals()
+{
     Platform::init();
     RedWindow::init();
 }
 
-void Application::cleanup_globals()
+void Application::init_remainder()
+{
+    Platform::set_process_loop(*this);
+    init_monitors();
+    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;
+    bool full_screen;
 
     init_globals();
     LOG_INFO("starting %s", version_str);
     std::auto_ptr<Application> app(new Application());
     AutoAbort auto_abort(*app.get());
-    if (app->process_cmd_line(argc, argv)) {
+    if (app->process_cmd_line(argc, argv, full_screen)) {
+        init_platform_globals();
+        app->init_remainder();
+        if (full_screen) {
+            app->enter_full_screen();
+        } else {
+            app->_main_screen->show(true, NULL);
+        }
         ret = app->run();
+        cleanup_platform_globals();
     } else {
         ret = app->_exit_code;
     }
diff --git a/client/application.h b/client/application.h
index f9bbd53..4133dfe 100644
--- a/client/application.h
+++ b/client/application.h
@@ -290,7 +290,7 @@ private:
     bool set_disabled_display_effects(CmdLineParser& parser, char *val, const char* arg0,
                                       DisplaySetting& disp_setting);
     void on_cmd_line_invalid_arg(const char* arg0, const char* what, const char* val);
-    bool process_cmd_line(int argc, char** argv);
+    bool process_cmd_line(int argc, char** argv, bool& full_screen);
     void register_channels();
     void abort();
     void init_menu();
@@ -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_remainder();
 
     friend class DisconnectedEvent;
     friend class ConnectionErrorEvent;


More information about the Spice-commits mailing list