VirtualBox

Changeset 100566 in vbox


Ignore:
Timestamp:
Jul 13, 2023 6:50:43 PM (19 months ago)
Author:
vboxsync
Message:

Shared Clipboard: Added ShClEventWaitEx() + ShClEventSignalEx() for easier error propagation when waiting for events, plus new error codes VERR_SHCLPB_EVENT_FAILED + VERR_SHCLPB_GUEST_ERROR. bugref:9437

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard.h

    r100451 r100566  
    189189    /** Payload to this event, optional (NULL). */
    190190    PSHCLEVENTPAYLOAD   pPayload;
     191    /** Result code (IPRT-style) to assign. */
     192    int                 rc;
    191193} SHCLEVENT;
    192194/** Pointer to a shared clipboard event. */
     
    236238uint32_t ShClEventRetain(PSHCLEVENT pEvent);
    237239uint32_t ShClEventRelease(PSHCLEVENT pEvent);
     240int ShClEventSignalEx(PSHCLEVENT pEvent, int rc, PSHCLEVENTPAYLOAD pPayload);
    238241int ShClEventSignal(PSHCLEVENT pEvent, PSHCLEVENTPAYLOAD pPayload);
    239242int ShClEventWait(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, PSHCLEVENTPAYLOAD *ppPayload);
     243int ShClEventWaitEx(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, int *pRc, PSHCLEVENTPAYLOAD *ppPayload);
    240244/** @} */
    241245
  • trunk/include/VBox/err.h

    r100183 r100566  
    30733073/** Shared Clipboard transfer ID not found. */
    30743074#define VERR_SHCLPB_TRANSFER_ID_NOT_FOUND           (-7150)
     3075/** Shared Clipboard guest error. */
     3076#define VERR_SHCLPB_GUEST_ERROR                     (-7151)
     3077/** Shared Clipboard event failed error. */
     3078#define VERR_SHCLPB_EVENT_FAILED                    (-7152)
    30753079/** @} */
    30763080
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp

    r100328 r100566  
    457457 *
    458458 * @returns VBox status code.
     459 * @retval  VERR_SHCLPB_EVENT_FAILED if the event has a set error code.
    459460 * @param   pEvent              Event to wait for.
    460461 * @param   uTimeoutMs          Timeout (in ms) to wait.
     462 * @param   pRc                 Where to return the event rc. Optional and can be NULL.
    461463 * @param   ppPayload           Where to store the (allocated) event payload on success. Needs to be free'd with
    462464 *                              SharedClipboardPayloadFree(). Optional.
    463465 */
    464 int ShClEventWait(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, PSHCLEVENTPAYLOAD *ppPayload)
     466int ShClEventWaitEx(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, int *pRc, PSHCLEVENTPAYLOAD *ppPayload)
    465467{
    466468    AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
     
    471473    if (RT_SUCCESS(rc))
    472474    {
     475        if (RT_FAILURE(pEvent->rc))
     476            rc = VERR_SHCLPB_EVENT_FAILED;
     477
     478        if (pRc)
     479            *pRc = pEvent->rc;
     480
    473481        if (ppPayload)
    474482        {
     
    486494
    487495/**
     496 * Waits for an event to get signalled.
     497 *
     498 * @returns VBox status code.
     499 * @retval  VERR_SHCLPB_EVENT_FAILED if the event has a set error code.
     500 * @param   pEvent              Event to wait for.
     501 * @param   uTimeoutMs          Timeout (in ms) to wait.
     502 * @param   ppPayload           Where to store the (allocated) event payload on success. Needs to be free'd with
     503 *                              SharedClipboardPayloadFree(). Optional.
     504 */
     505int ShClEventWait(PSHCLEVENT pEvent, RTMSINTERVAL uTimeoutMs, PSHCLEVENTPAYLOAD *ppPayload)
     506{
     507    return ShClEventWaitEx(pEvent, uTimeoutMs, NULL /* pRc */, ppPayload);
     508}
     509
     510/**
    488511 * Retains an event by increasing its reference count.
    489512 *
     
    527550
    528551/**
     552 * Signals an event, extended version.
     553 *
     554 * @returns VBox status code.
     555 * @param   pEvent              Event to signal.
     556 * @param   rc                  Result code to set.
     557 * @param   pPayload            Event payload to associate. Takes ownership on
     558 *                              success. Optional.
     559 */
     560int ShClEventSignalEx(PSHCLEVENT pEvent, int rc, PSHCLEVENTPAYLOAD pPayload)
     561{
     562    AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
     563
     564    Assert(pEvent->pPayload == NULL);
     565
     566    pEvent->rc       = rc;
     567    pEvent->pPayload = pPayload;
     568
     569    int rc2 = RTSemEventMultiSignal(pEvent->hEvtMulSem);
     570    if (RT_FAILURE(rc2))
     571        pEvent->pPayload = NULL; /* (no race condition if consumer also enters the critical section) */
     572
     573    LogFlowFuncLeaveRC(rc2);
     574    return rc2;
     575}
     576
     577/**
    529578 * Signals an event.
    530579 *
     
    536585int ShClEventSignal(PSHCLEVENT pEvent, PSHCLEVENTPAYLOAD pPayload)
    537586{
    538     AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
    539 
    540     Assert(pEvent->pPayload == NULL);
    541 
    542     pEvent->pPayload = pPayload;
    543 
    544     int rc = RTSemEventMultiSignal(pEvent->hEvtMulSem);
    545     if (RT_FAILURE(rc))
    546         pEvent->pPayload = NULL; /* (no race condition if consumer also enters the critical section) */
    547 
    548     LogFlowFuncLeaveRC(rc);
    549     return rc;
     587    return ShClEventSignalEx(pEvent, VINF_SUCCESS, pPayload);
    550588}
    551589
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