static void testInit(RTTEST hTest) { RTTestSub(hTest, "Testing USBProxyLinuxChooseMethod"); for (unsigned i = 0; i < RT_ELEMENTS(s_testEnvironment); ++i) { bool fUsingUsbfs = true; const char *pcszDevicesRoot = ""; TestUSBSetEnv(s_testEnvironment[i].pcszEnvUsb, s_testEnvironment[i].pcszEnvUsbRoot); TestUSBSetupInit(s_testEnvironment[i].pcszUsbfsRoot, s_testEnvironment[i].fUsbfsAccessible, s_testEnvironment[i].pcszDevicesRoot, s_testEnvironment[i].fDevicesAccessible, s_testEnvironment[i].rcMethodInit); int rc = USBProxyLinuxChooseMethod(&fUsingUsbfs, &pcszDevicesRoot); RTTESTI_CHECK_MSG(rc == s_testEnvironment[i].rcExpected, ("rc=%Rrc (test index %i) instead of %Rrc!\n", rc, i, s_testEnvironment[i].rcExpected)); RTTESTI_CHECK_MSG(!RTStrCmp(pcszDevicesRoot, s_testEnvironment[i].pcszDevicesRootExpected), ("testGetDevicesRoot() returned %s (test index %i) instead of %s!\n", pcszDevicesRoot, i, s_testEnvironment[i].pcszDevicesRootExpected)); RTTESTI_CHECK_MSG( fUsingUsbfs == s_testEnvironment[i].fUsingUsbfsExpected, ("testGetUsingUsbfs() returned %RTbool (test index %i) instead of %RTbool!\n", fUsingUsbfs, i, s_testEnvironment[i].fUsingUsbfsExpected)); } }
RD_BOOL rdpusb_init(void) { bool fUseUsbfs; if (RT_SUCCESS(USBProxyLinuxChooseMethod(&fUseUsbfs, &g_pcszDevicesRoot))) { g_fUseSysfs = !fUseUsbfs; rdpusb_channel = channel_register("vrdpusb", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP, rdpusb_process); return (rdpusb_channel != NULL); } return false; }
/** * Initializes the object (called right after construction). * * @returns VBox status code. */ int USBProxyBackendLinux::init(void) { const char *pcszDevicesRoot; int rc = USBProxyLinuxChooseMethod(&mUsingUsbfsDevices, &pcszDevicesRoot); if (RT_SUCCESS(rc)) { mDevicesRoot = pcszDevicesRoot; rc = mUsingUsbfsDevices ? initUsbfs() : initSysfs(); /* For the day when we have VBoxSVC release logging... */ LogRel((RT_SUCCESS(rc) ? "Successfully initialised host USB using %s\n" : "Failed to initialise host USB using %s\n", mUsingUsbfsDevices ? "USBFS" : "sysfs")); } return rc; }