本文整理匯總了C++中CFUUIDGetUUIDBytes函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFUUIDGetUUIDBytes函數的具體用法?C++ CFUUIDGetUUIDBytes怎麽用?C++ CFUUIDGetUUIDBytes使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFUUIDGetUUIDBytes函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CreateDeviceInterfaceUsingOldMethod
void CreateDeviceInterfaceUsingOldMethod(io_object_t scsiDevice, IOSCSIDeviceInterface ***interface)
{
io_name_t className;
IOCFPlugInInterface **plugInInterface = NULL;
HRESULT plugInResult = S_OK;
kern_return_t kr = kIOReturnSuccess;
SInt32 score = 0;
// Get the object's class name just to display it
kr = IOObjectGetClass(scsiDevice, className);
if (kr != kIOReturnSuccess) {
fprintf(stderr, "Failed to get class name. (0x%08x)\n", kr);
}
else {
fprintf(stderr, "Found device class \"%s\" using old method.\n", className);
// Create the base interface of type IOCFPlugInInterface.
// This object will be used to create the SCSI device interface object.
kr = IOCreatePlugInInterfaceForService( scsiDevice,
kIOSCSIUserClientTypeID, kIOCFPlugInInterfaceID,
&plugInInterface, &score);
if (kr != kIOReturnSuccess) {
fprintf(stderr, "Couldn't create a plugin interface for the io_service_t. (0x%08x)\n", kr);
}
else {
// Query the base plugin interface for an instance of the specific SCSI device interface
// object.
plugInResult = (*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOSCSIDeviceInterfaceID),
(LPVOID *) interface);
if (plugInResult != S_OK) {
fprintf(stderr, "Couldn't create SCSI device interface. (%ld)\n", plugInResult);
}
// We're now finished with the instance of IOCFPlugInInterface.
IODestroyPlugInInterface(plugInInterface);
}
}
}
示例2: iterate_devices
static void iterate_devices(void* context, io_iterator_t iterator){
io_service_t device;
while((device = IOIteratorNext(iterator)) != 0){
// Get the plugin interface for the device
IOCFPlugInInterface** plugin;
SInt32 score;
kern_return_t err = IOCreatePlugInInterfaceForService(device, kIOHIDDeviceTypeID, kIOCFPlugInInterfaceID, &plugin, &score);
if(err != kIOReturnSuccess){
ckb_err("Failed to create device plugin: %x\n", err);
continue;
}
// Get the device interface
hid_dev_t handle;
err = (*plugin)->QueryInterface(plugin, CFUUIDGetUUIDBytes(kIOHIDDeviceDeviceInterfaceID), (LPVOID*)&handle);
if(err != kIOReturnSuccess){
ckb_err("QueryInterface failed: %x\n", err);
continue;
}
// Plugin is no longer needed
IODestroyPlugInInterface(plugin);
// Seize the device handle
euid_guard_start;
err = (*handle)->open(handle, kIOHIDOptionsTypeSeizeDevice);
euid_guard_stop;
if(err != kIOReturnSuccess){
ckb_err("Failed to seize device: %x\n", err);
continue;
}
// Connect it
io_object_t* rm_notify = 0;
usbdevice* kb = usbadd(handle, &rm_notify);
if(kb)
// If successful, register for removal notification
IOServiceAddInterestNotification(notify, device, kIOGeneralInterest, remove_device, kb, rm_notify);
else {
// Otherwise, release it now
(*handle)->close(handle, kIOHIDOptionsTypeNone);
remove_device(0, device, kIOMessageServiceIsTerminated, 0);
}
}
}
示例3: CreateRemoteIsochPort
IOReturn
CreateRemoteIsochPort( IOFireWireLibNubRef nub, IOFireWireLibRemoteIsochPortRef* outPort )
{
cout << i << "+CreateRemoteIsochPort\n" ;
IOFireWireLibRemoteIsochPortRef port ;
port = (**nub).CreateRemoteIsochPort( nub, false, CFUUIDGetUUIDBytes( kIOFireWireRemoteIsochPortInterfaceID ) ) ;
if (!port)
return kIOReturnError ;
(**port).SetGetSupportedHandler( port, & RemotePort_GetSupported ) ;
(**port).SetAllocatePortHandler( port, & RemotePort_AllocatePort ) ;
(**port).SetReleasePortHandler( port, & RemotePort_ReleasePort ) ;
(**port).SetStartHandler( port, & RemotePort_Start ) ;
(**port).SetStopHandler( port, & RemotePort_Stop ) ;
*outPort = port ;
return kIOReturnSuccess ;
}
示例4: CFUUIDGetUUIDBytes
HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::QueryInterface(REFIID iid,
LPVOID *ppv)
{
HRESULT result = E_NOINTERFACE;
*ppv = nullptr;
CFUUIDBytes unknown = CFUUIDGetUUIDBytes(IUnknownUUID);
if (memcmp(&iid, &unknown, sizeof(REFIID)) == 0) {
*ppv = this;
AddRef();
result = S_OK;
} else if (memcmp(&iid, &IID_IDeckLinkNotificationCallback,
sizeof(REFIID)) == 0) {
*ppv = (IDeckLinkNotificationCallback *)this;
AddRef();
result = S_OK;
}
return result;
}
示例5: CFUUIDGetUUIDBytes
////////////////////////////////////////////////////////////
/// Store the interface to the joystick/gamepad for future usage
////////////////////////////////////////////////////////////
int JoystickSupport::GetDeviceInterface(io_object_t *hidDevice, JoystickDevice &joystick)
{
IOCFPlugInInterface **plugInInterface;
HRESULT plugInResult;
SInt32 score = 0;
IOReturn ioRes;
if (IOCreatePlugInInterfaceForService(*hidDevice, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score) == kIOReturnSuccess)
{
plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID*)&(joystick.hidDeviceInterface));
if( plugInResult == S_OK )
{
(*plugInInterface)->Release(plugInInterface);
ioRes = (*(joystick.hidDeviceInterface))->open(joystick.hidDeviceInterface, 0);
}
}
return ioRes;
}
示例6: openDeviceInterface
unsigned long openDeviceInterface(UInt32 hidDevice, struct deviceRecord *deviceRec)
{
IOReturn result = 0;
HRESULT plugInResult = 0;
SInt32 score = 0;
IOCFPlugInInterface **plugInInterface = NULL;
if (!deviceRec->interface)
{
result = IOCreatePlugInInterfaceForService(hidDevice, kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &plugInInterface, &score);
if (kIOReturnSuccess == result)
{
// Call a method of the intermediate plug-in to create the device interface
plugInResult =
(*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void **) &(deviceRec->interface));
if (verbose && plugInResult)
printf("Can't get HID device info.\n");
IODestroyPlugInInterface(plugInInterface);
}
else if (verbose)
printf("Failed to create USB interface.\n");
}
if (deviceRec->interface)
{
result = (*(IOHIDDeviceInterface**) deviceRec->interface)->open(deviceRec->interface, 0);
if (verbose && result)
printf("Failed to open USB device interface.\n");
}
return result;
}
示例7: FWDevice_readQuadlet
// Read a 32bit value
static VALUE FWDevice_readQuadlet(VALUE Self, VALUE StartAddr)
{
FWDevice *device;
Data_Get_Struct(Self, FWDevice, device);
IOCFPlugInInterface **cfPlugInInterface = NULL;
SInt32 theScore;
IOFireWireLibDeviceRef fwIntf;
IOReturn result = IOCreatePlugInInterfaceForService(device->Device,
kIOFireWireLibTypeID, kIOCFPlugInInterfaceID,
&cfPlugInInterface, &theScore);
(*cfPlugInInterface)->QueryInterface(cfPlugInInterface,
CFUUIDGetUUIDBytes(kIOFireWireDeviceInterfaceID),
(void **) &fwIntf);
assert((*fwIntf)->InterfaceIsInited(fwIntf));
VALUE ret;
if((*fwIntf)->Open(fwIntf) == 0)
{
// Set destination adress. Note that the upper 48 bits identify
// the device on the bus and the address set by the operating system.
uint64_t startaddr = rb_num2ull(StartAddr);
FWAddress fwaddr;
fwaddr.nodeID = 0;
fwaddr.addressHi = startaddr >> 32;
fwaddr.addressLo = startaddr & 0xffffffffL;
// do the actual read
UInt32 val = 0;
result = (*fwIntf)->ReadQuadlet(fwIntf, device->Device, &fwaddr, &val, false, 0);
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("value")), INT2FIX(val));
rb_hash_aset(ret, ID2SYM(rb_intern("resultcode")), INT2FIX(result));
}
示例8: InitUserID
// Generate a unique user ID. We're using a GUID form,
// but not jumping through hoops to make it cryptographically
// secure. We just want it to distinguish unique users.
static nsresult
InitUserID(nsACString& aUserID)
{
nsID id;
// copied shamelessly from nsUUIDGenerator.cpp
#if defined(XP_WIN)
HRESULT hr = CoCreateGuid((GUID*)&id);
if (NS_FAILED(hr))
return NS_ERROR_FAILURE;
#elif defined(XP_MACOSX)
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
if (!uuid)
return NS_ERROR_FAILURE;
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuid);
memcpy(&id, &bytes, sizeof(nsID));
CFRelease(uuid);
#else
// UNIX or some such thing
id.m0 = random();
id.m1 = random();
id.m2 = random();
*reinterpret_cast<PRUint32*>(&id.m3[0]) = random();
*reinterpret_cast<PRUint32*>(&id.m3[4]) = random();
#endif
char* id_cstr = id.ToString();
NS_ENSURE_TRUE(id_cstr, NS_ERROR_OUT_OF_MEMORY);
nsDependentCString id_str(id_cstr);
aUserID = Substring(id_str, 1, id_str.Length()-2);
PR_Free(id_cstr);
return NS_OK;
}
示例9: get_default_name
static krb5_error_code KRB5_CALLCONV
get_default_name(krb5_context context,
const krb5_cc_ops *ops,
const char *cachename,
char **str)
{
CFUUIDRef uuid = NULL;
CFUUIDBytes bytes;
uuid = HeimCredCopyDefaultCredential(kHEIMTypeKerberos, NULL);
if (uuid == NULL) {
return _krb5_expand_default_cc_name(context, cachename, str);
}
bytes = CFUUIDGetUUIDBytes(uuid);
char uuidstr[37];
uuid_unparse((void *)&bytes, uuidstr);
CFRELEASE_NULL(uuid);
asprintf(str, "%s:%s", ops->prefix, uuidstr);
return 0;
}
示例10: wxLogSysError
//.........這裏部分代碼省略.........
}
if ( IORegistryEntryCreateCFProperties
(
pObject,
&pDictionary,
kCFAllocatorDefault,
kNilOptions
) != KERN_SUCCESS )
{
wxLogDebug(wxT("IORegistryEntryCreateCFProperties failed"));
}
//
// Now we get the attributes of each "product" in the iterator
//
//Get [product] name
CFStringRef cfsProduct = (CFStringRef)
CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey));
m_szProductName =
wxCFStringRef( wxCFRetain(cfsProduct)
).AsString();
//Get the Product ID Key
CFNumberRef cfnProductId = (CFNumberRef)
CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductIDKey));
if (cfnProductId)
{
CFNumberGetValue(cfnProductId, kCFNumberIntType, &m_nProductId);
}
//Get the Vendor ID Key
CFNumberRef cfnVendorId = (CFNumberRef)
CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDVendorIDKey));
if (cfnVendorId)
{
CFNumberGetValue(cfnVendorId, kCFNumberIntType, &m_nManufacturerId);
}
//
// End attribute getting
//
//Create the interface (good grief - long function names!)
SInt32 nScore;
IOCFPlugInInterface** ppPlugin;
if(IOCreatePlugInInterfaceForService(pObject,
kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &ppPlugin,
&nScore) != kIOReturnSuccess)
{
wxLogSysError(wxT("Could not create HID Interface for product"));
return false;
}
//Now, the final thing we can check before we fall back to asserts
//(because the dtor only checks if the device is ok, so if anything
//fails from now on the dtor will delete the device anyway, so we can't break from this).
//Get the HID interface from the plugin to the mach port
if((*ppPlugin)->QueryInterface(ppPlugin,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
(void**) &m_ppDevice) != S_OK)
{
wxLogSysError(wxT("Could not get device interface from HID interface"));
return false;
}
//release the plugin
(*ppPlugin)->Release(ppPlugin);
//open the HID interface...
if ( (*m_ppDevice)->open(m_ppDevice, 0) != S_OK )
{
wxLogDebug(wxT("HID device: open failed"));
}
//
//Now the hard part - in order to scan things we need "cookies"
//
CFArrayRef cfaCookies = (CFArrayRef)CFDictionaryGetValue(pDictionary,
CFSTR(kIOHIDElementKey));
BuildCookies(cfaCookies);
//cleanup
CFRelease(pDictionary);
IOObjectRelease(pObject);
//iterator cleanup
IOObjectRelease(pIterator);
return true;
}
//iterator cleanup
IOObjectRelease(pIterator);
return false; //no device
}//end Create()
示例11: darwinHIDKeyboardCacheCreateEntry
/**
* Creates a keyboard cache entry.
*
* @returns true if the entry was created successfully, otherwise false.
* @param pKeyboardEntry Pointer to the entry.
* @param KeyboardDevice The keyboard device to create the entry for.
*
*/
static bool darwinHIDKeyboardCacheCreateEntry(struct KeyboardCacheData *pKeyboardEntry, io_object_t KeyboardDevice)
{
unsigned long cRefs = 0;
memset(pKeyboardEntry, 0, sizeof(*pKeyboardEntry));
/*
* Query the HIDDeviceInterface for this HID (keyboard) object.
*/
SInt32 Score = 0;
IOCFPlugInInterface **ppPlugInInterface = NULL;
IOReturn rc = IOCreatePlugInInterfaceForService(KeyboardDevice, kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &ppPlugInInterface, &Score);
if (rc == kIOReturnSuccess)
{
IOHIDDeviceInterface **ppHidDeviceInterface = NULL;
HRESULT hrc = (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
(LPVOID *)&ppHidDeviceInterface);
cRefs = (*ppPlugInInterface)->Release(ppPlugInInterface); MY_CHECK_CREFS(cRefs);
ppPlugInInterface = NULL;
if (hrc == S_OK)
{
rc = (*ppHidDeviceInterface)->open(ppHidDeviceInterface, 0);
if (rc == kIOReturnSuccess)
{
/*
* create a removal callback.
*/
/** @todo */
/*
* Create the queue so we can insert elements while searching the properties.
*/
IOHIDQueueInterface **ppHidQueueInterface = (*ppHidDeviceInterface)->allocQueue(ppHidDeviceInterface);
if (ppHidQueueInterface)
{
rc = (*ppHidQueueInterface)->create(ppHidQueueInterface, 0, 32);
if (rc != kIOReturnSuccess)
{
AssertMsgFailed(("rc=%d\n", rc));
cRefs = (*ppHidQueueInterface)->Release(ppHidQueueInterface); MY_CHECK_CREFS(cRefs);
ppHidQueueInterface = NULL;
}
}
else
AssertFailed();
pKeyboardEntry->ppHidQueueInterface = ppHidQueueInterface;
/*
* Brute force getting of attributes.
*/
/** @todo read up on how to do this in a less resource intensive way! Suggestions are welcome! */
CFMutableDictionaryRef PropertiesRef = 0;
kern_return_t krc = IORegistryEntryCreateCFProperties(KeyboardDevice, &PropertiesRef, kCFAllocatorDefault, kNilOptions);
if (krc == KERN_SUCCESS)
{
darwinBruteForcePropertySearch(PropertiesRef, pKeyboardEntry);
CFRelease(PropertiesRef);
}
else
AssertMsgFailed(("krc=%#x\n", krc));
if (ppHidQueueInterface)
{
/*
* Now install our queue callback.
*/
CFRunLoopSourceRef RunLoopSrcRef = NULL;
rc = (*ppHidQueueInterface)->createAsyncEventSource(ppHidQueueInterface, &RunLoopSrcRef);
if (rc == kIOReturnSuccess)
{
CFRunLoopRef RunLoopRef = (CFRunLoopRef)GetCFRunLoopFromEventLoop(GetMainEventLoop());
CFRunLoopAddSource(RunLoopRef, RunLoopSrcRef, kCFRunLoopDefaultMode);
}
/*
* Now install our queue callback.
*/
rc = (*ppHidQueueInterface)->setEventCallout(ppHidQueueInterface, darwinQueueCallback, ppHidQueueInterface, pKeyboardEntry);
if (rc != kIOReturnSuccess)
AssertMsgFailed(("rc=%d\n", rc));
}
/*
* Complete the new keyboard cache entry.
*/
pKeyboardEntry->ppHidDeviceInterface = ppHidDeviceInterface;
pKeyboardEntry->ppHidQueueInterface = ppHidQueueInterface;
return true;
}
//.........這裏部分代碼省略.........
示例12: platform_update_device_list
forensic1394_result platform_update_device_list(forensic1394_bus *bus)
{
CFMutableDictionaryRef matchingDict;
io_iterator_t iterator;
io_object_t currdev;
IOReturn iret;
forensic1394_result fret = FORENSIC1394_RESULT_SUCCESS;
// We need to get the systems local device node to update the CSR
matchingDict = IOServiceMatching("IOFireWireDevice");
iret = IOServiceGetMatchingServices(kIOMasterPortDefault,
matchingDict,
&iterator);
require_assertion(iret == kIOReturnSuccess, cleanupMatchingServices,
fret, FORENSIC1394_RESULT_OTHER_ERROR);
while ((currdev = IOIteratorNext(iterator)))
{
IOCFPlugInInterface **plugIn;
SInt32 theScore;
UInt32 generation;
UInt16 nodeid;
// Allocate memory for a forensic1394 device
forensic1394_dev *fdev = malloc(sizeof(forensic1394_dev));
// And for the platform specific structure
fdev->pdev = malloc(sizeof(platform_dev));
// Copy over the device IO object to the structure
fdev->pdev->dev = currdev;
// Get an plug-in interface to the device
IOCreatePlugInInterfaceForService(currdev,
kIOFireWireLibTypeID,
kIOCFPlugInInterfaceID,
&plugIn, &theScore);
// Ensure we got an interface
require_assertion(plugIn, cleanupPlugIn, fret, FORENSIC1394_RESULT_OTHER_ERROR);
// Use this to get an interface to the firewire device
(*plugIn)->QueryInterface(plugIn,
CFUUIDGetUUIDBytes(kIOFireWireDeviceInterfaceID_v9),
(void **) &fdev->pdev->devIntrf);
// Ensure the interface is inited
require_assertion((*fdev->pdev->devIntrf)->InterfaceIsInited(fdev->pdev->devIntrf),
cleanupDevIntrf, fret, FORENSIC1394_RESULT_OTHER_ERROR);
// Save the bus the device is attached to
fdev->bus = bus;
// The device is not open
fdev->is_open = 0;
// Copy the ROM
copy_device_csr(currdev, fdev->rom);
// Parse the ROM to extract useful fragments
common_parse_csr(fdev);
// Get the bus generation
(*fdev->pdev->devIntrf)->GetBusGeneration(fdev->pdev->devIntrf,
&generation);
// Get the node ID
(*fdev->pdev->devIntrf)->GetRemoteNodeID(fdev->pdev->devIntrf,
generation,
&nodeid);
fdev->generation = generation;
fdev->node_id = nodeid;
// Add this new device to the device list
fdev->next = bus->dev_link;
bus->dev_link = fdev;
bus->ndev++;
// Continue; everything from here on in is damage control
continue;
cleanupDevIntrf:
// Release the device interface
(*fdev->pdev->devIntrf)->Release(fdev->pdev->devIntrf);
cleanupPlugIn:
// Release the plug-in interface
IODestroyPlugInInterface(plugIn);
// Release the IO object
IOObjectRelease(fdev->pdev->dev);
// Release the partially allocated device
free(fdev->pdev);
free(fdev);
//.........這裏部分代碼省略.........
示例13: IOCreatePlugInInterfaceForService
kern_return_t
IOCreatePlugInInterfaceForService(io_service_t service,
CFUUIDRef pluginType, CFUUIDRef interfaceType,
IOCFPlugInInterface *** theInterface, SInt32 * theScore)
{
CFDictionaryRef plist = 0;
CFArrayRef plists;
CFArrayRef factories;
CFMutableArrayRef candidates;
CFMutableArrayRef scores;
CFIndex index;
CFIndex insert;
CFUUIDRef factoryID;
kern_return_t kr;
SInt32 score;
IOCFPlugInInterface ** interface;
Boolean haveOne;
kr = IOFindPlugIns( service, pluginType,
&factories, &plists );
if( KERN_SUCCESS != kr) {
if (factories) CFRelease(factories);
if (plists) CFRelease(plists);
return( kr );
}
if ((KERN_SUCCESS != kr)
|| (factories == NULL)
|| (0 == CFArrayGetCount(factories))) {
// printf("No factories for type\n");
if (factories) CFRelease(factories);
if (plists) CFRelease(plists);
return( kIOReturnUnsupported );
}
candidates = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
scores = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
// allocate and Probe all
if (candidates && scores) {
CFIndex numfactories = CFArrayGetCount(factories);
for ( index = 0; index < numfactories; index++ ) {
IUnknownVTbl ** iunknown;
factoryID = (CFUUIDRef) CFArrayGetValueAtIndex(factories, index);
iunknown = (IUnknownVTbl **)
CFPlugInInstanceCreate(NULL, factoryID, pluginType);
if (!iunknown) {
// printf("Failed to create instance (link error?)\n");
continue;
}
(*iunknown)->QueryInterface(iunknown, CFUUIDGetUUIDBytes(interfaceType),
(LPVOID *)&interface);
// Now we are done with IUnknown interface
(*iunknown)->Release(iunknown);
if (!interface) {
// printf("Failed to get interface.\n");
continue;
}
if (plists)
plist = (CFDictionaryRef) CFArrayGetValueAtIndex( plists, index );
score = 0; // from property table
kr = (*interface)->Probe(interface, plist, service, &score);
if (kIOReturnSuccess == kr) {
CFIndex numscores = CFArrayGetCount(scores);
for (insert = 0; insert < numscores; insert++) {
if (score > (SInt32) ((intptr_t) CFArrayGetValueAtIndex(scores, insert)))
break;
}
CFArrayInsertValueAtIndex(candidates, insert, (void *) interface);
CFArrayInsertValueAtIndex(scores, insert, (void *) (intptr_t) score);
} else
(*interface)->Release(interface);
}
}
// Start in score order
CFIndex candidatecount = CFArrayGetCount(candidates);
for (haveOne = false, index = 0;
index < candidatecount;
index++) {
Boolean freeIt;
if (plists)
plist = (CFDictionaryRef) CFArrayGetValueAtIndex(plists, index );
interface = (IOCFPlugInInterface **)
CFArrayGetValueAtIndex(candidates, index );
if (!haveOne) {
haveOne = (kIOReturnSuccess == (*interface)->Start(interface, plist, service));
freeIt = !haveOne;
if (haveOne) {
*theInterface = interface;
*theScore = (SInt32) (intptr_t)
CFArrayGetValueAtIndex(scores, index );
}
} else
//.........這裏部分代碼省略.........
示例14: UPSDeviceAdded
void UPSDeviceAdded(void *refCon, io_iterator_t iterator)
{
io_object_t upsDevice = MACH_PORT_NULL;
UPSDataRef upsDataRef = NULL;
CFDictionaryRef upsProperties = NULL;
CFDictionaryRef upsEvent = NULL;
CFSetRef upsCapabilites = NULL;
CFRunLoopSourceRef upsEventSource = NULL;
CFRunLoopTimerRef upsEventTimer = NULL;
CFTypeRef typeRef = NULL;
IOCFPlugInInterface ** plugInInterface = NULL;
IOUPSPlugInInterface_v140 ** upsPlugInInterface = NULL;
HRESULT result = S_FALSE;
IOReturn kr;
SInt32 score;
while ( (upsDevice = IOIteratorNext(iterator)) )
{
// Create the CF plugin for this device
kr = IOCreatePlugInInterfaceForService(upsDevice, kIOUPSPlugInTypeID,
kIOCFPlugInInterfaceID, &plugInInterface, &score);
if ( kr != kIOReturnSuccess )
goto UPSDEVICEADDED_NONPLUGIN_CLEANUP;
// Grab the new v140 interface
result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID_v140),
(LPVOID)&upsPlugInInterface);
if ( ( result == S_OK ) && upsPlugInInterface )
{
kr = (*upsPlugInInterface)->createAsyncEventSource(upsPlugInInterface, &typeRef);
if ((kr != kIOReturnSuccess) || !typeRef)
goto UPSDEVICEADDED_FAIL;
if ( CFGetTypeID(typeRef) == CFRunLoopTimerGetTypeID() )
{
upsEventTimer = (CFRunLoopTimerRef)typeRef;
CFRunLoopAddTimer(CFRunLoopGetCurrent(), upsEventTimer, kCFRunLoopDefaultMode);
}
else if ( CFGetTypeID(typeRef) == CFRunLoopSourceGetTypeID() )
{
upsEventSource = (CFRunLoopSourceRef)typeRef;
CFRunLoopAddSource(CFRunLoopGetCurrent(), upsEventSource, kCFRunLoopDefaultMode);
}
}
// Couldn't grab the new interface. Fallback on the old.
else
{
result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID),
(LPVOID)&upsPlugInInterface);
}
// Got the interface
if ( ( result == S_OK ) && upsPlugInInterface )
{
kr = (*upsPlugInInterface)->getProperties(upsPlugInInterface, &upsProperties);
if (kr != kIOReturnSuccess)
goto UPSDEVICEADDED_FAIL;
upsDataRef = GetPrivateData(upsProperties);
if ( !upsDataRef )
goto UPSDEVICEADDED_FAIL;
upsDataRef->upsPlugInInterface = (IOUPSPlugInInterface **)upsPlugInInterface;
upsDataRef->upsEventSource = upsEventSource;
upsDataRef->upsEventTimer = upsEventTimer;
upsDataRef->isPresent = true;
kr = (*upsPlugInInterface)->getCapabilities(upsPlugInInterface, &upsCapabilites);
if (kr != kIOReturnSuccess)
goto UPSDEVICEADDED_FAIL;
kr = CreatePowerManagerUPSEntry(upsDataRef, upsProperties, upsCapabilites);
if (kr != kIOReturnSuccess)
goto UPSDEVICEADDED_FAIL;
kr = (*upsPlugInInterface)->getEvent(upsPlugInInterface, &upsEvent);
if (kr != kIOReturnSuccess)
goto UPSDEVICEADDED_FAIL;
ProcessUPSEvent(upsDataRef, upsEvent);
(*upsPlugInInterface)->setEventCallback(upsPlugInInterface, UPSEventCallback, NULL, upsDataRef);
IOServiceAddInterestNotification(
gNotifyPort, // notifyPort
upsDevice, // service
kIOGeneralInterest, // interestType
DeviceNotification, // callback
upsDataRef, // refCon
&(upsDataRef->notification) // notification
);
//.........這裏部分代碼省略.........
示例15: try_device
/** Try out the given device and see if there's a match. Returns 0 on
* success, -1 on failure.
*/
static int try_device(io_service_t device, usb_handle *handle) {
kern_return_t kr;
IOCFPlugInInterface **plugin = NULL;
IOUSBDeviceInterface500** dev = NULL;
SInt32 score;
HRESULT result;
UInt8 serialIndex;
UInt32 locationId;
// Create an intermediate plugin.
kr = IOCreatePlugInInterfaceForService(device,
kIOUSBDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugin, &score);
if ((kr != 0) || (plugin == NULL)) {
goto error;
}
// Now create the device interface.
result = (*plugin)->QueryInterface(plugin, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID500),
(LPVOID*)&dev);
if ((result != 0) || (dev == NULL)) {
ERR("Couldn't create a device interface (%08x)\n", (int) result);
goto error;
}
/*
* We don't need the intermediate interface after the device interface
* is created.
*/
IODestroyPlugInInterface(plugin);
// So, we have a device, finally. Grab its vitals.
kr = (*dev)->GetDeviceVendor(dev, &handle->info.dev_vendor);
if (kr != 0) {
ERR("GetDeviceVendor");
goto error;
}
kr = (*dev)->GetDeviceProduct(dev, &handle->info.dev_product);
if (kr != 0) {
ERR("GetDeviceProduct");
goto error;
}
kr = (*dev)->GetDeviceClass(dev, &handle->info.dev_class);
if (kr != 0) {
ERR("GetDeviceClass");
goto error;
}
kr = (*dev)->GetDeviceSubClass(dev, &handle->info.dev_subclass);
if (kr != 0) {
ERR("GetDeviceSubClass");
goto error;
}
kr = (*dev)->GetDeviceProtocol(dev, &handle->info.dev_protocol);
if (kr != 0) {
ERR("GetDeviceProtocol");
goto error;
}
kr = (*dev)->GetLocationID(dev, &locationId);
if (kr != 0) {
ERR("GetLocationId");
goto error;
}
snprintf(handle->info.device_path, sizeof(handle->info.device_path),
"usb:%" PRIu32 "X", (unsigned int)locationId);
kr = (*dev)->USBGetSerialNumberStringIndex(dev, &serialIndex);
if (serialIndex > 0) {
IOUSBDevRequest req;
UInt16 buffer[256];
req.bmRequestType = USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
req.bRequest = kUSBRqGetDescriptor;
req.wValue = (kUSBStringDesc << 8) | serialIndex;
//language ID (en-us) for serial number string
req.wIndex = 0x0409;
req.pData = buffer;
req.wLength = sizeof(buffer);
kr = (*dev)->DeviceRequest(dev, &req);
if (kr == kIOReturnSuccess && req.wLenDone > 0) {
int i, count;
// skip first word, and copy the rest to the serial string, changing shorts to bytes.
count = (req.wLenDone - 1) / 2;
for (i = 0; i < count; i++)
handle->info.serial_number[i] = buffer[i + 1];
handle->info.serial_number[i] = 0;
}
//.........這裏部分代碼省略.........