~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/HostServices/SharedClipboard/service.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
718
718
    return rc;
719
719
}
720
720
 
721
 
/** This structure corresponds to the original layout of the
722
 
 * VBOXCLIPBOARDCLIENTDATA structure.  As the structure was saved as a whole
723
 
 * when saving state, we need to remember it forever in order to preserve
724
 
 * compatibility.
725
 
 * @todo the first person who needs to make an incompatible change to the
726
 
 *       saved state should switch to saving individual data members.  So far,
727
 
 *       there are only three we care about anyway! */
728
 
typedef struct _CLIPSAVEDSTATEDATA
 
721
/**
 
722
 * SSM descriptor table for the VBOXCLIPBOARDCLIENTDATA structure.
 
723
 */
 
724
static SSMFIELD const g_aClipboardClientDataFields[] =
729
725
{
730
 
    struct _CLIPSAVEDSTATEDATA *pNext;
731
 
    struct _CLIPSAVEDSTATEDATA *pPrev;
732
 
 
733
 
    VBOXCLIPBOARDCONTEXT *pCtx;
734
 
 
735
 
    uint32_t u32ClientID;
736
 
 
737
 
    bool fAsync: 1; /* Guest is waiting for a message. */
738
 
 
739
 
    bool fMsgQuit: 1;
740
 
    bool fMsgReadData: 1;
741
 
    bool fMsgFormats: 1;
742
 
 
743
 
    struct {
744
 
        VBOXHGCMCALLHANDLE callHandle;
745
 
        VBOXHGCMSVCPARM *paParms;
746
 
    } async;
747
 
 
748
 
    struct {
749
 
         void *pv;
750
 
         uint32_t cb;
751
 
         uint32_t u32Format;
752
 
    } data;
753
 
 
754
 
    uint32_t u32AvailableFormats;
755
 
    uint32_t u32RequestedFormat;
756
 
 
757
 
} CLIPSAVEDSTATEDATA;
 
726
    SSMFIELD_ENTRY(VBOXCLIPBOARDCLIENTDATA, u32ClientID),  /* for validation purposes */
 
727
    SSMFIELD_ENTRY(VBOXCLIPBOARDCLIENTDATA, fMsgQuit),
 
728
    SSMFIELD_ENTRY(VBOXCLIPBOARDCLIENTDATA, fMsgReadData),
 
729
    SSMFIELD_ENTRY(VBOXCLIPBOARDCLIENTDATA, fMsgFormats),
 
730
    SSMFIELD_ENTRY(VBOXCLIPBOARDCLIENTDATA, u32RequestedFormat),
 
731
    SSMFIELD_ENTRY_TERM()
 
732
};
758
733
 
