VirtualBox

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


Ignore:
Timestamp:
Jul 22, 2008 8:12:42 AM (17 years ago)
Author:
vboxsync
Message:

Guest properties: initial commit of new interface

Location:
trunk/src/VBox/HostServices
Files:
1 edited
3 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestProperties/Makefile.kmk

    r10795 r10797  
    3131# The shared folder service DLL.
    3232#
    33 DLLS += VBoxSharedInfoSvc
    34 VBoxSharedInfoSvc_TEMPLATE  = VBOXR3
    35 VBoxSharedInfoSvc_NAME.os2  = VBoxSIS
    36 VBoxSharedInfoSvc_DEFS      = VBOX_HGCM
    37 VBoxSharedInfoSvc_INCS      = $(PATH_ROOT)/src/VBox/Main/include
    38 VBoxSharedInfoSvc_INCS.win  = \
     33DLLS += VBoxGuestPropSvc
     34VBoxGuestPropSvc_TEMPLATE  = VBOXR3
     35VBoxGuestPropSvc_NAME.os2  = VBoxSIS
     36VBoxGuestPropSvc_DEFS      = VBOX_HGCM
     37VBoxGuestPropSvc_INCS      = $(PATH_ROOT)/src/VBox/Main/include
     38VBoxGuestPropSvc_INCS.win  = \
    3939        $(PATH_TOOL_$(VBOX_VCC_TOOL)_ATLMFC_INC) \
    4040        $(VBOX_PATH_SDK)
    4141
    42 VBoxSharedInfoSvc_SOURCES = \
     42VBoxGuestPropSvc_SOURCES = \
    4343        service.cpp
    4444
    45 VBoxSharedInfoSvc_LIBS = \
     45VBoxGuestPropSvc_LIBS = \
    4646        $(LIB_VMM) \
    4747        $(LIB_RUNTIME) \
  • trunk/src/VBox/HostServices/GuestProperties/noncopyable.h

    r10795 r10797  
    2020 */
    2121
    22 #ifndef ___svcinfo_noncopyable_h
    23 # define ___svcinfo_noncopyable_h
     22#ifndef ___guestprop_noncopyable_h
     23# define ___guestprop_noncopyable_h
    2424
    25 namespace svcInfo {
     25namespace guestProp {
    2626
    2727class noncopyable
     
    3535};
    3636
    37 } /* namespace svcInfo */
     37} /* namespace guestProp */
    3838
    39 typedef svcInfo::noncopyable noncopyable;
     39typedef guestProp::noncopyable noncopyable;
    4040
    41 #endif /* ___svcinfo_noncopyable_h not defined */
     41#endif /* ___guestprop_noncopyable_h not defined */
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r10795 r10797  
    11/** @file
    22 *
    3  * Shared Information Services:
     3 * Guest Property Service:
    44 * Host service entry points.
    55 */
     
    2222
    2323/**
    24  * An HGCM service for passing requests which do not need any persistant state
    25  * to handle.  We currently only support three types of request - set guest
    26  * property (SET_CONFIG_KEY and SET_CONFIG_KEY_HOST), get guest property
    27  * (GET_CONFIG_KEY and GET_CONFIG_KEY_HOST) and remove guest property
    28  * (DEL_CONFIG_KEY and DEL_CONFIG_KEY_HOST).  These may be used to read, to
    29  * write and to remove configuration information which is available to
    30  * both guest and host.  This configuration information is stored in a CFGM
    31  * node using the CFGM APIs.  It is the responsibility of whoever creates the
    32  * service to create this node and to tell the service about it using the
    33  * SET_CFGM_NODE host call.  It is also the responsibility of the service
    34  * creator to save this information to disk and to retrieve it when needed.
    35  * Since the CFGM APIs are single threaded, the creator must also ensure that
    36  * no-one else accesses the configuration node while the service is running.
    37  *
    38  * If this service is extended to deal with new requests it would probably be a
    39  * good idea to split it up into several files.
     24 * This HGCM service allows the guest to set and query values in a property
     25 * store on the host.  The service proxies the guest requests to the service
     26 * owner on the host using a request callback provided by the owner, and is
     27 * notified of changes to properties made by the host.  It forwards these
     28 * notifications to clients in the guest which have expressed interest and
     29 * are waiting for notification.
     30 *
     31 * The service currently consists of two threads.  One of these is the main
     32 * HGCM service thread which waits for requests from the guest and schedules
     33 * these to the second thread.  The second thread deals with the requests
     34 * sequentially by calling the callback provided by the service owner,
     35 * notifying the guest clients when it has finished dealing with a given
     36 * request.
     37 *
     38 * Guest requests to wait for notification are dealt with differently.  They
     39 * are added to a list of open notification requests but do not schedule
     40 * anything in the request thread except for a possible timeout.
    4041 */
    4142
     
    4546*   Header Files                                                               *
    4647*******************************************************************************/
    47 #include <VBox/HostServices/VBoxInfoSvc.h>
     48#include <VBox/HostServices/GuestPropertySvc.h>
    4849
    4950#include <memory>  /* for auto_ptr */
     
    8283
    8384
    84 namespace svcInfo {
     85/** Set a uint64_t value to an HGCM parameter structure */
     86static void VBoxHGCMParmUInt64Set (VBOXHGCMSVCPARM *pParm, uint64_t u64)
     87{
     88    pParm->type = VBOX_HGCM_SVC_PARM_64BIT;
     89    pParm->u.uint64 = u64;
     90}
     91
     92
     93namespace guestProp {
    8594
    8695/**
     
    158167    int validateValue(char *pszValue, uint32_t cbValue);
    159168    int getKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
     169    int getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    160170    int setKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    161171    int delKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
     
    190200        /* We want the byte length, not the Utf8 length */
    191201        count = strlen(pszKey);
    192     if (RT_SUCCESS(rc) && (count > KEY_MAX_LEN))
     202    if (RT_SUCCESS(rc) && (count > MAX_NAME_LEN))
    193203        rc = VERR_INVALID_PARAMETER;
    194204
     
    220230        /* We want the byte length, not the Utf8 length */
    221231        count = strlen(pszValue);
    222     if (RT_SUCCESS(rc) && (count > KEY_MAX_VALUE_LEN))
     232    if (RT_SUCCESS(rc) && (count > MAX_VALUE_LEN))
    223233        rc = VERR_INVALID_PARAMETER;
    224234
     
    267277    if (RT_SUCCESS(rc) && (cbValueActual > cbValue))
    268278        rc = VERR_BUFFER_OVERFLOW;
    269     if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
     279    if (RT_SUCCESS(rc))
    270280        rc = CFGMR3QueryString(mpNode, pszKey, pszValue, cbValue);
    271     if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
     281    if (RT_SUCCESS(rc))
    272282        Log2(("Queried string %s, rc=%Rrc, value=%.*s\n", pszKey, rc, cbValue, pszValue));
     283    else if (VERR_CFGM_VALUE_NOT_FOUND == rc)
     284        rc = VERR_NOT_FOUND;
     285    LogFlowThisFunc(("rc = %Rrc\n", rc));
     286    return rc;
     287}
     288
     289
     290/**
     291 * Retrieve a value from the guest registry by key, checking the validity
     292 * of the arguments passed.  If the guest has not allocated enough buffer
     293 * space for the value then we return VERR_OVERFLOW and set the size of the
     294 * buffer needed in the "size" HGCM parameter.  If the key was not found at
     295 * all, we return VERR_NOT_FOUND.
     296 *
     297 * @returns iprt status value
     298 * @param   cParms  the number of HGCM parameters supplied
     299 * @param   paParms the array of HGCM parameters
     300 * @thread  HGCM
     301 */
     302int Service::getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     303{
     304    int rc = VINF_SUCCESS;
     305    char *pszName, *pchBuf;
     306    uint32_t cbName, cbBuf;
     307    size_t cbValueActual;
     308
     309    LogFlowThisFunc(("\n"));
     310    if (   (cParms != 4)  /* Hardcoded value as the next lines depend on it. */
     311        || (paParms[0].type != VBOX_HGCM_SVC_PARM_PTR)    /* name */
     312        || (paParms[1].type != VBOX_HGCM_SVC_PARM_PTR)    /* buffer */
     313       )
     314        rc = VERR_INVALID_PARAMETER;
     315    if (RT_SUCCESS(rc))
     316        rc = VBoxHGCMParmPtrGet(&paParms[0], (void **) &pszName, &cbName);
     317    if (RT_SUCCESS(rc))
     318        rc = VBoxHGCMParmPtrGet(&paParms[1], (void **) &pchBuf, &cbBuf);
     319    if (RT_SUCCESS(rc))
     320        rc = validateKey(pszName, cbName);
     321    if (RT_SUCCESS(rc))
     322        rc = CFGMR3QuerySize(mpNode, pszName, &cbValueActual);
     323    if (RT_SUCCESS(rc))
     324    {
     325        /* Temporary hack for an empty flags string */
     326        cbValueActual += 1;
     327        VBoxHGCMParmUInt32Set(&paParms[3], cbValueActual);
     328    }
     329    if (RT_SUCCESS(rc) && (cbValueActual > cbBuf))
     330        rc = VERR_BUFFER_OVERFLOW;
     331    if (RT_SUCCESS(rc))
     332        rc = CFGMR3QueryString(mpNode, pszName, pchBuf, cbBuf);
     333    if (RT_SUCCESS(rc))
     334    {
     335        /* No timestamp */
     336        VBoxHGCMParmUInt64Set(&paParms[2], 0);
     337        /* No flags */
     338        pchBuf[cbValueActual - 1] = 0;
     339    }
     340    if (RT_SUCCESS(rc))
     341        Log2(("Queried string %s, rc=%Rrc, value=%.*s\n", pszName, rc, cbBuf, pchBuf));
    273342    else if (VERR_CFGM_VALUE_NOT_FOUND == rc)
    274343        rc = VERR_NOT_FOUND;
     
    313382        for (PCFGMNODE pChild = CFGMR3GetFirstChild(mpNode); pChild != 0; pChild = CFGMR3GetNextChild(pChild))
    314383            ++cChildren;
    315         if (cChildren >= KEY_MAX_KEYS)
     384        if (cChildren >= MAX_KEYS)
    316385            rc = VERR_TOO_MUCH_DATA;
    317386    }
     
    381450    switch (eFunction)
    382451    {
    383         /* The guest wishes to read a configuration value */
    384         case GET_CONFIG_KEY:
    385             LogFlowFunc(("GET_CONFIG_KEY\n"));
    386             rc = getKey(cParms, paParms);
    387             break;
    388 
    389         /* The guest wishes to set a configuration value */
    390         case SET_CONFIG_KEY:
    391             LogFlowFunc(("SET_CONFIG_KEY\n"));
     452        /* The guest wishes to read a property */
     453        case GET_PROP:
     454            LogFlowFunc(("GET_PROP\n"));
     455            rc = getProperty(cParms, paParms);
     456            break;
     457
     458        /* The guest wishes to set a property */
     459        case SET_PROP:
     460            LogFlowFunc(("SET_PROP\n"));
     461            rc = setKey(cParms - 1, paParms);
     462            break;
     463
     464        /* The guest wishes to set a property value */
     465        case SET_PROP_VALUE:
     466            LogFlowFunc(("SET_PROP_VALUE\n"));
    392467            rc = setKey(cParms, paParms);
    393468            break;
    394469
    395470        /* The guest wishes to remove a configuration value */
    396         case DEL_CONFIG_KEY:
    397             LogFlowFunc(("DEL_CONFIG_KEY\n"));
     471        case DEL_PROP:
     472            LogFlowFunc(("DEL_PROP\n"));
    398473            rc = delKey(cParms, paParms);
    399474            break;
     
    476551}
    477552
    478 } /* namespace svcInfo */
    479 
    480 using svcInfo::Service;
     553} /* namespace guestProp */
     554
     555using guestProp::Service;
    481556
    482557/**
  • trunk/src/VBox/HostServices/Makefile.kmk

    r10051 r10797  
    4242 endif
    4343endif
    44 ifdef VBOX_WITH_INFO_SVC
    45  include $(PATH_SUB_CURRENT)/SharedInfoServices/Makefile.kmk
     44ifdef VBOX_WITH_GUEST_PROPS
     45 include $(PATH_SUB_CURRENT)/GuestProperties/Makefile.kmk
    4646endif
    4747
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