VirtualBox

source: vbox/trunk/include/VBox/pdmasynccompletion.h@ 27920

Last change on this file since 27920 was 27920, checked in by vboxsync, 15 years ago

AsyncCompletion: Return error code for completed requests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 13.7 KB
Line 
1/* $Id: pdmasynccompletion.h 27920 2010-03-31 19:02:48Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device Manager, Async I/O Completion. (VMM)
4 */
5
6/*
7 * Copyright (C) 2007-2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___VBox_pdmasynccompletion_h
32#define ___VBox_pdmasynccompletion_h
33
34#include <VBox/types.h>
35#include <VBox/err.h>
36#include <iprt/assert.h>
37
38RT_C_DECLS_BEGIN
39
40/** @defgroup grp_pdm_async_completion The PDM Async I/O Completion API
41 * @ingroup grp_pdm
42 * @{
43 */
44
45/** Pointer to a PDM async completion template handle. */
46typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
47/** Pointer to a PDM async completion template handle pointer. */
48typedef PPDMASYNCCOMPLETIONTEMPLATE *PPPDMASYNCCOMPLETIONTEMPLATE;
49
50/** Pointer to a PDM async completion task handle. */
51typedef struct PDMASYNCCOMPLETIONTASK *PPDMASYNCCOMPLETIONTASK;
52/** Pointer to a PDM async completion task handle pointer. */
53typedef PPDMASYNCCOMPLETIONTASK *PPPDMASYNCCOMPLETIONTASK;
54
55/** Pointer to a PDM async completion endpoint handle. */
56typedef struct PDMASYNCCOMPLETIONENDPOINT *PPDMASYNCCOMPLETIONENDPOINT;
57/** Pointer to a PDM async completion endpoint handle pointer. */
58typedef PPDMASYNCCOMPLETIONENDPOINT *PPPDMASYNCCOMPLETIONENDPOINT;
59
60
61/**
62 * Completion callback for devices.
63 *
64 * @param pDevIns The device instance.
65 * @param pvUser User argument.
66 * @param rc The status code of the completed request.
67 */
68typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDEV(PPDMDEVINS pDevIns, void *pvUser, int rc);
69/** Pointer to a FNPDMASYNCCOMPLETEDEV(). */
70typedef FNPDMASYNCCOMPLETEDEV *PFNPDMASYNCCOMPLETEDEV;
71
72
73/**
74 * Completion callback for drivers.
75 *
76 * @param pDrvIns The driver instance.
77 * @param pvTemplateUser User argument given when creating the template.
78 * @param pvUser User argument given during request initiation.
79 * @param rc The status code of the completed request.
80 */
81typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDRV(PPDMDRVINS pDrvIns, void *pvTemplateUser, void *pvUser, int rc);
82/** Pointer to a FNPDMASYNCCOMPLETEDRV(). */
83typedef FNPDMASYNCCOMPLETEDRV *PFNPDMASYNCCOMPLETEDRV;
84
85
86/**
87 * Completion callback for USB devices.
88 *
89 * @param pUsbIns The USB device instance.
90 * @param pvUser User argument.
91 * @param rc The status code of the completed request.
92 */
93typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEUSB(PPDMUSBINS pUsbIns, void *pvUser, int rc);
94/** Pointer to a FNPDMASYNCCOMPLETEUSB(). */
95typedef FNPDMASYNCCOMPLETEUSB *PFNPDMASYNCCOMPLETEUSB;
96
97
98/**
99 * Completion callback for internal.
100 *
101 * @param pVM Pointer to the shared VM structure.
102 * @param pvUser User argument for the task.
103 * @param pvUser2 User argument for the template.
104 * @param rc The status code of the completed request.
105 */
106typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEINT(PVM pVM, void *pvUser, void *pvUser2, int rc);
107/** Pointer to a FNPDMASYNCCOMPLETEINT(). */
108typedef FNPDMASYNCCOMPLETEINT *PFNPDMASYNCCOMPLETEINT;
109
110
111/**
112 * Creates a async completion template for a device instance.
113 *
114 * The template is used when creating new completion tasks.
115 *
116 * @returns VBox status code.
117 * @param pVM Pointer to the shared VM structure.
118 * @param pDevIns The device instance.
119 * @param ppTemplate Where to store the template pointer on success.
120 * @param pfnCompleted The completion callback routine.
121 * @param pszDesc Description.
122 */
123VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDEV pfnCompleted, const char *pszDesc);
124
125/**
126 * Creates a async completion template for a driver instance.
127 *
128 * The template is used when creating new completion tasks.
129 *
130 * @returns VBox status code.
131 * @param pVM Pointer to the shared VM structure.
132 * @param pDrvIns The driver instance.
133 * @param ppTemplate Where to store the template pointer on success.
134 * @param pfnCompleted The completion callback routine.
135 * @param pvTemplateUser Template user argument.
136 * @param pszDesc Description.
137 */
138VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser, const char *pszDesc);
139
140/**
141 * Creates a async completion template for a USB device instance.
142 *
143 * The template is used when creating new completion tasks.
144 *
145 * @returns VBox status code.
146 * @param pVM Pointer to the shared VM structure.
147 * @param pUsbIns The USB device instance.
148 * @param ppTemplate Where to store the template pointer on success.
149 * @param pfnCompleted The completion callback routine.
150 * @param pszDesc Description.
151 */
152VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEUSB pfnCompleted, const char *pszDesc);
153
154/**
155 * Creates a async completion template for internally by the VMM.
156 *
157 * The template is used when creating new completion tasks.
158 *
159 * @returns VBox status code.
160 * @param pVM Pointer to the shared VM structure.
161 * @param ppTemplate Where to store the template pointer on success.
162 * @param pfnCompleted The completion callback routine.
163 * @param pvUser2 The 2nd user argument for the callback.
164 * @param pszDesc Description.
165 */
166VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateInternal(PVM pVM, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEINT pfnCompleted, void *pvUser2, const char *pszDesc);
167
168/**
169 * Destroys the specified async completion template.
170 *
171 * @returns VBox status codes:
172 * @retval VINF_SUCCESS on success.
173 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if the template is still in use.
174 *
175 * @param pTemplate The template in question.
176 */
177VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroy(PPDMASYNCCOMPLETIONTEMPLATE pTemplate);
178
179/**
180 * Destroys all the specified async completion templates for the given device instance.
181 *
182 * @returns VBox status codes:
183 * @retval VINF_SUCCESS on success.
184 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
185 *
186 * @param pVM Pointer to the shared VM structure.
187 * @param pDevIns The device instance.
188 */
189VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
190
191/**
192 * Destroys all the specified async completion templates for the given driver instance.
193 *
194 * @returns VBox status codes:
195 * @retval VINF_SUCCESS on success.
196 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
197 *
198 * @param pVM Pointer to the shared VM structure.
199 * @param pDrvIns The driver instance.
200 */
201VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
202
203/**
204 * Destroys all the specified async completion templates for the given USB device instance.
205 *
206 * @returns VBox status codes:
207 * @retval VINF_SUCCESS on success.
208 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
209 *
210 * @param pVM Pointer to the shared VM structure.
211 * @param pUsbIns The USB device instance.
212 */
213VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
214
215
216/**
217 * Opens a file as a async completion endpoint.
218 *
219 * @returns VBox status code.
220 * @param ppEndpoint Where to store the opaque endpoint handle on success.
221 * @param pszFilename Path to the file which is to be opened. (UTF-8)
222 * @param fFlags Open flags, see grp_pdmacep_file_flags.
223 * @param pTemplate Handle to the completion callback template to use
224 * for this end point.
225 */
226VMMR3DECL(int) PDMR3AsyncCompletionEpCreateForFile(PPPDMASYNCCOMPLETIONENDPOINT ppEndpoint,
227 const char *pszFilename, uint32_t fFlags,
228 PPDMASYNCCOMPLETIONTEMPLATE pTemplate);
229
230/** @defgroup grp_pdmacep_file_flags Flags for PDMR3AsyncCompletionEpCreateForFile
231 * @{ */
232/** Open the file in read-only mode. */
233#define PDMACEP_FILE_FLAGS_READ_ONLY RT_BIT_32(0)
234/** whether file content should be cached by the endpoint. */
235#define PDMACEP_FILE_FLAGS_CACHING RT_BIT_32(1)
236/** @} */
237
238/**
239 * Closes a endpoint waiting for any pending tasks to finish.
240 *
241 * @returns nothing.
242 * @param pEndpoint Handle of the endpoint.
243 */
244VMMR3DECL(void) PDMR3AsyncCompletionEpClose(PPDMASYNCCOMPLETIONENDPOINT pEndpoint);
245
246/**
247 * Creates a read task on the given endpoint.
248 *
249 * @returns VBox status code.
250 * @param pEndpoint The file endpoint to read from.
251 * @param off Where to start reading from.
252 * @param paSegments Scatter gather list to store the data in.
253 * @param cSegments Number of segments in the list.
254 * @param cbRead The overall number of bytes to read.
255 * @param pvUser Opaque user data returned in the completion callback
256 * upon completion of the task.
257 * @param ppTask Where to store the task handle on success.
258 */
259VMMR3DECL(int) PDMR3AsyncCompletionEpRead(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
260 PCPDMDATASEG paSegments, size_t cSegments,
261 size_t cbRead, void *pvUser,
262 PPPDMASYNCCOMPLETIONTASK ppTask);
263
264/**
265 * Creates a write task on the given endpoint.
266 *
267 * @returns VBox status code.
268 * @param pEndpoint The file endpoint to write to.
269 * @param off Where to start writing at.
270 * @param paSegments Scatter gather list of the data to write.
271 * @param cSegments Number of segments in the list.
272 * @param cbWrite The overall number of bytes to write.
273 * @param pvUser Opaque user data returned in the completion callback
274 * upon completion of the task.
275 * @param ppTask Where to store the task handle on success.
276 */
277VMMR3DECL(int) PDMR3AsyncCompletionEpWrite(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
278 PCPDMDATASEG paSegments, size_t cSegments,
279 size_t cbWrite, void *pvUser,
280 PPPDMASYNCCOMPLETIONTASK ppTask);
281
282/**
283 * Creates a flush task on the given endpoint.
284 *
285 * Every read and write task initiated before the flush task is
286 * finished upon completion of this task.
287 *
288 * @returns VBox status code.
289 * @param pEndpoint The file endpoint to flush.
290 * @param pvUser Opaque user data returned in the completion callback
291 * upon completion of the task.
292 * @param ppTask Where to store the task handle on success.
293 */
294VMMR3DECL(int) PDMR3AsyncCompletionEpFlush(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
295 void *pvUser,
296 PPPDMASYNCCOMPLETIONTASK ppTask);
297
298/**
299 * Queries the size of an endpoint.
300 * Not that some endpoints may not support this and will return an error
301 * (sockets for example).
302 *
303 * @returns VBox status code.
304 * @retval VERR_NOT_SUPPORTED if the endpoint does not support this operation.
305 * @param pEndpoint The file endpoint.
306 * @param pcbSize Where to store the size of the endpoint.
307 */
308VMMR3DECL(int) PDMR3AsyncCompletionEpGetSize(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
309 uint64_t *pcbSize);
310
311/**
312 * Sets the size of an endpoint.
313 * Not that some endpoints may not support this and will return an error
314 * (sockets for example).
315 *
316 * @returns VBox status code.
317 * @retval VERR_NOT_SUPPORTED if the endpoint does not support this operation.
318 * @param pEndpoint The file endpoint.
319 * @param cbSize The size to set.
320 *
321 * @note PDMR3AsyncCompletionEpFlush should be called before this operation is executed.
322 */
323VMMR3DECL(int) PDMR3AsyncCompletionEpSetSize(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
324 uint64_t cbSize);
325
326/**
327 * Cancels a async completion task.
328 *
329 * If you want to use this method, you have to take great create to make sure
330 * you will never attempt cancel a task which has been completed. Since there is
331 * no reference counting or anything on the task it self, you have to serialize
332 * the cancelation and completion paths such that the aren't racing one another.
333 *
334 * @returns VBox status code
335 * @param pTask The Task to cancel.
336 */
337VMMR3DECL(int) PDMR3AsyncCompletionTaskCancel(PPDMASYNCCOMPLETIONTASK pTask);
338
339/** @} */
340
341RT_C_DECLS_END
342
343#endif
344
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette