~n-muench/ubuntu/quantal/open-vm-tools/open-vm-tools.may2.sid-sync

« back to all changes in this revision

Viewing changes to vmware-user/vmware-user.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-30 09:48:43 UTC
  • mfrom: (1.1.5 upstream) (2.4.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090530094843-gdpza57r5iqsf124
Tags: 2009.05.22-167859-1
MergingĀ upstreamĀ versionĀ 2009.05.22-167859.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
#include "dnd.h"
56
56
#include "syncDriver.h"
57
57
#include "str.h"
58
 
#include "guestApp.h" // for ALLOW_TOOLS_IN_FOREIGN_VM
 
58
#include "guestApp.h"
59
59
#include "unity.h"
60
60
#include "ghIntegration.h"
61
61
#include "resolution.h"
98
98
                                size_t argsSize, void *clientData);
99
99
void VMwareUserRpcInErrorCB    (void *clientdata, char const *status);
100
100
 
101
 
extern "C" {
102
 
extern Bool ForeignTools_Initialize(GuestApp_Dict *configDictionaryParam,
103
 
                                    DblLnkLst_Links *eventQueue);
104
 
extern void ForeignTools_Shutdown(void);
105
 
}
106
 
 
107
101
static Bool InitGroupLeader(Window *groupLeader, Window *rootWindow);
108
102
static Bool AcquireDisplayLock(void);
109
103
static Bool QueryX11Lock(Display *dpy, Window w, Atom lockAtom);
110
104
static void ReloadSelf(void);
111
105
static void VMwareUserRegisterCopyPaste(bool reg);
 
106
static void VMwareUserRegisterDnD(bool reg);
112
107
 
113
108
 
114
109
/*
145
140
Bool gCanUseVMwareCtrl;
146
141
Bool gCanUseVMwareCtrlTopologySet;
147
142
guint gTimeoutId;
148
 
int gBlockFd = -1;
 
143
DnDBlockControl gBlockCtrl = { -1 };
149
144
 
150
145
/*
151
146
 * All signals that:
199
194
         FoundryToolsDaemon_UnregisterOpenUrl();
200
195
         gOpenUrlRegistered = FALSE;
201
196
      }
202
 
      if (gDnDRegistered) {
203
 
         DnD_Unregister(gHGWnd, gGHWnd);
204
 
         gDnDRegistered = FALSE;
205
 
      }
206
197
 
207
198
      CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
208
 
      if (p && p->IsRegistered()) {
209
 
         p->Unregister();
 
199
      if (p) {
 
200
         p->UnregisterDnD();
 
201
         p->UnregisterCP();
210
202
      }
211
203
      RpcIn_Destruct(gRpcIn);
212
204
      gRpcIn = NULL;
372
364
VMwareUserRpcInResetCB(RpcInData *data)   // IN/OUT
373
365
{
374
366
   Debug("----------toolbox: Received 'reset' from vmware\n");
375
 
   if (gDnDRegistered) {
376
 
      DnD_OnReset(gHGWnd, gGHWnd);
377
 
   }
378
367
   CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
379
368
   if (p) {
380
369
      p->OnReset();
439
428
   } else {
440
429
      FoundryToolsDaemon_RegisterOpenUrlCapability();
441
430
   }
442
 
   if (!gDnDRegistered) {
443
 
      gDnDRegistered = DnD_Register(gHGWnd, gGHWnd);
444
 
      if (gDnDRegistered) {
445
 
         UnityDnD state;
446
 
         state.detWnd = gGHWnd;
447
 
         state.setMode = DnD_SetMode;
448
 
         Unity_SetActiveDnDDetWnd(&state);
449
 
      }
450
 
   } else if (DnD_GetVmxDnDVersion() > 1) {
451
 
      if (!DnD_RegisterCapability()) {
452
 
         DnD_Unregister(gHGWnd, gGHWnd);
453
 
         gDnDRegistered = FALSE;
454
 
      }
455
 
   }
456
431
 
 
432
   VMwareUserRegisterDnD(TRUE);
457
433
   VMwareUserRegisterCopyPaste(TRUE);
458
434
 
459
435
   if (!HgfsServerManager_CapReg(TOOLS_DND_NAME, gHgfsServerRegistered)) {
473
449
 * VMwareUserRegisterCopyPaste
474
450
 *
475
451
 *      Call the CopyPasteDnDWrapper singleton to register, or unregister,
476
 
 *      copy and paste with the host. The wrapper class will try whatever
477
 
 *      versions are supported, in highest to lowest order when registering.
 
452
 *      copy and paste with the host. The wrapper class will try
 
453
 *      whatever versions are supported, in highest to lowest order when
 
454
 *      registering.
478
455
 *
479
456
 * Results:
480
457
 *      None.
492
469
   if (p) {
493
470
      p->SetUserData(static_cast<void *>(gUserMainWidget));
494
471
      if (reg) {
495
 
         p->Register();
496
 
      } else {
497
 
         p->Unregister();
 
472
         p->RegisterCP();
 
473
      } else {
 
474
         p->UnregisterCP();
 
475
      }
 
476
   }
 
477
}
 
478
 
 
479
 
 
480
/*
 
481
 *-----------------------------------------------------------------------------
 
482
 *
 
483
 * VMwareUserRegisterDnD
 
484
 *
 
485
 *      Call the CopyPasteDnDWrapper singleton to register, or unregister,
 
486
 *      drag and drop with the host. The wrapper class will try
 
487
 *      whatever versions are supported, in highest to lowest order when
 
488
 *      registering.
 
489
 *
 
490
 * Results:
 
491
 *      None.
 
492
 *
 
493
 * Side effects:
 
494
 *      Drag and drop capabilities will be (un)registered.
 
495
 *
 
496
 *-----------------------------------------------------------------------------
 
497
 */
 
