PDMAsyncCompletionInternal.h revision 4a84dc427be90198c27abbade6d24523c80bfa12
/* $Id$ */
/** @file
* PDM - Pluggable Device Manager, Async I/O Completion internal header.
*/
/*
* Copyright (C) 2006-2010 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.
*/
#ifndef ___PDMAsyncCompletionInternal_h
#define ___PDMAsyncCompletionInternal_h
#include <iprt/critsect.h>
#include <iprt/memcache.h>
#include "PDMInternal.h"
/**
* PDM Async completion endpoint operations.
*/
typedef struct PDMASYNCCOMPLETIONEPCLASSOPS
{
/** Version identifier. */
/** Name of the endpoint class. */
const char *pcszName;
/** Class type. */
/** Size of the global endpoint class data in bytes. */
/** Size of an endpoint in bytes. */
/** size of a task in bytes. */
/**
* Initializes the global data for a endpoint class.
*
* @returns VBox status code.
* @param pClassGlobals Pointer to the uninitialized globals data.
* @param pCfgNode Node for querying configuration data.
*/
DECLR3CALLBACKMEMBER(int, pfnInitialize, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals, PCFGMNODE pCfgNode));
/**
* Frees all allocated resources which were allocated during init.
*
* @returns VBox status code.
* @param pClassGlobals Pointer to the globals data.
*/
/**
* Initializes a given endpoint.
*
* @returns VBox status code.
* @param pEndpoint Pointer to the uninitialized endpoint.
* @param pszUri Pointer to the string containing the endpoint
* destination (filename, IP address, ...)
* @param fFlags Creation flags.
*/
/**
* Closes a endpoint finishing all tasks.
*
* @returns VBox status code.
* @param pEndpoint Pointer to the endpoint to be closed.
*/
/**
* Initiates a read request from the given endpoint.
*
* @returns VBox status code.
* @param pTask Pointer to the task object associated with the request.
* @param pEndpoint Endpoint the request is for.
* @param off Where to start reading from.
* @param paSegments Scatter gather list to store the data in.
* @param cSegments Number of segments in the list.
* @param cbRead The overall number of bytes to read.
*/
/**
* Initiates a write request to the given endpoint.
*
* @returns VBox status code.
* @param pTask Pointer to the task object associated with the request.
* @param pEndpoint Endpoint the request is for.
* @param off Where to start writing to.
* @param paSegments Scatter gather list to store the data in.
* @param cSegments Number of segments in the list.
* @param cbRead The overall number of bytes to write.
*/
/**
* Initiates a flush request on the given endpoint.
*
* @returns VBox status code.
* @param pTask Pointer to the task object associated with the request.
* @param pEndpoint Endpoint the request is for.
*/
/**
* Queries the size of the endpoint. Optional.
*
* @returns VBox status code.
* @param pEndpoint Endpoint the request is for.
* @param pcbSize Where to store the size of the endpoint.
*/
/**
* Sets the size of the endpoint. Optional.
* This is a synchronous operation.
*
*
* @returns VBox status code.
* @param pEndpoint Endpoint the request is for.
* @param cbSize New size for the endpoint.
*/
/** Initialization safety marker. */
/** Pointer to a async completion endpoint class operation table. */
/** Const pointer to a async completion endpoint class operation table. */
typedef const PDMASYNCCOMPLETIONEPCLASSOPS *PCPDMASYNCCOMPLETIONEPCLASSOPS;
/** Version for the endpoint class operations structure. */
#define PDMAC_EPCLASS_OPS_VERSION 0x00000001
/** Pointer to a bandwidth control manager. */
typedef struct PDMACBWMGR *PPDMACBWMGR;
/**
* PDM Async completion endpoint class.
* Common data.
*/
typedef struct PDMASYNCCOMPLETIONEPCLASS
{
/** Pointer to the VM. */
/** Critical section protecting the lists below. */
/** Number of endpoints in the list. */
volatile unsigned cEndpoints;
/** Head of endpoints with this class. */
/** Head of the bandwidth managers for this class. */
/** Pointer to the callback table. */
/** Task cache. */
/** Flag whether to gather advanced statistics about requests. */
/** Pointer to the PDM async completion endpoint class data. */
/**
* A PDM Async completion endpoint.
* Common data.
*/
typedef struct PDMASYNCCOMPLETIONENDPOINT
{
/** Next endpoint in the list. */
/** Previous endpoint in the list. */
/** Pointer to the class this endpoint belongs to. */
/** Template associated with this endpoint. */
/** Reference count. */
unsigned cUsers;
/** URI describing the endpoint */
char *pszUri;
/** Pointer to the assigned bandwidth manager. */
volatile PPDMACBWMGR pBwMgr;
/** Aligns following statistic counters on a 8 byte boundary. */
/** @name Request size statistics.
* @{ */
/** @} */
/** @name Request completion time statistics.
* @{ */
/** @} */
/**
* A PDM async completion task handle.
* Common data.
*/
typedef struct PDMASYNCCOMPLETIONTASK
{
/** Next task in the list
* (for free and assigned tasks). */
/** Previous task in the list
* (for free and assigned tasks). */
/** Endpoint this task is assigned to. */
/** Opaque user data for this task. */
void *pvUser;
/** Start timestamp. */
/**
* Called by the endpoint if a task has finished.
*
* @returns nothing
* @param pTask Pointer to the finished task.
* @param rc Status code of the completed request.
* @param fCallCompletionHandler Flag whether the completion handler should be called to
* inform the owner of the task that it has completed.
*/
void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, int rc, bool fCallCompletionHandler);
/**
* Checks if the endpoint is allowed to transfer the given amount of bytes.
*
* @returns true if the endpoint is allowed to transfer the data.
* false otherwise
* @param pEndpoint The endpoint.
* @param cbTransfer The number of bytes to transfer.
* @param pmsWhenNext Where to store the number of milliseconds
* until the bandwidth is refreshed.
* Only set if false is returned.
*/
bool pdmacEpIsTransferAllowed(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, uint32_t cbTransfer, RTMSINTERVAL *pmsWhenNext);
#endif /* !___PDMAsyncCompletionInternal_h */