VirtualBox

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

Last change on this file since 44528 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: StatusImpl.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
2/** @file
3 * VBox frontends: Basic Frontend (BFE):
4 * Implementation of VMStatus class
5 */
6
7/*
8 * Copyright (C) 2006-2012 Oracle Corporation
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
19#ifdef VBOXBFE_WITHOUT_COM
20# include "COMDefs.h"
21#else
22# include <VBox/com/defs.h>
23#endif
24#include <VBox/vmm/pdm.h>
25#include <VBox/vmm/cfgm.h>
26#include <VBox/err.h>
27#include <iprt/assert.h>
28#include <VBox/log.h>
29#include <iprt/asm.h>
30#include <iprt/uuid.h>
31#include "StatusImpl.h"
32
33// defines
34////////////////////////////////////////////////////////////////////////////////
35
36// globals
37////////////////////////////////////////////////////////////////////////////////
38
39/**
40 * The Main status driver instance data.
41 */
42typedef struct DRVMAINSTATUS
43{
44 /** The LED connectors. */
45 PDMILEDCONNECTORS ILedConnectors;
46 /** Pointer to the LED ports interface above us. */
47 PPDMILEDPORTS pLedPorts;
48 /** Pointer to the array of LED pointers. */
49 PPDMLED *papLeds;
50 /** The unit number corresponding to the first entry in the LED array. */
51 RTUINT iFirstLUN;
52 /** The unit number corresponding to the last entry in the LED array.
53 * (The size of the LED array is iLastLUN - iFirstLUN + 1.) */
54 RTUINT iLastLUN;
55} DRVMAINSTATUS, *PDRVMAINSTATUS;
56
57
58/**
59 * Notification about a unit which have been changed.
60 *
61 * The driver must discard any pointers to data owned by
62 * the unit and requery it.
63 *
64 * @param pInterface Pointer to the interface structure containing the called function pointer.
65 * @param iLUN The unit number.
66 */
67DECLCALLBACK(void) VMStatus::drvUnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN)
68{
69 PDRVMAINSTATUS pData = (PDRVMAINSTATUS)(void *)pInterface;
70 if (iLUN >= pData->iFirstLUN && iLUN <= pData->iLastLUN)
71 {
72 PPDMLED pLed;
73 int rc = pData->pLedPorts->pfnQueryStatusLed(pData->pLedPorts, iLUN, &pLed);
74 if (RT_FAILURE(rc))
75 pLed = NULL;
76 ASMAtomicXchgPtr((void * volatile *)&pData->papLeds[iLUN - pData->iFirstLUN], pLed);
77 Log(("drvUnitChanged: iLUN=%d pLed=%p\n", iLUN, pLed));
78 }
79}
80
81
82/**
83 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
84 */
85DECLCALLBACK(void *) VMStatus::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
86{
87 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
88 PDRVMAINSTATUS pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINSTATUS);
89 if (RTUuidCompare2Strs(pszIID, PDMIBASE_IID) == 0)
90 return &pDrvIns->IBase;
91 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDCONNECTORS, &pDrv->ILedConnectors);
92 return NULL;
93}
94
95
96/**
97 * Destruct a status driver instance.
98 *
99 * @returns VBox status.
100 * @param pDrvIns The driver instance data.
101 */
102DECLCALLBACK(void) VMStatus::drvDestruct(PPDMDRVINS pDrvIns)
103{
104 PDRVMAINSTATUS pData = PDMINS_2_DATA(pDrvIns, PDRVMAINSTATUS);
105 LogFlow(("VMStatus::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
106 if (pData->papLeds)
107 {
108 unsigned iLed = pData->iLastLUN - pData->iFirstLUN + 1;
109 while (iLed-- > 0)
110 ASMAtomicXchgPtr((void * volatile *)&pData->papLeds[iLed], NULL);
111 }
112}
113
114
115/**
116 * Construct a status driver instance.
117 *
118 * @copydoc FNPDMDRVCONSTRUCT
119 */
120DECLCALLBACK(int) VMStatus::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
121{
122 PDRVMAINSTATUS pData = PDMINS_2_DATA(pDrvIns, PDRVMAINSTATUS);
123 LogFlow(("VMStatus::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
124
125 /*
126 * Validate configuration.
127 */
128 if (!CFGMR3AreValuesValid(pCfg, "papLeds\0First\0Last\0"))
129 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
130 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
131 ("Configuration error: Not possible to attach anything to this driver!\n"),
132 VERR_PDM_DRVINS_NO_ATTACH);
133
134 /*
135 * Data.
136 */
137 pDrvIns->IBase.pfnQueryInterface = VMStatus::drvQueryInterface;
138 pData->ILedConnectors.pfnUnitChanged = VMStatus::drvUnitChanged;
139
140 /*
141 * Read config.
142 */
143 int rc = CFGMR3QueryPtr(pCfg, "papLeds", (void **)&pData->papLeds);
144 if (RT_FAILURE(rc))
145 {
146 AssertMsgFailed(("Configuration error: Failed to query the \"papLeds\" value! rc=%Rrc\n", rc));
147 return rc;
148 }
149
150 rc = CFGMR3QueryU32(pCfg, "First", &pData->iFirstLUN);
151 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
152 pData->iFirstLUN = 0;
153 else if (RT_FAILURE(rc))
154 {
155 AssertMsgFailed(("Configuration error: Failed to query the \"First\" value! rc=%Rrc\n", rc));
156 return rc;
157 }
158
159 rc = CFGMR3QueryU32(pCfg, "Last", &pData->iLastLUN);
160 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
161 pData->iLastLUN = 0;
162 else if (RT_FAILURE(rc))
163 {
164 AssertMsgFailed(("Configuration error: Failed to query the \"Last\" value! rc=%Rrc\n", rc));
165 return rc;
166 }
167 if (pData->iFirstLUN > pData->iLastLUN)
168 {
169 AssertMsgFailed(("Configuration error: Invalid unit range %u-%u\n", pData->iFirstLUN, pData->iLastLUN));
170 return VERR_GENERAL_FAILURE;
171 }
172
173 /*
174 * Get the ILedPorts interface of the above driver/device and
175 * query the LEDs we want.
176 */
177 pData->pLedPorts = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
178 AssertMsgReturn(pData->pLedPorts, ("Configuration error: No led ports interface above!\n"),
179 VERR_PDM_MISSING_INTERFACE_ABOVE);
180
181 for (unsigned i = pData->iFirstLUN; i <= pData->iLastLUN; i++)
182 VMStatus::drvUnitChanged(&pData->ILedConnectors, i);
183
184 return VINF_SUCCESS;
185}
186
187
188/**
189 * VMStatus driver registration record.
190 */
191const PDMDRVREG VMStatus::DrvReg =
192{
193 /* u32Version */
194 PDM_DRVREG_VERSION,
195 /* szName */
196 "MainStatus",
197 /* szRCMod */
198 "",
199 /* szR0Mod */
200 "",
201 /* pszDescription */
202 "Main status driver (Main as in the API).",
203 /* fFlags */
204 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
205 /* fClass. */
206 PDM_DRVREG_CLASS_STATUS,
207 /* cMaxInstances */
208 ~0U,
209 /* cbInstance */
210 sizeof(DRVMAINSTATUS),
211 /* pfnConstruct */
212 VMStatus::drvConstruct,
213 /* pfnDestruct */
214 VMStatus::drvDestruct,
215 /* pfnRelocate */
216 NULL,
217 /* pfnIOCtl */
218 NULL,
219 /* pfnPowerOn */
220 NULL,
221 /* pfnReset */
222 NULL,
223 /* pfnSuspend */
224 NULL,
225 /* pfnResume */
226 NULL,
227 /* pfnAttach */
228 NULL,
229 /* pfnDetach */
230 NULL,
231 /* pfnPowerOff */
232 NULL,
233 /* pfnSoftReset */
234 NULL,
235 /* u32EndVersion */
236 PDM_DRVREG_VERSION
237};
238
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