VirtualBox

Changeset 34253 in vbox


Ignore:
Timestamp:
Nov 22, 2010 3:34:38 PM (14 years ago)
Author:
vboxsync
Message:

HostServices/GuestControl: Added guest clients reference counting for non-blocking responses without timeout, documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestControl/service.cpp

    r33540 r34253  
    167167    /** Client contexts list. */
    168168    ClientContextsList mClientContextsList;
    169 
     169    /** Number of connected clients. */
     170    uint32_t mNumClients;
    170171public:
    171172    explicit Service(PVBOXHGCMSVCHELPERS pHelpers)
     
    173174        , mpfnHostCallback(NULL)
    174175        , mpvHostData(NULL)
     176        , mNumClients(0)
    175177    {
    176178    }
     
    293295
    294296
    295 /** @todo Write some nice doc headers! */
    296 /* Stores a HGCM request in an internal buffer (pEx). Needs to be freed later using execBufferFree(). */
     297/**
     298 * Stores a HGCM request in an internal buffer. Needs to be free'd using paramBufferFree().
     299 *
     300 * @return  IPRT status code.
     301 * @param   pBuf                    Buffer to store the HGCM request into.
     302 * @param   uMsg                    Message type.
     303 * @param   cParms                  Number of parameters of HGCM request.
     304 * @param   paParms                 Array of parameters of HGCM request.
     305 */
    297306int Service::paramBufferAllocate(PVBOXGUESTCTRPARAMBUFFER pBuf, uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    298307{
     
    361370}
    362371
    363 /* Frees a buffered HGCM request. */
     372/**
     373 * Frees a buffered HGCM request.
     374 *
     375 * @return  IPRT status code.
     376 * @param   pBuf                    Parameter buffer to free.
     377 */
    364378void Service::paramBufferFree(PVBOXGUESTCTRPARAMBUFFER pBuf)
    365379{
     
    382396}
    383397
    384 /* Assigns data from a buffered HGCM request to the current HGCM request. */
     398/**
     399 * Assigns data from a buffered HGCM request to the current HGCM request.
     400 *
     401 * @return  IPRT status code.
     402 * @param   pBuf                    Parameter buffer to assign.
     403 * @param   cParms                  Number of parameters the HGCM request can handle.
     404 * @param   paParms                 Array of parameters of HGCM request to fill the data into.
     405 */
    385406int Service::paramBufferAssign(PVBOXGUESTCTRPARAMBUFFER pBuf, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    386407{
     
    423444}
    424445
     446/**
     447 * Handles a client which just connected.
     448 *
     449 * @return  IPRT status code.
     450 * @param   u32ClientID
     451 * @param   pvClient
     452 */
    425453int Service::clientConnect(uint32_t u32ClientID, void *pvClient)
    426454{
    427455    LogFlowFunc(("New client (%ld) connected\n", u32ClientID));
     456    mNumClients++;
    428457    return VINF_SUCCESS;
    429458}
    430459
     460/**
     461 * Handles a client which disconnected. This functiond does some
     462 * internal cleanup as well as sends notifications to the host so
     463 * that the host can do the same (if required).
     464 *
     465 * @return  IPRT status code.
     466 * @param   u32ClientID             The client's ID of which disconnected.
     467 * @param   pvClient                User data, not used at the moment.
     468 */
    431469int Service::clientDisconnect(uint32_t u32ClientID, void *pvClient)
    432470{
    433471    LogFlowFunc(("Client (%ld) disconnected\n", u32ClientID));
     472    mNumClients--;
     473    Assert(mNumClients >= 0);
    434474
    435475    /*
     
    484524}
    485525
     526/**
     527 * Sends a specified host command to a client.
     528 *
     529 * @return  IPRT status code.
     530 * @param   pCmd                    Host comamnd to send.
     531 * @param   callHandle              Call handle of the client to send the command to.
     532 * @param   cParms                  Number of parameters.
     533 * @param   paParms                 Array of parameters.
     534 */
    486535int Service::sendHostCmdToGuest(HostCmd *pCmd, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    487536{
     
    509558}
    510559
    511 /*
     560/**
    512561 * Either fills in parameters from a pending host command into our guest context or
    513562 * defer the guest call until we have something from the host.
     563 *
     564 * @return  IPRT status code.
     565 * @param   u32ClientID                 The client's ID.
     566 * @param   callHandle                  The client's call handle.
     567 * @param   cParms                      Number of parameters.
     568 * @param   paParms                     Array of parameters.
    514569 */
    515570int Service::retrieveNextHostCmd(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle,
     
    571626}
    572627
    573 /*
     628/**
    574629 * Client asks itself (in another thread) to cancel all pending waits which are blocking the client
    575630 * from shutting down / doing something else.
     631 *
     632 * @return  IPRT status code.
     633 * @param   u32ClientID                 The client's ID.
    576634 */
    577635int Service::cancelPendingWaits(uint32_t u32ClientID)
     
    598656}
    599657
     658/**
     659 * Notifies the host (using low-level HGCM callbacks) about an event
     660 * which was sent from the client.
     661 *
     662 * @return  IPRT status code.
     663 * @param   eFunction               Function (event) that occured.
     664 * @param   cParms                  Number of parameters.
     665 * @param   paParms                 Array of parameters.
     666 */
    600667int Service::notifyHost(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    601668{
     
    657724}
    658725
     726/**
     727 * Processes a command receiveed from the host side and re-routes it to
     728 * a connect client on the guest.
     729 *
     730 * @return  IPRT status code.
     731 * @param   eFunction               Function code to process.
     732 * @param   cParms                  Number of parameters.
     733 * @param   paParms                 Array of parameters.
     734 */
    659735int Service::processHostCmd(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    660736{
    661     int rc = VINF_SUCCESS;
     737    /*
     738     * If no client is connected at all we don't buffer any host commands
     739     * and immediately return an error to the host. This avoids the host
     740     * waiting for a response from the guest side in case VBoxService on
     741     * the guest is not running/system is messed up somehow.
     742     */
     743    if (mNumClients <= 0)
     744        return VERR_NOT_FOUND;
    662745
    663746    HostCmd newCmd;
    664     rc = paramBufferAllocate(&newCmd.mParmBuf, eFunction, cParms, paParms);
     747    int rc = paramBufferAllocate(&newCmd.mParmBuf, eFunction, cParms, paParms);
    665748    if (   RT_SUCCESS(rc)
    666749        && newCmd.mParmBuf.uParmCount > 0)
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