VirtualBox

root/trunk/include/VBox/hgcmsvc.h

Revision 13890, 8.6 kB (checked in by vboxsync, 2 weeks ago)

hgcmsvc.h: copy and paste typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /** @file
2  * VBox - Host-Guest Communication Manager (HGCM):
3  * Service library definitions.
4  */
5
6 /*
7  * Copyright (C) 2006-2007 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_hgcm_h
32 #define ___VBox_hgcm_h
33
34 #include <VBox/cdefs.h>
35 #include <VBox/types.h>
36 #include <VBox/err.h>
37
38 /** @todo proper comments. */
39
40 /**
41  * Service interface version.
42  *
43  * Includes layout of both VBOXHGCMSVCFNTABLE and VBOXHGCMSVCHELPERS.
44  *
45  * A service can work with these structures if major version
46  * is equal and minor version of service is <= version of the
47  * structures.
48  *
49  * For example when a new helper is added at the end of helpers
50  * structure, then the minor version will be increased. All older
51  * services still can work because they have their old helpers
52  * unchanged.
53  *
54  * Revision history.
55  * 1.1->2.1 Because the pfnConnect now also has the pvClient parameter.
56  * 2.1->2.2 Because pfnSaveState and pfnLoadState were added
57  * 2.2->3.1 Because pfnHostCall is now synchronous, returns rc, and parameters were changed
58  * 3.1->3.2 Because pfnRegisterExtension was added
59  * 3.2->3.3 Because pfnDisconnectClient helper was added
60  * 3.3->4.1 Because the pvService entry and parameter was added
61  */
62 #define VBOX_HGCM_SVC_VERSION_MAJOR (0x0004)
63 #define VBOX_HGCM_SVC_VERSION_MINOR (0x0001)
64 #define VBOX_HGCM_SVC_VERSION ((VBOX_HGCM_SVC_VERSION_MAJOR << 16) + VBOX_HGCM_SVC_VERSION_MINOR)
65
66
67 /** Typed pointer to distinguish a call to service. */
68 struct VBOXHGCMCALLHANDLE_TYPEDEF;
69 typedef struct VBOXHGCMCALLHANDLE_TYPEDEF *VBOXHGCMCALLHANDLE;
70
71 /** Service helpers pointers table. */
72 typedef struct _VBOXHGCMSVCHELPERS
73 {
74     /** The service has processed the Call request. */
75     DECLR3CALLBACKMEMBER(void, pfnCallComplete, (VBOXHGCMCALLHANDLE callHandle, int32_t rc));
76
77     void *pvInstance;
78
79     /** The service disconnects the client. */
80     DECLR3CALLBACKMEMBER(void, pfnDisconnectClient, (void *pvInstance, uint32_t u32ClientID));
81 } VBOXHGCMSVCHELPERS;
82
83 typedef VBOXHGCMSVCHELPERS *PVBOXHGCMSVCHELPERS;
84
85
86 #define VBOX_HGCM_SVC_PARM_INVALID (0U)
87 #define VBOX_HGCM_SVC_PARM_32BIT (1U)
88 #define VBOX_HGCM_SVC_PARM_64BIT (2U)
89 #define VBOX_HGCM_SVC_PARM_PTR   (3U)
90
91 typedef struct VBOXHGCMSVCPARM
92 {
93     /** VBOX_HGCM_SVC_PARM_* values. */
94     uint32_t type;
95
96     union
97     {
98         uint32_t uint32;
99         uint64_t uint64;
100         struct
101         {
102             uint32_t size;
103             void *addr;
104         } pointer;
105     } u;
106 #ifdef __cplusplus
107     /** Extract a uint32_t value from an HGCM parameter structure */
108     int getUInt32 (uint32_t *u32)
109     {
110         int rc = VINF_SUCCESS;
111         if (type != VBOX_HGCM_SVC_PARM_32BIT)
112             rc = VERR_INVALID_PARAMETER;
113         if (RT_SUCCESS(rc))
114             *u32 = u.uint32;
115         return rc;
116     }
117
118     /** Extract a uint64_t value from an HGCM parameter structure */
119     int getUInt64 (uint64_t *u64)
120     {
121         int rc = VINF_SUCCESS;
122         if (type != VBOX_HGCM_SVC_PARM_64BIT)
123             rc = VERR_INVALID_PARAMETER;
124         if (RT_SUCCESS(rc))
125             *u64 = u.uint64;
126         return rc;
127     }
128
129     /** Extract a pointer value from an HGCM parameter structure */
130     int getPointer (void **ppv, uint32_t *pcb)
131     {
132         if (type == VBOX_HGCM_SVC_PARM_PTR)
133         {
134             *ppv = u.pointer.addr;
135             *pcb = u.pointer.size;
136             return VINF_SUCCESS;
137         }
138
139         return VERR_INVALID_PARAMETER;
140     }
141
142     /** Extract a constant pointer value from an HGCM parameter structure */
143     int getPointer (const void **ppv, uint32_t *pcb)
144     {
145         if (type == VBOX_HGCM_SVC_PARM_PTR)
146         {
147             *ppv = u.pointer.addr;
148             *pcb = u.pointer.size;
149             return VINF_SUCCESS;
150         }
151
152         return VERR_INVALID_PARAMETER;
153     }
154
155     /** Set a uint32_t value to an HGCM parameter structure */
156     void setUInt32(uint32_t u32)
157     {
158         type = VBOX_HGCM_SVC_PARM_32BIT;
159         u.uint32 = u32;
160     }
161
162     /** Set a uint64_t value to an HGCM parameter structure */
163     void setUInt64(uint64_t u64)
164     {
165         type = VBOX_HGCM_SVC_PARM_64BIT;
166         u.uint64 = u64;
167     }
168
169     /** Set a pointer value to an HGCM parameter structure */
170     void setPointer(void *pv, uint32_t cb)
171     {
172         type = VBOX_HGCM_SVC_PARM_PTR;
173         u.pointer.addr = pv;
174         u.pointer.size = cb;
175     }
176
177     VBOXHGCMSVCPARM() : type(VBOX_HGCM_SVC_PARM_INVALID) {}
178 #endif
179 } VBOXHGCMSVCPARM;
180
181 typedef VBOXHGCMSVCPARM *PVBOXHGCMSVCPARM;
182
183 /** Service specific extension callback.
184  *  This callback is called by the service to perform service specific operation.
185  * 
186  * @param pvExtension The extension pointer.
187  * @param u32Function What the callback is supposed to do.
188  * @param pvParm      The function parameters.
189  * @param cbParm      The size of the function parameters.
190  */
191 typedef DECLCALLBACK(int) FNHGCMSVCEXT(void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
192 typedef FNHGCMSVCEXT *PFNHGCMSVCEXT;
193
194 /** The Service DLL entry points.
195  *
196  *  HGCM will call the DLL "VBoxHGCMSvcLoad"
197  *  function and the DLL must fill in the VBOXHGCMSVCFNTABLE
198  *  with function pointers.
199  */
200
201 /* The structure is used in separately compiled binaries so an explicit packing is required. */
202 #pragma pack(1)
203 typedef struct _VBOXHGCMSVCFNTABLE
204 {
205     /** Filled by HGCM */
206
207     /** Size of the structure. */
208     uint32_t                 cbSize;
209
210     /** Version of the structure, including the helpers. */
211     uint32_t                 u32Version;
212
213     PVBOXHGCMSVCHELPERS      pHelpers;
214
215     /** Filled by the service. */
216
217     /** Size of client information the service want to have. */
218     uint32_t                 cbClient;
219 #if ARCH_BITS == 64
220     /** Ensure that the following pointers are properly aligned on 64-bit system. */
221     uint32_t                 u32Alignment0;
222 #endif
223
224     /** Uninitialize service */
225     DECLR3CALLBACKMEMBER(int, pfnUnload, (void *pvService));
226
227     /** Inform the service about a client connection. */
228     DECLR3CALLBACKMEMBER(int, pfnConnect, (void *pvService, uint32_t u32ClientID, void *pvClient));
229
230     /** Inform the service that the client wants to disconnect. */
231     DECLR3CALLBACKMEMBER(int, pfnDisconnect, (void *pvService, uint32_t u32ClientID, void *pvClient));
232
233     /** Service entry point.
234      *  Return code is passed to pfnCallComplete callback.
235      */
236     DECLR3CALLBACKMEMBER(void, pfnCall, (void *pvService, VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]));
237
238     /** Host Service entry point meant for privileged features invisible to the guest.
239      *  Return code is passed to pfnCallComplete callback.
240      */
241     DECLR3CALLBACKMEMBER(int, pfnHostCall, (void *pvService, uint32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]));
242  
243     /** Inform the service about a VM save operation. */
244     DECLR3CALLBACKMEMBER(int, pfnSaveState, (void *pvService, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM));
245
246     /** Inform the service about a VM load operation. */
247     DECLR3CALLBACKMEMBER(int, pfnLoadState, (void *pvService, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM));
248
249     /** Register a service extension callback. */
250     DECLR3CALLBACKMEMBER(int, pfnRegisterExtension, (void *pvService, PFNHGCMSVCEXT pfnExtension, void *pvExtension));
251
252     /** User/instance data pointer for the service. */
253     void *pvService;
254
255 } VBOXHGCMSVCFNTABLE;
256 #pragma pack()
257
258
259 /** Service initialization entry point. */
260 typedef DECLCALLBACK(int) VBOXHGCMSVCLOAD(VBOXHGCMSVCFNTABLE *ptable);
261 typedef VBOXHGCMSVCLOAD *PFNVBOXHGCMSVCLOAD;
262 #define VBOX_HGCM_SVCLOAD_NAME "VBoxHGCMSvcLoad"
263
264 #endif
Note: See TracBrowser for help on using the browser.

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy