Changeset 69067 in vbox for trunk/src/VBox/Devices/Samples
- Timestamp:
- Oct 13, 2017 8:41:13 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 118349
- Location:
- trunk/src/VBox/Devices/Samples
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Samples/DevPlayground.cpp
r67579 r69067 8 8 * 9 9 * To enable this device for a particular VM: 10 * VBoxManage setextradata vmname VBoxInternal/PDM/Devices/playground/Path .../obj/VBox SampleDevice/VBoxSampleDevice10 * VBoxManage setextradata vmname VBoxInternal/PDM/Devices/playground/Path .../obj/VBoxPlaygroundDevice/VBoxPlaygroundDevice 11 11 * VBoxManage setextradata vmname VBoxInternal/Devices/playground/0/Config/Whatever1 0 12 12 */ 13 13 14 14 /* 15 * Copyright (C) 2009-201 6Oracle Corporation15 * Copyright (C) 2009-2017 Oracle Corporation 16 16 * 17 17 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 #include <VBox/err.h> 34 34 #include <VBox/log.h> 35 36 #include <VBox/com/assert.h> 37 #include <VBox/com/defs.h> 38 #include <VBox/com/string.h> 39 #include <VBox/com/Guid.h> 40 #include <VBox/com/VirtualBox.h> 35 41 36 42 #include <iprt/assert.h> … … 67 73 68 74 75 #define PLAYGROUND_SSM_VERSION 3 76 77 69 78 /********************************************************************************************************************************* 70 79 * Device Functions * … … 119 128 120 129 /** 121 * @interface_method_impl{PDMDEVREG,pfnDestruct} 122 */ 123 static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns) 124 { 125 /* 126 * Check the versions here as well since the destructor is *always* called. 127 */ 128 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); 130 * @callback_method_impl{FNSSMDEVSAVEEXEC} 131 */ 132 static DECLCALLBACK(int) devPlaygroundSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 133 { 134 PVBOXPLAYGROUNDDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE); 135 136 /* dummy (real devices would need to save their state here) */ 137 RT_NOREF(pThis); 138 139 /* Demo of some API stuff - very unusual, think twice if there's no better 140 * solution which doesn't need API interaction. */ 141 HRESULT hrc = S_OK; 142 com::Bstr bstrSnapName; 143 com::Guid uuid(COM_IIDOF(ISnapshot)); 144 ISnapshot *pSnap = (ISnapshot *)PDMDevHlpQueryGenericUserObject(pDevIns, uuid.raw()); 145 if (pSnap) 146 { 147 hrc = pSnap->COMGETTER(Name)(bstrSnapName.asOutParam()); 148 AssertComRCReturn(hrc, VERR_INVALID_STATE); 149 } 150 com::Utf8Str strSnapName(bstrSnapName); 151 SSMR3PutStrZ(pSSM, strSnapName.c_str()); 152 LogRel(("Playground: saving state of snapshot '%s', hrc=%Rhrc\n", strSnapName.c_str(), hrc)); 153 154 return VINF_SUCCESS; 155 } 156 157 /** 158 * @callback_method_impl{FNSSMDEVLOADEXEC} 159 */ 160 static DECLCALLBACK(int) devPlaygroundLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 161 { 162 PVBOXPLAYGROUNDDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE); 163 164 if (uVersion > PLAYGROUND_SSM_VERSION) 165 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION; 166 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass); 167 168 /* dummy (real devices would need to load their state here) */ 169 RT_NOREF(pThis); 170 171 /* Reading the stuff written to saved state, just a demo. */ 172 char szSnapName[256]; 173 int rc = SSMR3GetStrZ(pSSM, szSnapName, sizeof(szSnapName)); 174 AssertRCReturn(rc, rc); 175 LogRel(("Playground: loading state of snapshot '%s'\n", szSnapName)); 129 176 130 177 return VINF_SUCCESS; … … 138 185 { 139 186 RT_NOREF(iInstance, pCfg); 187 int rc = VINF_SUCCESS; 140 188 141 189 /* … … 171 219 PCIDevSetHeaderType(&pFun->PciDev, 0x80); /* normal, multifunction device */ 172 220 173 intrc = PDMDevHlpPCIRegisterEx(pDevIns, &pFun->PciDev, iPciFun, 0 /*fFlags*/, iPciDevNo, iPciFun,221 rc = PDMDevHlpPCIRegisterEx(pDevIns, &pFun->PciDev, iPciFun, 0 /*fFlags*/, iPciDevNo, iPciFun, 174 222 pThis->aPciFuns[iPciFun].szName); 175 223 AssertLogRelRCReturn(rc, rc); 176 224 177 225 /* First region. */ 178 RTGCPHYS const cbFirst = iPciFun == 0 ? 8*_1 G64: iPciFun * _4K;226 RTGCPHYS const cbFirst = iPciFun == 0 ? 8*_1M : iPciFun * _4K; 179 227 rc = PDMDevHlpPCIIORegionRegisterEx(pDevIns, &pFun->PciDev, 0, cbFirst, 180 228 (PCIADDRESSSPACE)( PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64 … … 193 241 194 242 /* Second region. */ 195 RTGCPHYS const cbSecond = iPciFun == 0 ? 256*_1G64: iPciFun * _32K;243 RTGCPHYS const cbSecond = iPciFun == 0 ? 32*_1M : iPciFun * _32K; 196 244 rc = PDMDevHlpPCIIORegionRegisterEx(pDevIns, &pFun->PciDev, 2, cbSecond, 197 245 (PCIADDRESSSPACE)( PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64 … … 213 261 } 214 262 215 return VINF_SUCCESS; 216 } 217 218 RT_C_DECLS_BEGIN 219 extern const PDMDEVREG g_DevicePlayground; 220 RT_C_DECLS_END 263 /* 264 * Save state handling. 265 */ 266 rc = PDMDevHlpSSMRegister(pDevIns, PLAYGROUND_SSM_VERSION, sizeof(*pThis), devPlaygroundSaveExec, devPlaygroundLoadExec); 267 if (RT_FAILURE(rc)) 268 return rc; 269 270 return VINF_SUCCESS; 271 } 272 273 274 /** 275 * @interface_method_impl{PDMDEVREG,pfnDestruct} 276 */ 277 static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns) 278 { 279 /* 280 * Check the versions here as well since the destructor is *always* called. 281 */ 282 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); 283 284 return VINF_SUCCESS; 285 } 286 221 287 222 288 /** 223 289 * The device registration structure. 224 290 */ 225 const PDMDEVREG g_DevicePlayground =291 static const PDMDEVREG g_DevicePlayground = 226 292 { 227 293 /* u32Version */ … … 274 340 PDM_DEVREG_VERSION 275 341 }; 342 343 344 /** 345 * Register devices provided by the plugin. 346 * 347 * @returns VBox status code. 348 * @param pCallbacks Pointer to the callback table. 349 * @param u32Version VBox version number. 350 */ 351 extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version) 352 { 353 LogFlow(("VBoxPlaygroundDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version)); 354 355 AssertLogRelMsgReturn(u32Version >= VBOX_VERSION, 356 ("VirtualBox version %#x, expected %#x or higher\n", u32Version, VBOX_VERSION), 357 VERR_VERSION_MISMATCH); 358 AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION, 359 ("callback version %#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION), 360 VERR_VERSION_MISMATCH); 361 362 return pCallbacks->pfnRegister(pCallbacks, &g_DevicePlayground); 363 } 364 -
trunk/src/VBox/Devices/Samples/Makefile.kmk
r63885 r69067 5 5 6 6 # 7 # Copyright (C) 2009-201 6Oracle Corporation7 # Copyright (C) 2009-2017 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 26 26 VBoxSampleDevice_TEMPLATE = VBOXR3 27 27 VBoxSampleDevice_SOURCES = \ 28 VBoxSampleDevice.cpp \ 29 DevPlayground.cpp 28 VBoxSampleDevice.cpp 30 29 VBoxSampleDevice_LIBS = \ 31 30 $(LIB_RUNTIME) \ 32 $(LIB_VMM) \ 33 $(LIB_REM) 31 $(LIB_VMM) 34 32 35 33 # … … 42 40 VBoxSampleDriver_LIBS = \ 43 41 $(LIB_RUNTIME) \ 44 $(LIB_VMM) \ 45 $(LIB_REM) 42 $(LIB_VMM) 43 44 45 # 46 # VBoxPlaygroundDevice - A device module demonstrating some unusual features. 47 # 48 DLLS += VBoxPlaygroundDevice 49 VBoxPlaygroundDevice_TEMPLATE = VBOXR3 50 VBoxPlaygroundDevice_SOURCES = \ 51 DevPlayground.cpp 52 VBoxPlaygroundDevice_LIBS = \ 53 $(PATH_STAGE_LIB)/VBoxCOM$(VBOX_SUFF_LIB) \ 54 $(LIB_RUNTIME) \ 55 $(LIB_VMM) 56 57 ifdef VBOX_WITH_XPCOM 58 ## @todo may be worth creating the VBOX_XPCOM SDK def, or just a SDK_VBOXXPCOM. 59 VBoxPlaygroundDevice_DEFS += VBOX_WITH_XPCOM 60 ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 61 VBoxPlaygroundDevice_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 62 endif 63 VBoxPlaygroundDevice_INCS += \ 64 $(VBOX_XPCOM_INCS) 65 VBoxPlaygroundDevice_INTERMEDIATES += \ 66 $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h 67 VBoxPlaygroundDevice_LIBS += \ 68 $(LIB_XPCOM) 69 else # COM 70 VBoxPlaygroundDevice_INCS += \ 71 $(VBOX_PATH_SDK)/bindings/mscom/include 72 VBoxPlaygroundDevice_INTERMEDIATES += \ 73 $(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h 74 endif # COM 75 46 76 47 77 include $(FILE_KBUILD_SUB_FOOTER) -
trunk/src/VBox/Devices/Samples/VBoxSampleDevice.cpp
r63911 r69067 158 158 VERR_VERSION_MISMATCH); 159 159 160 /* Two devices in this module. */ 161 extern const PDMDEVREG g_DevicePlayground; 162 int rc = pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample); 163 if (RT_SUCCESS(rc)) 164 rc = pCallbacks->pfnRegister(pCallbacks, &g_DevicePlayground); 165 return rc; 160 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample); 166 161 } 167 162
Note:
See TracChangeset
for help on using the changeset viewer.