tstOpenUSBDev.cpp revision 59190ecd61435d19ba3515b876272aee7bd12298
/* $Id$ */
/** @file
* Testcase that attempts to locate and open the specfied device.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* Oracle Corporation confidential
* All rights reserved
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <IOKit/IOKitLib.h>
#include <mach/mach_error.h>
#include <IOKit/IOCFPlugIn.h>
#include <iprt/initterm.h>
/**
* Gets an unsigned 32-bit integer value.
*
* @param DictRef The dictionary.
* @param KeyStrRef The key name.
* @param pu32 Where to store the key value.
*/
{
if (ValRef)
{
return true;
}
*pu32 = 0;
return false;
}
/**
* Gets an unsigned 64-bit integer value.
*
* @param DictRef The dictionary.
* @param KeyStrRef The key name.
* @param pu64 Where to store the key value.
*/
{
if (ValRef)
{
return true;
}
*pu64 = 0;
return false;
}
{
/*
* Create a plugin interface for the device and query its IOUSBDeviceInterface.
*/
int vrc = VINF_SUCCESS;
if (irc == kIOReturnSuccess)
{
{
/*
* Try open the device for exclusive access.
*/
if (irc == kIOReturnExclusiveAccess)
{
RTThreadSleep(20);
}
if (irc == kIOReturnSuccess)
{
#if 0
/*
* Re-enumerate the device and bail out.
*/
if (irc != kIOReturnSuccess)
{
}
#endif
}
else if (irc == kIOReturnExclusiveAccess)
{
RTPrintf("%s: The device is being used by another process (irc=kIOReturnExclusiveAccess)\n", argv0);
}
else
{
}
}
else
{
RTPrintf("%s: Failed to create plugin interface for the device, hrc=%#x (vrc=%Rrc).\n", argv0, hrc, vrc);
}
}
else
{
RTPrintf("%s: Failed to open the device, plug-in creation failed with irc=%#x (vrc=%Rrc).\n", argv0, irc, vrc);
}
return vrc;
}
{
RTPrintf("syntax: %s [criteria]\n"
"\n"
"Criteria:\n"
" -l <location>\n"
" -s <session>\n"
, argv0);
return 1;
}
{
RTR3Init();
/*
* Show help if not arguments.
*/
if (argc <= 1)
/*
* Parse arguments.
*/
static const RTGETOPTDEF g_aOptions[] =
{
};
uint64_t u64SessionId = 0;
uint32_t u32LocationId = 0;
int ch;
int i = 1;
{
switch (ch)
{
case 'l':
break;
case 's':
break;
case 'h':
case 'V':
RTPrintf("$Revision$\n");
return 0;
default:
}
}
/*
* Open the master port.
*/
if (krc != KERN_SUCCESS)
{
return 1;
}
/*
* Iterate the USB devices and find all that matches.
*/
if (!RefMatchingDict)
{
return 1;
}
if (irc != kIOReturnSuccess)
{
return 1;
}
unsigned cDevices = 0;
unsigned cMatches = 0;
{
cDevices++;
if (krc == KERN_SUCCESS)
{
if ( ( !u64SessionId
&& u64CurSessionId == u64SessionId))
&& ( !u32LocationId
&& u32CurLocationId == u32LocationId))
)
{
cMatches++;
}
else
}
}
/*
* Bitch if we didn't find anything matching the criteria.
*/
if (!cMatches)
return !cMatches;
}