]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
[VMTools] [DnD] [Code Refactor] - part 1 - dndGuest/dndcp sides refactor
authorOliver Kurth <okurth@vmware.com>
Fri, 27 Jul 2018 18:46:23 +0000 (11:46 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 27 Jul 2018 18:46:23 +0000 (11:46 -0700)
These code changes are based on following two principles:
1. No functional impact/change on DnD & Copy Paste feature for WS/Fusion.
2. The DnD base code is ready for Horizon View DnD feature target for
   an upcoming release.

Summary for this patch:
1. The dependency refactor to add a new folder dndGuestBase (lib\dndGuestBase)
   to extract the common code shared by WS/FS and View.
2. Add two sub folders to dndGuestBase (vm-inc and crt-inc) to contain
   the WF/FS or view specific header files. (for example,
   vm-inc/vmGuestDnDSrc.hh, crt-inc/crtGuestDnDSrc.hh....)
3. The header files start with 'crt' will not be used by WS/FS, they are
   added only for specifying the new folder structure.
4. Move WS/FS specific dndGuest/dndcp codes to WS/FS specific derived
   classes like VMGuestDnDCPMgr, VMGuestDnDMgr, VMCopyPasteDnDWrapper and so on.
5. Also have created some Horizon View specific codes on mkvchanserver in
   local environment to verify most of interfaces in the base classes are
   ready for Horizon View side DnD development.

32 files changed:
open-vm-tools/services/plugins/dndcp/Makefile.am
open-vm-tools/services/plugins/dndcp/copyPasteDnDX11.cpp
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDCPMgr.cc [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDCPMgr.hh [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDMgr.cc [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDMgr.hh [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDSrc.cc [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDSrc.hh [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestFileTransfer.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestFileTransfer.cc with 77% similarity]
open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestFileTransfer.hh [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDImpl.h [moved from open-vm-tools/services/plugins/dndcp/copyPasteDnDImpl.h with 93% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDWrapper.cpp [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDWrapper.h [moved from open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.h with 82% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDX11.h [moved from open-vm-tools/services/plugins/dndcp/copyPasteDnDX11.h with 95% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dndFileList.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/dndFileList.cc with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dndFileList.hh [moved from open-vm-tools/services/plugins/dndcp/dndGuest/dndFileList.hh with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dndPluginInt.h [moved from open-vm-tools/services/plugins/dndcp/dndPluginInt.h with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dndRpcV3.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/dndRpcV3.cc with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dndRpcV3.hh [moved from open-vm-tools/services/plugins/dndcp/dndGuest/dndRpcV3.hh with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dndUIX11.h [moved from open-vm-tools/services/plugins/dndcp/dndUIX11.h with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/dragDetWndX11.h [moved from open-vm-tools/services/plugins/dndcp/dragDetWndX11.h with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestCopyPaste.hh [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestCopyPaste.hh with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnD.hh [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnD.hh with 87% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDCPMgr.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDCPMgr.cc with 59% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDCPMgr.hh [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDCPMgr.hh with 81% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDDest.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDDest.cc with 100% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDMgr.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDMgr.cc with 89% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDSrc.cc [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDSrc.cc with 86% similarity]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestFileTransfer.cc [new file with mode: 0644]
open-vm-tools/services/plugins/dndcp/dndGuestBase/guestFileTransfer.hh [moved from open-vm-tools/services/plugins/dndcp/dndGuest/guestFileTransfer.hh with 78% similarity]
open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.cpp [moved from open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.cpp with 52% similarity]
open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.h [new file with mode: 0644]

index 8097fa61b5522cff04da85a324be36a7747a7eb9..141181926f2533c3addef473569dbd2625f1d462 100644 (file)
@@ -25,6 +25,7 @@ libdndcp_la_CPPFLAGS += @GTK_CPPFLAGS@
 libdndcp_la_CPPFLAGS += @PLUGIN_CPPFLAGS@
 libdndcp_la_CPPFLAGS += -I$(top_srcdir)/services/plugins/dndcp/dnd
 libdndcp_la_CPPFLAGS += -I$(top_srcdir)/services/plugins/dndcp/dndGuest
+libdndcp_la_CPPFLAGS += -I$(top_srcdir)/services/plugins/dndcp/dndGuestBase
 libdndcp_la_CPPFLAGS += -I$(top_srcdir)/services/plugins/dndcp/stringxx
 libdndcp_la_CPPFLAGS += -I$(top_srcdir)/services/plugins/dndcp/xutils
 libdndcp_la_CPPFLAGS += -I$(top_srcdir)/include
@@ -57,18 +58,24 @@ libdndcp_la_SOURCES += dnd/dndCPMsgV4.c
 libdndcp_la_SOURCES += dnd/dndLinux.c
 libdndcp_la_SOURCES += dnd/dndMsg.c
 
+libdndcp_la_SOURCES += dndGuestBase/copyPasteDnDWrapper.cpp
+libdndcp_la_SOURCES += dndGuestBase/dndFileList.cc
+libdndcp_la_SOURCES += dndGuestBase/dndRpcV3.cc
+libdndcp_la_SOURCES += dndGuestBase/guestDnDCPMgr.cc
+libdndcp_la_SOURCES += dndGuestBase/guestDnDDest.cc
+libdndcp_la_SOURCES += dndGuestBase/guestDnDSrc.cc
+libdndcp_la_SOURCES += dndGuestBase/guestDnDMgr.cc
+libdndcp_la_SOURCES += dndGuestBase/guestFileTransfer.cc
+
 libdndcp_la_SOURCES += dndGuest/copyPasteRpcV3.cc
-libdndcp_la_SOURCES += dndGuest/dndFileList.cc
-libdndcp_la_SOURCES += dndGuest/dndRpcV3.cc
 libdndcp_la_SOURCES += dndGuest/guestCopyPasteDest.cc
 libdndcp_la_SOURCES += dndGuest/guestCopyPasteMgr.cc
 libdndcp_la_SOURCES += dndGuest/guestCopyPasteSrc.cc
-libdndcp_la_SOURCES += dndGuest/guestDnDCPMgr.cc
-libdndcp_la_SOURCES += dndGuest/guestDnDDest.cc
-libdndcp_la_SOURCES += dndGuest/guestDnDMgr.cc
-libdndcp_la_SOURCES += dndGuest/guestDnDSrc.cc
-libdndcp_la_SOURCES += dndGuest/guestFileTransfer.cc
+libdndcp_la_SOURCES += dndGuest/vmGuestDnDCPMgr.cc
+libdndcp_la_SOURCES += dndGuest/vmGuestFileTransfer.cc
+libdndcp_la_SOURCES += dndGuest/vmGuestDnDSrc.cc
 libdndcp_la_SOURCES += dndGuest/copyPasteRpcV4.cc
+libdndcp_la_SOURCES += dndGuest/vmGuestDnDMgr.cc
 libdndcp_la_SOURCES += dndGuest/dndRpcV4.cc
 libdndcp_la_SOURCES += dndGuest/fileTransferRpcV4.cc
 libdndcp_la_SOURCES += dndGuest/rpcV3Util.cpp
@@ -80,7 +87,7 @@ libdndcp_la_SOURCES += xutils/xutils.cc
 
 libdndcp_la_SOURCES += copyPasteCompat.c
 libdndcp_la_SOURCES += copyPasteCompatX11.c
-libdndcp_la_SOURCES += copyPasteDnDWrapper.cpp
+libdndcp_la_SOURCES += vmCopyPasteDnDWrapper.cpp
 libdndcp_la_SOURCES += copyPasteDnDX11.cpp
 libdndcp_la_SOURCES += copyPasteUIX11.cpp
 libdndcp_la_SOURCES += dndUIX11.cpp
@@ -99,6 +106,9 @@ libdndcp_la_CPPFLAGS += -DDND_IS_XDG
 libdndcp_la_SOURCES  += dnd/dndXdg.c
 endif
 
+# DND_VM is used to distinguish the dnd feature between WS/FS and View
+libdndcp_la_CPPFLAGS += -DDND_VM
+
 BUILT_SOURCES =
 BUILT_SOURCES += cpFileContents.h
 BUILT_SOURCES += cpFileContents_xdr.c
index 4c2f3d8d56399140ceecac3e8ce7c965220adf49..eef054b994a834f111b640daff9716e6247b14ad 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "copyPasteDnDWrapper.h"
 #include "copyPasteDnDX11.h"
+#include "copyPasteUIX11.h"
 #include "dndPluginIntX11.h"
 #include "tracer.hh"
 
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDCPMgr.cc b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDCPMgr.cc
new file mode 100644 (file)
index 0000000..50b5a6a
--- /dev/null
@@ -0,0 +1,131 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestDnDCPMgr.cc --
+ *
+ * The inherited implementation of common class GuestDnDCPMgr in VM side.
+ */
+
+#include "dndCPTransportGuestRpc.hpp"
+#include "vmGuestDnDCPMgr.hh"
+#include "vmGuestDnDMgr.hh"
+#include "vmGuestFileTransfer.hh"
+
+
+/**
+ *
+ * Destructor.
+ */
+
+VMGuestDnDCPMgr::~VMGuestDnDCPMgr()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   delete mDnDMgr;
+   mDnDMgr = NULL;
+   delete mFileTransfer;
+   mFileTransfer = NULL;
+   delete mTransport;
+   mTransport = NULL;
+}
+
+
+/**
+ * Initialize the VMGuestDnDCPMgr object. All owner should call this first before
+ * calling any other function.
+ *
+ * @param[in] ctx ToolsAppCtx
+ */
+
+void
+VMGuestDnDCPMgr::Init(ToolsAppCtx *ctx)
+{
+   mToolsAppCtx = ctx;
+
+   ASSERT(mToolsAppCtx);
+
+   if (mFileTransfer) {
+      delete mFileTransfer;
+   }
+   mFileTransfer = new VMGuestFileTransfer(GetTransport());
+}
+
+
+/**
+ * Get the DnDCPTransport object.
+ *
+ * XXX Implementation here is temporary and should be replaced with rpcChannel.
+ *
+ * @return a pointer to the manager's DnDCPTransport instance.
+ */
+
+DnDCPTransport *
+VMGuestDnDCPMgr::GetTransport(void)
+{
+   if (!mTransport) {
+      ASSERT(mToolsAppCtx);
+      mTransport = new DnDCPTransportGuestRpc(mToolsAppCtx->rpc);
+   }
+   return mTransport;
+}
+
+
+/**
+ * Get the GuestDnDMgr object.
+ *
+ * @return a pointer to the GuestDnDMgr instance.
+ */
+
+GuestDnDMgr *
+VMGuestDnDCPMgr::GetDnDMgr(void)
+{
+   if (!mDnDMgr) {
+      /* mEventQueue must be set before this call. */
+      mDnDMgr = new VMGuestDnDMgr(GetTransport(), mToolsAppCtx);
+   }
+   return mDnDMgr;
+}
+
+
+/**
+ * Create an instance of class VMGuestDnDCPMgr.
+ *
+ * @return a pointer to the VMGuestDnDCPMgr instance.
+ */
+
+VMGuestDnDCPMgr *
+VMGuestDnDCPMgr::CreateInstance(void)
+{
+   return new VMGuestDnDCPMgr();
+}
+
+
+/**
+ * Get the GuestCopyPasteMgr object.
+ *
+ * @return a pointer to the GuestCopyPasteMgr instance.
+ */
+
+GuestCopyPasteMgr *
+VMGuestDnDCPMgr::GetCopyPasteMgr(void)
+{
+   if (!mCPMgr) {
+      mCPMgr = new GuestCopyPasteMgr(GetTransport());
+   }
+   return mCPMgr;
+}
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDCPMgr.hh b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDCPMgr.hh
new file mode 100644 (file)
index 0000000..d06a61a
--- /dev/null
@@ -0,0 +1,56 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestDnDCPMgr.hh --
+ *
+ * The inherited implementation of common class GuestDnDCPMgr in VM side.
+ */
+
+#ifndef VM_GUEST_DND_CP_MGR_HH
+#define VM_GUEST_DND_CP_MGR_HH
+
+#include "guestDnDCPMgr.hh"
+
+extern "C" {
+   #include "vmware/tools/guestrpc.h"
+   #include "vmware/tools/plugin.h"
+}
+
+class VMGuestDnDCPMgr
+   : public GuestDnDCPMgr
+{
+public:
+   virtual ~VMGuestDnDCPMgr();
+   void Init(ToolsAppCtx *ctx);
+   virtual GuestDnDMgr *GetDnDMgr(void);
+   virtual DnDCPTransport *GetTransport(void);
+   virtual GuestCopyPasteMgr *GetCopyPasteMgr(void);
+
+   static VMGuestDnDCPMgr *CreateInstance(void);
+
+private:
+   VMGuestDnDCPMgr(void) : GuestDnDCPMgr() { }
+   VMGuestDnDCPMgr(const VMGuestDnDCPMgr &mgr);
+   VMGuestDnDCPMgr& operator=(const VMGuestDnDCPMgr &mgr);
+
+private:
+   ToolsAppCtx *mToolsAppCtx;
+};
+
+#endif // VM_GUEST_DND_CP_MGR_HH
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDMgr.cc b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDMgr.cc
new file mode 100644 (file)
index 0000000..9c5020a
--- /dev/null
@@ -0,0 +1,124 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestDnDMgr.cc --
+ *
+ * The inherited implementation of common class GuestDnDMgr in VM side.
+ */
+
+#include "dndRpcV3.hh"
+#include "dndRpcV4.hh"
+#include "tracer.hh"
+#include "vmGuestDnDMgr.hh"
+
+extern "C" {
+#include "debug.h"
+}
+
+
+/**
+ * Constructor.
+ *
+ * @param[in] transport for sending/receiving packets.
+ * @param[in] ctx ToolsAppCtx
+ */
+
+VMGuestDnDMgr::VMGuestDnDMgr(DnDCPTransport *transport,
+                             ToolsAppCtx *ctx)
+   : GuestDnDMgr(transport, ctx),
+     mToolsAppCtx(ctx)
+{
+   ASSERT(mToolsAppCtx);
+}
+
+
+/**
+ * Add DnD un-grab timeout event.
+ */
+
+void
+VMGuestDnDMgr::AddDnDUngrabTimeoutEvent()
+{
+   if (NULL == mUngrabTimeout) {
+      g_debug("%s: adding UngrabTimeout\n", __FUNCTION__);
+      mUngrabTimeout = g_timeout_source_new(UNGRAB_TIMEOUT);
+      VMTOOLSAPP_ATTACH_SOURCE(mToolsAppCtx, mUngrabTimeout,
+                               GuestDnDMgr::DnDUngrabTimeout, this, NULL);
+      g_source_unref(mUngrabTimeout);
+   }
+}
+
+
+/**
+ * Add Unity DnD detect timeout event.
+ */
+
+void
+VMGuestDnDMgr::AddUnityDnDDetTimeoutEvent()
+{
+   mUnityDnDDetTimeout = g_timeout_source_new(UNITY_DND_DET_TIMEOUT);
+   VMTOOLSAPP_ATTACH_SOURCE(mToolsAppCtx,
+                            mUnityDnDDetTimeout,
+                            GuestDnDMgr::DnDUnityDetTimeout,
+                            this,
+                            NULL);
+   g_source_unref(mUnityDnDDetTimeout);
+}
+
+
+/**
+ * Add hide detect window timer.
+ */
+
+void
+VMGuestDnDMgr::AddHideDetWndTimerEvent()
+{
+   if (NULL == mHideDetWndTimer) {
+      g_debug("%s: add timer to hide detection window.\n", __FUNCTION__);
+      mHideDetWndTimer = g_timeout_source_new(HIDE_DET_WND_TIMER);
+      VMTOOLSAPP_ATTACH_SOURCE(mToolsAppCtx, mHideDetWndTimer,
+                               GuestDnDMgr::DnDHideDetWndTimer, this, NULL);
+      g_source_unref(mHideDetWndTimer);
+   } else {
+      g_debug("%s: mHideDetWndTimer is not NULL, quit.\n", __FUNCTION__);
+   }
+}
+
+
+/**
+ * Create DnD rpc with input version.
+ *
+ * @param[in] version input version number
+ */
+
+void
+VMGuestDnDMgr::CreateDnDRpcWithVersion(uint32 version)
+{
+   switch(version) {
+   case 4:
+      mRpc = new DnDRpcV4(mDnDTransport);
+      break;
+   case 3:
+      mRpc = new DnDRpcV3(mDnDTransport);
+      break;
+   default:
+      g_debug("%s: unsupported DnD version\n", __FUNCTION__);
+      break;
+   }
+}
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDMgr.hh b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDMgr.hh
new file mode 100644 (file)
index 0000000..76f828e
--- /dev/null
@@ -0,0 +1,51 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestDnDMgr.hh --
+ *
+ * The inherited implementation of common class GuestDnDMgr in VM side.
+ */
+
+#ifndef VM_GUEST_DND_MGR_HH
+#define VM_GUEST_DND_MGR_HH
+
+#include "guestDnD.hh"
+
+extern "C" {
+   #include "vmware/tools/plugin.h"
+}
+
+class VMGuestDnDMgr
+   : public GuestDnDMgr
+{
+public:
+   VMGuestDnDMgr(DnDCPTransport *transport,
+                 ToolsAppCtx *ctx);
+
+protected:
+   virtual void AddDnDUngrabTimeoutEvent();
+   virtual void AddUnityDnDDetTimeoutEvent();
+   virtual void AddHideDetWndTimerEvent();
+   virtual void CreateDnDRpcWithVersion(uint32 version);
+
+private:
+   ToolsAppCtx *mToolsAppCtx;
+};
+
+#endif // VM_GUEST_DND_MGR_HH
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDSrc.cc b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDSrc.cc
new file mode 100644 (file)
index 0000000..11c9fd5
--- /dev/null
@@ -0,0 +1,103 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestDnDSrc.cc --
+ *
+ * The inherited implementation of common class GuestDnDSrc in VM side.
+ */
+
+#include "util.h"
+#include "vmGuestDnDSrc.hh"
+
+#include "file.h"
+#include "str.h"
+
+
+/**
+ * Constructor.
+ *
+ * @param[in] mgr guest DnD manager
+ */
+
+VMGuestDnDSrc::VMGuestDnDSrc(GuestDnDMgr *mgr)
+   : GuestDnDSrc(mgr)
+{
+}
+
+
+/**
+ * Creates a directory for file transfer. If the destination dir is provided,
+ * we will attempt to copy files to that directory.
+ *
+ * @param[in] destDir the preferred destination directory
+ *
+ * @return the destination directory on success, an empty string on failure.
+ */
+
+const std::string&
+VMGuestDnDSrc::SetupDestDir(const std::string &destDir)
+{
+   mStagingDir = "";
+
+   if (!destDir.empty() && File_Exists(destDir.c_str())) {
+      mStagingDir = destDir;
+      const char *lastSep = Str_Strrchr(mStagingDir.c_str(), DIRSEPC);
+      if (lastSep && lastSep[1] != '\0') {
+         mStagingDir += DIRSEPS;
+      }
+
+      return mStagingDir;
+   } else {
+      char *newDir;
+
+      newDir = DnD_CreateStagingDirectory();
+      if (newDir != NULL) {
+         mStagingDir = newDir;
+
+         char *lastSep = Str_Strrchr(newDir, DIRSEPC);
+         if (lastSep && lastSep[1] != '\0') {
+            mStagingDir += DIRSEPS;
+         }
+         free(newDir);
+         g_debug("%s: destination dir is: %s", __FUNCTION__, mStagingDir.c_str());
+
+         return mStagingDir;
+      } else {
+         g_debug("%s: destination dir is not created", __FUNCTION__);
+         return mStagingDir;
+      }
+   }
+}
+
+
+/**
+ * Clean the staging files.
+ *
+ * @param[in] fileTransferResult the file transfer result
+ */
+
+void
+VMGuestDnDSrc::CleanStagingFiles(bool fileTransferResult)
+{
+   if (!fileTransferResult && !mStagingDir.empty()) {
+      /* Delete all files if host canceled the file transfer. */
+      DnD_DeleteStagingFiles(mStagingDir.c_str(), FALSE);
+      mStagingDir.clear();
+   }
+}
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDSrc.hh b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestDnDSrc.hh
new file mode 100644 (file)
index 0000000..29a6cc1
--- /dev/null
@@ -0,0 +1,41 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestDnDSrc.hh --
+ *
+ * The inherited implementation of common class GuestDnDSrc in VM side.
+ */
+
+#ifndef VM_GUEST_DND_SRC_HH
+#define VM_GUEST_DND_SRC_HH
+
+#include "guestDnD.hh"
+
+class VMGuestDnDSrc
+   : public GuestDnDSrc
+{
+public:
+   VMGuestDnDSrc(GuestDnDMgr *mgr);
+
+protected:
+   virtual const std::string& SetupDestDir(const std::string &destDir);
+   virtual void CleanStagingFiles(bool fileTransferResult);
+};
+
+#endif // VM_GUEST_DND_SRC_HH
similarity index 77%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestFileTransfer.cc
rename to open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestFileTransfer.cc
index 2d386d9efb0defe4345ce521131d57639ffdbb0f..8a93feacc10f6f12bf4c83318e59550d1993a706 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2018 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
  *********************************************************/
 
 /**
- * @guestFileTransfer.cc --
+ * @vmGuestFileTransfer.cc --
  *
- * Implementation of common layer file transfer object for guest.
+ * VM side implementation of file transfer object for guest.
  */
 
-#include "guestFileTransfer.hh"
 #include "fileTransferRpcV4.hh"
+#include "vmGuestFileTransfer.hh"
 
 extern "C" {
    #include "debug.h"
@@ -38,13 +38,14 @@ extern "C" {
  * @param[in] transport pointer to a transport object.
  */
 
-GuestFileTransfer::GuestFileTransfer(DnDCPTransport *transport)
+VMGuestFileTransfer::VMGuestFileTransfer(DnDCPTransport *transport)
+   : GuestFileTransfer(transport)
 {
    ASSERT(transport);
    mRpc = new FileTransferRpcV4(transport);
    mRpc->Init();
    mRpc->HgfsPacketReceived.connect(
-      sigc::mem_fun(this, &GuestFileTransfer::OnRpcRecvHgfsPacket));
+      sigc::mem_fun(this, &VMGuestFileTransfer::OnRpcRecvHgfsPacket));
    HgfsServerManager_DataInit(&mHgfsServerMgrData,
                               "DnDGuestHgfsMgr",
                               NULL,
@@ -56,11 +57,14 @@ GuestFileTransfer::GuestFileTransfer(DnDCPTransport *transport)
 /**
  * Destructor.
  */
-GuestFileTransfer::~GuestFileTransfer(void)
+VMGuestFileTransfer::~VMGuestFileTransfer(void)
 {
-   delete mRpc;
-   mRpc = NULL;
    HgfsServerManager_Unregister(&mHgfsServerMgrData);
+
+   if (NULL != mRpc) {
+      delete mRpc;
+      mRpc = NULL;
+   }
 }
 
 
@@ -73,9 +77,9 @@ GuestFileTransfer::~GuestFileTransfer(void)
  */
 
 void
-GuestFileTransfer::OnRpcRecvHgfsPacket(uint32 sessionId,
-                                       const uint8 *packet,
-                                       size_t packetSize)
+VMGuestFileTransfer::OnRpcRecvHgfsPacket(uint32 sessionId,
+                                         const uint8 *packet,
+                                         size_t packetSize)
 {
    char replyPacket[HGFS_LARGE_PACKET_MAX];
    size_t replyPacketSize;
@@ -91,4 +95,3 @@ GuestFileTransfer::OnRpcRecvHgfsPacket(uint32 sessionId,
                                    &replyPacketSize);
    mRpc->SendHgfsReply(sessionId, (const uint8 *)replyPacket, replyPacketSize);
 }
-
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestFileTransfer.hh b/open-vm-tools/services/plugins/dndcp/dndGuest/vmGuestFileTransfer.hh
new file mode 100644 (file)
index 0000000..17cf313
--- /dev/null
@@ -0,0 +1,51 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @vmGuestFileTransfer.hh --
+ *
+ * VM side implementation of file transfer object for guest.
+ */
+
+#ifndef VM_GUEST_FILE_TRANSFER_HH
+#define VM_GUEST_FILE_TRANSFER_HH
+
+#include <sigc++/trackable.h>
+#include "fileTransferRpc.hh"
+#include "dndCPTransport.h"
+#include "guestFileTransfer.hh"
+extern "C" {
+#include "hgfsServerManager.h"
+}
+
+class VMGuestFileTransfer
+   : public GuestFileTransfer
+{
+public:
+   VMGuestFileTransfer(DnDCPTransport *transport);
+   ~VMGuestFileTransfer(void);
+
+private:
+   void OnRpcRecvHgfsPacket(uint32 sessionId,
+                            const uint8 *packet,
+                            size_t packetSize);
+
+   HgfsServerMgrData mHgfsServerMgrData;
+};
+
+#endif // VM_GUEST_FILE_TRANSFER_HH
similarity index 93%
rename from open-vm-tools/services/plugins/dndcp/copyPasteDnDImpl.h
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDImpl.h
index 0cf0fa5d216224ea02b1fd2535bec6adbfef0bc8..84bd3da03ccc016e3f4ce93190926a1c49fb6575 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
 #define __COPYPASTEDNDIMPL_H__
 
 #include "vmware.h"
+#include "vm_basic_types.h"
 
 extern "C" {
 #include "vmware/tools/plugin.h"
 }
 
+typedef struct ToolsAppCtx ToolsAppCtx;
 class CopyPasteDnDImpl
 {
 public:
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDWrapper.cpp b/open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDWrapper.cpp
new file mode 100644 (file)
index 0000000..1879afd
--- /dev/null
@@ -0,0 +1,494 @@
+/*********************************************************
+ * Copyright (C) 2010-2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @file copyPasteDnDWrapper.cpp
+ *
+ * This singleton class implements a wrapper around various versions of
+ * copy and paste and dnd protocols, and provides some convenience functions
+ * that help to make VMwareUser a bit cleaner.
+ */
+
+#define G_LOG_DOMAIN "dndcp"
+
+#if defined(HAVE_GTKMM)
+#include "copyPasteDnDX11.h"
+#endif
+
+#if defined(WIN32)
+#include "copyPasteDnDWin32.h"
+#ifdef DND_VM
+#include "vmCopyPasteDnDWin32.h"
+#else
+#include "crtCopyPasteDnDWin32.h"
+#endif
+#endif
+
+#if defined(__APPLE__)
+#include "copyPasteDnDMac.h"
+#endif
+
+#ifdef DND_VM
+#include "vmCopyPasteDnDWrapper.h"
+#else
+#include "crtCopyPasteDnDWrapper.h"
+#endif
+
+#include "copyPasteDnDWrapper.h"
+#include "guestDnDCPMgr.hh"
+#include "vmware.h"
+
+
+/**
+ * CopyPasteDnDWrapper is a singleton, here is a pointer to its only instance.
+ */
+
+CopyPasteDnDWrapper *CopyPasteDnDWrapper::m_instance = NULL;
+
+/**
+ *
+ * Get an instance of CopyPasteDnDWrapper, which is an application singleton.
+ *
+ * @return a pointer to the singleton CopyPasteDnDWrapper object, or NULL if
+ * for some reason it could not be allocated.
+ */
+
+CopyPasteDnDWrapper *
+CopyPasteDnDWrapper::GetInstance()
+{
+   if (!m_instance) {
+#ifdef DND_VM
+      m_instance = VMCopyPasteDnDWrapper::CreateInstance();
+#else
+      m_instance = CRTCopyPasteDnDWrapper::CreateInstance();
+#endif
+   }
+   ASSERT(m_instance);
+   return m_instance;
+}
+
+
+/**
+ *
+ * Destroy the singleton object.
+ */
+
+void
+CopyPasteDnDWrapper::Destroy()
+{
+   if (m_instance) {
+      g_debug("%s: destroying self\n", __FUNCTION__);
+      delete m_instance;
+      m_instance = NULL;
+   }
+}
+
+
+/**
+ *
+ * Constructor.
+ */
+
+CopyPasteDnDWrapper::CopyPasteDnDWrapper() :
+   m_isCPEnabled(FALSE),
+   m_isDnDEnabled(FALSE),
+   m_isCPRegistered(FALSE),
+   m_isDnDRegistered(FALSE),
+   m_cpVersion(0),
+   m_dndVersion(0),
+   m_pimpl(NULL)
+{
+}
+
+
+/**
+ *
+ * Call the implementation class pointer/grab initialization code. See
+ * the implementation code for further details.
+ */
+
+void
+CopyPasteDnDWrapper::PointerInit()
+{
+   ASSERT(m_pimpl);
+
+   m_pimpl->PointerInit();
+}
+
+
+/**
+ *
+ * Initialize the wrapper by instantiating the platform specific impl
+ * class. Effectively, this function is a factory that produces a
+ * platform implementation of the DnD/Copy Paste UI layer.
+ *
+ * @param[in] ctx tools app context.
+ */
+
+void
+CopyPasteDnDWrapper::Init(ToolsAppCtx *ctx)
+{
+   GuestDnDCPMgr *p = GuestDnDCPMgr::GetInstance();
+   ASSERT(p);
+   p->Init(ctx);
+
+   if (!m_pimpl) {
+#if defined(HAVE_GTKMM)
+      m_pimpl = new CopyPasteDnDX11();
+#endif
+#if defined(WIN32)
+#ifdef DND_VM
+      m_pimpl = new VMCopyPasteDnDWin32();
+#else
+      m_pimpl = new CRTCopyPasteDnDWin32();
+#endif
+#endif
+#if defined(__APPLE__)
+      m_pimpl = new CopyPasteDnDMac();
+#endif
+
+      if (m_pimpl) {
+         m_pimpl->Init(ctx);
+         /*
+          * Tell the Guest DnD Manager what capabilities we support.
+          */
+         p->SetCaps(m_pimpl->GetCaps());
+      }
+   }
+}
+
+
+/**
+ *
+ * Destructor.
+ */
+
+CopyPasteDnDWrapper::~CopyPasteDnDWrapper()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   if (m_pimpl) {
+      if (IsCPRegistered()) {
+         m_pimpl->UnregisterCP();
+      }
+      if (IsDnDRegistered()) {
+         m_pimpl->UnregisterDnD();
+      }
+      delete m_pimpl;
+   }
+   GuestDnDCPMgr::Destroy();
+}
+
+
+/**
+ *
+ * Register copy and paste capabilities with the VMX. Try newest version
+ * first, then fall back to the legacy implementation.
+ *
+ * @return TRUE on success, FALSE on failure
+ */
+
+gboolean
+CopyPasteDnDWrapper::RegisterCP()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   ASSERT(m_pimpl);
+   if (IsCPEnabled()) {
+      return m_pimpl->RegisterCP();
+   }
+   return false;
+}
+
+
+/**
+ *
+ * Register DnD capabilities with the VMX. Handled by the platform layer.
+ *
+ * @return TRUE on success, FALSE on failure
+ */
+
+gboolean
+CopyPasteDnDWrapper::RegisterDnD()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   ASSERT(m_pimpl);
+   if (IsDnDEnabled()) {
+      return m_pimpl->RegisterDnD();
+   }
+   return false;
+}
+
+
+/**
+ *
+ * Unregister copy paste capabilities. Handled by platform layer.
+ */
+
+void
+CopyPasteDnDWrapper::UnregisterCP()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   ASSERT(m_pimpl);
+   return m_pimpl->UnregisterCP();
+}
+
+
+/**
+ *
+ * Unregister DnD capabilities. Handled by platform layer.
+ */
+
+void
+CopyPasteDnDWrapper::UnregisterDnD()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   ASSERT(m_pimpl);
+   return m_pimpl->UnregisterDnD();
+}
+
+
+/**
+ *
+ * Get the version of the copy paste protocol being wrapped.
+ *
+ * @return copy paste protocol version.
+ */
+
+int
+CopyPasteDnDWrapper::GetCPVersion()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   return m_cpVersion;
+}
+
+
+/**
+ *
+ * Get the version of the DnD protocol being wrapped.
+ *
+ * @return DnD protocol version.
+ */
+
+int
+CopyPasteDnDWrapper::GetDnDVersion()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   return m_dndVersion;
+}
+
+
+/**
+ *
+ * Set a flag indicating that we are wrapping an initialized and registered
+ * copy paste implementation, or not.
+ *
+ * @param[in] isRegistered If TRUE, protocol is registered, otherwise FALSE.
+ */
+
+void
+CopyPasteDnDWrapper::SetCPIsRegistered(gboolean isRegistered)
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   m_isCPRegistered = isRegistered;
+}
+
+
+/**
+ *
+ * Get the flag indicating that we are wrapping an initialized and registered
+ * copy paste implementation, or not.
+ *
+ * @return TRUE if copy paste is initialized, otherwise FALSE.
+ */
+
+gboolean
+CopyPasteDnDWrapper::IsCPRegistered()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   return m_isCPRegistered;
+}
+
+
+/**
+ *
+ * Set a flag indicating that we are wrapping an initialized and registered
+ * DnD implementation, or not.
+ *
+ * @param[in] isRegistered If TRUE, protocol is registered, otherwise FALSE.
+ */
+
+void
+CopyPasteDnDWrapper::SetDnDIsRegistered(gboolean isRegistered)
+{
+   m_isDnDRegistered = isRegistered;
+}
+
+
+/**
+ *
+ * Get the flag indicating that we are wrapping an initialized and registered
+ * DnD implementation, or not.
+ *
+ * @return TRUE if DnD is initialized, otherwise FALSE.
+ */
+
+gboolean
+CopyPasteDnDWrapper::IsDnDRegistered()
+{
+   return m_isDnDRegistered;
+}
+
+
+/**
+ *
+ * Set a flag indicating that copy paste is enabled, or not. This is called
+ * in response to SetOption RPC being received.
+ *
+ * @param[in] isEnabled If TRUE, copy paste is enabled, otherwise FALSE.
+ */
+
+void
+CopyPasteDnDWrapper::SetCPIsEnabled(gboolean isEnabled)
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   m_isCPEnabled = isEnabled;
+   if (!isEnabled && IsCPRegistered()) {
+      UnregisterCP();
+   } else if (isEnabled && !IsCPRegistered()) {
+      RegisterCP();
+   }
+}
+
+
+/**
+ *
+ * Get the flag indicating that copy paste was enabled (via SetOption RPC).
+ *
+ * @return TRUE if copy paste is enabled, otherwise FALSE.
+ */
+
+gboolean
+CopyPasteDnDWrapper::IsCPEnabled()
+{
+   return m_isCPEnabled;
+}
+
+
+/**
+ *
+ * Set a flag indicating that DnD is enabled, or not. This is called
+ * in response to SetOption RPC being received.
+ *
+ * @param[in] isEnabled If TRUE, DnD is enabled, otherwise FALSE.
+ */
+
+void
+CopyPasteDnDWrapper::SetDnDIsEnabled(gboolean isEnabled)
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   m_isDnDEnabled = isEnabled;
+   if (!isEnabled && IsDnDRegistered()) {
+      UnregisterDnD();
+   } else if (isEnabled && !IsDnDRegistered()) {
+      RegisterDnD();
+   }
+}
+
+
+/**
+ *
+ * Get the flag indicating that DnD was enabled (via SetOption) or not.
+ *
+ * @return TRUE if DnD is enabled, otherwise FALSE.
+ */
+
+gboolean
+CopyPasteDnDWrapper::IsDnDEnabled()
+{
+   return m_isDnDEnabled;
+}
+
+
+/**
+ *
+ * Handle reset.
+ */
+
+void
+CopyPasteDnDWrapper::OnResetInternal()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+}
+
+
+/**
+ *
+ * Handle reset.
+ *
+ * Schedule the post-reset actions to happen a little after one cycle of the
+ * RpcIn loop. This will give vmware a chance to receive the ATR
+ * reinitialize the channel if appropriate.
+ */
+
+void
+CopyPasteDnDWrapper::OnReset()
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   AddDnDPluginResetTimer();
+}
+
+
+/**
+ *
+ * Handle cap reg. This is cross-platform so handle here instead of the
+ * platform implementation.
+ */
+
+void
+CopyPasteDnDWrapper::OnCapReg(gboolean set)
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+}
+
+
+/**
+ *
+ * Handle SetOption
+ */
+
+gboolean
+CopyPasteDnDWrapper::OnSetOption(const char *option, const char *value)
+{
+   g_debug("%s: enter.\n", __FUNCTION__);
+   return TRUE;
+}
+
+
+/**
+ * Get capabilities by calling platform implementation.
+ *
+ * @return 32-bit mask of DnD/CP capabilities.
+ */
+
+uint32
+CopyPasteDnDWrapper::GetCaps()
+{
+   ASSERT(m_pimpl);
+
+   g_debug("%s: enter.\n", __FUNCTION__);
+   return m_pimpl->GetCaps();
+}
similarity index 82%
rename from open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.h
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDWrapper.h
index ff95d1d7725f759d4d90161454eee3abbdf0cb5f..ac18845551ccc1e44274cab81f7e0be2ac2a0b89 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
@@ -33,7 +33,7 @@
 class CopyPasteDnDWrapper
 {
 public:
-   ~CopyPasteDnDWrapper();
+   virtual ~CopyPasteDnDWrapper();
    static CopyPasteDnDWrapper *GetInstance();
    static void Destroy();
    gboolean RegisterCP();
@@ -41,9 +41,9 @@ public:
    gboolean RegisterDnD();
    void UnregisterDnD();
    void SetDnDVersion(int version) {m_dndVersion = version;};
-   int GetDnDVersion();
+   virtual int GetDnDVersion();
    void SetCPVersion(int version) {m_cpVersion = version;};
-   int GetCPVersion();
+   virtual int GetCPVersion();
    void SetCPIsRegistered(gboolean isRegistered);
    gboolean IsCPRegistered();
    void SetDnDIsRegistered(gboolean isRegistered);
@@ -53,21 +53,26 @@ public:
    void SetCPIsEnabled(gboolean isEnabled);
    gboolean IsCPEnabled();
    void OnReset();
-   void OnResetInternal();
-   void OnCapReg(gboolean set);
-   gboolean OnSetOption(const char *option, const char *value);
-   void Init(ToolsAppCtx *ctx);
+   virtual void OnResetInternal();
+   virtual void OnCapReg(gboolean set);
+   virtual gboolean OnSetOption(const char *option, const char *value);
+   virtual void Init(ToolsAppCtx *ctx);
    void PointerInit(void);
-   ToolsAppCtx *GetToolsAppCtx() {return m_ctx;};
+   virtual ToolsAppCtx *GetToolsAppCtx() {return NULL;};
    uint32 GetCaps();
-private:
+
+protected:
    /*
     * We're a singleton, so it is a compile time error to call these.
     */
    CopyPasteDnDWrapper();
    CopyPasteDnDWrapper(const CopyPasteDnDWrapper &wrapper);
    CopyPasteDnDWrapper& operator=(const CopyPasteDnDWrapper &wrapper);
-private:
+
+protected:
+   virtual void AddDnDPluginResetTimer(void) { }
+
+protected:
    gboolean m_isCPEnabled;
    gboolean m_isDnDEnabled;
    gboolean m_isCPRegistered;
@@ -75,7 +80,6 @@ private:
    int m_cpVersion;
    int m_dndVersion;
    static CopyPasteDnDWrapper *m_instance;
-   ToolsAppCtx *m_ctx;
    CopyPasteDnDImpl *m_pimpl;
 };
 
similarity index 95%
rename from open-vm-tools/services/plugins/dndcp/copyPasteDnDX11.h
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/copyPasteDnDX11.h
index 7c08607991cfad8c9bf1b9ab328709b46b37fbc9..05a03cf3925f230bed620bba37311b934409cef6 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
@@ -27,7 +27,6 @@
 #define __COPYPASTEDNDX11_H__
 
 #include "dnd.h"     /* for DnDBlockControl */
-#include "copyPasteUIX11.h"
 #include "dndUIX11.h"
 #include <gtk/gtk.h>
 #include "vm_basic_types.h"
@@ -37,6 +36,8 @@ extern "C" {
 void CopyPasteDnDWrapper_SetUnityMode(Bool mode);
 }
 
+class CopyPasteUIX11;
+
 class CopyPasteDnDX11 : public CopyPasteDnDImpl
 {
 public:
similarity index 87%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnD.hh
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnD.hh
index 80b0c69bc391c2cbd57074374c50af9cd86b79d4..bf8603915c3912f3328788d33540fe0c4309a29f 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
@@ -39,6 +39,10 @@ extern "C" {
    #include "vmware/tools/plugin.h"
 }
 
+#define UNGRAB_TIMEOUT 500        // 0.5s
+#define HIDE_DET_WND_TIMER 500    // 0.5s
+#define UNITY_DND_DET_TIMEOUT 500 // 0.5s
+
 enum GUEST_DND_STATE {
    GUEST_DND_INVALID = 0,
    GUEST_DND_READY,
@@ -62,7 +66,7 @@ class GuestDnDMgr
 public:
    GuestDnDMgr(DnDCPTransport *transport,
                ToolsAppCtx *ctx);
-   ~GuestDnDMgr(void);
+   virtual ~GuestDnDMgr(void);
 
    sigc::signal<void, int, int> moveMouseChanged;
    sigc::signal<void, bool, int, int> updateDetWndChanged;
@@ -107,7 +111,12 @@ public:
    void VmxDnDVersionChanged(uint32 version);
    bool IsDragEnterAllowed(void);
    Bool CheckCapability(uint32 capsRequest);
-private:
+
+   static gboolean DnDUngrabTimeout(void *clientData);
+   static gboolean DnDHideDetWndTimer(void *clientData);
+   static gboolean DnDUnityDetTimeout(void *clientData);
+
+protected:
    void OnRpcSrcDragBegin(uint32 sessionId,
                           const CPClipboard *clip);
    void OnRpcQueryExiting(uint32 sessionId, int32 x, int32 y);
@@ -119,6 +128,11 @@ private:
                        int32 y);
    void OnPingReply(uint32 capabilities);
 
+   virtual void AddDnDUngrabTimeoutEvent() = 0;
+   virtual void AddUnityDnDDetTimeoutEvent() = 0;
+   virtual void AddHideDetWndTimerEvent() = 0;
+   virtual void CreateDnDRpcWithVersion(uint32 version) = 0;
+
    GuestDnDSrc *mSrc;
    GuestDnDDest *mDest;
    DnDRpc *mRpc;
@@ -127,7 +141,6 @@ private:
    GSource *mHideDetWndTimer;
    GSource *mUnityDnDDetTimeout;
    GSource *mUngrabTimeout;
-   ToolsAppCtx *mToolsAppCtx;
    bool mDnDAllowed;
    DnDCPTransport *mDnDTransport;
    uint32 mCapabilities;
@@ -139,14 +152,14 @@ class GuestDnDSrc
 {
 public:
    GuestDnDSrc(GuestDnDMgr *mgr);
-   ~GuestDnDSrc(void);
+   virtual ~GuestDnDSrc(void);
 
    /* Common DnD layer API exposed to UI (all platforms) for DnD source. */
    void UIDragBeginDone(void);
    void UIUpdateFeedback(DND_DROPEFFECT feedback);
    void OnRpcDragBegin(const CPClipboard *clip);
 
-private:
+protected:
    /* Callbacks from rpc for DnD source. */
    void OnRpcUpdateMouse(uint32 sessionId, int32 x, int32 y);
    void OnRpcDrop(uint32 sessionId, int32 x, int32 y);
@@ -155,7 +168,8 @@ private:
                           bool success,
                           const uint8 *stagingDirCP,
                           uint32 sz);
-   const std::string& SetupDestDir(const std::string &destDir);
+   virtual const std::string& SetupDestDir(const std::string &destDir);
+   virtual void CleanStagingFiles(bool fileTransferResult) { }
 
    GuestDnDMgr *mMgr;
    DnDRpc *mRpc;
similarity index 59%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDCPMgr.cc
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDCPMgr.cc
index 84b44d34d3b588451256236f1a917aa338357fa2..74a13dcfd5e5c90ab92b12d8e6c0bdcebc855775 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
  */
 
 #include "guestDnDCPMgr.hh"
-#include "dndCPTransportGuestRpc.hpp"
+
+// The MACRO DND_VM is only used for WS/FS
+#ifdef DND_VM
+#include "vmGuestDnDCPMgr.hh"
+#else
+#include "crtGuestDnDCPMgr.hh"
+#endif
 
 extern "C" {
    #include "debug.h"
@@ -43,7 +49,6 @@ GuestDnDCPMgr::GuestDnDCPMgr()
      mCPMgr(NULL),
      mFileTransfer(NULL),
      mTransport(NULL),
-     mToolsAppCtx(NULL),
      mLocalCaps(0xffffffff)
 {
 }
@@ -56,12 +61,6 @@ GuestDnDCPMgr::GuestDnDCPMgr()
 GuestDnDCPMgr::~GuestDnDCPMgr(void)
 {
    g_debug("%s: enter\n", __FUNCTION__);
-   delete mDnDMgr;
-   mDnDMgr = NULL;
-   delete mFileTransfer;
-   mFileTransfer = NULL;
-   delete mTransport;
-   mTransport = NULL;
 }
 
 
@@ -76,7 +75,11 @@ GuestDnDCPMgr *
 GuestDnDCPMgr::GetInstance(void)
 {
    if (!m_instance) {
-      m_instance = new GuestDnDCPMgr;
+#ifdef DND_VM
+      m_instance = VMGuestDnDCPMgr::CreateInstance();
+#else
+      m_instance = CRTGuestDnDCPMgr::CreateInstance();
+#endif
    }
    return m_instance;
 }
@@ -96,79 +99,6 @@ GuestDnDCPMgr::Destroy(void)
 }
 
 
-/**
- * Initialize the GuestDnDCPMgr object. All owner should call this first before
- * calling any other function.
- *
- * @param[in] ctx ToolsAppCtx
- */
-
-void
-GuestDnDCPMgr::Init(ToolsAppCtx *ctx)
-{
-   mToolsAppCtx = ctx;
-
-   ASSERT(mToolsAppCtx);
-
-   if (mFileTransfer) {
-      delete mFileTransfer;
-   }
-   mFileTransfer = new GuestFileTransfer(GetTransport());
-}
-
-
-/**
- * Get the GuestDnDCPMgr object.
- *
- * @return a pointer to the GuestDnDCPMgr instance.
- */
-
-GuestDnDMgr *
-GuestDnDCPMgr::GetDnDMgr(void)
-{
-   if (!mDnDMgr) {
-      /* mEventQueue must be set before this call. */
-      mDnDMgr = new GuestDnDMgr(GetTransport(), mToolsAppCtx);
-   }
-   return mDnDMgr;
-}
-
-
-/**
- * Get the GuestCopyPasteMgr object.
- *
- * @return a pointer to the GuestCopyPasteMgr instance.
- */
-
-GuestCopyPasteMgr *
-GuestDnDCPMgr::GetCopyPasteMgr(void)
-{
-   if (!mCPMgr) {
-      mCPMgr = new GuestCopyPasteMgr(GetTransport());
-   }
-   return mCPMgr;
-}
-
-
-/**
- * Get the DnDCPTransport object.
- *
- * XXX Implementation here is temporary and should be replaced with rpcChannel.
- *
- * @return a pointer to the manager's DnDCPTransport instance.
- */
-
-DnDCPTransport *
-GuestDnDCPMgr::GetTransport(void)
-{
-   if (!mTransport) {
-      ASSERT(mToolsAppCtx);
-      mTransport = new DnDCPTransportGuestRpc(mToolsAppCtx->rpc);
-   }
-   return mTransport;
-}
-
-
 /**
  * API for starting the transport main loop from python.
  */
similarity index 81%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDCPMgr.hh
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDCPMgr.hh
index e4539dd00a3700c572cba96f552c49ac9e45c491..45e86ea1e807a17145c6ea165ea83e7797142c8f 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
 #include "guestCopyPaste.hh"
 #include "guestFileTransfer.hh"
 
-extern "C" {
-   #include "vmware/tools/guestrpc.h"
-   #include "vmware/tools/plugin.h"
-}
-
 struct DblLnkLst_Links;
+struct ToolsAppCtx;
 
 class GuestDnDCPMgr
 {
 public:
-   ~GuestDnDCPMgr();
-   static GuestDnDCPMgr *GetInstance();
+   virtual ~GuestDnDCPMgr();
+   static GuestDnDCPMgr *GetInstance(void);
    static void Destroy();
-   GuestDnDMgr *GetDnDMgr(void);
-   GuestCopyPasteMgr *GetCopyPasteMgr(void);
-   DnDCPTransport *GetTransport(void);
+   virtual GuestDnDMgr *GetDnDMgr(void) { return NULL; }
+   virtual GuestCopyPasteMgr *GetCopyPasteMgr(void) { return NULL; }
+   virtual DnDCPTransport *GetTransport(void) { return NULL; }
    void StartLoop();
    void EndLoop();
    void IterateLoop();
-   void Init(ToolsAppCtx *ctx);
+   virtual void Init(ToolsAppCtx *ctx) { }
    void SetCaps(uint32 caps) {mLocalCaps = caps;};
    uint32 GetCaps() {return mLocalCaps;};
-private:
+
+protected:
    /* We're a singleton, so it is a compile time error to call these. */
    GuestDnDCPMgr(void);
    GuestDnDCPMgr(const GuestDnDCPMgr &mgr);
@@ -62,7 +59,6 @@ private:
    GuestCopyPasteMgr *mCPMgr;
    GuestFileTransfer *mFileTransfer;
    DnDCPTransport *mTransport;
-   ToolsAppCtx *mToolsAppCtx;
    uint32 mLocalCaps;
 };
 
similarity index 89%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDMgr.cc
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDMgr.cc
index 0913b3b39d65ff55b60ad75eb2649cd0107ff5a1..832590cef06c9c6807296f8585f06afa9d97a73a 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
 
 #include "tracer.hh"
 #include "guestDnD.hh"
-#include "dndRpcV4.hh"
-#include "dndRpcV3.hh"
 #include "guestDnDCPMgr.hh"
 
+#ifdef DND_VM
+#include "vmGuestDnDSrc.hh"
+#else
+#include "crtGuestDnDSrc.hh"
+#endif
+
 extern "C" {
    #include "debug.h"
 }
 
 
-#define UNGRAB_TIMEOUT 500        // 0.5s
-#define HIDE_DET_WND_TIMER 500    // 0.5s
-#define UNITY_DND_DET_TIMEOUT 500 // 0.5s
-
-
-/**
- * Callback for DnDUngrab timeout. This will be called if there is no pending
- * GH DnD when user dragged leaving the guest.
- *
- * @param[in] clientData
- *
- * @return FALSE always
- */
-
-static gboolean
-DnDUngrabTimeout(void *clientData)
-{
-   TRACE_CALL();
-
-   ASSERT(clientData);
-   GuestDnDMgr *dnd = (GuestDnDMgr *)clientData;
-   /* Call actual callback. */
-   dnd->UngrabTimeout();
-   return FALSE;
-}
-
-
-/**
- * Callback for HideDetWndTimer.
- *
- * @param[in] clientData
- *
- * @return FALSE always
- */
-
-
-static gboolean
-DnDHideDetWndTimer(void *clientData)
-{
-   TRACE_CALL();
-
-   ASSERT(clientData);
-   GuestDnDMgr *dnd = (GuestDnDMgr *)clientData;
-   dnd->SetHideDetWndTimer(NULL);
-   dnd->HideDetWnd();
-   return FALSE;
-}
-
-
-/**
- * Callback for UnityDnDDetTimeout.
- *
- * @param[in] clientData
- *
- * @return FALSE always
- */
-
-
-static gboolean
-DnDUnityDetTimeout(void *clientData)
-{
-   TRACE_CALL();
-
-   ASSERT(clientData);
-   GuestDnDMgr *dnd = (GuestDnDMgr *)clientData;
-   dnd->UnityDnDDetTimeout();
-   return FALSE;
-}
-
-
 /**
  * Constructor.
  *
@@ -120,13 +54,11 @@ GuestDnDMgr::GuestDnDMgr(DnDCPTransport *transport,
    mHideDetWndTimer(NULL),
    mUnityDnDDetTimeout(NULL),
    mUngrabTimeout(NULL),
-   mToolsAppCtx(ctx),
    mDnDAllowed(false),
    mDnDTransport(transport),
    mCapabilities(0xffffffff)
 {
    ASSERT(transport);
-   ASSERT(mToolsAppCtx);
 }
 
 
@@ -310,7 +242,12 @@ GuestDnDMgr::OnRpcSrcDragBegin(uint32 sessionId,
    SetSessionId(sessionId);
 
    ASSERT(clip);
-   mSrc = new GuestDnDSrc(this);
+
+#ifdef DND_VM
+   mSrc = new VMGuestDnDSrc(this);
+#else
+   mSrc = new CRTGuestDnDSrc(this);
+#endif
 
    mSrc->OnRpcDragBegin(clip);
 }
@@ -354,12 +291,7 @@ GuestDnDMgr::OnRpcQueryExiting(uint32 sessionId,
     * this is here in case the drag isn't picked up by our drag detection window
     * for some reason.
     */
-   if (NULL == mUngrabTimeout) {
-      g_debug("%s: adding UngrabTimeout\n", __FUNCTION__);
-      mUngrabTimeout = g_timeout_source_new(UNGRAB_TIMEOUT);
-      VMTOOLSAPP_ATTACH_SOURCE(mToolsAppCtx, mUngrabTimeout, DnDUngrabTimeout, this, NULL);
-      g_source_unref(mUngrabTimeout);
-   }
+   AddDnDUngrabTimeoutEvent();
 }
 
 
@@ -431,13 +363,7 @@ GuestDnDMgr::OnRpcUpdateUnityDetWnd(uint32 sessionId,
        * this window to accept drop in cancel case.
        */
       UpdateDetWnd(show, 1, 1);
-      mUnityDnDDetTimeout = g_timeout_source_new(UNITY_DND_DET_TIMEOUT);
-      VMTOOLSAPP_ATTACH_SOURCE(mToolsAppCtx,
-                               mUnityDnDDetTimeout,
-                               DnDUnityDetTimeout,
-                               this,
-                               NULL);
-      g_source_unref(mUnityDnDDetTimeout);
+      AddUnityDnDDetTimeoutEvent();
       SetSessionId(sessionId);
    } else {
       /*
@@ -536,15 +462,7 @@ GuestDnDMgr::DelayHideDetWnd(void)
 {
    TRACE_CALL();
 
-   if (NULL == mHideDetWndTimer) {
-      g_debug("%s: add timer to hide detection window.\n", __FUNCTION__);
-      mHideDetWndTimer = g_timeout_source_new(HIDE_DET_WND_TIMER);
-      VMTOOLSAPP_ATTACH_SOURCE(mToolsAppCtx, mHideDetWndTimer,
-                               DnDHideDetWndTimer, this, NULL);
-      g_source_unref(mHideDetWndTimer);
-   } else {
-      g_debug("%s: mHideDetWndTimer is not NULL, quit.\n", __FUNCTION__);
-   }
+   AddHideDetWndTimerEvent();
 }
 
 
@@ -642,17 +560,8 @@ GuestDnDMgr::VmxDnDVersionChanged(uint32 version)
       mRpc = NULL;
    }
 
-   switch(version) {
-   case 4:
-      mRpc = new DnDRpcV4(mDnDTransport);
-      break;
-   case 3:
-      mRpc = new DnDRpcV3(mDnDTransport);
-      break;
-   default:
-      g_debug("%s: unsupported DnD version\n", __FUNCTION__);
-      break;
-   }
+   CreateDnDRpcWithVersion(version);
+
    if (mRpc) {
       mRpc->pingReplyChanged.connect(
          sigc::mem_fun(this, &GuestDnDMgr::OnPingReply));
@@ -709,3 +618,66 @@ GuestDnDMgr::OnPingReply(uint32 capabilities)
    mCapabilities = capabilities;
 }
 
+
+/**
+ * Callback for DnDUngrab timeout. This will be called if there is no pending
+ * GH DnD when user dragged leaving the guest.
+ *
+ * @param[in] clientData
+ *
+ * @return FALSE always
+ */
+
+gboolean
+GuestDnDMgr::DnDUngrabTimeout(void *clientData)
+{
+   TRACE_CALL();
+
+   ASSERT(clientData);
+   GuestDnDMgr *dnd = (GuestDnDMgr *)clientData;
+   /* Call actual callback. */
+   dnd->UngrabTimeout();
+   return FALSE;
+}
+
+
+/**
+ * Callback for HideDetWndTimer.
+ *
+ * @param[in] clientData
+ *
+ * @return FALSE always
+ */
+
+gboolean
+GuestDnDMgr::DnDHideDetWndTimer(void *clientData)
+{
+   TRACE_CALL();
+
+   ASSERT(clientData);
+   GuestDnDMgr *dnd = (GuestDnDMgr *)clientData;
+   dnd->SetHideDetWndTimer(NULL);
+   dnd->HideDetWnd();
+   return FALSE;
+}
+
+
+/**
+ * Callback for UnityDnDDetTimeout.
+ *
+ * @param[in] clientData
+ *
+ * @return FALSE always
+ */
+
+gboolean
+GuestDnDMgr::DnDUnityDetTimeout(void *clientData)
+{
+   TRACE_CALL();
+
+   ASSERT(clientData);
+   GuestDnDMgr *dnd = (GuestDnDMgr *)clientData;
+   dnd->UnityDnDDetTimeout();
+   return FALSE;
+}
+
similarity index 86%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestDnDSrc.cc
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/guestDnDSrc.cc
index b63835b7f4c73aafd80297561a125481a9adce98..1ab0ff2e5e9134eaf9d49254313c59b87614a857 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
@@ -248,11 +248,8 @@ GuestDnDSrc::OnRpcGetFilesDone(uint32 sessionId,
                                const uint8 *stagingDirCP,
                                uint32 sz)
 {
-   if (!success && !mStagingDir.empty()) {
-      /* Delete all files if host canceled the file transfer. */
-      DnD_DeleteStagingFiles(mStagingDir.c_str(), FALSE);
-      mStagingDir.clear();
-   }
+   CleanStagingFiles(success);
+
    /* UI should remove block with this signal. */
    mMgr->getFilesDoneChanged.emit(success);
    mMgr->HideDetWnd();
@@ -273,36 +270,5 @@ GuestDnDSrc::OnRpcGetFilesDone(uint32 sessionId,
 const std::string &
 GuestDnDSrc::SetupDestDir(const std::string &destDir)
 {
-   mStagingDir = "";
-
-   if (!destDir.empty() && File_Exists(destDir.c_str())) {
-      mStagingDir = destDir;
-      const char *lastSep = Str_Strrchr(mStagingDir.c_str(), DIRSEPC);
-      if (lastSep && lastSep[1] != '\0') {
-         mStagingDir += DIRSEPS;
-      }
-
-      return mStagingDir;
-   } else {
-      char *newDir;
-
-      newDir = DnD_CreateStagingDirectory();
-      if (newDir != NULL) {
-         mStagingDir = newDir;
-
-         char *lastSep = Str_Strrchr(newDir, DIRSEPC);
-         if (lastSep && lastSep[1] != '\0') {
-            mStagingDir += DIRSEPS;
-         }
-         free(newDir);
-         g_debug("%s: destdir: %s", __FUNCTION__, mStagingDir.c_str());
-
-         return mStagingDir;
-      } else {
-         g_debug("%s: destdir not created", __FUNCTION__);
-         return mStagingDir;
-      }
-   }
+   return mStagingDir;
 }
-
-
diff --git a/open-vm-tools/services/plugins/dndcp/dndGuestBase/guestFileTransfer.cc b/open-vm-tools/services/plugins/dndcp/dndGuestBase/guestFileTransfer.cc
new file mode 100644 (file)
index 0000000..66a895e
--- /dev/null
@@ -0,0 +1,52 @@
+/*********************************************************
+ * Copyright (C) 2010-2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @guestFileTransfer.cc --
+ *
+ * Implementation of common layer file transfer object for guest.
+ */
+
+#include "guestFileTransfer.hh"
+
+extern "C" {
+   #include "debug.h"
+}
+
+#include "hgfsServer.h"
+
+
+/**
+ * Create transport object and register callback.
+ *
+ * @param[in] transport pointer to a transport object.
+ */
+
+GuestFileTransfer::GuestFileTransfer(DnDCPTransport *transport)
+   : mRpc(NULL)
+{
+   ASSERT(transport);
+}
+
+
+/**
+ * Destructor.
+ */
+GuestFileTransfer::~GuestFileTransfer(void)
+{
+}
similarity index 78%
rename from open-vm-tools/services/plugins/dndcp/dndGuest/guestFileTransfer.hh
rename to open-vm-tools/services/plugins/dndcp/dndGuestBase/guestFileTransfer.hh
index 654b6c1f688cd4fec427f60aed783f7cf1272caf..a7069ed4f8c1c70ebfad10c1ccecce2fdaa8c0ef 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
 #include <sigc++/trackable.h>
 #include "fileTransferRpc.hh"
 #include "dndCPTransport.h"
-extern "C" {
-#include "hgfsServerManager.h"
-}
 
 class GuestFileTransfer
    : public sigc::trackable
 {
 public:
    GuestFileTransfer(DnDCPTransport *transport);
-   ~GuestFileTransfer(void);
-
-private:
-   void OnRpcRecvHgfsPacket(uint32 sessionId,
-                            const uint8 *packet,
-                            size_t packetSize);
+   virtual ~GuestFileTransfer(void);
 
+protected:
    FileTransferRpc *mRpc;
-   HgfsServerMgrData mHgfsServerMgrData;
 };
 
 #endif // GUEST_FILE_TRANSFER_HH
similarity index 52%
rename from open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.cpp
rename to open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.cpp
index 9388f9b7303bbc7be2a803d6b68c9a28563b8d74..aa58faed27044a1015acc3747d809d7e3b1a3299 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2010-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2018 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
  *********************************************************/
 
 /**
- * @file copyPasteDnDWrapper.cpp
+ * @file vmCopyPasteDnDWrapper.cpp
  *
- * This singleton class implements a wrapper around various versions of
- * copy and paste and dnd protocols, and provides some convenience functions
- * that help to make VMwareUser a bit cleaner.
+ * The inherited implementation of common class CopyPasteDnDWrapper in VM side.
  */
 
-#define G_LOG_DOMAIN "dndcp"
-
-#if defined(HAVE_GTKMM)
-#include "copyPasteDnDX11.h"
-#endif
-
-#if defined(WIN32)
-#include "copyPasteDnDWin32.h"
-#endif
-
-#if defined(__APPLE__)
-#include "copyPasteDnDMac.h"
-#endif
-
-#include "copyPasteDnDWrapper.h"
 #include "guestDnDCPMgr.hh"
+#include "vmCopyPasteDnDWrapper.h"
 #include "vmware.h"
 
 extern "C" {
-#include "rpcout.h"
-#include "vmware/guestrpc/tclodefs.h"
-#include "vmware/tools/plugin.h"
-#include "vmware/tools/utils.h"
-#include <string.h>
+   #include "rpcout.h"
+   #include "vmware/guestrpc/tclodefs.h"
+   #include "vmware/tools/plugin.h"
+   #include "vmware/tools/utils.h"
+   #include <string.h>
 }
 
-/**
- * CopyPasteDnDWrapper is a singleton, here is a pointer to its only instance.
- */
-
-CopyPasteDnDWrapper *CopyPasteDnDWrapper::m_instance = NULL;
 
 /**
  *
- * Get an instance of CopyPasteDnDWrapper, which is an application singleton.
+ * Timer callback for reset. Handle it by calling the member function
+ * that handles reset.
  *
- * @return a pointer to the singleton CopyPasteDnDWrapper object, or NULL if
- * for some reason it could not be allocated.
- */
-
-CopyPasteDnDWrapper *
-CopyPasteDnDWrapper::GetInstance()
-{
-   if (!m_instance) {
-      m_instance = new CopyPasteDnDWrapper;
-   }
-   ASSERT(m_instance);
-   return m_instance;
-}
-
-
-/**
+ * @param[in] clientData pointer to the CopyPasteDnDWrapper instance that
+ * issued the timer.
  *
- * Destroy the singleton object.
+ * @return FALSE always.
  */
 
-void
-CopyPasteDnDWrapper::Destroy()
+static gboolean
+DnDPluginResetSent(void *clientData)
 {
-   if (m_instance) {
-      g_debug("%s: destroying self\n", __FUNCTION__);
-      delete m_instance;
-      m_instance = NULL;
-   }
-}
-
-
-/**
- *
- * Constructor.
- */
+   CopyPasteDnDWrapper *p = reinterpret_cast<CopyPasteDnDWrapper *>(clientData);
 
-CopyPasteDnDWrapper::CopyPasteDnDWrapper() :
-   m_isCPEnabled(FALSE),
-   m_isDnDEnabled(FALSE),
-   m_isCPRegistered(FALSE),
-   m_isDnDRegistered(FALSE),
-   m_cpVersion(0),
-   m_dndVersion(0),
-   m_ctx(NULL),
-   m_pimpl(NULL)
-{
+   ASSERT(p);
+   p->OnResetInternal();
+   return FALSE;
 }
 
 
 /**
  *
- * Call the implementation class pointer/grab initialization code. See
- * the implementation code for further details.
+ * Create an instance for class VMCopyPasteDnDWrapper.
+ *
+ * @return a pointer to the VMCopyPasteDnDWrapper instance.
  */
 
-void
-CopyPasteDnDWrapper::PointerInit()
+VMCopyPasteDnDWrapper *
+VMCopyPasteDnDWrapper::CreateInstance(void)
 {
-   ASSERT(m_pimpl);
-
-   m_pimpl->PointerInit();
+   return new VMCopyPasteDnDWrapper();
 }
 
 
@@ -134,397 +81,20 @@ CopyPasteDnDWrapper::PointerInit()
  */
 
 void
-CopyPasteDnDWrapper::Init(ToolsAppCtx *ctx)
+VMCopyPasteDnDWrapper::Init(ToolsAppCtx *ctx)
 {
    m_ctx = ctx;
-
-   GuestDnDCPMgr *p = GuestDnDCPMgr::GetInstance();
-   ASSERT(p);
-   p->Init(ctx);
-
-   if (!m_pimpl) {
-#if defined(HAVE_GTKMM)
-      m_pimpl = new CopyPasteDnDX11();
-#endif
-#if defined(WIN32)
-      m_pimpl = new CopyPasteDnDWin32();
-#endif
-#if defined(__APPLE__)
-      m_pimpl = new CopyPasteDnDMac();
-#endif
-      if (m_pimpl) {
-         m_pimpl->Init(ctx);
-         /*
-          * Tell the Guest DnD Manager what capabilities we support.
-          */
-         p->SetCaps(m_pimpl->GetCaps());
-      }
-   }
-}
-
-
-/**
- *
- * Destructor.
- */
-
-CopyPasteDnDWrapper::~CopyPasteDnDWrapper()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   if (m_pimpl) {
-      if (IsCPRegistered()) {
-         m_pimpl->UnregisterCP();
-      }
-      if (IsDnDRegistered()) {
-         m_pimpl->UnregisterDnD();
-      }
-      delete m_pimpl;
-   }
-   GuestDnDCPMgr::Destroy();
-}
-
-
-/**
- *
- * Register copy and paste capabilities with the VMX. Try newest version
- * first, then fall back to the legacy implementation.
- *
- * @return TRUE on success, FALSE on failure
- */
-
-gboolean
-CopyPasteDnDWrapper::RegisterCP()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   ASSERT(m_pimpl);
-   if (IsCPEnabled()) {
-      return m_pimpl->RegisterCP();
-   }
-   return false;
-}
-
-
-/**
- *
- * Register DnD capabilities with the VMX. Handled by the platform layer.
- *
- * @return TRUE on success, FALSE on failure
- */
-
-gboolean
-CopyPasteDnDWrapper::RegisterDnD()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   ASSERT(m_pimpl);
-   if (IsDnDEnabled()) {
-      return m_pimpl->RegisterDnD();
-   }
-   return false;
-}
-
-
-/**
- *
- * Unregister copy paste capabilities. Handled by platform layer.
- */
-
-void
-CopyPasteDnDWrapper::UnregisterCP()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   ASSERT(m_pimpl);
-   return m_pimpl->UnregisterCP();
-}
-
-
-/**
- *
- * Unregister DnD capabilities. Handled by platform layer.
- */
-
-void
-CopyPasteDnDWrapper::UnregisterDnD()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   ASSERT(m_pimpl);
-   return m_pimpl->UnregisterDnD();
-}
-
-
-/**
- *
- * Get the version of the copy paste protocol being wrapped.
- *
- * @return copy paste protocol version.
- */
-
-int
-CopyPasteDnDWrapper::GetCPVersion()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   if (IsCPRegistered()) {
-      char *reply = NULL;
-      size_t replyLen;
-
-      ToolsAppCtx *ctx = GetToolsAppCtx();
-      if (!RpcChannel_Send(ctx->rpc, QUERY_VMX_COPYPASTE_VERSION,
-                           strlen(QUERY_VMX_COPYPASTE_VERSION), &reply, &replyLen)) {
-         g_debug("%s: could not get VMX copyPaste "
-               "version capability: %s\n", __FUNCTION__, reply ? reply : "NULL");
-         m_cpVersion = 1;
-      } else {
-         m_cpVersion = atoi(reply);
-      }
-      free(reply);
-   }
-   g_debug("%s: got version %d\n", __FUNCTION__, m_cpVersion);
-   return m_cpVersion;
-}
-
-
-/**
- *
- * Get the version of the DnD protocol being wrapped.
- *
- * @return DnD protocol version.
- */
-
-int
-CopyPasteDnDWrapper::GetDnDVersion()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   if (IsDnDRegistered()) {
-      char *reply = NULL;
-      size_t replyLen;
-
-      ToolsAppCtx *ctx = GetToolsAppCtx();
-      if (!RpcChannel_Send(ctx->rpc, QUERY_VMX_DND_VERSION,
-                           strlen(QUERY_VMX_DND_VERSION), &reply, &replyLen)) {
-         g_debug("%s: could not get VMX dnd "
-               "version capability: %s\n", __FUNCTION__, reply ? reply : "NULL");
-         m_dndVersion = 1;
-      } else {
-         m_dndVersion = atoi(reply);
-      }
-      free(reply);
-   }
-   g_debug("%s: got version %d\n", __FUNCTION__, m_dndVersion);
-   return m_dndVersion;
-}
-
-
-/**
- *
- * Set a flag indicating that we are wrapping an initialized and registered
- * copy paste implementation, or not.
- *
- * @param[in] isRegistered If TRUE, protocol is registered, otherwise FALSE.
- */
-
-void
-CopyPasteDnDWrapper::SetCPIsRegistered(gboolean isRegistered)
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   m_isCPRegistered = isRegistered;
-}
-
-
-/**
- *
- * Get the flag indicating that we are wrapping an initialized and registered
- * copy paste implementation, or not.
- *
- * @return TRUE if copy paste is initialized, otherwise FALSE.
- */
-
-gboolean
-CopyPasteDnDWrapper::IsCPRegistered()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   return m_isCPRegistered;
-}
-
-
-/**
- *
- * Set a flag indicating that we are wrapping an initialized and registered
- * DnD implementation, or not.
- *
- * @param[in] isRegistered If TRUE, protocol is registered, otherwise FALSE.
- */
-
-void
-CopyPasteDnDWrapper::SetDnDIsRegistered(gboolean isRegistered)
-{
-   m_isDnDRegistered = isRegistered;
-}
-
-
-/**
- *
- * Get the flag indicating that we are wrapping an initialized and registered
- * DnD implementation, or not.
- *
- * @return TRUE if DnD is initialized, otherwise FALSE.
- */
-
-gboolean
-CopyPasteDnDWrapper::IsDnDRegistered()
-{
-   return m_isDnDRegistered;
-}
-
-
-/**
- *
- * Set a flag indicating that copy paste is enabled, or not. This is called
- * in response to SetOption RPC being received.
- *
- * @param[in] isEnabled If TRUE, copy paste is enabled, otherwise FALSE.
- */
-
-void
-CopyPasteDnDWrapper::SetCPIsEnabled(gboolean isEnabled)
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-   m_isCPEnabled = isEnabled;
-   if (!isEnabled && IsCPRegistered()) {
-      UnregisterCP();
-   } else if (isEnabled && !IsCPRegistered()) {
-      RegisterCP();
-   }
-}
-
-
-/**
- *
- * Get the flag indicating that copy paste was enabled (via SetOption RPC).
- *
- * @return TRUE if copy paste is enabled, otherwise FALSE.
- */
-
-gboolean
-CopyPasteDnDWrapper::IsCPEnabled()
-{
-   return m_isCPEnabled;
+   CopyPasteDnDWrapper::Init(ctx);
 }
 
 
 /**
  *
- * Set a flag indicating that DnD is enabled, or not. This is called
- * in response to SetOption RPC being received.
- *
- * @param[in] isEnabled If TRUE, DnD is enabled, otherwise FALSE.
+ * Add the DnD plugin reset timer.
  */
 
 void
-CopyPasteDnDWrapper::SetDnDIsEnabled(gboolean isEnabled)
-{
-   m_isDnDEnabled = isEnabled;
-   if (!isEnabled && IsDnDRegistered()) {
-      UnregisterDnD();
-   } else if (isEnabled && !IsDnDRegistered()) {
-      RegisterDnD();
-   }
-}
-
-
-/**
- *
- * Get the flag indicating that DnD was enabled (via SetOption) or not.
- *
- * @return TRUE if DnD is enabled, otherwise FALSE.
- */
-
-gboolean
-CopyPasteDnDWrapper::IsDnDEnabled()
-{
-   return m_isDnDEnabled;
-}
-
-
-/**
- *
- * Timer callback for reset. Handle it by calling the member function
- * that handles reset.
- *
- * @param[in] clientData pointer to the CopyPasteDnDWrapper instance that
- * issued the timer.
- *
- * @return FALSE always.
- */
-
-static gboolean
-DnDPluginResetSent(void *clientData)
-{
-   CopyPasteDnDWrapper *p = reinterpret_cast<CopyPasteDnDWrapper *>(clientData);
-
-   ASSERT(p);
-   p->OnResetInternal();
-   return FALSE;
-}
-
-
-/**
- *
- * Handle reset.
- */
-
-void
-CopyPasteDnDWrapper::OnResetInternal()
-{
-   g_debug("%s: enter\n", __FUNCTION__);
-
-   /*
-    * Reset DnD/Copy/Paste only if vmx said we can. The reason is that
-    * we may also get reset request from vmx when user is taking snapshot
-    * or recording. If there is an ongoing DnD/copy/paste, we should not
-    * reset here. For details please refer to bug 375928.
-    */
-   char *reply = NULL;
-   size_t replyLen;
-   ToolsAppCtx *ctx = GetToolsAppCtx();
-   if (RpcChannel_Send(ctx->rpc, "dnd.is.active",
-                       strlen("dnd.is.active"), &reply, &replyLen) &&
-       (1 == atoi(reply))) {
-      g_debug("%s: ignore reset while file transfer is busy.\n", __FUNCTION__);
-      goto exit;
-   }
-
-   if (IsDnDRegistered()) {
-      UnregisterDnD();
-   }
-   if (IsCPRegistered()) {
-      UnregisterCP();
-   }
-   if (IsCPEnabled() && !IsCPRegistered()) {
-      RegisterCP();
-   }
-   if (IsDnDEnabled() && !IsDnDRegistered()) {
-      RegisterDnD();
-   }
-   if (!IsDnDRegistered() || !IsCPRegistered()) {
-      g_debug("%s: unable to reset fully DnD %d CP %d!\n",
-            __FUNCTION__, IsDnDRegistered(), IsCPRegistered());
-   }
-
-exit:
-   free(reply);
-}
-
-
-/**
- *
- * Handle reset.
- *
- * Schedule the post-reset actions to happen a little after one cycle of the
- * RpcIn loop. This will give vmware a chance to receive the ATR
- * reinitialize the channel if appropriate.
- */
-
-void
-CopyPasteDnDWrapper::OnReset()
+VMCopyPasteDnDWrapper::AddDnDPluginResetTimer(void)
 {
    GSource *src;
 
@@ -544,7 +114,7 @@ CopyPasteDnDWrapper::OnReset()
  */
 
 void
-CopyPasteDnDWrapper::OnCapReg(gboolean set)
+VMCopyPasteDnDWrapper::OnCapReg(gboolean set)
 {
    g_debug("%s: enter\n", __FUNCTION__);
    char *reply = NULL;
@@ -625,7 +195,7 @@ CopyPasteDnDWrapper::OnCapReg(gboolean set)
             ASSERT(version >= 1);
             SetCPVersion(version);
             g_debug("%s: VMX is copypaste version %d\n", __FUNCTION__,
-                  GetCPVersion());
+                    GetCPVersion());
             if (version == 3) {
                /*
                 * VMDB still has version 4 in it, which will cause a V3
@@ -653,11 +223,128 @@ CopyPasteDnDWrapper::OnCapReg(gboolean set)
 
 /**
  *
- * Handle SetOption
+ * Get the version of the copy paste protocol being wrapped.
+ *
+ * @return copy paste protocol version.
+ */
+
+int
+VMCopyPasteDnDWrapper::GetCPVersion()
+{
+   g_debug("%s: enter\n", __FUNCTION__);
+   if (IsCPRegistered()) {
+      char *reply = NULL;
+      size_t replyLen;
+
+      ToolsAppCtx *ctx = GetToolsAppCtx();
+      if (!RpcChannel_Send(ctx->rpc, QUERY_VMX_COPYPASTE_VERSION,
+         strlen(QUERY_VMX_COPYPASTE_VERSION), &reply, &replyLen)) {
+            g_debug("%s: could not get VMX copyPaste "
+                    "version capability: %s\n", __FUNCTION__,
+                    reply ? reply : "NULL");
+            m_cpVersion = 1;
+      } else {
+         m_cpVersion = atoi(reply);
+      }
+      free(reply);
+   }
+   g_debug("%s: got version %d\n", __FUNCTION__, m_cpVersion);
+   return m_cpVersion;
+}
+
+
+/**
+ *
+ * Get the version of the DnD protocol being wrapped.
+ *
+ * @return DnD protocol version.
+ */
+
+int
+VMCopyPasteDnDWrapper::GetDnDVersion()
+{
+   g_debug("%s: enter\n", __FUNCTION__);
+   if (IsDnDRegistered()) {
+      char *reply = NULL;
+      size_t replyLen;
+
+      ToolsAppCtx *ctx = GetToolsAppCtx();
+      if (!RpcChannel_Send(ctx->rpc, QUERY_VMX_DND_VERSION,
+         strlen(QUERY_VMX_DND_VERSION), &reply, &replyLen)) {
+            g_debug("%s: could not get VMX dnd "
+                    "version capability: %s\n", __FUNCTION__,
+                    reply ? reply : "NULL");
+            m_dndVersion = 1;
+      } else {
+         m_dndVersion = atoi(reply);
+      }
+      free(reply);
+   }
+   g_debug("%s: got version %d\n", __FUNCTION__, m_dndVersion);
+   return m_dndVersion;
+}
+
+
+/**
+ *
+ * Handle reset.
+ */
+
+void
+VMCopyPasteDnDWrapper::OnResetInternal()
+{
+   g_debug("%s: enter\n", __FUNCTION__);
+
+   /*
+    * Reset DnD/Copy/Paste only if vmx said we can. The reason is that
+    * we may also get reset request from vmx when user is taking snapshot
+    * or recording. If there is an ongoing DnD/copy/paste, we should not
+    * reset here. For details please refer to bug 375928.
+    */
+   char *reply = NULL;
+   size_t replyLen;
+   ToolsAppCtx *ctx = GetToolsAppCtx();
+   if (RpcChannel_Send(ctx->rpc, "dnd.is.active",
+                       strlen("dnd.is.active"), &reply, &replyLen) &&
+       (1 == atoi(reply))) {
+      g_debug("%s: ignore reset while file transfer is busy.\n", __FUNCTION__);
+      goto exit;
+   }
+
+   if (IsDnDRegistered()) {
+      UnregisterDnD();
+   }
+   if (IsCPRegistered()) {
+      UnregisterCP();
+   }
+   if (IsCPEnabled() && !IsCPRegistered()) {
+      RegisterCP();
+   }
+   if (IsDnDEnabled() && !IsDnDRegistered()) {
+      RegisterDnD();
+   }
+   if (!IsDnDRegistered() || !IsCPRegistered()) {
+      g_debug("%s: unable to reset fully DnD %d CP %d!\n",
+              __FUNCTION__, IsDnDRegistered(), IsCPRegistered());
+   }
+
+exit:
+   free(reply);
+}
+
+
+/**
+ *
+ * Handle SetOption.
+ *
+ * @param[in] option option name
+ * @param[in] option option value
+ * @return TRUE on success, FALSE on failure
  */
 
 gboolean
-CopyPasteDnDWrapper::OnSetOption(const char *option, const char *value)
+VMCopyPasteDnDWrapper::OnSetOption(const char *option,
+                                   const char *value)
 {
    gboolean ret = false;
    bool bEnable;
@@ -677,18 +364,3 @@ CopyPasteDnDWrapper::OnSetOption(const char *option, const char *value)
 
    return ret;
 }
-
-
-/**
- * Get capabilities by calling platform implementation.
- *
- * @return 32-bit mask of DnD/CP capabilities.
- */
-
-uint32
-CopyPasteDnDWrapper::GetCaps()
-{
-   ASSERT(m_pimpl);
-
-   return m_pimpl->GetCaps();
-}
diff --git a/open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.h b/open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.h
new file mode 100644 (file)
index 0000000..eebcaff
--- /dev/null
@@ -0,0 +1,57 @@
+/*********************************************************
+ * Copyright (C) 2018 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.
+ *
+ *********************************************************/
+
+/**
+ * @file vmCopyPasteDnDWrapper.h
+ *
+ * The inherited implementation of common class CopyPasteDnDWrapper in VM side.
+ */
+
+#ifndef __VM_COPYPASTEDNDWRAPPER_H__
+#define __VM_COPYPASTEDNDWRAPPER_H__
+
+#include "copyPasteDnDWrapper.h"
+
+class VMCopyPasteDnDWrapper
+   : public CopyPasteDnDWrapper
+{
+public:
+   ~VMCopyPasteDnDWrapper() { }
+
+   static VMCopyPasteDnDWrapper *CreateInstance(void);
+   virtual void Init(ToolsAppCtx *ctx);
+   virtual ToolsAppCtx *GetToolsAppCtx() { return m_ctx; }
+   virtual void OnCapReg(gboolean set);
+   virtual int GetCPVersion();
+   virtual int GetDnDVersion();
+   virtual void OnResetInternal();
+   virtual gboolean OnSetOption(const char *option, const char *value);
+
+protected:
+   void AddDnDPluginResetTimer(void);
+
+private:
+   VMCopyPasteDnDWrapper() : m_ctx(NULL) { }
+   VMCopyPasteDnDWrapper(const VMCopyPasteDnDWrapper &wrapper);
+   VMCopyPasteDnDWrapper& operator=(const VMCopyPasteDnDWrapper &wrapper);
+
+private:
+   ToolsAppCtx *m_ctx;
+};
+
+#endif // __VM_COPYPASTEDNDWRAPPER_H__