문제

I'm trying to learn how to get information from PCI devices in Mac OS X. So far I haven't been able to find anything about it in sysctl(3) and it seems the old devinfo(3) facilities from BSD are not available.

I need a C facility for this, I know there is an I/O kit framework for Objective C but I cannot use this.

The specific information I'm after is pretty basic, just vendor and device ID's.

도움이 되었습니까?

해결책

I/O Kit is the system framework for device information. It is not an Objective-C API; instead, Apple use a restricted subset of C++. Quoting the I/O Kit Fundamentals document,

Apple considered several programming languages for the I/O Kit and chose a restricted subset of C++.

C++ was chosen for several reasons. The C++ compiler is mature and the language provides support for system programming. In addition, there is already a large community of Macintosh (and BSD) developers with C++ experience.

The restricted subset disallows certain features of C++, including

  • Exceptions
  • Multiple inheritance
  • Templates
  • Runtime type information (RTTI)—the I/O Kit uses its own implementation of a runtime typing system

These features were dropped because they were deemed unsuitable for use within a multithreaded kernel. If you feel you need these features, you should reconsider your design. You should be able to write any driver you require using I/O Kit with these restrictions in place.

If you cannot use C++ then one alternative is to have your C program call /usr/bin/ioreg and parse its results.


Edit: you might want to take a look at the Accessing Hardware from Applications document. It looks like accessing the I/O registry can be done with C code for the most part (if not all), with a bit of Core Foundation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top