VirtualBox

source: vbox/trunk/src/VBox/Storage/testcase/VDScript.h@ 78327

Last change on this file since 78327 was 76578, checked in by vboxsync, 6 years ago

Storage: scm --guard-relative-to-dir {parent}

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/** @file
2 *
3 * VBox HDD container test utility - scripting engine.
4 */
5
6/*
7 * Copyright (C) 2013-2019 Oracle Corporation
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
18#ifndef VBOX_INCLUDED_SRC_testcase_VDScript_h
19#define VBOX_INCLUDED_SRC_testcase_VDScript_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/** Handle to the scripting context. */
25typedef struct VDSCRIPTCTXINT *VDSCRIPTCTX;
26/** Pointer to a scripting context handle. */
27typedef VDSCRIPTCTX *PVDSCRIPTCTX;
28
29/**
30 * Supprted primitive types in the scripting engine.
31 */
32typedef enum VDSCRIPTTYPE
33{
34 /** Invalid type, do not use. */
35 VDSCRIPTTYPE_INVALID = 0,
36 /** void type, used for no return value of methods. */
37 VDSCRIPTTYPE_VOID,
38 /** unsigned 8bit integer. */
39 VDSCRIPTTYPE_UINT8,
40 VDSCRIPTTYPE_INT8,
41 VDSCRIPTTYPE_UINT16,
42 VDSCRIPTTYPE_INT16,
43 VDSCRIPTTYPE_UINT32,
44 VDSCRIPTTYPE_INT32,
45 VDSCRIPTTYPE_UINT64,
46 VDSCRIPTTYPE_INT64,
47 VDSCRIPTTYPE_STRING,
48 VDSCRIPTTYPE_BOOL,
49 VDSCRIPTTYPE_POINTER,
50 /** As usual, the 32bit blowup hack. */
51 VDSCRIPTTYPE_32BIT_HACK = 0x7fffffff
52} VDSCRIPTTYPE;
53/** Pointer to a type. */
54typedef VDSCRIPTTYPE *PVDSCRIPTTYPE;
55/** Pointer to a const type. */
56typedef const VDSCRIPTTYPE *PCVDSCRIPTTYPE;
57
58/**
59 * Script argument.
60 */
61typedef struct VDSCRIPTARG
62{
63 /** Type of the argument. */
64 VDSCRIPTTYPE enmType;
65 /** Value */
66 union
67 {
68 uint8_t u8;
69 int8_t i8;
70 uint16_t u16;
71 int16_t i16;
72 uint32_t u32;
73 int32_t i32;
74 uint64_t u64;
75 int64_t i64;
76 const char *psz;
77 bool f;
78 void *p;
79 };
80} VDSCRIPTARG;
81/** Pointer to an argument. */
82typedef VDSCRIPTARG *PVDSCRIPTARG;
83
84/** Script callback. */
85typedef DECLCALLBACK(int) FNVDSCRIPTCALLBACK(PVDSCRIPTARG paScriptArgs, void *pvUser);
86/** Pointer to a script callback. */
87typedef FNVDSCRIPTCALLBACK *PFNVDSCRIPTCALLBACK;
88
89/**
90 * Callback registration structure.
91 */
92typedef struct VDSCRIPTCALLBACK
93{
94 /** The function name. */
95 const char *pszFnName;
96 /** The return type of the function. */
97 VDSCRIPTTYPE enmTypeReturn;
98 /** Pointer to the array of argument types. */
99 PCVDSCRIPTTYPE paArgs;
100 /** Number of arguments this method takes. */
101 unsigned cArgs;
102 /** The callback handler. */
103 PFNVDSCRIPTCALLBACK pfnCallback;
104} VDSCRIPTCALLBACK;
105/** Pointer to a callback register entry. */
106typedef VDSCRIPTCALLBACK *PVDSCRIPTCALLBACK;
107/** Pointer to a const callback register entry. */
108typedef const VDSCRIPTCALLBACK *PCVDSCRIPTCALLBACK;
109
110/**
111 * @{
112 */
113/** The address space stays assigned to a variable
114 * even if the pointer is casted to another type.
115 */
116#define VDSCRIPT_AS_FLAGS_TRANSITIVE RT_BIT(0)
117/** @} */
118
119/**
120 * Address space read callback
121 *
122 * @returns VBox status code.
123 * @param pvUser Opaque user data given on registration.
124 * @param Address The address to read from, address is stored in the member for
125 * base type given on registration.
126 * @param pvBuf Where to store the read bits.
127 * @param cbRead How much to read.
128 */
129typedef DECLCALLBACK(int) FNVDSCRIPTASREAD(void *pvUser, VDSCRIPTARG Address, void *pvBuf, size_t cbRead);
130/** Pointer to a read callback. */
131typedef FNVDSCRIPTASREAD *PFNVDSCRIPTASREAD;
132
133/**
134 * Address space write callback
135 *
136 * @returns VBox status code.
137 * @param pvUser Opaque user data given on registration.
138 * @param Address The address to write to, address is stored in the member for
139 * base type given on registration.
140 * @param pvBuf Data to write.
141 * @param cbWrite How much to write.
142 */
143typedef DECLCALLBACK(int) FNVDSCRIPTASWRITE(void *pvUser, VDSCRIPTARG Address, const void *pvBuf, size_t cbWrite);
144/** Pointer to a write callback. */
145typedef FNVDSCRIPTASWRITE *PFNVDSCRIPTASWRITE;
146
147/**
148 * Create a new scripting context.
149 *
150 * @returns VBox status code.
151 * @param phScriptCtx Where to store the scripting context on success.
152 */
153DECLHIDDEN(int) VDScriptCtxCreate(PVDSCRIPTCTX phScriptCtx);
154
155/**
156 * Destroys the given scripting context.
157 *
158 * @returns nothing.
159 * @param hScriptCtx The script context to destroy.
160 */
161DECLHIDDEN(void) VDScriptCtxDestroy(VDSCRIPTCTX hScriptCtx);
162
163/**
164 * Register callbacks for the scripting context.
165 *
166 * @returns VBox status code.
167 * @param hScriptCtx The script context handle.
168 * @param paCallbacks Pointer to the callbacks to register.
169 * @param cCallbacks Number of callbacks in the array.
170 * @param pvUser Opaque user data to pass on the callback invocation.
171 */
172DECLHIDDEN(int) VDScriptCtxCallbacksRegister(VDSCRIPTCTX hScriptCtx, PCVDSCRIPTCALLBACK paCallbacks,
173 unsigned cCallbacks, void *pvUser);
174
175/**
176 * Load a given script into the context.
177 *
178 * @returns VBox status code.
179 * @param hScriptCtx The script context handle.
180 * @param pszScript Pointer to the char buffer containing the script.
181 */
182DECLHIDDEN(int) VDScriptCtxLoadScript(VDSCRIPTCTX hScriptCtx, const char *pszScript);
183
184/**
185 * Execute a given method in the script context.
186 *
187 * @returns VBox status code.
188 * @param hScriptCtx The script context handle.
189 * @param pszFnCall The method to call.
190 * @param paArgs Pointer to arguments to pass.
191 * @param cArgs Number of arguments.
192 */
193DECLHIDDEN(int) VDScriptCtxCallFn(VDSCRIPTCTX hScriptCtx, const char *pszFnCall,
194 PVDSCRIPTARG paArgs, unsigned cArgs);
195
196/**
197 * Registers a new address space provider.
198 *
199 * @returns VBox status code.
200 * @param hScriptCtx The script context handle.
201 * @param pszType The type string.
202 * @param enmBaseType The base integer type to use for the address space.
203 * Bool and String are not supported of course.
204 * @param pfnRead The read callback for the registered address space.
205 * @param pfnWrite The write callback for the registered address space.
206 * @param pvUser Opaque user data to pass to the read and write callbacks.
207 * @param fFlags Flags, see VDSCRIPT_AS_FLAGS_*.
208 *
209 * @note This will automatically register a new type with the identifier given in pszType
210 * used for the pointer. Every variable with this type is automatically treated as a pointer.
211 *
212 * @note If the transitive flag is set the address space stays assigned even if the pointer value
213 * is casted to another pointer type.
214 * In the following example the pointer pStruct will use the registered address space for RTGCPHYS
215 * and dereferencing the pointer causes the read/write callbacks to be triggered.
216 *
217 * ...
218 * Struct *pStruct = (Struct *)(RTGCPHYS)0x12345678;
219 * pStruct->count++;
220 * ...
221 */
222DECLHIDDEN(int) VDScriptCtxAsRegister(VDSCRIPTCTX hScriptCtx, const char *pszType, VDSCRIPTTYPE enmBaseType,
223 PFNVDSCRIPTASREAD pfnRead, PFNVDSCRIPTASWRITE pfnWrite, void *pvUser,
224 uint32_t fFlags);
225
226#endif /* !VBOX_INCLUDED_SRC_testcase_VDScript_h */
Note: See TracBrowser for help on using the repository browser.

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