Service.h revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/** @file
* Base class for an host-guest service.
*/
/*
* Copyright (C) 2011-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___VBox_HostService_Service_h
#define ___VBox_HostService_Service_h
#include <memory> /* for auto_ptr */
{
{
: m_uMsg(0)
, m_cParms(0)
, m_paParms(0)
{
}
~Message()
{
cleanup();
}
{
{
LogFlowFunc(("Message type does not match (%u (buffer), %u (guest))\n",
return VERR_INVALID_PARAMETER;
}
{
LogFlowFunc(("Parameter count does not match (%u (buffer), %u (guest))\n",
return VERR_INVALID_PARAMETER;
}
// if (RT_FAILURE(rc))
// cleanup(aParms);
return rc;
}
{
/* Cleanup old messages. */
cleanup();
if (cParms > 0)
{
if (!m_paParms)
return VERR_NO_MEMORY;
}
if (RT_FAILURE(rc))
cleanup();
return rc;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
int copyParms(uint32_t cParms, PVBOXHGCMSVCPARM paParmsSrc, PVBOXHGCMSVCPARM paParmsDst, bool fCreatePtrs) const
{
int rc = VINF_SUCCESS;
{
switch (paParmsSrc[i].type)
{
case VBOX_HGCM_SVC_PARM_32BIT:
{
break;
}
case VBOX_HGCM_SVC_PARM_64BIT:
{
break;
}
case VBOX_HGCM_SVC_PARM_PTR:
{
/* Do we have to recreate the memory? */
if (fCreatePtrs)
{
/* Yes, do so. */
{
{
rc = VERR_NO_MEMORY;
break;
}
}
}
else
{
/* No, but we have to check if there is enough room. */
}
break;
}
default:
{
break;
}
}
if (RT_FAILURE(rc))
break;
}
return rc;
}
void cleanup()
{
if (m_paParms)
{
{
{
case VBOX_HGCM_SVC_PARM_PTR:
break;
}
}
m_paParms = 0;
}
m_cParms = 0;
m_uMsg = 0;
}
};
{
Client(uint32_t uClientId, VBOXHGCMCALLHANDLE hHandle, uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
{
if (m_cParms != 3)
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
{
if (m_cParms != 3)
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
{
}
};
{
/**
* @copydoc VBOXHGCMSVCLOAD
*/
{
int rc = VINF_SUCCESS;
else
{
LogFlowFunc(("ptable->cbSize = %d, ptable->u32Version = 0x%08X\n", pTable->cbSize, pTable->u32Version));
else
{
/* No exceptions may propagate outside. */
{
{
} catch (...)
{
}
if (RT_SUCCESS(rc))
{
/*
* We don't need an additional client data area on the host,
* because we're a class which can have members for that :-).
*/
/* These functions are mandatory */
/* Clear obligatory functions. */
/* Let the service itself initialize. */
/* Only on success stop the auto release of the auto_ptr. */
if (RT_SUCCESS(rc))
}
}
}
return rc;
}
virtual ~AbstractService() {};
, m_pvHostData(NULL)
{}
virtual void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) = 0;
virtual int hostCall(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) { return VINF_SUCCESS; }
/** Type definition for use in callback functions. */
typedef AbstractService SELF;
/** HGCM helper functions. */
/*
* Callback function supplied by the host for notification of updates
* to properties.
*/
/** User data pointer to be supplied to the host callback function. */
void *m_pvHostData;
/**
* @copydoc VBOXHGCMSVCHELPERS::pfnUnload
* Simply deletes the service object
*/
{
if (RT_SUCCESS(rc))
return rc;
}
/**
* @copydoc VBOXHGCMSVCHELPERS::pfnConnect
* Stub implementation of pfnConnect and pfnDisconnect.
*/
void *pvClient)
{
return rc;
}
/**
* @copydoc VBOXHGCMSVCHELPERS::pfnConnect
* Stub implementation of pfnConnect and pfnDisconnect.
*/
void *pvClient)
{
return rc;
}
/**
* @copydoc VBOXHGCMSVCHELPERS::pfnCall
* Wraps to the call member function
*/
void *pvClient,
{
LogFlowFunc(("pvService=%p, callHandle=%p, u32ClientID=%u, pvClient=%p, u32Function=%u, cParms=%u, paParms=%p\n", pvService, callHandle, u32ClientID, pvClient, u32Function, cParms, paParms));
LogFlowFunc(("returning\n"));
}
/**
* @copydoc VBOXHGCMSVCHELPERS::pfnHostCall
* Wraps to the hostCall member function
*/
{
LogFlowFunc(("pvService=%p, u32Function=%u, cParms=%u, paParms=%p\n", pvService, u32Function, cParms, paParms));
return rc;
}
/**
* @copydoc VBOXHGCMSVCHELPERS::pfnRegisterExtension
* Installs a host callback for notifications of property changes.
*/
void *pvExtension)
{
LogFlowFunc(("pvService=%p, pfnExtension=%p, pvExtention=%p\n", pvService, pfnExtension, pvExtension));
return VINF_SUCCESS;
}
};
}
#endif /* !___VBox_HostService_Service_h */