VirtualBox

Changeset 23885 in vbox


Ignore:
Timestamp:
Oct 19, 2009 7:15:49 PM (15 years ago)
Author:
vboxsync
Message:

SharedClipboard: Replaced the SSMR3PutMem with a struct descriptor.

Location:
trunk/src/VBox/HostServices/SharedClipboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard.h

    r19875 r23885  
    3939    uint32_t u32ClientID;
    4040
    41     bool fAsync: 1;        /* Guest is waiting for a message. */
    42     bool fReadPending: 1;  /* The guest is waiting for data from the host */
     41    bool fAsync;        /* Guest is waiting for a message. */
     42    bool fReadPending;  /* The guest is waiting for data from the host */
    4343
    44     bool fMsgQuit: 1;
    45     bool fMsgReadData: 1;
    46     bool fMsgFormats: 1;
     44    bool fMsgQuit;
     45    bool fMsgReadData;
     46    bool fMsgFormats;
    4747
    4848    struct {
  • trunk/src/VBox/HostServices/SharedClipboard/service.cpp

    r23883 r23885  
    719719}
    720720
    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
    729 {
    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;
    758 
    759 
    760721/**
    761  * SSM descriptor table for the CLIPSAVEDSTATEDATA structure.
     722 * SSM descriptor table for the VBOXCLIPBOARDCLIENTDATA structure.
    762723 */
    763 static SSMFIELD const g_aClipSavedStateDataFields[] =
    764 {
    765     SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, pNext),
    766     SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, pPrev),
    767     SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, pCtx),
    768     SSMFIELD_ENTRY(                 CLIPSAVEDSTATEDATA, u32ClientID),
    769     SSMFIELD_ENTRY_CUSTOM(fMsgQuit+fMsgReadData+fMsgFormats, RT_OFFSETOF(CLIPSAVEDSTATEDATA, u32ClientID) + 4, 4),
    770     SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, async.callHandle),
    771     SSMFIELD_ENTRY_IGN_HCPTR(       CLIPSAVEDSTATEDATA, async.paParms),
    772     SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, data.pv),
    773     SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, data.cb),
    774     SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, data.u32Format),
    775     SSMFIELD_ENTRY_IGNORE(          CLIPSAVEDSTATEDATA, u32AvailableFormats),
    776     SSMFIELD_ENTRY(                 CLIPSAVEDSTATEDATA, u32RequestedFormat),
     724static SSMFIELD const g_aClipboardClientDataFields[] =
     725{
     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),
    777731    SSMFIELD_ENTRY_TERM()
    778732};
     
    791745     * pending request.
    792746     */
    793     LogRel2(("svcSaveState: u32ClientID = %d\n", u32ClientID));
     747    LogRel2 (("svcSaveState: u32ClientID = %d\n", u32ClientID));
    794748
    795749    VBOXCLIPBOARDCLIENTDATA *pClient = (VBOXCLIPBOARDCLIENTDATA *)pvClient;
    796750
    797     CLIPSAVEDSTATEDATA savedState = { 0 };
    798     /* Save client structure length & contents */
    799     int rc = SSMR3PutU32(pSSM, sizeof(savedState));
    800     AssertRCReturn(rc, rc);
    801 
    802     savedState.u32ClientID        = pClient->u32ClientID;
    803     savedState.fMsgQuit           = pClient->fMsgQuit;
    804     savedState.fMsgReadData       = pClient->fMsgReadData;
    805     savedState.fMsgFormats        = pClient->fMsgFormats;
    806     savedState.u32RequestedFormat = pClient->u32RequestedFormat;
    807     rc = SSMR3PutMem(pSSM, &savedState, sizeof(savedState));
    808     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);
    809756
    810757    if (pClient->fAsync)
     
    814761    }
    815762
    816     vboxSvcClipboardCompleteReadData(pClient, VINF_SUCCESS, 0);
     763    vboxSvcClipboardCompleteReadData (pClient, VINF_SUCCESS, 0);
    817764
    818765    return VINF_SUCCESS;
     
    821768static DECLCALLBACK(int) svcLoadState(void *, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
    822769{
    823     LogRel2(("svcLoadState: u32ClientID = %d\n", u32ClientID));
     770    LogRel2 (("svcLoadState: u32ClientID = %d\n", u32ClientID));
    824771
    825772    VBOXCLIPBOARDCLIENTDATA *pClient = (VBOXCLIPBOARDCLIENTDATA *)pvClient;
    826773
    827774    /* Existing client can not be in async state yet. */
    828     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;
    829780
    830781    /* Restore the client data. */
    831     uint32_t len;
    832     int rc = SSMR3GetU32(pSSM, &len);
    833     AssertRCReturn(rc, rc);
    834 #if 1
    835     uint32_t cbExpected = SSMR3HandleHostBits (pSSM) == 64 ? 72 : 48;
    836     if (len != cbExpected)
    837     {
    838         LogRel2(("Client data size mismatch: expected %d, got %d\n", cbExpected, len));
     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));
    839865        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
    840866    }
    841     CLIPSAVEDSTATEDATA savedState;
    842     RT_ZERO (savedState);
    843     rc = SSMR3GetStructEx (pSSM, &savedState, sizeof(savedState), SSMSTRUCT_FLAGS_MEM_BAND_AID,
    844                            &g_aClipSavedStateDataFields[0], NULL);
    845     AssertRCReturn (rc, rc);
    846 
    847 #else
    848     if (len != sizeof(CLIPSAVEDSTATEDATA))
    849     {
    850         LogRel2(("Client data size mismatch: expected %d, got %d\n", sizeof (CLIPSAVEDSTATEDATA), len));
     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;
    851873        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
    852874    }
    853 
    854     CLIPSAVEDSTATEDATA savedState;
    855     rc = SSMR3GetMem(pSSM, &savedState, sizeof(savedState));
    856     AssertRCReturn(rc, rc);
    857 #endif
    858 
    859     /* Verify the loaded clients data and update the pClient. */
    860     if (pClient->u32ClientID != savedState.u32ClientID)
    861     {
    862         LogRel2(("Client ID mismatch: expected %d, got %d\n", pClient->u32ClientID, savedState.u32ClientID));
    863         return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
    864     }
    865 
    866     pClient->fMsgQuit           = savedState.fMsgQuit;
    867     pClient->fMsgReadData       = savedState.fMsgReadData;
    868     pClient->fMsgFormats        = savedState.fMsgFormats;
    869     pClient->u32RequestedFormat = savedState.u32RequestedFormat;
    870875
    871876    /* Actual host data are to be reported to guest (SYNC). */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette