service.cpp revision 99f33ab590a3a65e0cd082dd8d67779efb9cc6c9
/* $Id$ */
/** @file
* Drag and Drop Service.
*/
/*
* Copyright (C) 2011-2013 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.
*/
/** @page pg_svc_guest_control Guest Control HGCM Service
*
* This service acts as a proxy for handling and buffering host command requests
* and clients on the guest. It tries to be as transparent as possible to let
* the guest (client) and host side do their protocol handling as desired.
*
* The following terms are used:
* - Host: A host process (e.g. VBoxManage or another tool utilizing the Main API)
* which wants to control something on the guest.
* - Client: A client (e.g. VBoxService) running inside the guest OS waiting for
* new host commands to perform. There can be multiple clients connected
* to a service. A client is represented by its HGCM client ID.
* - Context ID: An (almost) unique ID automatically generated on the host (Main API)
* to not only distinguish clients but individual requests. Because
* the host does not know anything about connected clients it needs
* an indicator which it can refer to later. This context ID gets
* internally bound by the service to a client which actually processes
* the command in order to have a relationship between client<->context ID(s).
*
* The host can trigger commands which get buffered by the service (with full HGCM
* parameter info). As soon as a client connects (or is ready to do some new work)
* it gets a buffered host command to process it. This command then will be immediately
* removed from the command list. If there are ready clients but no new commands to be
* processed, these clients will be set into a deferred state (that is being blocked
* to return until a new command is available).
*
* If a client needs to inform the host that something happened, it can send a
* message to a low level HGCM callback registered in Main. This callback contains
* the actual data as well as the context ID to let the host do the next necessary
* steps for this context. This context ID makes it possible to wait for an event
* inside the host's Main API function (like starting a process on the guest and
* wait for getting its PID returned by the client) as well as cancelling blocking
* host calls in order the client terminated/crashed (HGCM detects disconnected
* clients and reports it to this service's callback).
*/
/******************************************************************************
* Header Files *
******************************************************************************/
#ifdef LOG_GROUP
#endif
#define LOG_GROUP LOG_GROUP_GUEST_DND
#include "dndmanager.h"
/******************************************************************************
* Service class declaration *
******************************************************************************/
/**
* Specialized drag & drop service class.
*/
{
public:
, m_pManager(0)
, m_cClients(0)
{}
protected:
/* HGCM service implementation */
int uninit();
void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
static DECLCALLBACK(int) progressCallback(uint32_t uPercentage, uint32_t uState, int rc, void *pvUser);
};
/******************************************************************************
* Service class implementation *
******************************************************************************/
{
/* Register functions. */
return VINF_SUCCESS;
}
int DragAndDropService::uninit()
{
delete m_pManager;
return VINF_SUCCESS;
}
{
if (m_cClients < UINT32_MAX)
m_cClients++;
else
AssertMsgFailed(("Maximum number of clients reached\n"));
return VINF_SUCCESS;
}
{
/* Remove all waiters with this clientId. */
{
{
delete pClient;
}
else
i++;
}
return VINF_SUCCESS;
}
{
switch (u32Mode)
{
break;
default:
}
}
void DragAndDropService::guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
{
LogFlowFunc(("u32ClientID=%RU32, u32Function=%RU32, cParms=%RU32\n",
int rc = VINF_SUCCESS;
switch (u32Function)
{
{
LogFlowFunc(("GUEST_DND_GET_NEXT_HOST_MSG\n"));
if ( cParms != 3
else
{
if ( RT_FAILURE(rc)
{
}
}
break;
}
{
LogFlowFunc(("GUEST_DND_HG_ACK_OP\n"));
if ( modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
{
LogFlowFunc(("=> ignoring!\n"));
break;
}
if ( cParms != 1
else
{
if (m_pfnHostCallback)
// m_pHelpers->pfnCallComplete(callHandle, rc);
}
break;
}
{
LogFlowFunc(("GUEST_DND_HG_REQ_DATA\n"));
if ( modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
{
LogFlowFunc(("=> ignoring!\n"));
break;
}
if ( cParms != 1
else
{
if (m_pfnHostCallback)
// m_pHelpers->pfnCallComplete(callHandle, rc);
// if (data.pszFormat)
// RTMemFree(data.pszFormat);
// if (data.pszTmpPath)
// RTMemFree(data.pszTmpPath);
}
break;
}
#ifdef VBOX_WITH_DRAG_AND_DROP_GH
{
LogFlowFunc(("GUEST_DND_GH_ACK_PENDING\n"));
if ( modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
{
LogFlowFunc(("=> ignoring!\n"));
break;
}
if ( cParms != 3
else
{
if (m_pfnHostCallback)
}
break;
}
{
LogFlowFunc(("GUEST_DND_GH_SND_DATA\n"));
if ( modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
{
LogFlowFunc(("=> ignoring\n"));
break;
}
if ( cParms != 2
else
{
if (m_pfnHostCallback)
}
break;
}
{
LogFlowFunc(("GUEST_DND_GH_EVT_ERROR\n"));
if ( modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
{
LogFlowFunc(("=> ignoring!\n"));
break;
}
if ( cParms != 1
else
{
if (m_pfnHostCallback)
}
break;
}
#endif
default:
{
/* All other messages are handled by the DnD manager. */
break;
}
}
/* If async execute is requested, we didn't notify the guest about
* completion. The client is queued into the waiters list and will be
* notified as soon as a new event is available. */
if (rc != VINF_HGCM_ASYNC_EXECUTE)
}
int DragAndDropService::hostMessage(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
{
int rc = VINF_SUCCESS;
#if 0
// bool fPush = true;
if (!m_clientQueue.empty())
{
/* Check if this was a request for getting the next host
* message. If so, return the message id and the parameter
* count. The message itself has to be queued. */
{
RTPrintf("client is waiting for next host msg\n");
// rc = VERR_TOO_MUCH_DATA;
/* temp */
// m_pHelpers->pfnCallComplete(pClient->handle(), rc);
// m_clientQueue.pop();
// delete pClient;
}
else
{
/* There is a request for a host message pending. Check
* if this is the correct message and if so deliver. If
* not the message will be queued. */
m_hostQueue.pop();
delete pMessage;
// if (RT_SUCCESS(rc))
// fPush = false;
}
/* In any case mark this client request as done. */
delete pClient;
}
// if (fPush)
// {
// RTPrintf("push message\n");
// m_hostQueue.push(pMessage);
// }
// else
// delete pMessage;
#endif
return rc;
}
{
int rc = VINF_SUCCESS;
{
if (cParms != 1)
else
}
else if (modeGet() != VBOX_DRAG_AND_DROP_MODE_OFF)
{
if ( RT_SUCCESS(rc)
&& !m_clientQueue.isEmpty())
{
/* Check if this was a request for getting the next host
* message. If so, return the message id and the parameter
* count. The message itself has to be queued. */
{
if (RT_SUCCESS(rc))
{
delete pClient;
}
else
AssertMsgFailed(("Should not happen!"));
}
else
AssertMsgFailed(("Should not happen!"));
}
// else
// AssertMsgFailed(("Should not happen %Rrc!", rc));
}
return rc;
}
DECLCALLBACK(int) DragAndDropService::progressCallback(uint32_t uPercentage, uint32_t uState, int rc, void *pvUser)
{
if (pSelf->m_pfnHostCallback)
{
LogFlowFunc(("GUEST_DND_HG_EVT_PROGRESS: uPercentage=%RU32, uState=%RU32, rc=%Rrc\n",
return pSelf->m_pfnHostCallback(pSelf->m_pvHostData, DragAndDropSvc::GUEST_DND_HG_EVT_PROGRESS, &data, sizeof(data));
}
return VINF_SUCCESS;
}
/**
* @copydoc VBOXHGCMSVCLOAD
*/
{
}