VirtualBox

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

Last change on this file since 14647 was 13837, checked in by vboxsync, 16 years ago

s/%Vr\([acfs]\)/%Rr\1/g - since I'm upsetting everyone anyway, better make the most of it...

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