498
 
 
499
static void
 
500
VMwareUserRegisterDnD(bool reg)  // IN: if TRUE, register, else unregister
 
501
{
 
502
   CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
 
503
   if (p) {
 
504
      p->SetUserData(static_cast<void *>(gUserMainWidget));
 
505
      p->SetEventQueue(gEventQueue);
 
506
      if (reg) {
 
507
         p->RegisterDnD();
 
508
      } else {
 
509
         p->UnregisterDnD();
498
510
      }
499
511
   }
500
512
}
736
748
   int index;
737
749
   GuestApp_Dict *confDict;
738
750
   const char *pathName;
 
751
   int blockFd = -1;
739
752
#ifdef USE_NOTIFY
740
753
   Bool notifyPresent = TRUE;
741
754
#endif
 
755
   Bool usingBlock;
742
756
 
743
757
   gOpenUrlRegistered = FALSE;
744
758
   gDnDRegistered = FALSE;
745
759
   gHgfsServerRegistered = FALSE;
746
 
   gBlockFd = -1;
747
760
   gReloadSelf = FALSE;
748
761
   gYieldBlock = FALSE;
749
762
   gSigExit = FALSE;
751
764
   Atomic_Init();
752
765
 
753
766
   if (!VmCheck_IsVirtualWorld()) {
754
 
#ifndef ALLOW_TOOLS_IN_FOREIGN_VM
755
767
      Warning("vmware-user must be run inside a virtual machine.\n");
756
768
      return EXIT_SUCCESS;
757
 
#else
758
 
      runningInForeignVM = TRUE;
759
 
#endif
760
769
   }
761
770
 
762
771
   confDict = Conf_Load();
803
812
             * blocking driver if it is not root. If guestd autostarts vmware-user,
804
813
             * guestd will first initialize it and pass block fd in with -blockFd.
805
814
             */
806
 
            if (index + 1 == argc) {
 
815
            if (++index >= argc) {
807
816
               Warning("The \""OPTION_BLOCK_FD"\" option on the command line requires an "
808
817
                       "argument.\n");
809
818
            }
810
819
 
811
 
            index++;
812
 
            if (!StrUtil_StrToInt(&gBlockFd, argv[index])) {
 
820
            if (!StrUtil_StrToInt(&blockFd, argv[index])) {
813
821
               Warning("The \""OPTION_BLOCK_FD"\" option on the command line requires a "
814
822
                       "valid integer.\n");
815
 
               gBlockFd = -1;
 
823
               blockFd = -1;
816
824
            }
817
 
            Debug("vmware-user got blockFd = %d\n", gBlockFd);
 
825
            Debug("vmware-user got blockFd = %d\n", blockFd);
818
826
         } else {
819
827
            Warning("Invalid \"%s\" option on the command line.\n", argv[index]);
820
828
         }
821
829
      }
822
830
   }
823
831
 
 
832
   /*
 
833
    * vmware-user runs as current active account, and can not initialize blocking
 
834
    * driver if it is not root. If guestd autostarts vmware-user, guestd will first
 
835
    * initialize it and pass block fd in. If manually run vmware-user, here will
 
836
    * try to initialize the blocking driver.
 
837
    */
 
