VirtualBox

Changeset 15883 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 8, 2009 8:10:33 PM (16 years ago)
Author:
vboxsync
Message:

HostServices/SharedClipboard/X11: documentation and function renaming

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/x11.cpp

    r14303 r15883  
    182182
    183183/**
    184  * Send a request to the guest to transfer the contents of its clipboard to the host.
    185  *
    186  * @param pCtx      Pointer to the host clipboard structure
    187  * @param u32Format The format in which the data should be transfered
    188  */
    189 static int vboxClipboardReadDataFromClient (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format)
     184 * Send a request to VBox to transfer the contents of its clipboard to X11.
     185 *
     186 * @param  pCtx      Pointer to the host clipboard structure
     187 * @param  u32Format The format in which the data should be transfered
     188 * @thread clipboard X11 event thread
     189 * @note   called by vboxClipboardConvert*
     190 */
     191static int vboxClipboardReadDataFromVBox (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format)
    190192{
    191193    VBOXCLIPBOARDCLIENTDATA *pClient = pCtx->pClient;
     
    194196    if (pClient == 0)
    195197    {
    196         Log(("vboxClipboardReadDataFromClient: host requested guest clipboard data after guest had disconnected.\n"));
     198        LogFunc(("host requested guest clipboard data after guest had disconnected.\n"));
    197199        pCtx->guestFormats = 0;
    198200        pCtx->waiter = 0;
     
    276278/**
    277279 * Convert the UTF-8 text returned from the X11 clipboard to UTF-16LE with Windows EOLS.
    278  * We are reading the host clipboard to make it available to the guest.
     280 * We are reading the X11 clipboard to make it available to VBox.
    279281 *
    280282 * @param pValue      Source UTF-8 text
     
    284286 * @param pcbActual   Where to store the size of the converted data
    285287 * @param pClient     Pointer to the client context structure
    286  */
    287 static void vboxClipboardGetUtf8(XtPointer pValue, unsigned cbSrcLen, void *pv, unsigned cb,
    288                                  uint32_t *pcbActual)
     288 * @thread clipboard X11 event thread
     289 * @note   called by vboxClipboardGetDataFromX11
     290 */
     291static void vboxClipboardGetUtf8FromX11(XtPointer pValue, unsigned cbSrcLen,
     292                                        void *pv, unsigned cb,
     293                                        uint32_t *pcbActual)
    289294{
    290295    size_t cwSrcLen, cwDestLen;
     
    325330/**
    326331 * Convert the COMPOUND_TEXT text returned from the X11 clipboard to UTF-16LE with Windows
    327  * EOLS.  We are reading the host clipboard to make it available to the guest.
     332 * EOLS.  We are reading the X11 clipboard to make it available to VBox.
    328333 *
    329334 * @param pValue      Source COMPOUND_TEXT text
     
    333338 * @param pcbActual   Where to store the size of the converted data
    334339 * @param pClient     Pointer to the client context structure
    335  */
    336 static void vboxClipboardGetCText(XtPointer pValue, unsigned cbSrcLen, void *pv, unsigned cb,
    337                                   uint32_t *pcbActual)
     340 * @thread clipboard X11 event thread
     341 * @note   called by vboxClipboardGetDataFromX11
     342 */
     343static void vboxClipboardGetCTextFromX11(XtPointer pValue, unsigned cbSrcLen,
     344                                         void *pv, unsigned cb,
     345                                         uint32_t *pcbActual)
    338346{
    339347    size_t cwSrcLen, cwDestLen;
     
    403411/**
    404412 * Convert the Latin1 text returned from the X11 clipboard to UTF-16LE with Windows EOLS
    405  * and place it in the global g_pcClipboardText variable.  We are reading the host clipboard to
    406  * make it available to the guest.
     413 * and place it in the global g_pcClipboardText variable.  We are reading the X11 clipboard to
     414 * make it available to VBox.
    407415 *
    408416 * @param pValue      Source Latin1 text
     
    412420 * @param pcbActual   Where to store the size of the converted data
    413421 * @param pClient     Pointer to the client context structure
    414  */
    415 static void vboxClipboardGetLatin1(XtPointer pValue, unsigned cbSourceLen, void *pv, unsigned cb,
     422 * @thread clipboard X11 event thread
     423 * @note   called by vboxClipboardGetDataFromX11
     424 */
     425static void vboxClipboardGetLatin1FromX11(XtPointer pValue, unsigned cbSourceLen, void *pv, unsigned cb,
    416426                                   uint32_t *pcbActual)
    417427{
     
    421431    int rc = VINF_SUCCESS;
    422432
    423     LogFlow (("vboxClipboardGetLatin1: converting Latin1 to Utf-16LE.  Original is %.*s\n",
    424               cbSourceLen, pu8SourceText));
     433    LogFlowFunc (("converting Latin1 to Utf-16LE.  Original is %.*s\n",
     434                  cbSourceLen, pu8SourceText));
    425435    *pcbActual = 0;  /* Only set this to the right value on success. */
    426436    for (unsigned i = 0; i < cbSourceLen; i++)
     
    454464}
    455465
    456 /** Convert the clipboard text from the current format to Utf-16 with Windows line breaks.
    457     We are reading the host clipboard to make it available to the guest. */
    458 static void vboxClipboardGetProc(Widget, XtPointer pClientData, Atom * /* selection */,
    459                                  Atom *atomType, XtPointer pValue, long unsigned int *pcLen,
    460                                  int *piFormat)
     466/**
     467 * Convert the clipboard text from the current format to Utf-16 with Windows line breaks.
     468 * We are reading the X11 clipboard to make it available to VBox.
     469 * @thread  clipboard X11 event thread
     470 * @note    Callback for XtGetSelectionValue, called from vboxClipboardReadData
     471 */
     472static void vboxClipboardGetDataFromX11(Widget, XtPointer pClientData,
     473                                        Atom * /* selection */, Atom *atomType,
     474                                        XtPointer pValue,
     475                                        long unsigned int *pcLen,
     476                                        int *piFormat)
    461477{
    462478    LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData, *pcLen, *piFormat));
     
    490506        break;
    491507    case CTEXT:
    492         vboxClipboardGetCText(pValue, cTextLen, g_ctx.requestBuffer, g_ctx.requestBufferSize,
     508        vboxClipboardGetCTextFromX11(pValue, cTextLen, g_ctx.requestBuffer, g_ctx.requestBufferSize,
    493509                              g_ctx.requestActualSize);
    494510        break;
     
    502518            && (RTStrUniLenEx(pu8SourceText, *pcLen, &cStringLen) == VINF_SUCCESS))
    503519        {
    504             vboxClipboardGetUtf8(pValue, cTextLen, g_ctx.requestBuffer, g_ctx.requestBufferSize,
     520            vboxClipboardGetUtf8FromX11(pValue, cTextLen, g_ctx.requestBuffer, g_ctx.requestBufferSize,
    505521                                 g_ctx.requestActualSize);
    506522            break;
     
    508524        else
    509525        {
    510             vboxClipboardGetLatin1(pValue, cTextLen, g_ctx.requestBuffer, g_ctx.requestBufferSize,
     526            vboxClipboardGetLatin1FromX11(pValue, cTextLen, g_ctx.requestBuffer, g_ctx.requestBufferSize,
    511527                                   g_ctx.requestActualSize);
    512528            break;
     
    514530    }
    515531    default:
    516         Log (("vboxClipboardGetProc: bad target format\n"));
     532        LogFunc (("bad target format\n"));
    517533        XtFree(reinterpret_cast<char *>(pValue));
    518534        RTSemMutexRelease(g_ctx.asyncMutex);
     
    523539}
    524540
    525 /** Callback to handle a reply to a request for the targets the current clipboard holder can
    526     handle.  We are reading the host clipboard to make it available to the guest. */
    527 static void vboxClipboardTargetsProc(Widget, XtPointer pClientData, Atom * /* selection */,
    528                                      Atom *atomType, XtPointer pValue, long unsigned int *pcLen,
    529                                      int *piFormat)
     541/**
     542 * Find out what targets the current X11 clipboard holder can handle.  We are
     543 * reading the X11 clipboard to make it available to VBox.
     544 * @thread  clipboard X11 event thread
     545 * @note    Callback for XtGetSelectionValue, called from vboxClipboardPollX11ForTargets
     546 */
     547static void vboxClipboardGetTargetsFromX11(Widget, XtPointer pClientData,
     548                                           Atom * /* selection */,
     549                                           Atom *atomType,
     550                                           XtPointer pValue,
     551                                           long unsigned int *pcLen,
     552                                           int *piFormat)
    530553{
    531554    Atom *atomTargets = reinterpret_cast<Atom *>(pValue);
     
    534557    Atom atomBestTarget = None;
    535558
    536     Log3 (("vboxClipboardTargetsProc called\n"));
     559    Log3 (("%s: called\n", __PRETTY_FUNCTION__));
    537560    if (*atomType == XT_CONVERT_FAIL)
    538561    {
    539         Log (("vboxClipboardTargetsProc: reading clipboard from host, X toolkit failed to convert the selection\n"));
     562        LogFunc (("reading clipboard from host, X toolkit failed to convert the selection\n"));
    540563        return;
    541564    }
     
    568591            if (szAtomName != 0)
    569592            {
    570                 Log2 (("vboxClipboardTargetsProc: the host offers target %s\n", szAtomName));
     593                Log2 (("%s: the host offers target %s\n", __PRETTY_FUNCTION__,
     594                       szAtomName));
    571595                XFree(szAtomName);
    572596            }
     
    582606            {
    583607                char *szAtomName = XGetAtomName(XtDisplay(g_ctx.widget), atomBestTarget);
    584                 Log2 (("vboxClipboardTargetsProc: switching to host text target %s.  Available targets are:\n",
    585                        szAtomName));
     608                Log2 (("%s: switching to host text target %s.  Available targets are:\n",
     609                       __PRETTY_FUNCTION__, szAtomName));
    586610                XFree(szAtomName);
    587611            }
    588612            else
    589             {
    590                 Log2(("vboxClipboardTargetsProc: no supported host text target found.  Available targets are:\n"));
    591             }
     613                Log2(("%s: no supported host text target found.  Available targets are:\n",
     614                      __PRETTY_FUNCTION__));
    592615            for (unsigned i = 0; i < cAtoms; ++i)
    593616            {
     
    595618                if (szAtomName != 0)
    596619                {
    597                     Log2 (("vboxClipboardTargetsProc:     %s\n", szAtomName));
     620                    Log2 (("%s:     %s\n", __PRETTY_FUNCTION__, szAtomName));
    598621                    XFree(szAtomName);
    599622                }
     
    612635
    613636/**
    614  * This callback is called every 200ms to check the contents of the host clipboard.
    615  */
    616 static void vboxClipboardTimerProc(XtPointer /* pUserData */, XtIntervalId * /* hTimerId */)
    617 {
    618     Log3 (("vboxClipboardTimerProc called\n"));
     637 * This callback is called every 200ms to check the contents of the X11 clipboard.
     638 * @thread  clipboard X11 event thread
     639 * @note    Callback for XtAppAddTimeOut, called from vboxClipboardThread and
     640 *          recursively retriggered
     641 */
     642static void vboxClipboardPollX11ForTargets(XtPointer /* pUserData */, XtIntervalId * /* hTimerId */)
     643{
     644    Log3 (("%s: called\n", __PRETTY_FUNCTION__));
    619645    /* Get the current clipboard contents */
    620646    if (g_ctx.eOwner == HOST && g_ctx.pClient != 0)
    621647    {
    622         Log3 (("vboxClipboardTimerProc: requesting the targets that the host clipboard offers\n"));
     648        Log3 (("%s: requesting the targets that the host clipboard offers\n",
     649               __PRETTY_FUNCTION__));
    623650        XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomTargets,
    624                             vboxClipboardTargetsProc, reinterpret_cast<XtPointer>(g_ctx.pClient),
     651                            vboxClipboardGetTargetsFromX11, reinterpret_cast<XtPointer>(g_ctx.pClient),
    625652                            CurrentTime);
    626653    }
    627654    /* Re-arm our timer */
    628     XtAppAddTimeOut(g_ctx.appContext, 200 /* ms */, vboxClipboardTimerProc, 0);
     655    XtAppAddTimeOut(g_ctx.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0);
    629656}
    630657
     
    646673/**
    647674 * The main loop of our clipboard reader.
     675 * @thread  clipboard X11 event thread
    648676 */
    649677static int vboxClipboardThread(RTTHREAD self, void * /* pvUser */)
     
    652680
    653681    /* Set up a timer to poll the host clipboard */
    654     XtAppAddTimeOut(g_ctx.appContext, 200 /* ms */, vboxClipboardTimerProc, 0);
     682    XtAppAddTimeOut(g_ctx.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0);
    655683
    656684    XtAppMainLoop(g_ctx.appContext);
     
    662690}
    663691
     692/** X11 specific initialisation for the shared clipboard. */
    664693int vboxClipboardInitX11 (void)
    665694{
     
    737766}
    738767
    739 /** Initialise the host side of the shared clipboard - called by the hgcm layer. */
     768/**
     769 * Initialise the host side of the shared clipboard.
     770 * @note    Called by the HGCM clipboard service
     771 * @thread  HGCM clipboard service thread
     772 */
    740773int vboxClipboardInit (void)
    741774{
     
    796829}
    797830
    798 /** Terminate the host side of the shared clipboard - called by the hgcm layer. */
     831/**
     832 * Terminate the host side of the shared clipboard.
     833 * @note    Called by the HGCM clipboard service
     834 * @thread  HGCM clipboard service thread
     835 */
    799836void vboxClipboardDestroy (void)
    800837{
     
    804841
    805842    /*
    806      * Immetiately return if we are not connected to the host X server.
     843     * Immediately return if we are not connected to the host X server.
    807844     */
    808845    if (!g_fHaveX11)
     
    834871
    835872/**
    836   * Enable the shared clipboard - called by the hgcm clipboard subsystem.
    837   *
    838   * @param   pClient Structure containing context information about the guest system
    839   * @returns RT status code
    840   */
     873 * Connect a guest the shared clipboard.
     874 *
     875 * @param   pClient Structure containing context information about the guest system
     876 * @returns RT status code
     877 * @note    Called by the HGCM clipboard service
     878 * @thread  HGCM clipboard service thread
     879 */
    841880int vboxClipboardConnect (VBOXCLIPBOARDCLIENTDATA *pClient)
    842881{
    843882    /*
    844      * Immetiately return if we are not connected to the host X server.
     883     * Immediately return if we are not connected to the host X server.
    845884     */
    846885    if (!g_fHaveX11)
     
    864903
    865904/**
    866  * Synchronise the contents of the host clipboard with the guest, called by the HGCM layer
     905 * Synchronise the contents of the host clipboard with the guest, called
    867906 * after a save and restore of the guest.
     907 * @note    Called by the HGCM clipboard service
     908 * @thread  HGCM clipboard service thread
    868909 */
    869910int vboxClipboardSync (VBOXCLIPBOARDCLIENTDATA *pClient)
    870911{
    871912    /*
    872      * Immetiately return if we are not connected to the host X server.
     913     * Immediately return if we are not connected to the host X server.
    873914     */
    874915    if (!g_fHaveX11)
     
    886927
    887928/**
    888  * Shut down the shared clipboard subsystem and "disconnect" the guest.
    889  */
    890 void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *pClient)
     929 * Shut down the shared clipboard service and "disconnect" the guest.
     930 * @note    Called by the HGCM clipboard service
     931 * @thread  HGCM clipboard service thread
     932 */
     933void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *)
    891934{
    892935    /*
    893      * Immetiately return if we are not connected to the host X server.
     936     * Immediately return if we are not connected to the host X server.
    894937     */
    895938    if (!g_fHaveX11)
     
    907950
    908951/**
    909  * Satisfy a request from the host for available clipboard targets.
     952 * Satisfy a request from X11 for clipboard targets supported by VBox.
    910953 *
    911954 * @returns true if we successfully convert the data to the format requested, false otherwise.
    912955 *
    913  * @param atomTypeReturn The type of the data we are returning
    914  * @param pValReturn     A pointer to the data we are returning.  This should be to memory
    915  *                       allocated by XtMalloc, which will be freed by the toolkit later
    916  * @param pcLenReturn    The length of the data we are returning
    917  * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    918  */
    919 static Boolean vboxClipboardConvertTargets(Atom *atomTypeReturn, XtPointer *pValReturn,
    920                                            unsigned long *pcLenReturn, int *piFormatReturn)
     956 * @param  atomTypeReturn The type of the data we are returning
     957 * @param  pValReturn     A pointer to the data we are returning.  This should be to memory
     958 *                        allocated by XtMalloc, which will be freed by the toolkit later
     959 * @param  pcLenReturn    The length of the data we are returning
     960 * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
     961 * @thread  clipboard X11 event thread
     962 * @note    called by vboxClipboardConvertForX11
     963 */
     964static Boolean vboxClipboardConvertTargetsForX11(Atom *atomTypeReturn, XtPointer *pValReturn,
     965                                                 unsigned long *pcLenReturn, int *piFormatReturn)
    921966{
    922967    unsigned uListSize = g_ctx.formatList.size();
     
    924969    unsigned cTargets = 0;
    925970
    926     LogFlow (("vboxClipboardConvertTargets called\n"));
     971    LogFlowFunc (("called\n"));
    927972    for (unsigned i = 0; i < uListSize; ++i)
    928973    {
     
    944989            if (szAtomName != 0)
    945990            {
    946                 Log2 (("vboxClipboardConvertTargets: returning target %s\n", szAtomName));
     991                Log2 (("%s: returning target %s\n", __PRETTY_FUNCTION__,
     992                       szAtomName));
    947993                XFree(szAtomName);
    948994            }
    949995            else
    950996            {
    951                 Log(("vboxClipboardConvertTargets: invalid atom %d in the list!\n", atomTargets[i]));
     997                Log(("%s: invalid atom %d in the list!\n", __PRETTY_FUNCTION__,
     998                     atomTargets[i]));
    952999            }
    9531000        }
     
    9611008
    9621009/**
    963  * Reset the contents of the buffer used to pass clipboard data from the guest to the host.
     1010 * Reset the contents of the buffer used to pass clipboard data from VBox to X11.
    9641011 * This must be done after every clipboard transfer.
    9651012 */
     
    9931040
    9941041    LogFlowFunc (("called\n"));
    995     rc = vboxClipboardReadDataFromClient(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
     1042    rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    9961043    if ((RT_FAILURE(rc)) || (g_ctx.pClient->data.cb == 0))
    9971044    {
    998         /* If vboxClipboardReadDataFromClient fails then pClient may be invalid */
    999         LogRelFunc (("vboxClipboardReadDataFromClient returned %Rrc%s\n", rc,
     1045        /* If vboxClipboardReadDataFromVBox fails then pClient may be invalid */
     1046        LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc,
    10001047                     RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
    10011048        vboxClipboardEmptyGuestBuffer();
     
    10481095 * @returns true if we successfully convert the data to the format requested, false otherwise.
    10491096 *
    1050  * @param atomTypeReturn The type of the data we are returning
    1051  * @param pValReturn     A pointer to the data we are returning.  This should be to memory
    1052  *                       allocated by XtMalloc, which will be freed by the toolkit later
    1053  * @param pcLenReturn    The length of the data we are returning
    1054  * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1055  */
    1056 static Boolean vboxClipboardConvertUtf8(Atom *atomTypeReturn, XtPointer *pValReturn,
    1057                                         unsigned long *pcLenReturn, int *piFormatReturn)
     1097 * @param  atomTypeReturn The type of the data we are returning
     1098 * @param  pValReturn     A pointer to the data we are returning.  This should be to memory
     1099 *                        allocated by XtMalloc, which will be freed by the toolkit later
     1100 * @param  pcLenReturn    The length of the data we are returning
     1101 * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
     1102 * @thread  clipboard X11 event thread
     1103 * @note    called by vboxClipboardConvertForX11
     1104 */
     1105static Boolean vboxClipboardConvertToUtf8ForX11(Atom *atomTypeReturn,
     1106                                                XtPointer *pValReturn,
     1107                                                unsigned long *pcLenReturn,
     1108                                                int *piFormatReturn)
    10581109{
    10591110    PRTUTF16 pu16SrcText, pu16DestText;
     
    10641115    LogFlowFunc (("called\n"));
    10651116    /* Read the clipboard data from the guest. */
    1066     rc = vboxClipboardReadDataFromClient(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
     1117    rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    10671118    if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0))
    10681119    {
    1069         /* If vboxClipboardReadDataFromClient fails then pClient may be invalid */
    1070         LogRelFunc (("vboxClipboardReadDataFromClient returned %Rrc%s\n", rc,
    1071                      RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
     1120        /* If vboxClipboardReadDataFromVBox fails then pClient may be invalid */
     1121        LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc,
     1122                      RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
    10721123        vboxClipboardEmptyGuestBuffer();
    10731124        return false;
     
    10791130    if (RT_FAILURE(rc))
    10801131    {
    1081         LogRel(("vboxClipboardConvertUtf8: clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
     1132        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
    10821133        vboxClipboardEmptyGuestBuffer();
    10831134        AssertRCReturn(rc, false);
     
    10921143    if (pu16DestText == 0)
    10931144    {
    1094         LogRel(("vboxClipboardConvertUtf8: failed to allocate %d bytes\n", cwDestLen * 2));
     1145        LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2));
    10951146        vboxClipboardEmptyGuestBuffer();
    10961147        return false;
     
    11001151    if (RT_FAILURE(rc))
    11011152    {
    1102         LogRel(("vboxClipboardConvertUtf8: clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
     1153        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
    11031154        RTMemFree(reinterpret_cast<void *>(pu16DestText));
    11041155        vboxClipboardEmptyGuestBuffer();
     
    11101161    if (pu8DestText == 0)
    11111162    {
    1112         LogRel(("vboxClipboardConvertUtf8: failed to allocate %d bytes\n", cwDestLen * 4));
     1163        LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 4));
    11131164        RTMemFree(reinterpret_cast<void *>(pu16DestText));
    11141165        vboxClipboardEmptyGuestBuffer();
     
    11211172    if (RT_FAILURE(rc))
    11221173    {
    1123         LogRel(("vboxClipboardConvertUtf8: clipboard conversion failed.  RTUtf16ToUtf8Ex() returned %Rrc.  Abandoning.\n", rc));
     1174        LogRelFunc (("clipboard conversion failed.  RTUtf16ToUtf8Ex() returned %Rrc.  Abandoning.\n", rc));
    11241175        XtFree(pu8DestText);
    11251176        vboxClipboardEmptyGuestBuffer();
     
    11401191 * @returns true if we successfully convert the data to the format requested, false otherwise.
    11411192 *
    1142  * @param atomTypeReturn The type of the data we are returning
    1143  * @param pValReturn     A pointer to the data we are returning.  This should be to memory
    1144  *                       allocated by XtMalloc, which will be freed by the toolkit later
    1145  * @param pcLenReturn    The length of the data we are returning
    1146  * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1147  */
    1148 static Boolean vboxClipboardConvertCText(Atom *atomTypeReturn, XtPointer *pValReturn,
    1149                                          unsigned long *pcLenReturn, int *piFormatReturn)
     1193 * @param  atomTypeReturn The type of the data we are returning
     1194 * @param  pValReturn     A pointer to the data we are returning.  This should be to memory
     1195 *                        allocated by XtMalloc, which will be freed by the toolkit later
     1196 * @param  pcLenReturn    The length of the data we are returning
     1197 * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
     1198 * @thread  clipboard X11 event thread
     1199 * @note    called by vboxClipboardConvertForX11
     1200 */
     1201static Boolean vboxClipboardConvertToCTextForX11(Atom *atomTypeReturn,
     1202                                                 XtPointer *pValReturn,
     1203                                                 unsigned long *pcLenReturn,
     1204                                                 int *piFormatReturn)
    11501205{
    11511206    PRTUTF16 pu16SrcText, pu16DestText;
     
    11571212    LogFlowFunc (("called\n"));
    11581213    /* Read the clipboard data from the guest. */
    1159     rc = vboxClipboardReadDataFromClient(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
     1214    rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
    11601215    if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0))
    11611216    {
    1162         /* If vboxClipboardReadDataFromClient fails then pClient may be invalid */
    1163         LogRelFunc (("vboxClipboardReadDataFromClient returned %Rrc%s\n", rc,
    1164                      RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
     1217        /* If vboxClipboardReadDataFromVBox fails then pClient may be invalid */
     1218        LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc,
     1219                      RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" :  ""));
    11651220        vboxClipboardEmptyGuestBuffer();
    11661221        return false;
     
    11721227    if (RT_FAILURE(rc))
    11731228    {
    1174         LogRel(("vboxClipboardConvertCText: clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
     1229        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16GetLinSize returned %Rrc.  Abandoning.\n", rc));
    11751230        vboxClipboardEmptyGuestBuffer();
    11761231        AssertRCReturn(rc, false);
     
    11851240    if (pu16DestText == 0)
    11861241    {
    1187         LogRel(("vboxClipboardConvertCText: failed to allocate %d bytes\n", cwDestLen * 2));
     1242        LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2));
    11881243        vboxClipboardEmptyGuestBuffer();
    11891244        return false;
     
    11931248    if (RT_FAILURE(rc))
    11941249    {
    1195         LogRel(("vboxClipboardConvertCText: clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
     1250        LogRelFunc (("clipboard conversion failed.  vboxClipboardUtf16WinToLin() returned %Rrc.  Abandoning.\n", rc));
    11961251        RTMemFree(reinterpret_cast<void *>(pu16DestText));
    11971252        vboxClipboardEmptyGuestBuffer();
     
    12031258    if (RT_FAILURE(rc))
    12041259    {
    1205         LogRel(("vboxClipboardConvertCText: clipboard conversion failed.  RTUtf16ToUtf8Ex() returned %Rrc.  Abandoning.\n", rc));
     1260        LogRelFunc (("clipboard conversion failed.  RTUtf16ToUtf8Ex() returned %Rrc.  Abandoning.\n", rc));
    12061261        vboxClipboardEmptyGuestBuffer();
    12071262        return false;
     
    12331288            pcReason = "unknown error";
    12341289        }
    1235         LogRel(("vboxClipboardConvertCText: Xutf8TextListToTextProperty failed.  Reason: %s\n",
     1290        LogRelFunc (("Xutf8TextListToTextProperty failed.  Reason: %s\n",
    12361291                pcReason));
    12371292        XFree(property.value);
     
    12491304
    12501305/**
    1251  * Callback to convert the guests clipboard data for an application on the host.  Called by the
     1306 * Callback to request VBox's clipboard data for an X11 client.  Called by the
    12521307 * X Toolkit.
    1253  * @returns true if we successfully convert the data to the format requested, false otherwise.
    1254  *
    1255  * @param atomSelection  The selection which is being requested.  We only handle the clipboard.
    1256  * @param atomTarget     The format we should convert the data to
    1257  * @param atomTypeReturn The type of the data we are returning
    1258  * @param pValReturn     A pointer to the data we are returning.  This should be to memory
    1259  *                       allocated by XtMalloc, which will be freed by the toolkit later
    1260  * @param pcLenReturn    The length of the data we are returning
    1261  * @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
    1262  */
    1263 static Boolean vboxClipboardConvertProc(Widget, Atom *atomSelection, Atom *atomTarget,
    1264                                         Atom *atomTypeReturn, XtPointer *pValReturn,
    1265                                         unsigned long *pcLenReturn, int *piFormatReturn)
     1308 * @thread  clipboard X11 event thread
     1309 * @note    callback for XtOwnSelection, called by vboxClipboardFormatAnnounce
     1310 */
     1311static Boolean vboxClipboardConvertForX11(Widget, Atom *atomSelection,
     1312                                          Atom *atomTarget,
     1313                                          Atom *atomTypeReturn,
     1314                                          XtPointer *pValReturn,
     1315                                          unsigned long *pcLenReturn,
     1316                                          int *piFormatReturn)
    12661317{
    12671318    g_eClipboardFormats eFormat = INVALID;
     
    12801331        if (szAtomName != 0)
    12811332        {
    1282             Log2 (("vboxClipboardConvertProc: request for format %s\n", szAtomName));
     1333            Log2 (("%s: request for format %s\n", __PRETTY_FUNCTION__, szAtomName));
    12831334            XFree(szAtomName);
    12841335        }
    12851336        else
    12861337        {
    1287             Log(("vboxClipboardConvertProc: request for invalid target atom %d!\n", *atomTarget));
     1338            LogFunc (("request for invalid target atom %d!\n", *atomTarget));
    12881339        }
    12891340    }
     
    13061357    {
    13071358    case TARGETS:
    1308         return vboxClipboardConvertTargets(atomTypeReturn, pValReturn, pcLenReturn,
    1309                                            piFormatReturn);
     1359        return vboxClipboardConvertTargetsForX11(atomTypeReturn, pValReturn,
     1360                                                 pcLenReturn, piFormatReturn);
    13101361    case UTF16:
    13111362        return vboxClipboardConvertUtf16(atomTypeReturn, pValReturn, pcLenReturn,
    13121363                                         piFormatReturn);
    13131364    case UTF8:
    1314         return vboxClipboardConvertUtf8(atomTypeReturn, pValReturn, pcLenReturn,
    1315                                         piFormatReturn);
     1365        return vboxClipboardConvertToUtf8ForX11(atomTypeReturn, pValReturn,
     1366                                                pcLenReturn, piFormatReturn);
    13161367    case CTEXT:
    1317         return vboxClipboardConvertCText(atomTypeReturn, pValReturn, pcLenReturn,
    1318                                          piFormatReturn);
     1368        return vboxClipboardConvertToCTextForX11(atomTypeReturn, pValReturn,
     1369                                                 pcLenReturn, piFormatReturn);
    13191370    default:
    1320         Log(("vboxClipboardConvertProc: bad format\n"));
    1321         return false;
    1322     }
    1323 }
    1324 
    1325 static void vboxClipboardLoseProc(Widget, Atom *)
    1326 {
    1327     LogFlow (("vboxClipboardLoseProc: called, giving the host clipboard ownership\n"));
     1371        LogFunc (("bad format\n"));
     1372        return false;
     1373    }
     1374}
     1375
     1376/**
     1377 * This is called by the X toolkit intrinsics to let us know that another
     1378 * X11 client has taken the clipboard.
     1379 * @note    callback for XtOwnSelection, called from vboxClipboardFormatAnnounce
     1380 * @thread  clipboard X11 event thread
     1381 */
     1382static void vboxClipboardReturnToX11(Widget, Atom *)
     1383{
     1384    LogFlowFunc (("called, giving VBox clipboard ownership\n"));
    13281385    g_ctx.eOwner = HOST;
    13291386    g_ctx.notifyGuest = true;
     
    13311388
    13321389/**
    1333  * The guest is taking possession of the shared clipboard.  Called by the HGCM clipboard
    1334  * subsystem.
     1390 * VBox is taking possession of the shared clipboard.
    13351391 *
    13361392 * @param pClient    Context data for the guest system
    13371393 * @param u32Formats Clipboard formats the guest is offering
     1394 * @note    Called by the HGCM clipboard service
     1395 * @thread  HGCM clipboard service thread
    13381396 */
    13391397void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats)
    13401398{
    13411399    /*
    1342      * Immetiately return if we are not connected to the host X server.
     1400     * Immediately return if we are not connected to the host X server.
    13431401     */
    13441402    if (!g_fHaveX11)
     
    13611419        return;
    13621420    }
    1363     Log2 (("vboxClipboardFormatAnnounce: giving the guest clipboard ownership\n"));
     1421    Log2 (("%s: giving the guest clipboard ownership\n", __PRETTY_FUNCTION__));
    13641422    g_ctx.eOwner = GUEST;
    13651423    g_ctx.hostTextFormat = INVALID;
    13661424    g_ctx.hostBitmapFormat = INVALID;
    1367     if (XtOwnSelection(g_ctx.widget, g_ctx.atomClipboard, CurrentTime, vboxClipboardConvertProc,
    1368                        vboxClipboardLoseProc, 0) != True)
    1369     {
    1370         Log2 (("vboxClipboardFormatAnnounce: returning clipboard ownership to the host\n"));
     1425    if (XtOwnSelection(g_ctx.widget, g_ctx.atomClipboard, CurrentTime, vboxClipboardConvertForX11,
     1426                       vboxClipboardReturnToX11, 0) != True)
     1427    {
     1428        Log2 (("%s: returning clipboard ownership to the host\n", __PRETTY_FUNCTION__));
    13711429        /* We set this so that the guest gets notified when we take the clipboard, even if no
    13721430          guest formats are found which we understand. */
     
    13741432        g_ctx.eOwner = HOST;
    13751433    }
    1376     XtOwnSelection(g_ctx.widget, g_ctx.atomPrimary, CurrentTime, vboxClipboardConvertProc,
     1434    XtOwnSelection(g_ctx.widget, g_ctx.atomPrimary, CurrentTime, vboxClipboardConvertForX11,
    13771435                   NULL, 0);
    13781436    LogFlowFunc(("returning\n"));
     
    13811439
    13821440/**
    1383  * Called by the HGCM clipboard subsystem when the guest wants to read the host clipboard.
     1441 * Called when VBox wants to read the X11 clipboard.
    13841442 *
    13851443 * @param pClient   Context information about the guest VM
     
    13881446 * @param cb        The size of the buffer to write the data to
    13891447 * @param pcbActual Where to write the actual size of the written data
     1448 * @note    Called by the HGCM clipboard service
     1449 * @thread  HGCM clipboard service thread
    13901450 */
    13911451int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, void *pv,
     
    13931453{
    13941454    /*
    1395      * Immetiately return if we are not connected to the host X server.
     1455     * Immediately return if we are not connected to the host X server.
    13961456     */
    13971457    if (!g_fHaveX11)
     
    14021462    }
    14031463
    1404     LogFlow(("vboxClipboardReadData: u32Format = %d, cb = %d\n", u32Format, cb));
     1464    LogFlowFunc (("u32Format = %d, cb = %d\n", u32Format, cb));
    14051465
    14061466    /*
     
    14301490        /* Send out a request for the data to the current clipboard owner */
    14311491        XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomHostTextFormat,
    1432                             vboxClipboardGetProc, reinterpret_cast<XtPointer>(g_ctx.pClient),
     1492                            vboxClipboardGetDataFromX11, reinterpret_cast<XtPointer>(g_ctx.pClient),
    14331493                            CurrentTime);
    14341494        /* When the data arrives, the vboxClipboardGetProc callback will be called.  The
     
    14661526
    14671527/**
    1468  * Called by the HGCM clipboard subsystem when we have requested data and that data arrives.
     1528 * Called when we have requested data from VBox and that data has arrived.
    14691529 *
    14701530 * @param pClient   Context information about the guest VM
     
    14721532 * @param cb        The size of the data written
    14731533 * @param u32Format The format of the data written
     1534 * @note    Called by the HGCM clipboard service
     1535 * @thread  HGCM clipboard service thread
    14741536 */
    14751537void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format)
     
    14781540        return;
    14791541
    1480     LogFlow(("vboxClipboardWriteData\n"));
     1542    LogFlowFunc (("called\n"));
    14811543
    14821544    /*
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