mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
Merge pull request #95 from wjwwood/issue_90_refresh
Release io_iterator_t object when finished with it in list_ports_osx.cc.
This commit is contained in:
commit
1a70b09bb1
@ -36,9 +36,9 @@ cfstring_to_string( CFStringRef cfstring )
|
|||||||
|
|
||||||
if( cfstring )
|
if( cfstring )
|
||||||
{
|
{
|
||||||
Boolean success = CFStringGetCString( cfstring,
|
Boolean success = CFStringGetCString( cfstring,
|
||||||
cstring,
|
cstring,
|
||||||
sizeof(cstring),
|
sizeof(cstring),
|
||||||
kCFStringEncodingASCII );
|
kCFStringEncodingASCII );
|
||||||
|
|
||||||
if( success )
|
if( success )
|
||||||
@ -106,7 +106,7 @@ get_parent_iousb_device( io_object_t& serial_port )
|
|||||||
result = 0;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
device = parent;
|
device = parent;
|
||||||
|
|
||||||
name = get_class_name(device);
|
name = get_class_name(device);
|
||||||
@ -125,15 +125,15 @@ get_string_property( io_object_t& device, const char* property )
|
|||||||
|
|
||||||
if( device )
|
if( device )
|
||||||
{
|
{
|
||||||
CFStringRef property_as_cfstring = CFStringCreateWithCString (
|
CFStringRef property_as_cfstring = CFStringCreateWithCString (
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
property,
|
property,
|
||||||
kCFStringEncodingASCII );
|
kCFStringEncodingASCII );
|
||||||
|
|
||||||
CFTypeRef name_as_cfstring = IORegistryEntryCreateCFProperty(
|
CFTypeRef name_as_cfstring = IORegistryEntryCreateCFProperty(
|
||||||
device,
|
device,
|
||||||
property_as_cfstring,
|
property_as_cfstring,
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
if( name_as_cfstring )
|
if( name_as_cfstring )
|
||||||
@ -142,12 +142,12 @@ get_string_property( io_object_t& device, const char* property )
|
|||||||
property_name = cfstring_to_string( static_cast<CFStringRef>(name_as_cfstring) );
|
property_name = cfstring_to_string( static_cast<CFStringRef>(name_as_cfstring) );
|
||||||
|
|
||||||
CFRelease(name_as_cfstring);
|
CFRelease(name_as_cfstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(property_as_cfstring)
|
if(property_as_cfstring)
|
||||||
CFRelease(property_as_cfstring);
|
CFRelease(property_as_cfstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
return property_name;
|
return property_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,14 +158,14 @@ get_int_property( io_object_t& device, const char* property )
|
|||||||
|
|
||||||
if( device )
|
if( device )
|
||||||
{
|
{
|
||||||
CFStringRef property_as_cfstring = CFStringCreateWithCString (
|
CFStringRef property_as_cfstring = CFStringCreateWithCString (
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
property,
|
property,
|
||||||
kCFStringEncodingASCII );
|
kCFStringEncodingASCII );
|
||||||
|
|
||||||
CFTypeRef number = IORegistryEntryCreateCFProperty( device,
|
CFTypeRef number = IORegistryEntryCreateCFProperty( device,
|
||||||
property_as_cfstring,
|
property_as_cfstring,
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
if(property_as_cfstring)
|
if(property_as_cfstring)
|
||||||
@ -175,8 +175,8 @@ get_int_property( io_object_t& device, const char* property )
|
|||||||
{
|
{
|
||||||
if( CFGetTypeID(number) == CFNumberGetTypeID() )
|
if( CFGetTypeID(number) == CFNumberGetTypeID() )
|
||||||
{
|
{
|
||||||
bool success = CFNumberGetValue( static_cast<CFNumberRef>(number),
|
bool success = CFNumberGetValue( static_cast<CFNumberRef>(number),
|
||||||
kCFNumberSInt16Type,
|
kCFNumberSInt16Type,
|
||||||
&result );
|
&result );
|
||||||
|
|
||||||
if( !success )
|
if( !success )
|
||||||
@ -187,7 +187,7 @@ get_int_property( io_object_t& device, const char* property )
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ string rtrim(const string& str)
|
|||||||
string whitespace = " \t\f\v\n\r";
|
string whitespace = " \t\f\v\n\r";
|
||||||
|
|
||||||
std::size_t found = result.find_last_not_of(whitespace);
|
std::size_t found = result.find_last_not_of(whitespace);
|
||||||
|
|
||||||
if (found != std::string::npos)
|
if (found != std::string::npos)
|
||||||
result.erase(found+1);
|
result.erase(found+1);
|
||||||
else
|
else
|
||||||
@ -244,7 +244,7 @@ serial::list_ports(void)
|
|||||||
|
|
||||||
if( device_path.empty() )
|
if( device_path.empty() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PortInfo port_info;
|
PortInfo port_info;
|
||||||
port_info.port = device_path;
|
port_info.port = device_path;
|
||||||
port_info.description = "n/a";
|
port_info.description = "n/a";
|
||||||
@ -267,18 +267,19 @@ serial::list_ports(void)
|
|||||||
if(serial_number.empty())
|
if(serial_number.empty())
|
||||||
serial_number = "None";
|
serial_number = "None";
|
||||||
|
|
||||||
int ret = snprintf( cstring, HARDWARE_ID_STRING_LENGTH, "USB VID:PID=%04x:%04x SNR=%s",
|
int ret = snprintf( cstring, HARDWARE_ID_STRING_LENGTH, "USB VID:PID=%04x:%04x SNR=%s",
|
||||||
vendor_id,
|
vendor_id,
|
||||||
product_id,
|
product_id,
|
||||||
serial_number.c_str() );
|
serial_number.c_str() );
|
||||||
|
|
||||||
if( (ret >= 0) && (ret < HARDWARE_ID_STRING_LENGTH) )
|
if( (ret >= 0) && (ret < HARDWARE_ID_STRING_LENGTH) )
|
||||||
port_info.hardware_id = cstring;
|
port_info.hardware_id = cstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
devices_found.push_back(port_info);
|
devices_found.push_back(port_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IOObjectRelease(serial_port_iterator);
|
||||||
return devices_found;
|
return devices_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user