VirtualBox

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

最後變更 在這個檔案從25971是 25966,由 vboxsync 提交於 15 年 前

PDMIBASE refactoring; use UUID as interface IDs.

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

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