VirtualBox

Changeset 75969 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Dec 5, 2018 12:08:09 PM (6 years ago)
Author:
vboxsync
Message:

HGCM,GuestProps: Added HGCM service notifications for VM power-on, VM resume, VM suspend, VM reset and VM power-off. Made use of the first two in guest properties to wake up guest programs waiting on any of the host version properties. Also moved inserting sysprep and host version properties to the services as that's a better home than ConsoleImpl/VMMDevInterface in my opinion.

Location:
trunk/src/VBox/Main/src-client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/HGCM.cpp

    r75853 r75969  
    176176
    177177        int HostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM *paParms);
     178        static void BroadcastNotify(HGCMNOTIFYEVENT enmEvent);
     179        void Notify(HGCMNOTIFYEVENT enmEvent);
    178180
    179181#ifdef VBOX_WITH_CRHGSMI
     
    401403 */
    402404
    403 #define SVC_MSG_LOAD       (0)  /* Load the service library and call VBOX_HGCM_SVCLOAD_NAME entry point. */
    404 #define SVC_MSG_UNLOAD     (1)  /* call pfnUnload and unload the service library. */
    405 #define SVC_MSG_CONNECT    (2)  /* pfnConnect */
    406 #define SVC_MSG_DISCONNECT (3)  /* pfnDisconnect */
    407 #define SVC_MSG_GUESTCALL  (4)  /* pfnGuestCall */
    408 #define SVC_MSG_HOSTCALL   (5)  /* pfnHostCall */
    409 #define SVC_MSG_LOADSTATE  (6)  /* pfnLoadState. */
    410 #define SVC_MSG_SAVESTATE  (7)  /* pfnSaveState. */
    411 #define SVC_MSG_QUIT       (8)  /* Terminate the thread. */
    412 #define SVC_MSG_REGEXT     (9)  /* pfnRegisterExtension */
    413 #define SVC_MSG_UNREGEXT   (10) /* pfnRegisterExtension */
     405#define SVC_MSG_LOAD       (0)  /**< Load the service library and call VBOX_HGCM_SVCLOAD_NAME entry point. */
     406#define SVC_MSG_UNLOAD     (1)  /**< call pfnUnload and unload the service library. */
     407#define SVC_MSG_CONNECT    (2)  /**< pfnConnect */
     408#define SVC_MSG_DISCONNECT (3)  /**< pfnDisconnect */
     409#define SVC_MSG_GUESTCALL  (4)  /**< pfnGuestCall */
     410#define SVC_MSG_HOSTCALL   (5)  /**< pfnHostCall */
     411#define SVC_MSG_LOADSTATE  (6)  /**< pfnLoadState. */
     412#define SVC_MSG_SAVESTATE  (7)  /**< pfnSaveState. */
     413#define SVC_MSG_QUIT       (8)  /**< Terminate the thread. */
     414#define SVC_MSG_REGEXT     (9)  /**< pfnRegisterExtension */
     415#define SVC_MSG_UNREGEXT   (10) /**< pfnRegisterExtension */
     416#define SVC_MSG_NOTIFY     (11) /**< pfnNotify */
    414417#ifdef VBOX_WITH_CRHGSMI
    415418# define SVC_MSG_HOSTFASTCALLASYNC (21) /* pfnHostCall */
     
    522525        /* Handle of the registered extension. */
    523526        HGCMSVCEXTHANDLE handle;
     527};
     528
     529class HGCMMsgNotify: public HGCMMsgCore
     530{
     531    public:
     532        /** The event. */
     533        HGCMNOTIFYEVENT enmEvent;
    524534};
    525535
     
    555565        case SVC_MSG_REGEXT:      return new HGCMMsgSvcRegisterExtension();
    556566        case SVC_MSG_UNREGEXT:    return new HGCMMsgSvcUnregisterExtension();
     567        case SVC_MSG_NOTIFY:      return new HGCMMsgNotify();
    557568        default:
    558569            AssertReleaseMsgFailed(("Msg id = %08X\n", u32MsgId));
     
    812823            } break;
    813824
     825            case SVC_MSG_NOTIFY:
     826            {
     827                HGCMMsgNotify *pMsg = (HGCMMsgNotify *)pMsgCore;
     828
     829                LogFlowFunc(("SVC_MSG_NOTIFY enmEvent = %d\n", pMsg->enmEvent));
     830
     831                pSvc->m_fntable.pfnNotify(pSvc->m_fntable.pvService, pMsg->enmEvent);
     832            } break;
     833
    814834            default:
    815835            {
     
    17941814}
    17951815
     1816/** Posts a broadcast notification event to all interested services.
     1817 *
     1818 * @param   enmEvent    The notification event.
     1819 */
     1820/*static*/ void HGCMService::BroadcastNotify(HGCMNOTIFYEVENT enmEvent)
     1821{
     1822    for (HGCMService *pService = sm_pSvcListHead; pService != NULL; pService = pService->m_pSvcNext)
     1823    {
     1824        pService->Notify(enmEvent);
     1825    }
     1826}
     1827
     1828/** Posts a broadcast notification event to the service.
     1829 *
     1830 * @param   enmEvent    The notification event.
     1831 */
     1832void HGCMService::Notify(HGCMNOTIFYEVENT enmEvent)
     1833{
     1834    LogFlowFunc(("%s enmEvent=%d pfnNotify=%p\n", m_pszSvcName, enmEvent, m_fntable.pfnNotify));
     1835    if (m_fntable.pfnNotify)
     1836    {
     1837        HGCMMsgCore *pCoreMsg;
     1838        int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_NOTIFY, hgcmMessageAllocSvc);
     1839        if (RT_SUCCESS(rc))
     1840        {
     1841            HGCMMsgNotify *pMsg = (HGCMMsgNotify *)pCoreMsg;
     1842            pMsg->enmEvent = enmEvent;
     1843
     1844            rc = hgcmMsgPost(pMsg, NULL);
     1845            AssertRC(rc);
     1846        }
     1847    }
     1848}
     1849
    17961850#ifdef VBOX_WITH_CRHGSMI
    17971851
     
    18561910
    18571911/* Messages processed by the main HGCM thread. */
    1858 #define HGCM_MSG_CONNECT    (10)  /* Connect a client to a service. */
    1859 #define HGCM_MSG_DISCONNECT (11)  /* Disconnect the specified client id. */
    1860 #define HGCM_MSG_LOAD       (12)  /* Load the service. */
    1861 #define HGCM_MSG_HOSTCALL   (13)  /* Call the service. */
    1862 #define HGCM_MSG_LOADSTATE  (14)  /* Load saved state for the specified service. */
    1863 #define HGCM_MSG_SAVESTATE  (15)  /* Save state for the specified service. */
    1864 #define HGCM_MSG_RESET      (16)  /* Disconnect all clients from the specified service. */
    1865 #define HGCM_MSG_QUIT       (17)  /* Unload all services and terminate the thread. */
    1866 #define HGCM_MSG_REGEXT     (18)  /* Register a service extension. */
    1867 #define HGCM_MSG_UNREGEXT   (19)  /* Unregister a service extension. */
     1912#define HGCM_MSG_CONNECT    (10)  /**< Connect a client to a service. */
     1913#define HGCM_MSG_DISCONNECT (11)  /**< Disconnect the specified client id. */
     1914#define HGCM_MSG_LOAD       (12)  /**< Load the service. */
     1915#define HGCM_MSG_HOSTCALL   (13)  /**< Call the service. */
     1916#define HGCM_MSG_LOADSTATE  (14)  /**< Load saved state for the specified service. */
     1917#define HGCM_MSG_SAVESTATE  (15)  /**< Save state for the specified service. */
     1918#define HGCM_MSG_RESET      (16)  /**< Disconnect all clients from the specified service. */
     1919#define HGCM_MSG_QUIT       (17)  /**< Unload all services and terminate the thread. */
     1920#define HGCM_MSG_REGEXT     (18)  /**< Register a service extension. */
     1921#define HGCM_MSG_UNREGEXT   (19)  /**< Unregister a service extension. */
     1922#define HGCM_MSG_BRD_NOTIFY (20)  /**< Broadcast notification event (VM state change). */
    18681923#ifdef VBOX_WITH_CRHGSMI
    1869 # define HGCM_MSG_SVCAQUIRE  (30)  /* Acquire a service handle (for fast host calls) */
    1870 # define HGCM_MSG_SVCRELEASE (31)  /* Release a service */
     1924# define HGCM_MSG_SVCAQUIRE  (30) /**< Acquire a service handle (for fast host calls) */
     1925# define HGCM_MSG_SVCRELEASE (31) /**< Release a service */
    18711926#endif
    18721927
     
    19532008};
    19542009
     2010class HGCMMsgMainBroadcastNotify: public HGCMMsgCore
     2011{
     2012    public:
     2013        /** The notification event. */
     2014        HGCMNOTIFYEVENT enmEvent;
     2015};
     2016
    19552017#ifdef VBOX_WITH_CRHGSMI
    19562018class HGCMMsgMainSvcAcquire: public HGCMMsgCore
     
    19862048        case HGCM_MSG_REGEXT:     return new HGCMMsgMainRegisterExtension();
    19872049        case HGCM_MSG_UNREGEXT:   return new HGCMMsgMainUnregisterExtension();
     2050        case HGCM_MSG_BRD_NOTIFY: return new HGCMMsgMainBroadcastNotify();
    19882051#ifdef VBOX_WITH_CRHGSMI
    19892052        case HGCM_MSG_SVCAQUIRE:  return new HGCMMsgMainSvcAcquire();
     
    21002163                    pService->ReleaseService();
    21012164                }
     2165            } break;
     2166
     2167            case HGCM_MSG_BRD_NOTIFY:
     2168            {
     2169                HGCMMsgMainBroadcastNotify *pMsg = (HGCMMsgMainBroadcastNotify *)pMsgCore;
     2170
     2171                LogFlowFunc(("HGCM_MSG_BRD_NOTIFY enmEvent=%d\n", pMsg->enmEvent));
     2172
     2173                HGCMService::BroadcastNotify(pMsg->enmEvent);
    21022174            } break;
    21032175
     
    21472219
    21482220                HGCMService::Reset();
     2221
     2222                HGCMService::BroadcastNotify(HGCMNOTIFYEVENT_RESET);
    21492223            } break;
    21502224
     
    25512625}
    25522626
    2553 /* The host calls the service.
     2627/** The host calls the service.
    25542628 *
    25552629 * @param pszServiceName The service name to be called.
     
    25572631 * @param cParms         Number of parameters.
    25582632 * @param paParms        Pointer to array of parameters.
     2633 * @param fWait          Whether to wait for the call to complete (default),
     2634 *                       or just post it and return immediately.
    25592635 * @return VBox rc.
    25602636 */
     
    25972673}
    25982674
     2675/** Posts a notification event to all services.
     2676 *
     2677 * @param   enmEvent    The notification event.
     2678 * @return  VBox rc.
     2679 */
     2680int HGCMBroadcastEvent(HGCMNOTIFYEVENT enmEvent)
     2681{
     2682    LogFlowFunc(("enmEvent=%d\n", enmEvent));
     2683
     2684    HGCMMsgCore *pCoreMsg;
     2685    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_BRD_NOTIFY, hgcmMainMessageAlloc);
     2686
     2687    if (RT_SUCCESS(rc))
     2688    {
     2689        HGCMMsgMainBroadcastNotify *pMsg = (HGCMMsgMainBroadcastNotify *)pCoreMsg;
     2690
     2691        pMsg->enmEvent = enmEvent;
     2692
     2693        rc = hgcmMsgPost(pMsg, NULL);
     2694    }
     2695
     2696    LogFlowFunc(("rc = %Rrc\n", rc));
     2697    return rc;
     2698}
     2699
     2700
    25992701#ifdef VBOX_WITH_CRHGSMI
    26002702int HGCMHostSvcHandleCreate(const char *pszServiceName, HGCMCVSHANDLE * phSvc)
  • trunk/src/VBox/Main/src-client/VMMDevInterface.cpp

    r75955 r75969  
    2929#include <VBox/shflsvc.h>
    3030#include <iprt/asm.h>
    31 #include <iprt/buildconfig.h>
    3231
    3332#ifdef VBOX_WITH_HGCM
     
    3635# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_CROGL)
    3736#  include <VBox/HostServices/VBoxCrOpenGLSvc.h>
    38 # endif
    39 # ifdef VBOX_WITH_GUEST_PROPS
    40 #  include <VBox/version.h>
    4137# endif
    4238#endif
     
    770766
    771767/**
     768 * @interface_method_impl{PDMDRVREG,pfnSuspend}
     769 */
     770/*static*/ DECLCALLBACK(void) VMMDev::drvSuspend(PPDMDRVINS pDrvIns)
     771{
     772    RT_NOREF(pDrvIns);
     773#ifdef VBOX_WITH_HGCM
     774    HGCMBroadcastEvent(HGCMNOTIFYEVENT_SUSPEND);
     775#endif
     776}
     777
     778/**
     779 * @interface_method_impl{PDMDRVREG,pfnResume}
     780 */
     781/*static*/ DECLCALLBACK(void) VMMDev::drvResume(PPDMDRVINS pDrvIns)
     782{
     783    RT_NOREF(pDrvIns);
     784#ifdef VBOX_WITH_HGCM
     785    HGCMBroadcastEvent(HGCMNOTIFYEVENT_RESUME);
     786#endif
     787}
     788
     789/**
     790 * @interface_method_impl{PDMDRVREG,pfnPowerOff}
     791 */
     792/*static*/ DECLCALLBACK(void) VMMDev::drvPowerOff(PPDMDRVINS pDrvIns)
     793{
     794    RT_NOREF(pDrvIns);
     795#ifdef VBOX_WITH_HGCM
     796    HGCMBroadcastEvent(HGCMNOTIFYEVENT_POWER_ON);
     797#endif
     798}
     799
     800/**
     801 * @interface_method_impl{PDMDRVREG,pfnPowerOn}
     802 */
     803/*static*/ DECLCALLBACK(void) VMMDev::drvPowerOn(PPDMDRVINS pDrvIns)
     804{
     805    RT_NOREF(pDrvIns);
     806#ifdef VBOX_WITH_HGCM
     807    HGCMBroadcastEvent(HGCMNOTIFYEVENT_POWER_ON);
     808#endif
     809}
     810
     811/**
    772812 * @interface_method_impl{PDMDRVREG,pfnReset}
    773813 */
     
    778818#ifdef VBOX_WITH_HGCM
    779819    HGCMHostReset();
    780 #endif /* VBOX_WITH_HGCM */
     820#endif
    781821}
    782822
     
    883923    AssertReturn(ptrConsole.isNotNull(), VERR_INVALID_POINTER);
    884924
    885     /* Load the service */
     925    /*
     926     * Load the service
     927     */
    886928    int rc = hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
    887929    if (RT_FAILURE(rc))
     
    890932        return VINF_SUCCESS; /* That is not a fatal failure. */
    891933    }
    892     /*
    893      * Initialize built-in properties that can be changed and saved.
    894      *
    895      * These are typically transient properties that the guest cannot
    896      * change.
    897      */
    898 
    899     /* Sysprep execution by VBoxService. */
    900     i_guestPropSet("/VirtualBox/HostGuest/SysprepExec", "", "TRANSIENT, RDONLYGUEST");
    901     i_guestPropSet("/VirtualBox/HostGuest/SysprepArgs", "", "TRANSIENT, RDONLYGUEST");
    902934
    903935    /*
     
    964996
    965997    /*
    966      * These properties have to be set before pulling over the properties
    967      * from the machine XML, to ensure that properties saved in the XML
    968      * will override them.
    969      */
    970     /* Set the raw VBox version string as a guest property. Used for host/guest
    971      * version comparison. */
    972     i_guestPropSet("/VirtualBox/HostInfo/VBoxVer", VBOX_VERSION_STRING_RAW, "TRANSIENT, RDONLYGUEST");
    973     /* Set the full VBox version string as a guest property. Can contain vendor-specific
    974      * information/branding and/or pre-release tags. */
    975     i_guestPropSet("/VirtualBox/HostInfo/VBoxVerExt", VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
    976     /* Set the VBox SVN revision as a guest property */
    977     i_guestPropSet("/VirtualBox/HostInfo/VBoxRev", RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
    978 
    979     /*
    980998     * Register the host notification callback
    981999     */
     
    11781196    NULL,
    11791197    /* pfnPowerOn */
    1180     NULL,
     1198    VMMDev::drvPowerOn,
    11811199    /* pfnReset */
    11821200    VMMDev::drvReset,
    11831201    /* pfnSuspend */
    1184     NULL,
     1202    VMMDev::drvSuspend,
    11851203    /* pfnResume */
    1186     NULL,
     1204    VMMDev::drvResume,
    11871205    /* pfnAttach */
    11881206    NULL,
     
    11901208    NULL,
    11911209    /* pfnPowerOff */
    1192     NULL,
     1210    VMMDev::drvPowerOff,
    11931211    /* pfnSoftReset */
    11941212    NULL,
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