From: VMware, Inc <> Date: Wed, 20 Jul 2011 20:46:14 +0000 (-0700) Subject: Move even more code out of lib/guestApp. X-Git-Tag: 2011.07.19-450511~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f3ebeac03fc9f5e7693ece88c44339322dc4f76f;p=thirdparty%2Fopen-vm-tools.git Move even more code out of lib/guestApp. This time it's mouse and old copy & paste protocol functions, which are only used by the dnd plugin. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/guestApp/guestApp.c b/open-vm-tools/lib/guestApp/guestApp.c index dbd36b85f..70e999ee5 100644 --- a/open-vm-tools/lib/guestApp/guestApp.c +++ b/open-vm-tools/lib/guestApp/guestApp.c @@ -278,250 +278,3 @@ GuestApp_GetConfPath(void) #endif } - -/* - *---------------------------------------------------------------------------- - * - * GuestApp_IsMouseAbsolute - * - * Are the host/guest capable of using absolute mouse mode? - * - * Results: - * TRUE if host is in absolute mouse mode, FALSE otherwise. - * - * Side effects: - * Issues Tools RPC. - * - *---------------------------------------------------------------------------- - */ - -GuestAppAbsoluteMouseState -GuestApp_GetAbsoluteMouseState(void) -{ - Backdoor_proto bp; - GuestAppAbsoluteMouseState state = GUESTAPP_ABSMOUSE_UNKNOWN; - - bp.in.cx.halfs.low = BDOOR_CMD_ISMOUSEABSOLUTE; - Backdoor(&bp); - if (bp.out.ax.word == 0) { - state = GUESTAPP_ABSMOUSE_UNAVAILABLE; - } else if (bp.out.ax.word == 1) { - state = GUESTAPP_ABSMOUSE_AVAILABLE; - } - - return state; -} - - -/* - *----------------------------------------------------------------------------- - * - * GuestApp_GetPos -- - * - * Retrieve the host notion of the guest pointer location. --hpreg - * - * Results: - * '*x' and '*y' are the coordinates (top left corner is 0, 0) of the - * host notion of the guest pointer location. (-100, -100) means that the - * mouse is not grabbed on the host. - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -void -GuestApp_GetPos(int16 *x, // OUT - int16 *y) // OUT -{ - Backdoor_proto bp; - - bp.in.cx.halfs.low = BDOOR_CMD_GETPTRLOCATION; - Backdoor(&bp); - *x = bp.out.ax.word >> 16; - *y = bp.out.ax.word; -} - - -/* - *----------------------------------------------------------------------------- - * - * GuestApp_SetPos -- - * - * Update the host notion of the guest pointer location. 'x' and 'y' are - * the coordinates (top left corner is 0, 0). --hpreg - * - * Results: - * None - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -void -GuestApp_SetPos(uint16 x, // IN - uint16 y) // IN -{ - Backdoor_proto bp; - - bp.in.cx.halfs.low = BDOOR_CMD_SETPTRLOCATION; - bp.in.size = (x << 16) | y; - Backdoor(&bp); -} - - -/* - * XXX The 5 functions below should be re-implemented using the message layer, - * to benefit from: - * . The high-bandwidth backdoor or the generic "send 4 bytes at a time" - * logic of the low-bandwidth backdoor - * . The restore/resume detection logic - * --hpreg - */ - -/* - *----------------------------------------------------------------------------- - * - * GuestApp_GetHostSelectionLen -- - * - * Retrieve the length of the clipboard (if any) to receive from the - * VMX. --hpreg - * - * Results: - * Length >= 0 if a clipboard must be retrieved from the host. - * < 0 on error (VMWARE_DONT_EXCHANGE_SELECTIONS or - * VMWARE_SELECTION_NOT_READY currently) - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -int32 -GuestApp_GetHostSelectionLen(void) -{ - Backdoor_proto bp; - - bp.in.cx.halfs.low = BDOOR_CMD_GETSELLENGTH; - Backdoor(&bp); - return bp.out.ax.word; -} - - -/* - *----------------------------------------------------------------------------- - * - * GuestAppGetNextPiece -- - * - * Retrieve the next 4 bytes of the host clipboard. --hpreg - * - * Results: - * The next 4 bytes of the host clipboard. - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -static uint32 -GuestAppGetNextPiece(void) -{ - Backdoor_proto bp; - - bp.in.cx.halfs.low = BDOOR_CMD_GETNEXTPIECE; - Backdoor(&bp); - return bp.out.ax.word; -} - - -/* - *----------------------------------------------------------------------------- - * - * GuestApp_GetHostSelection -- - * - * Retrieve the host clipboard. 'data' must be a buffer whose size is at - * least (('size' + 4 - 1) / 4) * 4 bytes. --hpreg - * - * Results: - * The host clipboard in 'data'. - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -void -GuestApp_GetHostSelection(unsigned int size, // IN - char *data) // OUT -{ - uint32 *current; - uint32 const *end; - - current = (uint32 *)data; - end = current + (size + sizeof *current - 1) / sizeof *current; - for (; current < end; current++) { - *current = GuestAppGetNextPiece(); - } -} - - -/* - *----------------------------------------------------------------------------- - * - * GuestApp_SetSelLength -- - * - * Tell the VMX about the length of the clipboard we are about to send - * to it. --hpreg - * - * Results: - * None - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -void -GuestApp_SetSelLength(uint32 length) // IN -{ - Backdoor_proto bp; - - bp.in.cx.halfs.low = BDOOR_CMD_SETSELLENGTH; - bp.in.size = length; - Backdoor(&bp); -} - - -/* - *----------------------------------------------------------------------------- - * - * GuestApp_SetNextPiece -- - * - * Send the next 4 bytes of the guest clipboard. --hpreg - * - * Results: - * None - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -void -GuestApp_SetNextPiece(uint32 data) // IN -{ - Backdoor_proto bp; - - bp.in.cx.halfs.low = BDOOR_CMD_SETNEXTPIECE; - bp.in.size = data; - Backdoor(&bp); -} - diff --git a/open-vm-tools/lib/include/guestApp.h b/open-vm-tools/lib/include/guestApp.h index 55be7c88d..e618eeb41 100644 --- a/open-vm-tools/lib/include/guestApp.h +++ b/open-vm-tools/lib/include/guestApp.h @@ -51,35 +51,6 @@ GuestApp_GetInstallPath(void); char * GuestApp_GetConfPath(void); -void -GuestApp_GetPos(int16 *x, // OUT - int16 *y); // OUT - -void -GuestApp_SetPos(uint16 x, // IN - uint16 y); // IN - -int32 -GuestApp_GetHostSelectionLen(void); - -void -GuestApp_GetHostSelection(unsigned int size, // IN - char *data); // OUT - -void -GuestApp_SetSelLength(uint32 length); // IN - -void -GuestApp_SetNextPiece(uint32 data); // IN - -typedef enum { - GUESTAPP_ABSMOUSE_UNAVAILABLE, - GUESTAPP_ABSMOUSE_AVAILABLE, - GUESTAPP_ABSMOUSE_UNKNOWN -} GuestAppAbsoluteMouseState; - -GuestAppAbsoluteMouseState GuestApp_GetAbsoluteMouseState(void); - #ifdef __cplusplus } #endif diff --git a/open-vm-tools/services/plugins/dndcp/Makefile.am b/open-vm-tools/services/plugins/dndcp/Makefile.am index 35c256afd..04422c7b9 100644 --- a/open-vm-tools/services/plugins/dndcp/Makefile.am +++ b/open-vm-tools/services/plugins/dndcp/Makefile.am @@ -67,6 +67,7 @@ libdndcp_la_SOURCES += dndGuest/dndCPTransportGuestRpc.cpp libdndcp_la_SOURCES += stringxx/string.cc +libdndcp_la_SOURCES += copyPasteCompat.c libdndcp_la_SOURCES += copyPasteCompatX11.c libdndcp_la_SOURCES += copyPasteDnDWrapper.cpp libdndcp_la_SOURCES += copyPasteDnDX11.cpp diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteCompat.c b/open-vm-tools/services/plugins/dndcp/copyPasteCompat.c new file mode 100644 index 000000000..7c1a7bf47 --- /dev/null +++ b/open-vm-tools/services/plugins/dndcp/copyPasteCompat.c @@ -0,0 +1,171 @@ +/********************************************************* + * Copyright (C) 2011 VMware, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation version 2.1 and no later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *********************************************************/ + +/* + * copyPasteCompat.c -- + * + * Legacy copy/paste functions. + */ + +#include "backdoor.h" +#include "backdoor_def.h" +#include "copyPasteCompat.h" + +/* + *----------------------------------------------------------------------------- + * + * CopyPaste_GetHostSelectionLen -- + * + * Retrieve the length of the clipboard (if any) to receive from the + * VMX. + * + * Results: + * Length >= 0 if a clipboard must be retrieved from the host. + * < 0 on error (VMWARE_DONT_EXCHANGE_SELECTIONS or + * VMWARE_SELECTION_NOT_READY currently) + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +int32 +CopyPaste_GetHostSelectionLen(void) +{ + Backdoor_proto bp; + + bp.in.cx.halfs.low = BDOOR_CMD_GETSELLENGTH; + Backdoor(&bp); + return bp.out.ax.word; +} + + +/* + *----------------------------------------------------------------------------- + * + * CopyPasteGetNextPiece -- + * + * Retrieve the next 4 bytes of the host clipboard. + * + * Results: + * The next 4 bytes of the host clipboard. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static uint32 +CopyPasteGetNextPiece(void) +{ + Backdoor_proto bp; + + bp.in.cx.halfs.low = BDOOR_CMD_GETNEXTPIECE; + Backdoor(&bp); + return bp.out.ax.word; +} + + +/* + *----------------------------------------------------------------------------- + * + * CopyPaste_GetHostSelection -- + * + * Retrieve the host clipboard. 'data' must be a buffer whose size is at + * least (('size' + 4 - 1) / 4) * 4 bytes. + * + * Results: + * The host clipboard in 'data'. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +CopyPaste_GetHostSelection(unsigned int size, // IN + char *data) // OUT +{ + uint32 *current; + uint32 const *end; + + current = (uint32 *)data; + end = current + (size + sizeof *current - 1) / sizeof *current; + for (; current < end; current++) { + *current = CopyPasteGetNextPiece(); + } +} + + +/* + *----------------------------------------------------------------------------- + * + * CopyPaste_SetSelLength -- + * + * Tell the VMX about the length of the clipboard we are about to send + * to it. + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +CopyPaste_SetSelLength(uint32 length) // IN +{ + Backdoor_proto bp; + + bp.in.cx.halfs.low = BDOOR_CMD_SETSELLENGTH; + bp.in.size = length; + Backdoor(&bp); +} + + +/* + *----------------------------------------------------------------------------- + * + * CopyPaste_SetNextPiece -- + * + * Send the next 4 bytes of the guest clipboard. + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +CopyPaste_SetNextPiece(uint32 data) // IN +{ + Backdoor_proto bp; + + bp.in.cx.halfs.low = BDOOR_CMD_SETNEXTPIECE; + bp.in.size = data; + Backdoor(&bp); +} + diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteCompat.h b/open-vm-tools/services/plugins/dndcp/copyPasteCompat.h index 30fd0bfe9..07374b272 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteCompat.h +++ b/open-vm-tools/services/plugins/dndcp/copyPasteCompat.h @@ -26,6 +26,8 @@ #if !defined _COPYPASTE_COMPAT_H #define _COPYPASTE_COMPAT_H +#include "vmware.h" + /* Functions to be compatible with old text copy/paste directly based on backdoor cmd. */ Bool CopyPaste_RequestSelection(void); Bool CopyPaste_GetBackdoorSelections(void); @@ -33,4 +35,17 @@ Bool CopyPaste_IsRpcCPSupported(void); void CopyPaste_Init(void); void CopyPaste_SetVersion(int version); +int32 +CopyPaste_GetHostSelectionLen(void); + +void +CopyPaste_GetHostSelection(unsigned int size, // IN + char *data); // OUT + +void +CopyPaste_SetSelLength(uint32 length); // IN + +void +CopyPaste_SetNextPiece(uint32 data); // IN + #endif diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c b/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c index e96a16ae6..fc6f183c3 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c +++ b/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c @@ -45,9 +45,9 @@ #include #include "vm_assert.h" +#include "copyPasteCompat.h" #include "str.h" #include "strutil.h" -#include "guestApp.h" #include "dnd.h" #include "util.h" #include "cpName.h" @@ -547,7 +547,7 @@ CopyPasteSelectionClearCB(GtkWidget *widget, // IN: unused * CopyPasteSetBackdoorSelections -- * * Set the clipboard one of two ways, the old way or the new way. - * The old way uses GuestApp_SetSel and there's only one selection. + * The old way uses CopyPaste_SetSelLength and there's only one selection. * Set backdoor selection with either primary selection or clipboard. * The primary selection is the first priority, then clipboard. * If both unavailable, set backdoor selection length to be 0. @@ -606,7 +606,7 @@ CopyPasteSetBackdoorSelections(void) } if (p == NULL) { - GuestApp_SetSelLength(0); + CopyPaste_SetSelLength(0); g_debug("CopyPasteSetBackdoorSelections Set empty text.\n"); } else { len = strlen((char *)p); @@ -616,9 +616,9 @@ CopyPasteSetBackdoorSelections(void) /* Here long string should already be truncated. */ ASSERT(aligned_len <= MAX_SELECTION_BUFFER_LENGTH); - GuestApp_SetSelLength(len); + CopyPaste_SetSelLength(len); for (i = 0; i < len; i += 4, p++) { - GuestApp_SetNextPiece(*p); + CopyPaste_SetNextPiece(*p); } } } @@ -630,9 +630,9 @@ CopyPasteSetBackdoorSelections(void) * CopyPaste_GetBackdoorSelections -- * * Get the clipboard "the old way". - * The old way uses GuestApp_SetSel and there's only one selection. - * We don't have to do anything for the "new way", since the host - * will just push PRIMARY and/or CLIPBOARD when they are available + * The old way uses CopyPaste_GetHostSelectionLen and there's only one + * selection. We don't have to do anything for the "new way", since the + * host will just push PRIMARY and/or CLIPBOARD when they are available * on the host. * * XXX: the "new way" isn't availble yet because the vmx doesn't @@ -658,11 +658,11 @@ CopyPaste_GetBackdoorSelections(void) return TRUE; } - selLength = GuestApp_GetHostSelectionLen(); + selLength = CopyPaste_GetHostSelectionLen(); if (selLength < 0 || selLength > MAX_SELECTION_BUFFER_LENGTH) { return FALSE; } else if (selLength > 0) { - GuestApp_GetHostSelection(selLength, gHostClipboardBuf); + CopyPaste_GetHostSelection(selLength, gHostClipboardBuf); gHostClipboardBuf[selLength] = 0; g_debug("CopyPaste_GetBackdoorSelections Get text [%s].\n", gHostClipboardBuf); gtk_selection_owner_set(gUserMainWidget, diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp b/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp index 922b49c29..043a4ccd7 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp +++ b/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp @@ -45,7 +45,6 @@ extern "C" { #include "cpNameUtil.h" #include "rpcout.h" #include "vmware/guestrpc/tclodefs.h" - #include "guestApp.h" } /* diff --git a/open-vm-tools/services/plugins/dndcp/dndPluginInt.h b/open-vm-tools/services/plugins/dndcp/dndPluginInt.h index 9be0cab1e..5f6536681 100644 --- a/open-vm-tools/services/plugins/dndcp/dndPluginInt.h +++ b/open-vm-tools/services/plugins/dndcp/dndPluginInt.h @@ -27,7 +27,6 @@ #define __DNDPLUGIN_INT_H__ extern "C" { - #include "guestApp.h" #include "conf.h" } diff --git a/open-vm-tools/services/plugins/dndcp/dndPluginIntX11.h b/open-vm-tools/services/plugins/dndcp/dndPluginIntX11.h index 405c768a0..4f48d5b16 100644 --- a/open-vm-tools/services/plugins/dndcp/dndPluginIntX11.h +++ b/open-vm-tools/services/plugins/dndcp/dndPluginIntX11.h @@ -31,8 +31,6 @@ #include "vm_basic_types.h" #include "dnd.h" -#include "guestApp.h" - #define UNGRABBED_POS (-100) extern Display *gXDisplay; diff --git a/open-vm-tools/services/plugins/dndcp/pointer.cpp b/open-vm-tools/services/plugins/dndcp/pointer.cpp index f5e6a6f2e..195c7955c 100644 --- a/open-vm-tools/services/plugins/dndcp/pointer.cpp +++ b/open-vm-tools/services/plugins/dndcp/pointer.cpp @@ -41,13 +41,21 @@ extern "C" { extern "C" { #include "vm_assert.h" - #include "guestApp.h" #include "backdoor_def.h" + #include "backdoor.h" #include "rpcvmx.h" } + +typedef enum { + ABSMOUSE_UNAVAILABLE, + ABSMOUSE_AVAILABLE, + ABSMOUSE_UNKNOWN +} AbsoluteMouseState; + + static Bool mouseIsGrabbed; -static GuestAppAbsoluteMouseState absoluteMouseState = GUESTAPP_ABSMOUSE_UNKNOWN; +static AbsoluteMouseState absoluteMouseState = ABSMOUSE_UNKNOWN; static uint8 gHostClipboardTries = 0; #if defined(WIN32) @@ -60,6 +68,41 @@ static gboolean PointerUpdatePointerLoop(gpointer clientData); #define POINTER_UPDATE_TIMEOUT 100 + +/* + *---------------------------------------------------------------------------- + * + * PointerGetAbsoluteMouseState + * + * Are the host/guest capable of using absolute mouse mode? + * + * Results: + * TRUE if host is in absolute mouse mode, FALSE otherwise. + * + * Side effects: + * Issues Tools RPC. + * + *---------------------------------------------------------------------------- + */ + +static AbsoluteMouseState +PointerGetAbsoluteMouseState(void) +{ + Backdoor_proto bp; + AbsoluteMouseState state = ABSMOUSE_UNKNOWN; + + bp.in.cx.halfs.low = BDOOR_CMD_ISMOUSEABSOLUTE; + Backdoor(&bp); + if (bp.out.ax.word == 0) { + state = ABSMOUSE_UNAVAILABLE; + } else if (bp.out.ax.word == 1) { + state = ABSMOUSE_AVAILABLE; + } + + return state; +} + + #if !defined(WIN32) /* *----------------------------------------------------------------------------- @@ -114,6 +157,67 @@ PointerSetXCursorPos(int x, int y) #endif + +/* + *----------------------------------------------------------------------------- + * + * PointerGetPos -- + * + * Retrieve the host notion of the guest pointer location. + * + * Results: + * '*x' and '*y' are the coordinates (top left corner is 0, 0) of the + * host notion of the guest pointer location. (-100, -100) means that the + * mouse is not grabbed on the host. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static void +PointerGetPos(int16 *x, // OUT + int16 *y) // OUT +{ + Backdoor_proto bp; + + bp.in.cx.halfs.low = BDOOR_CMD_GETPTRLOCATION; + Backdoor(&bp); + *x = bp.out.ax.word >> 16; + *y = bp.out.ax.word; +} + + +/* + *----------------------------------------------------------------------------- + * + * PointerSetPos -- + * + * Update the host notion of the guest pointer location. 'x' and 'y' are + * the coordinates (top left corner is 0, 0). + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static void +PointerSetPos(uint16 x, // IN + uint16 y) // IN +{ + Backdoor_proto bp; + + bp.in.cx.halfs.low = BDOOR_CMD_SETPTRLOCATION; + bp.in.size = (x << 16) | y; + Backdoor(&bp); +} + + /* *----------------------------------------------------------------------------- * @@ -138,7 +242,7 @@ PointerGrabbed(void) short hostPosX; short hostPosY; - GuestApp_GetPos(&hostPosX, &hostPosY); + PointerGetPos(&hostPosX, &hostPosY); #if defined(WIN32) SetCursorPos(hostPosX, hostPosY); #else @@ -220,7 +324,7 @@ PointerUpdatePointerLoop(gpointer clientData) // IN: unused int guestX, guestY; #endif - GuestApp_GetPos(&hostPosX, &hostPosY); + PointerGetPos(&hostPosX, &hostPosY); if (mouseIsGrabbed) { if (hostPosX == UNGRABBED_POS) { /* We transitioned from grabbed to ungrabbed */ @@ -243,13 +347,13 @@ PointerUpdatePointerLoop(gpointer clientData) // IN: unused * where to position the outside pointer if the user releases the guest * pointer via the key combination). */ - GuestApp_SetPos(guestPos.x, guestPos.y); + PointerSetPos(guestPos.x, guestPos.y); } } #else PointerGetXCursorPos(&guestX, &guestY); if ( hostPosX != guestX || hostPosY != guestY) { - GuestApp_SetPos(guestX, guestY); + PointerSetPos(guestX, guestY); } #endif CopyPasteDnDWrapper *wrapper = CopyPasteDnDWrapper::GetInstance(); @@ -271,7 +375,7 @@ PointerUpdatePointerLoop(gpointer clientData) // IN: unused } if (!CopyPaste_IsRpcCPSupported() || - (absoluteMouseState == GUESTAPP_ABSMOUSE_UNAVAILABLE)) { + (absoluteMouseState == ABSMOUSE_UNAVAILABLE)) { GSource *src; @@ -310,7 +414,7 @@ PointerUpdatePointerLoop(gpointer clientData) // IN: unused void Pointer_Init(ToolsAppCtx *ctx) { - absoluteMouseState = GuestApp_GetAbsoluteMouseState(); + absoluteMouseState = PointerGetAbsoluteMouseState(); PointerUpdatePointerLoop(NULL); mouseIsGrabbed = FALSE; }