VirtualBox

Ignore:
Timestamp:
Nov 12, 2020 10:15:18 AM (4 years ago)
Author:
vboxsync
Message:

Additions/VBoxClient: Big revamp of the internal service handling and termination fixes. A service now runs as part of a worker thread, while the main thread is used for initialization / shutdown and signal handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/clipboard.cpp

    r85834 r86871  
    5858
    5959/**
    60  * Global clipboard context information.
     60 * Struct keeping a Shared Clipboard context.
    6161 */
    6262struct SHCLCONTEXT
     
    7575};
    7676
    77 /** Only one client is supported. There seems to be no need for more clients. */
     77/** Only one context is supported at a time for now. */
    7878static SHCLCONTEXT g_Ctx;
    7979
     
    258258int vboxClipboardMain(void)
    259259{
    260     LogRel(("Worker loop running\n"));
    261 
    262260    int rc;
    263261
     
    331329                case VBGLR3CLIPBOARDEVENTTYPE_QUIT:
    332330                {
    333                     LogRel2(("Host requested termination\n"));
     331                    VBClLogVerbose(2, "Host requested termination\n");
    334332                    fShutdown = true;
    335333                    break;
     
    368366    }
    369367
    370     LogRel(("Worker loop ended\n"));
    371 
    372368    LogFlowFuncLeaveRC(rc);
    373369    return rc;
     
    377373static DECLCALLBACK(int) vboxClipoardFUSEThread(RTTHREAD hThreadSelf, void *pvUser)
    378374{
    379     RT_NOREF(hThreadSelf, pvUser);
     375    RT_NOREF(pvUser);
    380376
    381377    VbglR3Init();
     
    409405    }
    410406    else
    411         LogRel(("Error creating FUSE mount directory, rc=%Rrc\n", rc));
    412 
    413     LogFlowFuncLeaveRC(rc);
    414     return rc;
    415 }
    416 
    417 static int vboxClipboardFUSEStart()
     407        VBClLogError("Error creating FUSE mount directory, rc=%Rrc\n", rc);
     408
     409    LogFlowFuncLeaveRC(rc);
     410    return rc;
     411}
     412
     413static int vboxClipboardFUSEStart(void)
    418414{
    419415    LogFlowFuncEnter();
     
    430426}
    431427
    432 static int vboxClipboardFUSEStop()
     428static int vboxClipboardFUSEStop(void)
    433429{
    434430    LogFlowFuncEnter();
     
    444440#endif /* VBOX_WITH_SHARED_CLIPBOARD_FUSE */
    445441
    446 static const char *getName()
    447 {
    448     return "Shared Clipboard";
    449 }
    450 
    451 static const char *getPidFilePath()
    452 {
    453     return ".vboxclient-clipboard.pid";
    454 }
    455 
    456 static int init(struct VBCLSERVICE **pSelf)
    457 {
    458     RT_NOREF(pSelf);
    459 
     442/** @copydoc VBCLSERVICE::pfnInit */
     443static int vbclShClInit(void)
     444{
    460445    int rc;
    461446
     
    470455}
    471456
    472 static int run(struct VBCLSERVICE **ppInterface, bool fDaemonised)
    473 {
    474     RT_NOREF(ppInterface, fDaemonised);
     457/** @copydoc VBCLSERVICE::pfnWorker */
     458static int vbclShClWorker(bool volatile *pfShutdown)
     459{
     460    RT_NOREF(pfShutdown);
    475461
    476462    /* Initialise the guest library. */
     
    483469        {
    484470#endif
     471            /* Let the main thread know that it can continue spawning services. */
     472            RTThreadUserSignal(RTThreadSelf());
     473
    485474            rc = vboxClipboardMain();
    486475
     
    502491}
    503492
    504 static void cleanup(struct VBCLSERVICE **ppInterface)
    505 {
    506     RT_NOREF(ppInterface);
    507 
     493/** @copydoc VBCLSERVICE::pfnStop */
     494static void vbclShClStop(void)
     495{
     496    /* Disconnect from the host service.
     497     * This will also send a VBOX_SHCL_HOST_MSG_QUIT from the host so that we can break out from our message worker. */
     498    VbglR3ClipboardDisconnect(g_Ctx.CmdCtx.idClient);
     499    g_Ctx.CmdCtx.idClient = 0;
     500}
     501
     502/** @copydoc VBCLSERVICE::pfnTerm */
     503static int vbclShClTerm(void)
     504{
    508505#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    509506    ShClTransferCtxDestroy(&g_Ctx.TransferCtx);
    510507#endif
    511 }
    512 
    513 struct VBCLSERVICE vbclClipboardInterface =
    514 {
    515     getName,
    516     getPidFilePath,
    517     init,
    518     run,
    519     cleanup
     508
     509    return VINF_SUCCESS;
     510}
     511
     512VBCLSERVICE g_SvcClipboard =
     513{
     514    "shcl",                      /* szName */
     515    "Shared Clipboard",          /* pszDescription */
     516    ".vboxclient-clipboard.pid", /* pszPidFilePath */
     517    NULL,                        /* pszUsage */
     518    NULL,                        /* pszOptions */
     519    NULL,                        /* pfnOption */
     520    vbclShClInit,                /* pfnInit */
     521    vbclShClWorker,              /* pfnWorker */
     522    vbclShClStop,                /* pfnStop*/
     523    vbclShClTerm                 /* pfnTerm */
    520524};
    521525
    522 struct CLIPBOARDSERVICE
    523 {
    524     struct VBCLSERVICE *pInterface;
    525 };
    526 
    527 struct VBCLSERVICE **VBClGetClipboardService(void)
    528 {
    529     struct CLIPBOARDSERVICE *pService =
    530         (struct CLIPBOARDSERVICE *)RTMemAlloc(sizeof(*pService));
    531 
    532     if (!pService)
    533         VBClLogFatalError("Out of memory\n");
    534     pService->pInterface = &vbclClipboardInterface;
    535     return &pService->pInterface;
    536 }
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