Module: FW
- Defined in:
- lib/fw.rb,
ext/macosx/fwext.c
Defined Under Namespace
Classes: FWDevice
Class Method Summary collapse
-
.scanbus ⇒ Object
Scan the FW bus and enumerate the devices.
Class Method Details
.scanbus ⇒ Object
Scan the FW bus and enumerate the devices
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'ext/macosx/fwext.c', line 122
static VALUE scanbus()
{
VALUE ret = rb_ary_new();
mach_port_t master_port;
io_iterator_t iterator;
kern_return_t result = IOMasterPort(MACH_PORT_NULL, &master_port);
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("IOFireWireDevice");
result = IOServiceGetMatchingServices(master_port, matchingDictionary, &iterator);
io_object_t device;
while((device = IOIteratorNext(iterator)))
{
CFNumberRef guidRef = IORegistryEntryCreateCFProperty(device, CFSTR("GUID"), NULL, 0);
CFStringRef vendornameRef = IORegistryEntryCreateCFProperty(device, CFSTR("FireWire Vendor Name"), NULL, 0);
CFNumberRef speedRef = IORegistryEntryCreateCFProperty(device, CFSTR("FireWire Speed"), NULL, 0);
CFNumberRef nodeidRef = IORegistryEntryCreateCFProperty(device, CFSTR("FireWire Node ID"), NULL, 0);
CFNumberRef vendoridRef = IORegistryEntryCreateCFProperty(device, CFSTR("Vendor_ID"), NULL, 0);
CFIndex vendorname_len = CFStringGetLength(vendornameRef);
char *vendorname = (char*)malloc(vendorname_len + 1);
memset(vendorname, 0, vendorname_len);
long long guid;
SInt32 speed, vendorid, nodeid;
if(guidRef
&& CFNumberGetValue(guidRef, kCFNumberLongLongType, &guid)
&& vendornameRef
&& CFStringGetCString(vendornameRef, vendorname, vendorname_len + 1, kCFStringEncodingMacRoman)
&& speedRef
&& CFNumberGetValue(speedRef, kCFNumberSInt32Type, &speed)
&& nodeidRef
&& CFNumberGetValue(nodeidRef, kCFNumberSInt32Type, &nodeid)
&& vendoridRef
&& CFNumberGetValue(vendoridRef, kCFNumberSInt32Type, &vendorid)
)
{
VALUE fwdevice = FWDevice_new(device, guid, vendorname, vendorid, nodeid, speed);
rb_ary_push(ret, fwdevice);
CFRelease(guidRef);
CFRelease(vendornameRef);
CFRelease(speedRef);
CFRelease(nodeidRef);
CFRelease(vendoridRef);
}
}
return ret;
}
|