759
734
static DECLCALLBACK(int) svcSaveState(void *, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
760
735
{
769
744
     * by VMMDev. The service therefore must save state as if there were no
770
745
     * pending request.
771
746
     */
772
 
    LogRel2(("svcSaveState: u32ClientID = %d\n", u32ClientID));
 
747
    LogRel2 (("svcSaveState: u32ClientID = %d\n", u32ClientID));
773
748
 
774
749
    VBOXCLIPBOARDCLIENTDATA *pClient = (VBOXCLIPBOARDCLIENTDATA *)pvClient;
775
750
 
776
 
    CLIPSAVEDSTATEDATA savedState = { 0 };
777
 
    /* Save client structure length & contents */
778
 
    int rc = SSMR3PutU32(pSSM, sizeof(savedState));
779
 
    AssertRCReturn(rc, rc);
780
 
 
781
 
    savedState.u32ClientID        = pClient->u32ClientID;
782
 
    savedState.fMsgQuit           = pClient->fMsgQuit;
783
 
    savedState.fMsgReadData       = pClient->fMsgReadData;
784
 
    savedState.fMsgFormats        = pClient->fMsgFormats;
785
 
    savedState.u32RequestedFormat = pClient->u32RequestedFormat;
786
 
    rc = SSMR3PutMem(pSSM, &savedState, sizeof(savedState));
787
 
    AssertRCReturn(rc, rc);
 
751
    /* This field used to be the length. We're using it as a version field
 
752
       with the high bit set. */
 
753
    SSMR3PutU32 (pSSM, UINT32_C (0x80000002));
 
754
    int rc = SSMR3PutStructEx (pSSM, pClient, sizeof(*pClient), 0 /*fFlags*/, &g_aClipboardClientDataFields[0], NULL);
 
755
    AssertRCReturn (rc, rc);
788
756
 
789
757
    if (pClient->fAsync)
790
758
    {
792
760
        pClient->fAsync = false;
793
761
    }
794
762
 
795
 
    vboxSvcClipboardCompleteReadData(pClient, VINF_SUCCESS, 0);
 
763
    vboxSvcClipboardCompleteReadData (pClient, VINF_SUCCESS, 0);
796
764
 
797
765
    return VINF_SUCCESS;
798
766
}
799
767
 
800
768
static DECLCALLBACK(int) svcLoadState(void *, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
801
769
{
802
 
    LogRel2(("svcLoadState: u32ClientID = %d\n", u32ClientID));
 
770
    LogRel2 (("svcLoadState: u32ClientID = %d\n", u32ClientID));
803
771
 
804
772
    VBOXCLIPBOARDCLIENTDATA *pClient = (VBOXCLIPBOARDCLIENTDATA *)pvClient;
805
773
 
806
774
    /* Existing client can not be in async state yet. */
807
 
    Assert(!pClient->fAsync);
 
775
    Assert (!pClient->fAsync);
 
776
 
 
777
    /* Save the client ID for data validation. */
 
778
    /** @todo isn't this the same as u32ClientID? Playing safe for now... */
 
779
    uint32_t const u32ClientIDOld = pClient->u32ClientID;
808
780
 
809
781
    /* Restore the client data. */
810
 
    uint32_t len;
811
 
    int rc = SSMR3GetU32(pSSM, &len);
812
 
    AssertRCReturn(rc, rc);
813
 
 
814
 
    if (len != sizeof(CLIPSAVEDSTATEDATA))
815
 
    {
816
 
        LogRel2(("Client data size mismatch: expected %d, got %d\n", sizeof (CLIPSAVEDSTATEDATA), len));
817
 
        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
818
 
    }
819
 
 
820
 
    CLIPSAVEDSTATEDATA savedState;
821
 
    rc = SSMR3GetMem(pSSM, &savedState, sizeof(savedState));
822
 
    AssertRCReturn(rc, rc);
823
 
 
824
 
    /* Verify the loaded clients data and update the pClient. */
825
 
    if (pClient->u32ClientID != savedState.u32ClientID)
826
 
    {
827
 
        LogRel2(("Client ID mismatch: expected %d, got %d\n", pClient->u32ClientID, savedState.u32ClientID));
828
 
        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
829
 
    }
830
 
 
831
 
    pClient->fMsgQuit           = savedState.fMsgQuit;
832
 
    pClient->fMsgReadData       = savedState.fMsgReadData;
833
 
    pClient->fMsgFormats        = savedState.fMsgFormats;
834
 
    pClient->u32RequestedFormat = savedState.u32RequestedFormat;
 
782
    uint32_t lenOrVer;
 
783
    int rc = SSMR3GetU32 (pSSM, &lenOrVer);
 
784
    AssertRCReturn (rc, rc);
 
785
    if (lenOrVer == UINT32_C (0x80000002))
 
786
    {
 
787
        rc = SSMR3GetStructEx (pSSM, pClient, sizeof(*pClient), 0 /*fFlags*/, &g_aClipboardClientDataFields[0], NULL);
 
788
        AssertRCReturn (rc, rc);
 
789
    }
 
790
    else if (lenOrVer == (SSMR3HandleHostBits (pSSM) == 64 ? 72 : 48))
 
791
    {
 
792
        /**
 
793
         * This structure corresponds to the original layout of the
 
794
         * VBOXCLIPBOARDCLIENTDATA structure.  As the structure was saved as a whole
 
795
         * when saving state, we need to remember it forever in order to preserve
 
796
         * compatibility.
 
797
         *
 
798
         * (Starting with 3.1 this is no longer used.)
 
799
         */
 
800
        typedef struct _CLIPSAVEDSTATEDATA
 
801
        {
 
802
            struct _CLIPSAVEDSTATEDATA *pNext;
 
803
            struct _CLIPSAVEDSTATEDATA *pPrev;
 
804
 
 
805
            VBOXCLIPBOARDCONTEXT *pCtx;
 
806
 
 
807
            uint32_t u32ClientID;
 
808
 
 
809
            bool fAsync: 1; /* Guest is waiting for a message. */
 
810
 
 
811
            bool fMsgQuit: 1;
 
812
            bool fMsgReadData: 1;
 
813
            bool fMsgFormats: 1;
 
814
 
 
815
            struct {
 
816
                VBOXHGCMCALLHANDLE callHandle;
 
817
                VBOXHGCMSVCPARM *paParms;
 
818
            } async;
 
819
 
 
820
            struct {
 
821
                 void *pv;
 
822
                 uint32_t cb;
 
823
                 uint32_t u32Format;
 
824
            } data;
 
825
 
 
826
            uint32_t u32AvailableFormats;
 
827
            uint32_t u32RequestedFormat;
 
828
 
 
829
        } CLIPSAVEDSTATEDATA;
 
830
 
 
831
        /**
 
832
         * SSM descriptor table for the CLIPSAVEDSTATEDATA structure.
 
833
         */
 
834
        static SSMFIELD const s_aClipSavedStateDataFields30[] =
 
835
        {
 
836
            SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, pNext),
 
837
            SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, pPrev),
 
838
            SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, pCtx),
 
839
            SSMFIELD_ENTRY(                 CLIPSAVEDSTATEDATA, u32ClientID),
 
840
            SSMFIELD_ENTRY_CUSTOM(fMsgQuit+fMsgReadData+fMsgFormats, RT_OFFSETOF(CLIPSAVEDSTATEDATA, u32ClientID) + 4, 4),
 
841
            SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, async.callHandle),
 
842
            SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, async.paParms),
 
