VirtualBox

Ignore:
Timestamp:
Oct 17, 2024 7:44:43 AM (4 months ago)
Author:
vboxsync
Message:

Additions/VBoxTray: Implemented ability for easier user-controllable logging (also via verbose levels), support for running in foreground mode (with a console window attached to) and selective starting of sub services to easier pinpoint errors in release builds. Cleaned up initialization / termination code a little. See command line help for new options. bugref:10763

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnD.cpp

    r106061 r106411  
    3535#include <iprt/win/windows.h>
    3636#include "VBoxTray.h"
     37#include "VBoxTrayInternal.h"
    3738#include "VBoxHelpers.h"
    3839#include "VBoxDnD.h"
     
    130131 * Initializes the proxy window with a given DnD context.
    131132 *
    132  * @return  IPRT status code.
     133 * @return  VBox status code.
    133134 * @param   a_pCtx  Pointer to context to use.
    134135 */
     
    161162
    162163    if (RT_FAILURE(rc))
    163         LogRel(("DnD: Failed to initialize proxy window, rc=%Rrc\n", rc));
     164        VBoxTrayError("DnD: Failed to initialize proxy window, rc=%Rrc\n", rc);
    164165
    165166    LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
     
    203204 * Thread for handling the window's message pump.
    204205 *
    205  * @return  IPRT status code.
     206 * @return  VBox status code.
    206207 * @param   hThread                 Handle to this thread.
    207208 * @param   pvUser                  Pointer to VBoxDnDWnd instance which
     
    312313    else
    313314    {
    314         LogRel(("DnD: Unable to initialize OLE, hr=%Rhrc\n", hr));
     315        VBoxTrayError("DnD: Unable to initialize OLE, hr=%Rhrc\n", hr);
    315316        rc = VERR_COM_UNEXPECTED;
    316317    }
     
    415416            if (RT_FAILURE(rc))
    416417            {
    417                 LogRel(("DnD: Failed to create proxy window, rc=%Rrc\n", rc));
     418                VBoxTrayError("DnD: Failed to create proxy window, rc=%Rrc\n", rc);
    418419                return -1;
    419420            }
     
    626627                case VBGLR3DNDEVENTTYPE_QUIT:
    627628                {
    628                     LogRel(("DnD: Received quit message, shutting down ...\n"));
     629                    VBoxTrayInfo("DnD: Received quit message, shutting down ...\n");
    629630                    PostQuitMessage(0);
    630631                }
     
    652653                default:
    653654                {
    654                     LogRel(("DnD: Received unsupported message '%RU32'\n", pVbglR3Event->enmType));
     655                    VBoxTrayVerbose(1, "DnD: Received unsupported message '%RU32'\n", pVbglR3Event->enmType);
    655656                    rc = VERR_NOT_SUPPORTED;
    656657                    break;
     
    662663            {
    663664                /* Tell the user. */
    664                 LogRel(("DnD: Processing message %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc));
     665                VBoxTrayError("DnD: Processing message %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc);
    665666
    666667                /* If anything went wrong, do a reset and start over. */
     
    691692 * Registers this proxy window as a local drop target.
    692693 *
    693  * @return  IPRT status code.
     694 * @return  VBox status code.
    694695 */
    695696int VBoxDnDWnd::RegisterAsDropTarget(void)
     
    721722    }
    722723    if (hrc != DRAGDROP_E_INVALIDHWND) /* Could be because the DnD host service is not available. */
    723         LogRel(("DnD: Creating drop target failed with hr=%Rhrc\n", hrc));
     724        VBoxTrayError("DnD: Creating drop target failed with hr=%Rhrc\n", hrc);
     725
    724726    LogFlowFuncLeaveRC(VERR_NOT_SUPPORTED);
    725727    return VERR_NOT_SUPPORTED; /* Report back DnD as not being supported. */
     
    729731 * Unregisters this proxy as a drop target.
    730732 *
    731  * @return  IPRT status code.
     733 * @return  VBox status code.
    732734 */
    733735int VBoxDnDWnd::UnregisterAsDropTarget(void)
     
    761763 * Handles the creation of a proxy window.
    762764 *
    763  * @return  IPRT status code.
     765 * @return  VBox status code.
    764766 */
    765767int VBoxDnDWnd::OnCreate(void)
     
    769771    if (RT_FAILURE(rc))
    770772    {
    771         LogRel(("DnD: Connection to host service failed, rc=%Rrc\n", rc));
     773        VBoxTrayError("DnD: Connection to host service failed, rc=%Rrc\n", rc);
    772774        return rc;
    773775    }
     
    796798{
    797799    LogFlowThisFunc(("mMode=%ld, mState=%RU32\n", m_enmMode, m_enmState));
    798     LogRel(("DnD: Drag and drop operation aborted\n"));
     800    VBoxTrayInfo("DnD: Drag and drop operation aborted\n");
    799801
    800802    int rc = RTCritSectEnter(&m_CritSect);
     
    820822 * the guest's screen to initiate a host -> guest DnD operation.
    821823 *
    822  * @return  IPRT status code.
     824 * @return  VBox status code.
    823825 * @param   a_lstFormats            Supported formats offered by the host.
    824826 * @param   a_fDndLstActionsAllowed Supported actions offered by the host.
     
    859861    AssertReturnStmt(paFormatEtc, RTMemTmpFree(paFormatEtc), VERR_NO_TMP_MEMORY);
    860862
    861     LogRel2(("DnD: Reported formats:\n"));
     863    VBoxTrayVerbose(1, "DnD: Reported formats:\n");
    862864    for (size_t i = 0; i < a_lstFormats.size(); i++)
    863865    {
     
    908910        }
    909911
    910         LogRel2(("DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported));
     912        VBoxTrayVerbose(1, "DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported);
    911913    }
    912914
     
    927929        }
    928930
    929         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    930                           strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
    931                           15 * 1000 /* Time to display in msec */, NIIF_INFO);
     931        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     932                                    strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
     933                                    15 * 1000 /* Time to display in msec */, NIIF_INFO);
    932934    }
    933935
     
    938940    if (cFormatsActive)
    939941    {
    940         LogRel2(("DnD: %RU32 supported formats found:\n", cFormatsActive));
     942        VBoxTrayVerbose(1, "DnD: %RU32 supported formats found:\n", cFormatsActive);
    941943        for (size_t i = 0; i < cFormatsActive; i++)
    942             LogRel2(("DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str()));
     944            VBoxTrayVerbose(1, "DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str());
    943945    }
    944946    else
    945         LogRel(("DnD: Warning: No supported drag and drop formats on the guest found!\n"));
     947        VBoxTrayInfo("DnD: Warning: No supported drag and drop formats on the guest found!\n");
    946948
    947949    /*
     
    961963    }
    962964
    963     LogRel2(("DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects));
     965    VBoxTrayVerbose(1, "DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects);
    964966
    965967#ifdef RT_EXCEPTIONS_ENABLED
     
    994996 * the guest's screen.
    995997 *
    996  * @return  IPRT status code.
     998 * @return  VBox status code.
    997999 * @param   u32xPos                 Absolute X position (in pixels) of the host cursor
    9981000 *                                  inside the guest.
     
    10441046 * the guest's screen again.
    10451047 *
    1046  * @return  IPRT status code.
     1048 * @return  VBox status code.
    10471049 */
    10481050int VBoxDnDWnd::OnHgLeave(void)
     
    10521054
    10531055    if (g_cVerbosity)
    1054         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1055                           "Leave: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
    1056                           15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1056        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1057                                    "Leave: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
     1058                                    15 * 1000 /* Time to display in msec */, NIIF_INFO);
    10571059
    10581060    int rc = Abort();
     
    10661068 * and therefore start a "drop" action in the guest.
    10671069 *
    1068  * @return  IPRT status code.
     1070 * @return  VBox status code.
    10691071 */
    10701072int VBoxDnDWnd::OnHgDrop(void)
     
    10791081    {
    10801082        if (g_cVerbosity)
    1081             hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1082                               "Drop: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
    1083                               15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1083            VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1084                                        "Drop: Host -> Guest", VBOX_DND_SHOWBALLOON_HEADER,
     1085                                        15 * 1000 /* Time to display in msec */, NIIF_INFO);
    10841086
    10851087        if (m_lstFmtActive.size() >= 1)
     
    11011103            if (RT_SUCCESS(rc))
    11021104            {
    1103                 LogRel(("DnD: Requesting data as '%s' ...\n", m_strFmtReq.c_str()));
     1105                VBoxTrayInfo("DnD: Requesting data as '%s' ...\n", m_strFmtReq.c_str());
    11041106                rc = VbglR3DnDHGSendReqData(&m_cmdCtx, m_strFmtReq.c_str());
    11051107                if (RT_FAILURE(rc))
     
    11091111        }
    11101112        else /* Should never happen. */
    1111             LogRel(("DnD: Error: Host did not specify a data format for drop data\n"));
     1113            VBoxTrayError("DnD: Host did not specify a data format for drop data\n");
    11121114    }
    11131115
     
    11201122 * to the guest after a "drop" event.
    11211123 *
    1122  * @return  IPRT status code.
     1124 * @return  VBox status code.
    11231125 * @param   pMeta                   Pointer to meta data received.
    11241126 */
     
    11471149                case VBGLR3GUESTDNDMETADATATYPE_URI_LIST:
    11481150                {
    1149                     LogRel2(("DnD: URI transfer root directory is '%s'\n", DnDTransferListGetRootPathAbs(&pMeta->u.URI.Transfer)));
     1151                    VBoxTrayVerbose(1, "DnD: URI transfer root directory is '%s'\n",
     1152                                    DnDTransferListGetRootPathAbs(&pMeta->u.URI.Transfer));
    11501153
    11511154                    char  *pszBuf;
     
    11861189 * host -> guest operation.
    11871190 *
    1188  * @return  IPRT status code.
     1191 * @return  VBox status code.
    11891192 */
    11901193int VBoxDnDWnd::OnHgCancel(void)
     
    12131216 * this class again.
    12141217 *
    1215  * @return  IPRT status code.
     1218 * @return  VBox status code.
    12161219 */
    12171220int VBoxDnDWnd::OnGhIsDnDPending(void)
     
    13351338                case VERR_ACCESS_DENIED:
    13361339                {
    1337                     rc = hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1338                                            szMsg, szTitle,
    1339                                            15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1340                    rc = VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1341                                                     szMsg, szTitle,
     1342                                                     15 * 1000 /* Time to display in msec */, NIIF_INFO);
    13401343                    AssertRC(rc);
    13411344                    break;
     
    13461349            }
    13471350
    1348             LogRel2(("DnD: Host refuses drag and drop operation from guest: %Rrc\n", rc2));
     1351            VBoxTrayVerbose(1, "DnD: Host refuses drag and drop operation from guest: %Rrc\n", rc2);
    13491352            Reset();
    13501353        }
     
    13631366 * to send data in a specific format the host requested.
    13641367 *
    1365  * @return  IPRT status code.
     1368 * @return  VBox status code.
    13661369 * @param   pszFormat               Format the host requests the data in.
    13671370 * @param   cbFormat                Size (in bytes) of format string.
     
    13811384            strMsg += RTCStringFmt("Format: %s\n", strFormat.c_str());
    13821385
    1383             hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1384                               strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
    1385                               15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1386            VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1387                                        strMsg.c_str(), VBOX_DND_SHOWBALLOON_HEADER,
     1388                                        15 * 1000 /* Time to display in msec */, NIIF_INFO);
    13861389        }
    13871390
     
    14481451 * this class after processing.
    14491452 *
    1450  * @return  IPRT status code.
     1453 * @return  VBox status code.
    14511454 * @param   pEvent                  Event to inject.
    14521455 */
     
    14641467        if (s_iBitchedAboutFailedDnDMessages++ < 32)
    14651468        {
    1466             LogRel(("DnD: Processing event %p failed with %ld (%Rrc), skipping\n",
    1467                     pEvent, dwErr, RTErrConvertFromWin32(dwErr)));
     1469            VBoxTrayError("DnD: Processing event %p failed with %ld (%Rrc), skipping\n",
     1470                          pEvent, dwErr, RTErrConvertFromWin32(dwErr));
    14681471        }
    14691472
     
    14831486 * and do a reconnect to the DnD HGCM service.
    14841487 *
    1485  * @returns IPRT status code.
     1488 * @returns VBox status code.
    14861489 */
    14871490int VBoxDnDWnd::checkForSessionChange(void)
     
    15081511 * Hides the proxy window again.
    15091512 *
    1510  * @return  IPRT status code.
     1513 * @return  VBox status code.
    15111514 */
    15121515int VBoxDnDWnd::Hide(void)
     
    15241527 * spawned across all active guest monitors.
    15251528 *
    1526  * @return  IPRT status code.
     1529 * @return  VBox status code.
    15271530 */
    15281531int VBoxDnDWnd::makeFullscreen(void)
     
    15881591        {
    15891592            DWORD dwErr = GetLastError();
    1590             LogRel(("DnD: Failed to set proxy window position, rc=%Rrc\n",
    1591                     RTErrConvertFromWin32(dwErr)));
     1593            VBoxTrayError("DnD: Failed to set proxy window position, rc=%Rrc\n",
     1594                          RTErrConvertFromWin32(dwErr));
    15921595        }
    15931596    }
    15941597    else
    1595         LogRel(("DnD: Failed to determine virtual screen size, rc=%Rrc\n", rc));
     1598        VBoxTrayError("DnD: Failed to determine virtual screen size, rc=%Rrc\n", rc);
    15961599
    15971600    LogFlowFuncLeaveRC(rc);
     
    16021605 * Moves the guest mouse cursor to a specific position.
    16031606 *
    1604  * @return  IPRT status code.
     1607 * @return  VBox status code.
    16051608 * @param   x                       X position (in pixels) to move cursor to.
    16061609 * @param   y                       Y position (in pixels) to move cursor to.
     
    16481651 * Releases a previously pressed left guest mouse button.
    16491652 *
    1650  * @return  IPRT status code.
     1653 * @return  VBox status code.
    16511654 */
    16521655int VBoxDnDWnd::mouseRelease(void)
     
    16991702 * Sets the current operation mode of this proxy window.
    17001703 *
    1701  * @return  IPRT status code.
     1704 * @return  VBox status code.
    17021705 * @param   enmMode                 New mode to set.
    17031706 */
     
    17511754}
    17521755
    1753 /**
    1754  * Initializes drag and drop.
    1755  *
    1756  * @return  IPRT status code.
    1757  * @param   pEnv                        The DnD service's environment.
    1758  * @param   ppInstance                  The instance pointer which refer to this object.
    1759  */
    1760 DECLCALLBACK(int) VBoxDnDInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
     1756
     1757/**
     1758 * @interface_method_impl{VBOXSERVICEDESC,pfnPreInit}
     1759 */
     1760static DECLCALLBACK(int) vbtrDnDPreInit(void)
     1761{
     1762    return VINF_SUCCESS;
     1763}
     1764
     1765
     1766/**
     1767 * @interface_method_impl{VBOXSERVICEDESC,pfnOption}
     1768 */
     1769static DECLCALLBACK(int) vbtrDnDOption(const char **ppszShort, int argc, char **argv, int *pi)
     1770{
     1771    RT_NOREF(ppszShort, argc, argv, pi);
     1772
     1773    return -1;
     1774}
     1775
     1776/**
     1777 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     1778 */
     1779DECLCALLBACK(int) vbtrDnDInit(const PVBOXTRAYSVCENV pEnv, void **ppInstance)
    17611780{
    17621781    AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
     
    17741793    {
    17751794        /* Do not do drag and drop for remote sessions. */
    1776         LogRel(("DnD: Drag and drop has been disabled for a remote session\n"));
     1795        VBoxTrayInfo("DnD: Drag and drop has been disabled for a remote session\n");
    17771796        rc = VERR_NOT_SUPPORTED;
    17781797    }
     
    17911810        if (!fSupportedOS)
    17921811        {
    1793             LogRel(("DnD: Not supported Windows version, disabling drag and drop support\n"));
     1812            VBoxTrayInfo("DnD: Not supported Windows version, disabling drag and drop support\n");
    17941813            rc = VERR_NOT_SUPPORTED;
    17951814        }
     
    18421861        *ppInstance = pCtx;
    18431862
    1844         LogRel(("DnD: Drag and drop service successfully started\n"));
     1863        VBoxTrayInfo("DnD: Drag and drop service successfully started\n");
    18451864    }
    18461865    else
    1847         LogRel(("DnD: Initializing drag and drop service failed with rc=%Rrc\n", rc));
     1866        VBoxTrayError("DnD: Initializing drag and drop service failed with rc=%Rrc\n", rc);
    18481867
    18491868    LogFlowFuncLeaveRC(rc);
     
    18511870}
    18521871
    1853 DECLCALLBACK(int) VBoxDnDStop(void *pInstance)
     1872/**
     1873 * @interface_method_impl{VBOXSERVICEDESC,pfnStop}
     1874 */
     1875DECLCALLBACK(int) vbtrDnDStop(void *pInstance)
    18541876{
    18551877    AssertPtrReturn(pInstance, VERR_INVALID_POINTER);
     
    18701892}
    18711893
    1872 DECLCALLBACK(void) VBoxDnDDestroy(void *pInstance)
     1894/**
     1895 * @interface_method_impl{VBOXSERVICEDESC,pfnInit}
     1896 */
     1897DECLCALLBACK(void) vbtrDnDDestroy(void *pInstance)
    18731898{
    18741899    AssertPtrReturnVoid(pInstance);
     
    18971922}
    18981923
    1899 DECLCALLBACK(int) VBoxDnDWorker(void *pInstance, bool volatile *pfShutdown)
     1924/**
     1925 * @interface_method_impl{VBOXSERVICEDESC,pfnWorker}
     1926 */
     1927DECLCALLBACK(int) vbtrDnDWorker(void *pInstance, bool volatile *pfShutdown)
    19001928{
    19011929    AssertPtr(pInstance);
     
    19181946
    19191947    if (g_cVerbosity)
    1920         hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
    1921                           RTCStringFmt("Running (worker client ID %RU32)", pCtx->cmdCtx.uClientID).c_str(),
    1922                           VBOX_DND_SHOWBALLOON_HEADER,
    1923                           15 * 1000 /* Time to display in msec */, NIIF_INFO);
     1948        VBoxTrayHlpShowBalloonTipEx(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
     1949                                    RTCStringFmt("Running (worker client ID %RU32)", pCtx->cmdCtx.uClientID).c_str(),
     1950                                    VBOX_DND_SHOWBALLOON_HEADER,
     1951                                    15 * 1000 /* Time to display in msec */, NIIF_INFO);
    19241952
    19251953    /** @todo At the moment we only have one DnD proxy window. */
     
    19501978            cMsgSkippedInvalid = 0; /* Reset skipped messages count. */
    19511979
    1952             LogRel2(("DnD: Received new event, type=%RU32, rc=%Rrc\n", pVbglR3Event->enmType, rc));
     1980            VBoxTrayVerbose(2, "DnD: Received new event, type=%RU32, rc=%Rrc\n", pVbglR3Event->enmType, rc);
    19531981
    19541982            /* pEvent now owns pVbglR3Event. */
     
    19631991            }
    19641992            else
    1965                 LogRel(("DnD: Processing proxy window event %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc));
     1993                VBoxTrayInfo("DnD: Processing proxy window event %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc);
    19661994        }
    19671995
     
    19812009            if (cMsgSkippedInvalid++ > 32)
    19822010            {
    1983                 LogRel(("DnD: Too many invalid/skipped messages from host, exiting ...\n"));
     2011                VBoxTrayInfo("DnD: Too many invalid/skipped messages from host, exiting ...\n");
    19842012                break;
    19852013            }
     
    20112039    VbglR3DnDDisconnect(&pCtx->cmdCtx);
    20122040
    2013     LogRel(("DnD: Ended\n"));
     2041    VBoxTrayInfo("DnD: Ended\n");
    20142042
    20152043    LogFlowFuncLeaveRC(rc);
     
    20202048 * The service description.
    20212049 */
    2022 VBOXSERVICEDESC g_SvcDescDnD =
     2050VBOXTRAYSVCDESC g_SvcDescDnD =
    20232051{
    20242052    /* pszName. */
     
    20262054    /* pszDescription. */
    20272055    "Drag and Drop",
     2056    /* pszUsage. */
     2057    NULL,
     2058    /* pszOptions. */
     2059    NULL,
    20282060    /* methods */
    2029     VBoxDnDInit,
    2030     VBoxDnDWorker,
    2031     VBoxDnDStop,
    2032     VBoxDnDDestroy
     2061    vbtrDnDPreInit,
     2062    vbtrDnDOption,
     2063    vbtrDnDInit,
     2064    vbtrDnDWorker,
     2065    vbtrDnDStop,
     2066    vbtrDnDDestroy
    20332067};
    20342068
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