Topic: Capturing Battery/Power Change Events

I just completed modifying my Adafruit battery to add the temperature sensor, and 3-pin connector that is needed to make it compatible with the chumby hacker board.  I noticed that the chumby is very aware of the battery and it's charging state, and weather or not there is primary power or only battery power available to it.  It typed a number of message on the console indicating these state changes, and conditions.    That made me think of a question.  What mechanism is there (if any) to capture these events or state changes within user programs so that a user program could for instance detect the loss of primary power, do some clean up work and shut the chumby off when the cleanup work is done.  Is there a /proc/ file to examine, or any other mechanism to tell what POWER state the chumby is in from a user program?

Thanks for any info or suggestions about this topic.

Re: Capturing Battery/Power Change Events

Look in the directory "/sys/class/power_supply/battery/"