Article View: comp.sys.mac.programmer.codewarrior
Article #1067Re: mach/mach.h and IOKit functions
From: petrock99
Date: Fri, 08 Feb 2002 19:36
Date: Fri, 08 Feb 2002 19:36
65 lines
3691 bytes
3691 bytes
On 2/8/02 4:27 AM, in article B889043E.1AB3%petrock99-NOSPAM@hotmail.com,
"petrock99" <petrock99-NOSPAM@hotmail.com> wrote:
>>> Does CW7 support directly calling functions from IOKit?
>>
>> No, Pro 7 doesn't support this.
> You definitely can call IOKit functions from a CW project, you just have
> to have the right frameworks/headers/libraries linked in. I recently added
> code to one of my projects that would gather a bunch of info on the
> processor(s) that my app was running on (i.e. Bus speed, CPU speed, , cache
> size/tupe, CPU version etc etc). The only way to do that in a Mach-O app is
> through IOKit... You can use a command line tool called ioreg to help you
> figure out what keys to use etc... There is also the IORegistryExplorer in
> /Developer/Applications that does pretty much the same thing as ioreg, but
> with a GUI.
> The project is currently at work, I'll post up any funky settings I had
> tomorrow...
I took a look at my project, I didn't have any funky access paths, or
frameworks. I had the default Mach-O stationary access paths, and System,
IOKit and CoreFoundation frameworks...
The insludes I had in my source were
#include <stdio.h> // it was a console app...
#include <stdlib.h>
// these are the only other includes I had...
#include <mach/port.h>
#include <mach/kern_return.h>
#include <IOKit/IOKitLib.h>
#include <CoreFoundation/CFNumber.h>
#include <CoreFoundation/CFSet.h>
Here's a snippit of my code... This snippit will get the master port, then
get a "reference" to the cpus in the registry (not that cpus will point to
one or more cpu's... You need to setup an iterator to get to the underlying
cpu data)
mach_port_t masterport = MACH_PORT_NULL; // (don't release)
io_registry_entry_t cpus = MACH_PORT_NULL; // (needs release)
io_iterator_t iter = NULL; // (needs release)
kern_return_t status = KERN_SUCCESS;
// get master port
status = IOMasterPort(bootstrap_port, &masterPort);
if( status == KERN_SUCCESS )
cpus = IORegistryEntryFromPath( masterPort, kIODeviceTreePlane
":/cpus" );
if( cpus != MACH_PORT_NULL )
status = IORegistryEntryGetChildIterator( cpus, kIODeviceTreePlane,
&iter );
// clean up
if( cpus != MACH_PORT_NULL ) {
IOObjectRelease( cpus );
cpus = MACH_PORT_NULL;
}
Good luck...
--Rob
Technical Details
Message-ID:
<B88968A7.39C4%petrock99@hotmail.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!forum.apple.com!news.apple.com!not-for-mailReferences:
<3C602717.27F3AA60@vernier.com> <wankerl-3A87A1.14210406022002@news.mtwk.sps.mot.com> <B889043E.1AB3%petrock99-NOSPAM@hotmail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,d90ff54a1a5a9456 X-Google-Attributes: gid10bcce,public X-Google-Thread: f635e,d90ff54a1a5a9456 X-Google-Attributes: gidf635e,public X-Google-ArrivalTime: 2002-02-08 11:45:43 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!forum.apple.com!news.apple.com!not-for-mail From: petrock99 <petrock99@hotmail.com> Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac Subject: Re: mach/mach.h and IOKit functions Date: Fri, 08 Feb 2002 11:36:07 -0800 Organization: Apple Computer, Inc. Lines: 67 Message-ID: <B88968A7.39C4%petrock99@hotmail.com> References: <3C602717.27F3AA60@vernier.com> <wankerl-3A87A1.14210406022002@news.mtwk.sps.mot.com> <B889043E.1AB3%petrock99-NOSPAM@hotmail.com> NNTP-Posting-Host: petrock2.apple.com Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: news.apple.com 1013197125 21168 17.201.24.139 (8 Feb 2002 19:38:45 GMT) X-Complaints-To: usenet@news.apple.com NNTP-Posting-Date: 8 Feb 2002 19:38:45 GMT User-Agent: Microsoft-Entourage/9.0.2.4011