Is there any way to read information of peripherals such as battery,cpu like system_profiler in C++.

Need to read informations of peripherals such as bluetooth,cpu information like how system report generates and need it to be done in C++.

Requesting to direct how it could be done in C++ and not by system_profiler command.

I did go through IOKIT ,but each device is accessed through different ways and they are not generic.

Using Core Foundation , i need to retrieve these infos.

In IOKit documentation,many functions are in NSObject ,can you please help me in including this to C++ and work with objective C functions and is it possible?

Replies

Just run system_profiler and parse the results. You can try digging into lower level APIs if you want to work harder.

Just run

system_profiler
and parse the results.

Normally I’m not a fan of this approach, but

system_profiler
has a
-xml
flag which is a strong indication that it was specifically designed to support it.

@delldiag, reimplementing what

system_profiler
does is a very complex task, and there are some things you can’t replicate with public API. How you start depends on the specific info you’re interested in. The items you mentioned (battery, CPU, Bluetooth peripherals) all show up in the I/O registry, so if you want to head down this path you should read up on that, starting with I/O Kit Fundamentals.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Normally I’m not a fan of this approach, but system_profiler has a -xml flag which is a strong indication that it was specifically designed to support it.

You probably don't want to know what I do with lsregister. 🙂


For the record, here are a couple of open feedbacks:

Sep 26, 2016 at 6:40 PM – FB5767230

Sep 26, 2016 at 6:37 PM – FB5460801

I need to retrieve information using APIs and not systems sytsem_profiler. IOKit APIs are mainly pointing to objective C,but I need it to be done in C++. Requesting to direct how it could be done in C++

I need to retrieve information using APIs and not systems sytsem_profiler. IOKit APIs are mainly pointing to objective C,but I need it to be done in C++. Requesting to direct how it could be done in C++

I did go through IOKIT ,but each device is accessed through different ways and they are not generic.

Using Core Foundation , i need to retrieve these infos.

IN IOKit documentation,many functions are in NSObject ,can you please help me in including this to C++ and work with objective C functions and is it possible?

each device is accessed through different ways and they are not generic.

Right. Did I mention that this was not easy?

Requesting to direct how it could be done in C++

Hmmm, you seem to have a very different understanding of I/O Kit than I do. There’s not a single instance of

NSObject
in the IOKit framework:
% grep NSObject -r /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework   
%

Even on the kernel side there’s no Objective-C in I/O Kit; rather, the kernel side of I/O Kit uses C++, and likewise for DriverKit [1].

Despite that, your desire to do this entirely in C++ is going to make a hard problem even harder. While the IOKit framework is entirely C based, there are numerous other frameworks that are not, and thus artificially restricting yourself to C++ is effectively tying one hand behind your back. This code is all specific to Apple platforms, so there should be no problem with your using (at least) Objective-C++, which will give you access to these Objective-C frameworks.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] Ironically, DriverKit was also the name for the I/O Kit equivalent on NeXT systems, and it was written in Objective-C (-:

What are you trying to do here? At a high level? What kind of app are you writing?

Actually i'm writing an app to collect informations of peripherals such as bluetooth,wifi,ethernet in C++.

So i need a sample snippet/API or a view how this could be done in cpp.

Hi Eskimo,actually i'm writing an app to collect informations of peripherals such as bluetooth,wifi,ethernet in C++.

So i need a sample snippet/API or a view how this could be done in cpp.

Eg:Card type,firmware version ,COuntry code of WIFI

None of those are "peripherals" per se. There are no pre-canned snippets. The APIs are in C. You can wrap those in C++ if you like.