VirtualBox

Changeset 81443 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Oct 22, 2019 9:52:40 AM (5 years ago)
Author:
vboxsync
Message:

Shared Clipboard/Svc: Split up client initialization / resetting code into own functions for better testing coverage.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-internal.h

    r81441 r81443  
    198198int shclSvcMsgGet(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    199199
     200int shclSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
     201void shclSvcClientReset(PSHCLCLIENT pClient);
     202
     203int shclSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
     204int shclSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
     205void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
     206
    200207int shclSvcClientWakeup(PSHCLCLIENT pClient);
    201208
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r81352 r81443  
    239239
    240240/*********************************************************************************************************************************
    241 *   Prototypes                                                                                                                   *
    242 *********************************************************************************************************************************/
    243 static int shclSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
    244 static int shclSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
    245 static void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
    246 
    247 
    248 /*********************************************************************************************************************************
    249241*   Global Variables                                                                                                             *
    250242*********************************************************************************************************************************/
     
    508500
    509501    return VINF_SUCCESS;
     502}
     503
     504/**
     505 * Initializes a Shared Clipboard client.
     506 *
     507 * @param   pClient             Client to initialize.
     508 * @param   uClientID           HGCM client ID to assign client to.
     509 */
     510int shclSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID)
     511{
     512    AssertPtrReturn(pClient, VERR_INVALID_POINTER);
     513
     514    /* Assign the client ID. */
     515    pClient->State.uClientID = uClientID;
     516
     517    LogFlowFunc(("[Client %RU32]\n", pClient->State.uClientID));
     518
     519    /* Create the client's own event source. */
     520    int rc = ShClEventSourceCreate(&pClient->Events, 0 /* ID, ignored */);
     521    if (RT_SUCCESS(rc))
     522    {
     523        LogFlowFunc(("[Client %RU32] Using event source %RU32\n", uClientID, pClient->Events.uID));
     524
     525        /* Reset the client state. */
     526        shclSvcClientStateReset(&pClient->State);
     527
     528        /* (Re-)initialize the client state. */
     529        rc = shclSvcClientStateInit(&pClient->State, uClientID);
     530
     531#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     532        if (RT_SUCCESS(rc))
     533            rc = ShClTransferCtxInit(&pClient->TransferCtx);
     534#endif
     535    }
     536
     537    LogFlowFuncLeaveRC(rc);
     538    return rc;
     539}
     540
     541/**
     542 * Resets a Shared Clipboard client.
     543 *
     544 * @param   pClient             Client to reset.
     545 */
     546void shclSvcClientReset(PSHCLCLIENT pClient)
     547{
     548    if (!pClient)
     549        return;
     550
     551    LogFlowFunc(("[Client %RU32]\n", pClient->State.uClientID));
     552
     553    /* Reset message queue. */
     554    shclSvcMsgQueueReset(pClient);
     555
     556    /* Reset event source. */
     557    ShClEventSourceReset(&pClient->Events);
     558
     559    /* Reset pending state. */
     560    RT_ZERO(pClient->Pending);
     561
     562#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     563    shclSvcClientTransfersReset(pClient);
     564#endif
     565
     566    shclSvcClientStateReset(&pClient->State);
    510567}
    511568
     
    12731330    }
    12741331
    1275     shclSvcClientStateReset(&pClient->State);
    12761332    shclSvcClientStateDestroy(&pClient->State);
    1277 
    12781333    ShClEventSourceDestroy(&pClient->Events);
    12791334
     
    12961351    AssertPtr(pvClient);
    12971352
    1298     /* Assign the client ID. */
    1299     pClient->State.uClientID = u32ClientID;
    1300 
    1301     /* Create the client's own event source. */
    1302     int rc = ShClEventSourceCreate(&pClient->Events, 0 /* ID, ignored */);
     1353    int rc = shclSvcClientInit(pClient, u32ClientID);
    13031354    if (RT_SUCCESS(rc))
    13041355    {
    1305         LogFlowFunc(("[Client %RU32] Using event source %RU32\n", u32ClientID, pClient->Events.uID));
    1306 
    1307         /* Reset the client state. */
    1308         shclSvcClientStateReset(&pClient->State);
    1309 
    1310         /* (Re-)initialize the client state. */
    1311         rc = shclSvcClientStateInit(&pClient->State, u32ClientID);
     1356        rc = ShClSvcImplConnect(pClient, ShClSvcGetHeadless());
    13121357        if (RT_SUCCESS(rc))
    13131358        {
    1314 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    1315             rc = ShClTransferCtxInit(&pClient->TransferCtx);
    1316 #endif
    1317             if (RT_SUCCESS(rc))
    1318                 rc = ShClSvcImplConnect(pClient, ShClSvcGetHeadless());
    1319             if (RT_SUCCESS(rc))
    1320             {
    1321                 /* Assign weak pointer to client map .*/
    1322                 g_mapClients[u32ClientID] = pClient; /** @todo Handle OOM / collisions? */
    1323 
    1324                 /* For now we ASSUME that the first client ever connected is in charge for
    1325                  * communicating withe the service extension.
    1326                  *
    1327                  ** @todo This needs to be fixed ASAP w/o breaking older guest / host combos. */
    1328                 if (g_ExtState.uClientID == 0)
    1329                     g_ExtState.uClientID = u32ClientID;
    1330             }
     1359            /* Assign weak pointer to client map .*/
     1360            g_mapClients[u32ClientID] = pClient; /** @todo Handle OOM / collisions? */
     1361
     1362            /* For now we ASSUME that the first client ever connected is in charge for
     1363             * communicating withe the service extension.
     1364             *
     1365             ** @todo This needs to be fixed ASAP w/o breaking older guest / host combos. */
     1366            if (g_ExtState.uClientID == 0)
     1367                g_ExtState.uClientID = u32ClientID;
    13311368        }
    13321369    }
     
    16841721 * @param   uClientID           Client ID (HGCM) to use for this client state.
    16851722 */
    1686 static int shclSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID)
     1723int shclSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID)
    16871724{
    16881725    LogFlowFuncEnter();
     
    17021739 * @param   pClientState        Client state to destroy.
    17031740 */
    1704 static int shclSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState)
     1741int shclSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState)
    17051742{
    17061743    RT_NOREF(pClientState);
     
    17161753 * @param   pClientState    Client state to reset.
    17171754 */
    1718 static void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState)
     1755void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState)
    17191756{
    17201757    LogFlowFuncEnter();
     
    17281765#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    17291766    pClientState->Transfers.enmTransferDir = SHCLTRANSFERDIR_UNKNOWN;
    1730 #else
    1731     RT_NOREF(pClientState);
    17321767#endif
    17331768}
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