VirtualBox

Changeset 7249 in vbox


Ignore:
Timestamp:
Mar 3, 2008 5:50:55 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
28585
Message:

Use the critsect to serialize access to the pastboard so that the polling thread doesn't enter it at the same time as the service thread. Fixed the return code handling around queryNewPasteboardFormats (VERR_NOT_SUPPORTED should not propagate to Connect and Sync, even if returns codes are generally ignored by the service layer). Use pClient instead of the global (/me hates globals).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp

    r7242 r7249  
    3232/**
    3333 * Initialize the global pasteboard and return a reference to it.
    34  * 
     34 *
    3535 * @param pPasteboardRef Reference to the global pasteboard.
    3636 *
     
    4949/**
    5050 * Release the reference to the global pasteboard.
    51  * 
     51 *
    5252 * @param pPasteboardRef Reference to the global pasteboard.
    5353 */
     
    6161 * Inspect the global pasteboard for new content. Check if there is some type
    6262 * that is supported by vbox and return it.
    63  * 
     63 *
    6464 * @param   pPasteboardRef Reference to the global pasteboard.
    6565 * @param   pfFormats      Pointer for the bit combination of the
     
    6868 *                         last call.
    6969 *
    70  * @returns IPRT status code.
    71  */
    72 int queryNewPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pbChanged)
     70 * @returns IPRT status code. (Always VINF_SUCCESS atm.)
     71 */
     72int queryNewPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged)
    7373{
    7474    Log (("queryNewPasteboardFormats\n"));
    7575
    7676    OSStatus err = noErr;
    77     *pbChanged = true;
     77    *pfChanged = true;
    7878
    7979    PasteboardSyncFlags syncFlags;
     
    8383    if (!(syncFlags & kPasteboardModified))
    8484    {
    85         *pbChanged = false;
     85        *pfChanged = false;
    8686        return VINF_SUCCESS;
    8787    }
     
    9494
    9595    /* The id of the first element in the pasteboard */
    96     int rc = VERR_NOT_SUPPORTED;
     96    int rc = VINF_SUCCESS;
    9797    PasteboardItemID itemID;
    9898    if (!(err = PasteboardGetItemIdentifier (pPasteboard, 1, &itemID)))
     
    118118                }
    119119            }
    120             rc = VINF_SUCCESS;
    121120            CFRelease (flavorTypeArray);
    122121        }
     
    130129 * Read content from the host clipboard and write it to the internal clipboard
    131130 * structure for further processing.
    132  * 
     131 *
    133132 * @param   pPasteboardRef Reference to the global pasteboard.
    134133 * @param   fFormats       The format type which should be read.
     
    224223 * Write clipboard content to the host clipboard from the internal clipboard
    225224 * structure.
    226  * 
     225 *
    227226 * @param   pPasteboardRef Reference to the global pasteboard.
    228227 * @param   pv             The source buffer.
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.h

    r7242 r7249  
    2525void destroyPasteboard (PasteboardRef *pPasteboardRef);
    2626
    27 int queryNewPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pbChanged);
     27int queryNewPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged);
    2828int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual);
    2929int writeToPasteboard (PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat);
  • trunk/src/VBox/HostServices/SharedClipboard/darwin.cpp

    r7242 r7249  
    4444/**
    4545 * Checks if something is present on the clipboard and calls vboxSvcClipboardReportMsg.
    46  * 
     46 *
    4747 * @returns IPRT status code (ignored).
    4848 * @param   pCtx    The context.
     
    5454
    5555    uint32_t fFormats = 0;
    56     bool bChanged = false;
     56    bool fChanged = false;
    5757    /* Retrieve the formats currently in the clipboard and supported by vbox */
    58     int rc = queryNewPasteboardFormats (pCtx->pasteboard, &fFormats, &bChanged);
    59 
    60     if (bChanged)
     58    int rc = queryNewPasteboardFormats (pCtx->pasteboard, &fFormats, &fChanged);
     59    if (RT_SUCCESS (rc) && fChanged)
    6160    {
    6261        vboxSvcClipboardReportMsg (pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, fFormats);
     
    6867
    6968
    70 /** 
     69/**
    7170 * The poller thread.
    72  * 
     71 *
    7372 * This thread will check for the arrival of new data on the clipboard.
    74  * 
     73 *
    7574 * @returns VINF_SUCCESS (not used).
    7675 * @param   Thread      Our thread handle.
    7776 * @param   pvUser      Pointer to the VBOXCLIPBOARDCONTEXT structure.
    78  * 
     77 *
    7978 */
    8079static int vboxClipboardThread (RTTHREAD ThreadSelf, void *pvUser)
     
    8786    while (!pCtx->fTerminate)
    8887    {
     88        /* call this behind the lock because we don't know if the api is
     89           thread safe and in any case we're calling several methods. */
     90        vboxSvcClipboardLock();
    8991        vboxClipboardChanged (pCtx);
     92        vboxSvcClipboardUnlock();
     93
    9094        /* Sleep for 200 msecs before next poll */
    9195        RTThreadUserWait (ThreadSelf, 200);
     
    126130    Log (("vboxClipboardDestroy\n"));
    127131
    128     /* 
     132    /*
    129133     * Signal the termination of the polling thread and wait for it to respond.
    130134     */
     
    157161    }
    158162
     163    vboxSvcClipboardLock();
     164
    159165    pClient->pCtx = &g_ctx;
    160166    pClient->pCtx->pClient = pClient;
     
    163169    int rc = vboxClipboardSync (pClient);
    164170
     171    vboxSvcClipboardUnlock();
    165172    return rc;
    166173}
     
    173180{
    174181    /* Sync the host clipboard content with the client. */
     182    vboxSvcClipboardLock();
    175183    int rc = vboxClipboardChanged (pClient->pCtx);
     184    vboxSvcClipboardUnlock();
    176185
    177186    return rc;
     
    181190 * Shut down the shared clipboard subsystem and "disconnect" the guest.
    182191 */
    183 void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA * /* pClient */)
     192void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *pClient)
    184193{
    185194    Log (("vboxClipboardDisconnect\n"));
    186195
    187     g_ctx.pClient = NULL;
     196    vboxSvcClipboardLock();
     197    pClient->pCtx->pClient = NULL;
     198    vboxSvcClipboardUnlock();
    188199}
    189200
     
    195206 * @param u32Formats Clipboard formats the the guest is offering
    196207 */
    197 void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA * /* pClient */,
    198                                   uint32_t u32Formats)
     208void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats)
    199209{
    200210    Log (("vboxClipboardFormatAnnounce u32Formats %02X\n", u32Formats));
     
    205215    }
    206216
    207     vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
     217    vboxSvcClipboardReportMsg (pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
    208218                               u32Formats);
    209219}
     
    218228 * @param pcbActual Where to write the actual size of the written data
    219229 */
    220 int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA * /* pClient */, uint32_t u32Format,
     230int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format,
    221231                           void *pv, uint32_t cb, uint32_t * pcbActual)
    222232{
     233    vboxSvcClipboardLock();
     234
    223235    /* Default to no data available. */
    224236    *pcbActual = 0;
    225     int rc = readFromPasteboard (g_ctx.pasteboard, u32Format, pv, cb, pcbActual);
    226 
     237    int rc = readFromPasteboard (pClient->pCtx->pasteboard, u32Format, pv, cb, pcbActual);
     238
     239    vboxSvcClipboardUnlock();
    227240    return rc;
    228241}
     
    236249 * @param u32Format The format of the data written
    237250 */
    238 void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA * /* pClient */, void *pv,
     251void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv,
    239252                             uint32_t cb, uint32_t u32Format)
    240253{
    241     writeToPasteboard (g_ctx.pasteboard, pv, cb, u32Format);
    242 }
     254    vboxSvcClipboardLock();
     255
     256    writeToPasteboard (pClient->pCtx->pasteboard, pv, cb, u32Format);
     257
     258    vboxSvcClipboardUnlock();
     259}
Note: See TracChangeset for help on using the changeset viewer.

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