VirtualBox

Changeset 13376

Show
Ignore:
Timestamp:
10/17/08 16:20:28 (3 months ago)
Author:
vboxsync
Message:

HostServices/GuestProperties?: use an HGCM service extension instead of the callback type I added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/HostServices/GuestPropertySvc.h

    r13293 r13376  
    206206     * The parameter format matches that of ENUM_PROPS. 
    207207     */ 
    208     ENUM_PROPS_HOST = 6, 
    209     /** 
    210      * Register a callback with the service which will be called when a 
    211      * property is modified.  The callback is a function returning void and 
    212      * taking a pointer to a HOSTCALLBACKDATA structure. 
    213      */ 
    214     REGISTER_CALLBACK = 7 
    215 }; 
    216  
    217 typedef struct _HOSTCALLBACKDATA 
    218 
    219     /** Callback structure header */ 
    220     VBOXHGCMCALLBACKHDR hdr; 
    221     /** The name of the property that was changed */ 
    222     const char *pcszName; 
    223     /** The new property value, or NULL if the property was deleted */ 
    224     const char *pcszValue; 
    225     /** The timestamp of the modification */ 
    226     uint64_t u64Timestamp; 
    227     /** The flags field of the modified property */ 
    228     const char *pcszFlags; 
    229 } HOSTCALLBACKDATA, *PHOSTCALLBACKDATA; 
     208    ENUM_PROPS_HOST = 6 
     209}; 
    230210 
    231211/** 
     
    248228 
    249229/** 
     230 * Data structure to pass to the service extension callback.  We use this to 
     231 * notify the host of changes to properties. 
     232 */ 
     233typedef struct _HOSTCALLBACKDATA 
     234{ 
     235    /** Magic number to identify the structure */ 
     236    uint32_t u32Magic; 
     237    /** The name of the property that was changed */ 
     238    const char *pcszName; 
     239    /** The new property value, or NULL if the property was deleted */ 
     240    const char *pcszValue; 
     241    /** The timestamp of the modification */ 
     242    uint64_t u64Timestamp; 
     243    /** The flags field of the modified property */ 
     244    const char *pcszFlags; 
     245} HOSTCALLBACKDATA, *PHOSTCALLBACKDATA; 
     246 
     247enum 
     248{ 
     249    /** Magic number for sanity checking the HOSTCALLBACKDATA structure */ 
     250    HOSTCALLBACKMAGIC = 0x69c87a78 
     251}; 
     252 
     253/** 
    250254 * HGCM parameter structures.  Packing is explicitly defined as this is a wire format. 
    251255 */ 
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r13328 r13376  
    9191    pParm->u.uint64 = u64; 
    9292} 
    93  
    94 /** Extract a callback pointer value from an HGCM parameter structure */ 
    95 static int VBoxHGCMParmPtrGet (VBOXHGCMSVCPARM *pParm, 
    96                                PFNVBOXHGCMCALLBACK *ppfnCallback, 
    97                                void **ppvData) 
    98 { 
    99     if (pParm->type == VBOX_HGCM_SVC_PARM_CALLBACK) 
    100     { 
    101         *ppfnCallback = pParm->u.callback.pFunction; 
    102         *ppvData      = pParm->u.callback.pvData; 
    103         return VINF_SUCCESS; 
    104     } 
    105  
    106     return VERR_INVALID_PARAMETER; 
    107 } 
    108  
    10993 
    11094namespace guestProp { 
     
    135119    /** Callback function supplied by the host for notification of updates 
    136120     * to properties */ 
    137     PFNVBOXHGCMCALLBACK mpfnHostCallback; 
     121    PFNHGCMSVCEXT mpfnHostCallback; 
    138122    /** User data pointer to be supplied to the host callback function */ 
    139123    void *mpvHostData; 
     
    207191        SELF *pSelf = reinterpret_cast<SELF *>(pvService); 
    208192        return pSelf->hostCall(u32Function, cParms, paParms); 
     193    } 
     194 
     195    /** 
     196     * @copydoc VBOXHGCMSVCHELPERS::pfnRegisterExtension 
     197     * Installs a host callback for notifications of property changes. 
     198     */ 
     199    static DECLCALLBACK(int) svcRegisterExtension (void *pvService, 
     200                                                   PFNHGCMSVCEXT pfnExtension, 
     201                                                   void *pvExtension) 
     202    { 
     203        AssertLogRelReturn(VALID_PTR(pvService), VERR_INVALID_PARAMETER); 
     204        SELF *pSelf = reinterpret_cast<SELF *>(pvService); 
     205        // pSelf->mpfnHostCallback = pfnExtension; 
     206        pSelf->mpvHostData = pvExtension; 
     207        return VINF_SUCCESS; 
    209208    } 
    210209private: 
     
    218217    int enumProps(uint32_t cParms, VBOXHGCMSVCPARM paParms[]); 
    219218    void notifyHost(const char *pszProperty); 
    220     static DECLCALLBACK(int) reqNotify(PFNVBOXHGCMCALLBACK pfnCallback, 
     219    static DECLCALLBACK(int) reqNotify(PFNHGCMSVCEXT pfnCallback, 
    221220                                       void *pvData, char *pszName, 
    222221                                       char *pszValue, uint32_t u32TimeHigh, 
     
    882881 * @thread  request thread 
    883882 */ 
    884 int Service::reqNotify(PFNVBOXHGCMCALLBACK pfnCallback, void *pvData, 
     883int Service::reqNotify(PFNHGCMSVCEXT pfnCallback, void *pvData, 
    885884                       char *pszName, char *pszValue, uint32_t u32TimeHigh, 
    886885                       uint32_t u32TimeLow, char *pszFlags) 
    887886{ 
    888887    HOSTCALLBACKDATA HostCallbackData; 
    889     HostCallbackData.hdr.u32Magic = VBOXHGCMCALLBACKMAGIC; 
    890     HostCallbackData.hdr.cbStruct = sizeof(HostCallbackData); 
    891     HostCallbackData.hdr.pvData   = pvData; 
     888    HostCallbackData.u32Magic     = HOSTCALLBACKMAGIC; 
    892889    HostCallbackData.pcszName     = pszName; 
    893890    HostCallbackData.pcszValue    = pszValue; 
    894891    HostCallbackData.u64Timestamp = RT_MAKE_U64(u32TimeLow, u32TimeHigh); 
    895892    HostCallbackData.pcszFlags    = pszFlags; 
    896     pfnCallback(&HostCallbackData.hdr); 
     893    AssertRC(pfnCallback(pvData, 0, reinterpret_cast<void *>(&HostCallbackData), 
     894                         sizeof(HostCallbackData))); 
    897895    RTStrFree(pszName); 
    898896    RTStrFree(pszValue); 
     
    10371035            LogFlowFunc(("ENUM_PROPS\n")); 
    10381036            rc = enumProps(cParms, paParms); 
    1039             break; 
    1040         case REGISTER_CALLBACK: 
    1041             if ((1 != cParms) || (paParms[0].type != VBOX_HGCM_SVC_PARM_CALLBACK)) 
    1042                 rc = VERR_INVALID_PARAMETER; 
    1043             else 
    1044             { 
    1045                 PFNVBOXHGCMCALLBACK pfnCallback = NULL; 
    1046                 void *pvData = NULL; 
    1047                 rc = VBoxHGCMParmPtrGet (&paParms[0], &pfnCallback, &pvData); 
    1048                 mpfnHostCallback = pfnCallback; 
    1049                 mpvHostData = pvData; 
    1050             } 
    10511037            break; 
    10521038        default: 
     
    11211107                ptable->cbClient = 0; 
    11221108 
    1123                 ptable->pfnUnload     = Service::svcUnload; 
    1124                 ptable->pfnConnect    = Service::svcConnectDisconnect; 
    1125                 ptable->pfnDisconnect = Service::svcConnectDisconnect; 
    1126                 ptable->pfnCall       = Service::svcCall; 
    1127                 ptable->pfnHostCall   = Service::svcHostCall; 
    1128                 ptable->pfnSaveState  = NULL;  /* The service is stateless by definition, so the */ 
    1129                 ptable->pfnLoadState  = NULL;  /* normal construction done before restoring suffices */ 
    1130                 ptable->pfnRegisterExtension  = NULL
     1109                ptable->pfnUnload             = Service::svcUnload; 
     1110                ptable->pfnConnect            = Service::svcConnectDisconnect; 
     1111                ptable->pfnDisconnect         = Service::svcConnectDisconnect; 
     1112                ptable->pfnCall               = Service::svcCall; 
     1113                ptable->pfnHostCall           = Service::svcHostCall; 
     1114                ptable->pfnSaveState          = NULL;  /* The service is stateless by definition, so the */ 
     1115                ptable->pfnLoadState          = NULL;  /* normal construction done before restoring suffices */ 
     1116                ptable->pfnRegisterExtension  = Service::svcRegisterExtension
    11311117 
    11321118                /* Service specific initialization. */ 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy