VirtualBox

Changeset 43899 in vbox


Ignore:
Timestamp:
Nov 16, 2012 2:34:12 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82125
Message:

HostServices/HostChannel: code cleanup.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/HostChannel/HostChannel.cpp

    r43892 r43899  
    712712} VBOXHOSTCHANNELEVENT;
    713713
    714 /* This is called under the lock. */
    715 int vboxHostChannelQueryEvent(VBOXHOSTCHCLIENT *pClient,
    716                               bool *pfEvent,
    717                               uint32_t *pu32Handle,
    718                               uint32_t *pu32Id,
    719                               void *pvParm,
    720                               uint32_t cbParm,
    721                               uint32_t *pcbParmOut)
    722 {
     714int vboxHostChannelEventWait(VBOXHOSTCHCLIENT *pClient,
     715                             bool *pfEvent,
     716                             VBOXHGCMCALLHANDLE callHandle,
     717                             VBOXHGCMSVCPARM *paParms)
     718{
     719    int rc = vboxHostChannelLock();
     720    if (RT_FAILURE(rc))
     721    {
     722        return rc;
     723    }
     724
     725    if (pClient->fAsync)
     726    {
     727        /* If there is a wait request already, cancel it. */
     728        vboxHostChannelReportAsync(pClient, 0, VBOX_HOST_CHANNEL_EVENT_CANCELLED, NULL, 0);
     729        pClient->fAsync = false;
     730    }
     731
    723732    /* Check if there is something in the client's event queue. */
    724 
    725733    VBOXHOSTCHANNELEVENT *pEvent = RTListGetFirst(&pClient->listEvents, VBOXHOSTCHANNELEVENT, NodeEvent);
    726734
     
    732740        RTListNodeRemove(&pEvent->NodeEvent);
    733741
     742        HOSTCHLOG(("HostChannel: QueryEvent: (%d), cbEvent %d\n",
     743                   pClient->u32ClientID, pEvent->cbEvent));
     744
     745        vboxHostChannelEventParmsSet(paParms, pEvent->u32ChannelHandle,
     746                                     pEvent->u32Id, pEvent->pvEvent, pEvent->cbEvent);
     747
    734748        *pfEvent = true;
    735         *pu32Handle = pEvent->u32ChannelHandle;
    736         *pu32Id = pEvent->u32Id;
    737 
    738         uint32_t cbToCopy = RT_MIN(cbParm, pEvent->cbEvent);
    739 
    740         HOSTCHLOG(("HostChannel: QueryEvent: (%d), cbParm %d, cbEvent %d\n",
    741                         pClient->u32ClientID, cbParm, pEvent->cbEvent));
    742 
    743         if (cbToCopy > 0)
    744         {
    745             memcpy(pvParm, pEvent->pvEvent, cbToCopy);
    746         }
    747 
    748         *pcbParmOut = cbToCopy;
    749749
    750750        RTMemFree(pEvent);
     
    752752    else
    753753    {
     754        /* No event available at the time. Process asynchronously. */
     755        pClient->fAsync           = true;
     756        pClient->async.callHandle = callHandle;
     757        pClient->async.paParms    = paParms;
     758
    754759        /* Tell the caller that there is no event. */
    755760        *pfEvent = false;
    756761    }
    757762
    758     return VINF_SUCCESS;
    759 }
     763    vboxHostChannelUnlock();
     764    return rc;
     765}
     766
     767int vboxHostChannelEventCancel(VBOXHOSTCHCLIENT *pClient)
     768{
     769    int rc = vboxHostChannelLock();
     770
     771    if (RT_SUCCESS(rc))
     772    {
     773        if (pClient->fAsync)
     774        {
     775            /* If there is a wait request alredy, cancel it. */
     776            vboxHostChannelReportAsync(pClient, 0, VBOX_HOST_CHANNEL_EVENT_CANCELLED, NULL, 0);
     777
     778            pClient->fAsync = false;
     779        }
     780
     781        vboxHostChannelUnlock();
     782    }
     783
     784    return rc;
     785}
     786
    760787
    761788/* @thread provider */
  • trunk/src/VBox/HostServices/HostChannel/HostChannel.h

    r43785 r43899  
    9898                           uint32_t *pu32SizeDataReturned);
    9999
    100 int vboxHostChannelQueryEvent(VBOXHOSTCHCLIENT *pClient,
    101                               bool *pfEvent,
    102                               uint32_t *pu32Handle,
    103                               uint32_t *pu32Id,
    104                               void *pvParm,
    105                               uint32_t cbParm,
    106                               uint32_t *pcbParmOut);
     100int vboxHostChannelEventWait(VBOXHOSTCHCLIENT *pClient,
     101                             bool *pfEvent,
     102                             VBOXHGCMCALLHANDLE callHandle,
     103                             VBOXHGCMSVCPARM *paParms);
     104
     105int vboxHostChannelEventCancel(VBOXHOSTCHCLIENT *pClient);
    107106
    108107int vboxHostChannelQuery(VBOXHOSTCHCLIENT *pClient,
     
    121120
    122121
    123 void vboxHostChannelReportAsync(VBOXHOSTCHCLIENT *pClient, uint32_t u32ChannelHandle,
    124                                 uint32_t u32Id, const void *pvEvent, uint32_t cbEvent);
     122void vboxHostChannelEventParmsSet(VBOXHGCMSVCPARM *paParms,
     123                                  uint32_t u32ChannelHandle,
     124                                  uint32_t u32Id,
     125                                  const void *pvEvent,
     126                                  uint32_t cbEvent);
     127
     128void vboxHostChannelReportAsync(VBOXHOSTCHCLIENT *pClient,
     129                                uint32_t u32ChannelHandle,
     130                                uint32_t u32Id,
     131                                const void *pvEvent,
     132                                uint32_t cbEvent);
    125133
    126134#endif /* __VBOXHOSTCHANNEL__H */
  • trunk/src/VBox/HostServices/HostChannel/service.cpp

    r43462 r43899  
    107107}
    108108
     109void vboxHostChannelEventParmsSet(VBOXHGCMSVCPARM *paParms,
     110                                  uint32_t u32ChannelHandle,
     111                                  uint32_t u32Id,
     112                                  const void *pvEvent,
     113                                  uint32_t cbEvent)
     114{
     115    if (cbEvent > 0)
     116    {
     117        void *pvParm = NULL;
     118        uint32_t cbParm = 0;
     119
     120        VBoxHGCMParmPtrGet(&paParms[2], &pvParm, &cbParm);
     121
     122        uint32_t cbToCopy = RT_MIN(cbParm, cbEvent);
     123        if (cbToCopy > 0)
     124        {
     125            Assert(pvParm);
     126            memcpy(pvParm, pvEvent, cbToCopy);
     127        }
     128    }
     129
     130    VBoxHGCMParmUInt32Set(&paParms[0], u32ChannelHandle);
     131    VBoxHGCMParmUInt32Set(&paParms[1], u32Id);
     132    VBoxHGCMParmUInt32Set(&paParms[3], cbEvent);
     133}
     134
    109135/* This is called under the lock. */
    110136void vboxHostChannelReportAsync(VBOXHOSTCHCLIENT *pClient,
     
    114140                                uint32_t cbEvent)
    115141{
    116     if (cbEvent > 0)
    117     {
    118         void *pvParm = NULL;
    119         uint32_t cbParm = 0;
    120 
    121         VBoxHGCMParmPtrGet(&pClient->async.paParms[2], &pvParm, &cbParm);
    122 
    123         uint32_t cbToCopy = RT_MIN(cbParm, cbEvent);
    124         if (cbToCopy > 0)
    125         {
    126             memcpy(pvParm, pvEvent, cbToCopy);
    127         }
    128     }
    129 
    130     VBoxHGCMParmUInt32Set(&pClient->async.paParms[0], u32ChannelHandle);
    131     VBoxHGCMParmUInt32Set(&pClient->async.paParms[1], u32Id);
    132     VBoxHGCMParmUInt32Set(&pClient->async.paParms[3], cbEvent);
     142    Assert(RTCritSectIsOwner(&g_critsect));
     143
     144    vboxHostChannelEventParmsSet(pClient->async.paParms,
     145                                 u32ChannelHandle,
     146                                 u32Id,
     147                                 pvEvent,
     148                                 cbEvent);
    133149
    134150    LogRelFlow(("svcCall: CallComplete for pending\n"));
     
    438454            else
    439455            {
    440                 void *pvParm;
    441                 uint32_t cbParm;
    442 
    443                 rc = VBoxHGCMParmPtrGet(&paParms[2], &pvParm, &cbParm);
     456                bool fEvent = false;
     457
     458                rc = vboxHostChannelEventWait(pClient, &fEvent, callHandle, paParms);
    444459
    445460                if (RT_SUCCESS(rc))
    446461                {
    447                     /* This is accessed from the SVC thread and other threads. */
    448                     rc = vboxHostChannelLock();
    449 
    450                     if (RT_SUCCESS(rc))
     462                    if (!fEvent)
    451463                    {
    452                         if (pClient->fAsync)
    453                         {
    454                             /* If there is a wait request already, cancel it. */
    455                             vboxHostChannelReportAsync(pClient, 0, VBOX_HOST_CHANNEL_EVENT_CANCELLED, NULL, 0);
    456 
    457                             pClient->fAsync = false;
    458                         }
    459 
    460                         bool fEvent = false;
    461                         uint32_t u32Handle = 0;
    462                         uint32_t u32Id = 0;
    463                         uint32_t cbParmOut = 0;
    464 
    465                         rc = vboxHostChannelQueryEvent(pClient, &fEvent, &u32Handle, &u32Id,
    466                                                        pvParm, cbParm, &cbParmOut);
    467 
    468                         if (RT_SUCCESS(rc))
    469                         {
    470                             if (fEvent)
    471                             {
    472                                 VBoxHGCMParmUInt32Set(&paParms[0], u32Handle);
    473                                 VBoxHGCMParmUInt32Set(&paParms[1], u32Id);
    474                                 VBoxHGCMParmUInt32Set(&paParms[3], cbParmOut);
    475                             }
    476                             else
    477                             {
    478                                 /* No event available at the time. Process asynchronously. */
    479                                 fAsynchronousProcessing = true;
    480 
    481                                 pClient->fAsync           = true;
    482                                 pClient->async.callHandle = callHandle;
    483                                 pClient->async.paParms    = paParms;
    484 
    485                                 LogRel2(("svcCall: async.\n"));
    486                             }
    487                         }
    488 
    489                         vboxHostChannelUnlock();
     464                        /* No event available at the time. Process asynchronously. */
     465                        fAsynchronousProcessing = true;
     466
     467                        LogRel2(("svcCall: async.\n"));
    490468                    }
    491469                }
     
    503481            else
    504482            {
    505                 /* This is accessed from the SVC thread and other threads. */
    506                 rc = vboxHostChannelLock();
    507 
    508                 if (RT_SUCCESS(rc))
    509                 {
    510                     if (pClient->fAsync)
    511                     {
    512                         /* If there is a wait request alredy, cancel it. */
    513                         vboxHostChannelReportAsync(pClient, 0, VBOX_HOST_CHANNEL_EVENT_CANCELLED, NULL, 0);
    514 
    515                         pClient->fAsync = false;
    516                     }
    517 
    518                     vboxHostChannelUnlock();
    519                 }
     483                rc = vboxHostChannelEventCancel(pClient);
    520484            }
    521485        } break;
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