838
   usingBlock = blockFd >= 0 ?
 
839
                DnD_CompleteBlockInitialization(blockFd, &gBlockCtrl) :
 
840
                DnD_InitializeBlocking(&gBlockCtrl);
 
841
 
 
842
   if (!usingBlock) {
 
843
      Debug("%s: vmware-user failed to initialize blocking driver.\n",
 
844
            __FUNCTION__);
 
845
   }
 
846
 
824
847
   if (Signal_SetGroupHandler(gSignals, olds, ARRAYSIZE(gSignals),
825
848
                              VMwareUserSignalHandler) == 0 ) {
826
849
      Panic("vmware-user can't set signal handler\n");
851
874
      Debug_EnableToFile(NULL, FALSE);
852
875
   }
853
876
 
854
 
   /*
855
 
    * vmware-user runs as current active account, and can not initialize blocking
856
 
    * driver if it is not root. If guestd autostarts vmware-user, guestd will first
857
 
    * initialize it and pass block fd in. If manually run vmware-user, here will
858
 
    * try to initialize the blocking driver.
859
 
    */
860
 
 
861
 
   if (gBlockFd < 0) {
862
 
      gBlockFd = DnD_InitializeBlocking();
863
 
      if (gBlockFd < 0) {
864
 
         Debug("%s: vmware-user failed to initialize blocking driver.\n",
865
 
         __FUNCTION__);
866
 
      }
867
 
   }
868
 
 
869
877
   gUserMainWidget = VMwareUser_CreateWindow();
870
878
 
871
 
   CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
872
 
   if (p) {
873
 
      p->SetUserData(static_cast<void *>(gUserMainWidget));
874
 
      p->SetBlockFd(gBlockFd);
875
 
   }
876
 
 
877
879
   gHGWnd = VMwareUser_CreateWindow();
878
880
   gGHWnd = VMwareUser_CreateWindow();
879
881
   /*
893
895
      return EXIT_FAILURE;
894
896
   }
895
897
 
896
 
   if (runningInForeignVM) {
897
 
      Bool success = ForeignTools_Initialize(confDict, gEventQueue);
898
 
      if (!success) {
899
 
         return EXIT_FAILURE;
900
 
      }
 
898
   CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
 
899
   if (p) {
 
900
      p->SetUserData(static_cast<void *>(gUserMainWidget));
 
901
      p->SetBlockControl(&gBlockCtrl);
 
902
      p->SetEventQueue(gEventQueue);
 
903
      p->SetHGWnd(gHGWnd);
 
904
      p->SetGHWnd(gGHWnd);
901
905
   }
902
906
 
903
907
   EventManager_Add(gEventQueue, CONF_POLL_TIME, VMwareUserConfFileLoop,
972
976
         break;
973
977
      }
974
978
 
975
 
      /* XXX Refactor this. */
976
979
      if (gYieldBlock) {
977
 
         Debug("Yielding vmblock descriptor.\n");
978
 
         if (gDnDRegistered) {
979
 
            DnD_Unregister(gHGWnd, gGHWnd);
980
 
            gDnDRegistered = FALSE;
981
 
         }
982
980
         CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
983
981
         if (p) {
984
 
            p->Unregister();
 
982
            p->UnregisterDnD();
 
983
            p->UnregisterCP();
985
984
         }
986
 
         if (gBlockFd >= 0 && !DnD_UninitializeBlocking(gBlockFd)) {
 
985
 
 
986
         if (DnD_BlockIsReady(&gBlockCtrl) &&
 
987
             !DnD_UninitializeBlocking(&gBlockCtrl)) {
987
988
            Debug("vmware-user failed to uninitialize blocking.\n");
988
989
         }
989
 
         gBlockFd = -1;
990
990
         gYieldBlock = FALSE;
991
991
      }
992
992
   }
993
993
 
994
 
   if (runningInForeignVM) {
995
 
      ForeignTools_Shutdown();
996
 
   }
997
 
 
998
994
   Signal_ResetGroupHandler(gSignals, olds, ARRAYSIZE(gSignals));
999
995
 
1000
 
   if (gBlockFd >= 0 && !DnD_UninitializeBlocking(gBlockFd)) {
 
996
   if (DnD_BlockIsReady(&gBlockCtrl) &&
 
997
       !DnD_UninitializeBlocking(&gBlockCtrl)) {
1001
998
      Debug("vmware-user failed to uninitialize blocking.\n");
1002
999
   }
1003
1000