VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/StatusImpl.cpp@ 4982

Last change on this file since 4982 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/** @file
2 *
3 * VBox frontends: Basic Frontend (BFE):
4 * Implementation of VMStatus class
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifdef VBOXBFE_WITHOUT_COM
20# include "COMDefs.h"
21#else
22# include <VBox/com/defs.h>
23#endif
24#include <VBox/pdm.h>
25#include <VBox/cfgm.h>
26#include <VBox/err.h>
27#include <iprt/assert.h>
28#include <VBox/log.h>
29#include <iprt/asm.h>
30#include "StatusImpl.h"
31
32// defines
33////////////////////////////////////////////////////////////////////////////////
34
35// globals
36////////////////////////////////////////////////////////////////////////////////
37
38/**
39 * The Main status driver instance data.
40 */
41typedef struct DRVMAINSTATUS
42{
43 /** The LED connectors. */
44 PDMILEDCONNECTORS ILedConnectors;
45 /** Pointer to the LED ports interface above us. */
46 PPDMILEDPORTS pLedPorts;
47 /** Pointer to the array of LED pointers. */
48 PPDMLED *papLeds;
49 /** The unit number corresponding to the first entry in the LED array. */
50 RTUINT iFirstLUN;
51 /** The unit number corresponding to the last entry in the LED array.
52 * (The size of the LED array is iLastLUN - iFirstLUN + 1.) */
53 RTUINT iLastLUN;
54} DRVMAINSTATUS, *PDRVMAINSTATUS;
55
56
57/**
58 * Notification about a unit which have been changed.
59 *
60 * The driver must discard any pointers to data owned by
61 * the unit and requery it.
62 *
63 * @param pInterface Pointer to the interface structure containing the called function pointer.
64 * @param iLUN The unit number.
65 */
66DECLCALLBACK(void) VMStatus::drvUnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN)
67{
68 PDRVMAINSTATUS pData = (PDRVMAINSTATUS)(void *)pInterface;
69 if (iLUN >= pData->iFirstLUN && iLUN <= pData->iLastLUN)
70 {
71 PPDMLED pLed;
72 int rc = pData->pLedPorts->pfnQueryStatusLed(pData->pLedPorts, iLUN, &pLed);
73 if (VBOX_FAILURE(rc))
74 pLed = NULL;
75 ASMAtomicXchgPtr((void * volatile *)&pData->papLeds[iLUN - pData->iFirstLUN], pLed);
76 Log(("drvUnitChanged: iLUN=%d pLed=%p\n", iLUN, pLed));
77 }
78}
79
80
81/**
82 * Queries an interface to the driver.
83 *
84 * @returns Pointer to interface.
85 * @returns NULL if the interface was not supported by the driver.
86 * @param pInterface Pointer to this interface structure.
87 * @param enmInterface The requested interface identification.
88 */
89DECLCALLBACK(void *) VMStatus::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
90{
91 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
92 PDRVMAINSTATUS pDrv = PDMINS2DATA(pDrvIns, PDRVMAINSTATUS);
93 switch (enmInterface)
94 {
95 case PDMINTERFACE_BASE:
96 return &pDrvIns->IBase;
97 case PDMINTERFACE_LED_CONNECTORS:
98 return &pDrv->ILedConnectors;
99 default:
100 return NULL;
101 }
102}
103
104
105/**
106 * Destruct a status driver instance.
107 *
108 * @returns VBox status.
109 * @param pDrvIns The driver instance data.
110 */
111DECLCALLBACK(void) VMStatus::drvDestruct(PPDMDRVINS pDrvIns)
112{
113 PDRVMAINSTATUS pData = PDMINS2DATA(pDrvIns, PDRVMAINSTATUS);
114 LogFlow(("VMStatus::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
115 if (pData->papLeds)
116 {
117 unsigned iLed = pData->iLastLUN - pData->iFirstLUN + 1;
118 while (iLed-- > 0)
119 ASMAtomicXchgPtr((void * volatile *)&pData->papLeds[iLed], NULL);
120 }
121}
122
123
124/**
125 * Construct a status driver instance.
126 *
127 * @returns VBox status.
128 * @param pDrvIns The driver instance data.
129 * If the registration structure is needed, pDrvIns->pDrvReg points to it.
130 * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
131 * of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
132 * iInstance it's expected to be used a bit in this function.
133 */
134DECLCALLBACK(int) VMStatus::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
135{
136 PDRVMAINSTATUS pData = PDMINS2DATA(pDrvIns, PDRVMAINSTATUS);
137 LogFlow(("VMStatus::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
138
139 /*
140 * Validate configuration.
141 */
142 if (!CFGMR3AreValuesValid(pCfgHandle, "papLeds\0First\0Last\0"))
143 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
144 PPDMIBASE pBaseIgnore;
145 int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBaseIgnore);
146 if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
147 {
148 AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
149 return VERR_PDM_DRVINS_NO_ATTACH;
150 }
151
152 /*
153 * Data.
154 */
155 pDrvIns->IBase.pfnQueryInterface = VMStatus::drvQueryInterface;
156 pData->ILedConnectors.pfnUnitChanged = VMStatus::drvUnitChanged;
157
158 /*
159 * Read config.
160 */
161 rc = CFGMR3QueryPtr(pCfgHandle, "papLeds", (void **)&pData->papLeds);
162 if (VBOX_FAILURE(rc))
163 {
164 AssertMsgFailed(("Configuration error: Failed to query the \"papLeds\" value! rc=%Vrc\n", rc));
165 return rc;
166 }
167
168 rc = CFGMR3QueryU32(pCfgHandle, "First", &pData->iFirstLUN);
169 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
170 pData->iFirstLUN = 0;
171 else if (VBOX_FAILURE(rc))
172 {
173 AssertMsgFailed(("Configuration error: Failed to query the \"First\" value! rc=%Vrc\n", rc));
174 return rc;
175 }
176
177 rc = CFGMR3QueryU32(pCfgHandle, "Last", &pData->iLastLUN);
178 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
179 pData->iLastLUN = 0;
180 else if (VBOX_FAILURE(rc))
181 {
182 AssertMsgFailed(("Configuration error: Failed to query the \"Last\" value! rc=%Vrc\n", rc));
183 return rc;
184 }
185 if (pData->iFirstLUN > pData->iLastLUN)
186 {
187 AssertMsgFailed(("Configuration error: Invalid unit range %u-%u\n", pData->iFirstLUN, pData->iLastLUN));
188 return VERR_GENERAL_FAILURE;
189 }
190
191 /*
192 * Get the ILedPorts interface of the above driver/device and
193 * query the LEDs we want.
194 */
195 pData->pLedPorts = (PPDMILEDPORTS)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_LED_PORTS);
196 if (!pData->pLedPorts)
197 {
198 AssertMsgFailed(("Configuration error: No led ports interface above!\n"));
199 return VERR_PDM_MISSING_INTERFACE_ABOVE;
200 }
201
202 for (unsigned i = pData->iFirstLUN; i <= pData->iLastLUN; i++)
203 VMStatus::drvUnitChanged(&pData->ILedConnectors, i);
204
205 return VINF_SUCCESS;
206}
207
208
209/**
210 * VMStatus driver registration record.
211 */
212const PDMDRVREG VMStatus::DrvReg =
213{
214 /* u32Version */
215 PDM_DRVREG_VERSION,
216 /* szDriverName */
217 "MainStatus",
218 /* pszDescription */
219 "Main status driver (Main as in the API).",
220 /* fFlags */
221 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
222 /* fClass. */
223 PDM_DRVREG_CLASS_STATUS,
224 /* cMaxInstances */
225 ~0,
226 /* cbInstance */
227 sizeof(DRVMAINSTATUS),
228 /* pfnConstruct */
229 VMStatus::drvConstruct,
230 /* pfnDestruct */
231 VMStatus::drvDestruct,
232 /* pfnIOCtl */
233 NULL,
234 /* pfnPowerOn */
235 NULL,
236 /* pfnReset */
237 NULL,
238 /* pfnSuspend */
239 NULL,
240 /* pfnResume */
241 NULL,
242 /* pfnDetach */
243 NULL
244};
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