/** $Id$ */
/** @file
* USBLib - Library for wrapping up the VBoxUSB functionality, Darwin flavor.
*/
/*
* Copyright (C) 2007-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxUSBInterface.h"
#include <mach/mach_port.h>
#include <IOKit/IOKitLib.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The IOClass key of the service (see VBoxUSB.cpp / Info.plist). */
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Reference counter. */
/** The IOMasterPort. */
/** The current service connection. */
{
/*
* Already open?
* This isn't properly serialized, but we'll be fine with the current usage.
*/
if (g_cUsers)
{
return VINF_SUCCESS;
}
/*
* Finding the VBoxUSB service.
*/
if (kr != kIOReturnSuccess)
{
return RTErrConvertFromDarwinKern(kr);
}
if (!ClassToMatch)
{
return VERR_GENERAL_FAILURE;
}
/* Create an io_iterator_t for all instances of our drivers class that exist in the IORegistry. */
if (kr != kIOReturnSuccess)
{
return RTErrConvertFromDarwinKern(kr);
}
/* Get the first item in the iterator and release it. */
if (!ServiceObject)
{
LogRel(("USBLib: Couldn't find any matches.\n"));
return VERR_GENERAL_FAILURE;
}
/*
* Open the service.
* This will cause the user client class in VBoxUSB.cpp to be instantiated.
*/
kr = IOServiceOpen(ServiceObject, mach_task_self(), VBOXUSB_DARWIN_IOSERVICE_COOKIE, &g_Connection);
if (kr != kIOReturnSuccess)
{
return RTErrConvertFromDarwinKern(kr);
}
return VINF_SUCCESS;
}
{
if (!g_cUsers)
return VERR_WRONG_ORDER;
if (ASMAtomicDecU32(&g_cUsers) != 0)
return VINF_SUCCESS;
/*
* We're the last guy, close down the connection.
*/
if (kr != kIOReturnSuccess)
{
}
g_Connection = NULL;
return VINF_SUCCESS;
}
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
sizeof(*pFilter),
&cbOut,
(void *)pFilter,
&Out);
#else /* 10.5 and later */
#endif /* 10.5 and later */
if ( kr == kIOReturnSuccess
{
}
return NULL;
}
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
sizeof(pvId),
&cbOut,
&pvId,
&rc);
#else /* 10.5 and later */
#endif /* 10.5 and later */
}