843
            SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, data.pv),
 
844
            SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, data.cb),
 
845
            SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, data.u32Format),
 
846
            SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, u32AvailableFormats),
 
847
            SSMFIELD_ENTRY(                 CLIPSAVEDSTATEDATA, u32RequestedFormat),
 
848
            SSMFIELD_ENTRY_TERM()
 
849
        };
 
850
 
 
851
        CLIPSAVEDSTATEDATA savedState;
 
852
        RT_ZERO (savedState);
 
853
        rc = SSMR3GetStructEx (pSSM, &savedState, sizeof(savedState), SSMSTRUCT_FLAGS_MEM_BAND_AID,
 
854
                               &s_aClipSavedStateDataFields30[0], NULL);
 
855
        AssertRCReturn (rc, rc);
 
856
 
 
857
        pClient->fMsgQuit           = savedState.fMsgQuit;
 
858
        pClient->fMsgReadData       = savedState.fMsgReadData;
 
859
        pClient->fMsgFormats        = savedState.fMsgFormats;
 
860
        pClient->u32RequestedFormat = savedState.u32RequestedFormat;
 
861
    }
 
862
    else
 
863
    {
 
864
        LogRel (("Client data size mismatch: got %#x\n", lenOrVer));
 
865
        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
 
866
    }
 
867
 
 
868
    /* Verify the client ID. */
 
869
    if (pClient->u32ClientID != u32ClientIDOld)
 
870
    {
 
871
        LogRel (("Client ID mismatch: expected %d, got %d\n", u32ClientIDOld, pClient->u32ClientID));
 
872
        pClient->u32ClientID = u32ClientIDOld;
 
873
        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
 
874
    }
835
875
 
836
876
    /* Actual host data are to be reported to guest (SYNC). */
837
877
    vboxClipboardSync (pClient);