VirtualBox

Changeset 13376 in vbox for trunk/src


Ignore:
Timestamp:
Oct 17, 2008 2:20:28 PM (16 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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. */
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