getting battery life

I was wondering how i would get the battery life of a computer on linux i need for a java jni project i am using a windows and therefore have no way of testing it but i want the code to be platform independent so therefore i need a linux version here is my windows version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <locale>
#include <sstream>
#include <string>
#define UNKNOWN         0xFFFFFFFF

using namespace std;

int getLife()
{
        SYSTEM_POWER_STATUS status;
        GetSystemPowerStatus( &status );
        int life = status.BatteryLifePercent;
        return life;
}

int getSecs()
{
        SYSTEM_POWER_STATUS status;
        GetSystemPowerStatus( &status );
        int secs = status.BatteryLifeTime;
        return secs;
}

int main()
{
    cout<<getSecs();
    cout<<" ";
    cout<<getLife();  
    Sleep(10000);  
    return 0;
}
Topic archived. No new replies allowed.