VirtualBox

source: vbox/trunk/src/VBox/Devices/Samples/VBoxSampleDevice.cpp@ 86327

Last change on this file since 86327 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: VBoxSampleDevice.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBox Sample Device.
4 */
5
6/*
7 * Copyright (C) 2009-2020 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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_MISC
23#include <VBox/vmm/pdmdev.h>
24#include <VBox/version.h>
25#include <iprt/errcore.h>
26#include <VBox/log.h>
27
28#include <iprt/assert.h>
29
30
31/*********************************************************************************************************************************
32* Structures and Typedefs *
33*********************************************************************************************************************************/
34/**
35 * Device Instance Data.
36 */
37typedef struct VBOXSAMPLEDEVICE
38{
39 uint32_t Whatever;
40} VBOXSAMPLEDEVICE;
41typedef VBOXSAMPLEDEVICE *PVBOXSAMPLEDEVICE;
42
43
44
45static DECLCALLBACK(int) devSampleDestruct(PPDMDEVINS pDevIns)
46{
47 /*
48 * Check the versions here as well since the destructor is *always* called.
49 */
50 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
51
52 return VINF_SUCCESS;
53}
54
55
56static DECLCALLBACK(int) devSampleConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
57{
58 /*
59 * Check that the device instance and device helper structures are compatible.
60 */
61 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
62 NOREF(pCfg);
63
64 /*
65 * Initialize the instance data so that the destructor won't mess up.
66 */
67 PVBOXSAMPLEDEVICE pThis = PDMDEVINS_2_DATA(pDevIns, PVBOXSAMPLEDEVICE);
68 pThis->Whatever = 0;
69
70 /*
71 * Validate and read the configuration.
72 */
73 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Whatever1|Whatever2", "");
74
75 /*
76 * Use the instance number if necessary (not for this device, which in
77 * g_DeviceSample below declares a maximum instance count of 1).
78 */
79 NOREF(iInstance);
80
81 return VINF_SUCCESS;
82}
83
84
85/**
86 * The device registration structure.
87 */
88static const PDMDEVREG g_DeviceSample =
89{
90 /* .u32Version = */ PDM_DEVREG_VERSION,
91 /* .uReserved0 = */ 0,
92 /* .szName = */ "sample",
93 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
94 /* .fClass = */ PDM_DEVREG_CLASS_MISC,
95 /* .cMaxInstances = */ 1,
96 /* .uSharedVersion = */ 42,
97 /* .cbInstanceShared = */ sizeof(VBOXSAMPLEDEVICE),
98 /* .cbInstanceCC = */ 0,
99 /* .cbInstanceRC = */ 0,
100 /* .cMaxPciDevices = */ 0,
101 /* .cMaxMsixVectors = */ 0,
102 /* .pszDescription = */ "VBox Sample Device.",
103#if defined(IN_RING3)
104 /* .pszRCMod = */ "",
105 /* .pszR0Mod = */ "",
106 /* .pfnConstruct = */ devSampleConstruct,
107 /* .pfnDestruct = */ devSampleDestruct,
108 /* .pfnRelocate = */ NULL,
109 /* .pfnMemSetup = */ NULL,
110 /* .pfnPowerOn = */ NULL,
111 /* .pfnReset = */ NULL,
112 /* .pfnSuspend = */ NULL,
113 /* .pfnResume = */ NULL,
114 /* .pfnAttach = */ NULL,
115 /* .pfnDetach = */ NULL,
116 /* .pfnQueryInterface = */ NULL,
117 /* .pfnInitComplete = */ NULL,
118 /* .pfnPowerOff = */ NULL,
119 /* .pfnSoftReset = */ NULL,
120 /* .pfnReserved0 = */ NULL,
121 /* .pfnReserved1 = */ NULL,
122 /* .pfnReserved2 = */ NULL,
123 /* .pfnReserved3 = */ NULL,
124 /* .pfnReserved4 = */ NULL,
125 /* .pfnReserved5 = */ NULL,
126 /* .pfnReserved6 = */ NULL,
127 /* .pfnReserved7 = */ NULL,
128#elif defined(IN_RING0)
129 /* .pfnEarlyConstruct = */ NULL,
130 /* .pfnConstruct = */ NULL,
131 /* .pfnDestruct = */ NULL,
132 /* .pfnFinalDestruct = */ NULL,
133 /* .pfnRequest = */ NULL,
134 /* .pfnReserved0 = */ NULL,
135 /* .pfnReserved1 = */ NULL,
136 /* .pfnReserved2 = */ NULL,
137 /* .pfnReserved3 = */ NULL,
138 /* .pfnReserved4 = */ NULL,
139 /* .pfnReserved5 = */ NULL,
140 /* .pfnReserved6 = */ NULL,
141 /* .pfnReserved7 = */ NULL,
142#elif defined(IN_RC)
143 /* .pfnConstruct = */ NULL,
144 /* .pfnReserved0 = */ NULL,
145 /* .pfnReserved1 = */ NULL,
146 /* .pfnReserved2 = */ NULL,
147 /* .pfnReserved3 = */ NULL,
148 /* .pfnReserved4 = */ NULL,
149 /* .pfnReserved5 = */ NULL,
150 /* .pfnReserved6 = */ NULL,
151 /* .pfnReserved7 = */ NULL,
152#else
153# error "Not in IN_RING3, IN_RING0 or IN_RC!"
154#endif
155 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
156};
157
158
159/**
160 * Register devices provided by the plugin.
161 *
162 * @returns VBox status code.
163 * @param pCallbacks Pointer to the callback table.
164 * @param u32Version VBox version number.
165 */
166extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version)
167{
168 LogFlow(("VBoxSampleDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version));
169
170 AssertLogRelMsgReturn(u32Version >= VBOX_VERSION,
171 ("VirtualBox version %#x, expected %#x or higher\n", u32Version, VBOX_VERSION),
172 VERR_VERSION_MISMATCH);
173 AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION,
174 ("callback version %#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION),
175 VERR_VERSION_MISMATCH);
176
177 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);
178}
179
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