System Guts(power information)

M

MidiBot

Hello. I want to write a program in which the main functionality will
depend on whether or not my
computer is connected to a power adapter(this is for laptops). I looked
in the online-documentation for this and had no luck. I imagine it is
quite easy and may even be as simple as a boolean variable...?

All I want to be able to tell is whether or not my computer is being
externally powered. More specifically
I want to be able to have my program running, and be alerted if I
un-plug my power adapter.

I am using a Mac(powerbook) with java 1.4.2 if that makes any
difference.

Thank you very much.
 
R

Roedy Green

All I want to be able to tell is whether or not my computer is being
externally powered. More specifically
I want to be able to have my program running, and be alerted if I
un-plug my power adapter.

I don't know of any built in methods in Java to find that out. You
will have to either:

1. spawn something with exec that will find out for you.

2. write something in C to find out and write some JNI glue to it.

see http://mindprod.com/jgloss/jni.html
 
T

Thomas Weidenfeller

Hello. I want to write a program in which the main functionality will
depend on whether or not my
computer is connected to a power adapter(this is for laptops). I looked
in the online-documentation for this and had no luck. I imagine it is
quite easy and may even be as simple as a boolean variable...?

Use another language. One that is suited for Windows system programming.
Java is not.

/Thomas
 
J

Jeffrey Schwab

Thomas said:
Use another language. One that is suited for Windows system programming.
Java is not.

Why would someone using a Mac PowerBook be better off with a language
suited for Windows system programming?
 
T

Thomas Weidenfeller

Jeffrey said:
Why would someone using a Mac PowerBook be better off with a language
suited for Windows system programming?

Did the OP say Mac? Anyhow, the gist of my answer is still valid. Java
is not a good language for system programming.

/Thomas
 
R

Roedy Green

Did the OP say Mac? Anyhow, the gist of my answer is still valid. Java
is not a good language for system programming.

Given that "System" programming is often 1% tricky platform-dependent
stuff and 99% busywork, it is not necessarily a nutty idea to do
system code in Java. It guides you to keep the bulk of your code
platform-independent. Had you set out to develop in languages that let
you do system dependent stuff to easily, you would end up with several
quite different and incompatible programs, all that had to be
maintained totally independently.

The Java approach forces you to keep the system dependent parts in
clearly defined small boxes.

The main problem with the Java approach of system stuff is the
overhead of the Java-native barrier. You don't want to be crossing in
millions of times a second.
 
T

Thomas Weidenfeller

Roedy said:
Given that "System" programming is often 1% tricky platform-dependent
stuff and 99% busywork, it is not necessarily a nutty idea to do
system code in Java.

But if you end up spending 100% of your time kicking your language to do
the 1% tricky part it is not fun.


/Thomas
 
R

Roedy Green

But if you end up spending 100% of your time kicking your language to do
the 1% tricky part it is not fun.

In Java that part you do in C with some JNI glue. Java is well
designed to make most platform dependent things impossible.
 
G

Gordon Beaton

All I want to be able to tell is whether or not my computer is being
externally powered. More specifically I want to be able to have my
program running, and be alerted if I un-plug my power adapter.

If MacOSX provides a process file system (or similar) with information
about ACPI, APM, PMU or whatever it's called on that platform, then
you may be able to read the information from your Java application
using a FileReader.

If it doesn't, there may be an OS-utility that you can run using
Runtime.exec() to gather the information you need.

Failing that, you likely need to use JNI, as others have already
pointed out.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top