File: ibam.hpp

package info (click to toggle)
ibam 1%3A0.4-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 156 kB
  • ctags: 91
  • sloc: cpp: 699; makefile: 104; sh: 33
file content (182 lines) | stat: -rw-r--r-- 5,731 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// IBAM, the Intelligent Battery Monitor
// Copyright (C) 2001-2003, Sebastian Ritterbusch (IBAM@Ritterbusch.de)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#define IBAM_IGNORE_DATA_AFTER_X_SECONDS  3600
#define IBAM_MINIMAL_SECONDS_PER_PERCENT  10
#define IBAM_MAXIMAL_SECONDS_PER_PERCENT  800
#define IBAM_ASSUME_DEFAULT_BATTERY_MIN   120
#define IBAM_MAXIMAL_PROFILES             500

#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

using namespace std;

#include <sys/stat.h>  // for mkdir
#include <sys/types.h> // for mkdir

class battery_status
{
   protected:
      int acLineStatus;
      int batteryStatus;
      int chargeStatus;
      int remainingBatteryPercent;
      int remainingBatteryLifeSeconds;
      string Path;
   public:
      inline int   onBattery(void) const;
      inline int   charging(void)  const;
      inline int   percent(void)   const;
      inline int   seconds(void)   const;
      virtual inline void update(void) = 0;
     inline battery_status(string path);
     virtual inline ~battery_status(void);
};

class apm_status : public battery_status
{
   public:
      inline void update(void);
      inline apm_status(string path="/proc/apm");
};

class pmu_status : public battery_status
{
   public:
      inline void update(void);
      inline pmu_status(string path="/proc/pmu");
};
      
class acpi_status : public battery_status
{
   public:
      inline void update(void);
      inline acpi_status(string path="/proc/acpi");
};
      
class percent_data
{
   private:
      int      maxpercents;
      double  *time_for_percent;
      double  *time_deriv_for_percent;
      int     *time_samples;
      
      inline void size_to(int newpercents);
   
   public:
      inline percent_data(void);
      inline ~percent_data(void);
      friend inline ostream & operator <<(ostream & o,const percent_data & a);
      inline double add_data(int percent,double time_for,int samples=1);
      inline double average(int a,int b); // average from a to b
      inline double average_derivation(int a,int b); // standard derivation from a to b
      inline double add_data(int percent,double time_for,double time_deriv_for,int samples=1);
      friend inline istream & operator >>(istream & i,percent_data &a);
      inline istream & import(istream & i);
      inline double remain(int percent);
      inline double inverted_remain(int percent);
      inline double total(void);
};

class ibam
{
   private:
      percent_data data;
      int         data_changed;    // 1 if save of ibam.rc demanded
      battery_status  *apm;
      percent_data battery;
      int         battery_loaded;
      int         battery_changed;
      percent_data charge;
      int         charge_loaded;
      int         charge_changed;
      int         profile_changed;
      
      unsigned long  lasttime;
      int            lastpercent;
      double         lastratio;
      int            lastratiocount;
      int            laststatus;
      
      double         last_sec_per_min;
      double         last_sec_per_min_prediction;
      
      unsigned long  currenttime;
      int            currentpercent;
      int            currentstatus;
      
      string     home;
      
      int            isvalid;
      
      int            profile_logging; // 1 if cycle shall be logged for later analysis
      int            profile_number;  // number of profile (increased on each cycle change)
      int            profile_active;  // data has been written to current profile
      
   public:
      inline ibam(void);
      inline void import(void);
      inline void load_battery(void);
      inline void load_charge(void);
      inline void update_statistics(void);
      inline void ignore_statistics(void);
      inline void save(void);
      inline string profile_filename(int n,int type) const;
      inline int   current_profile_number(void) const;
      inline int   current_profile_type(void) const;

      inline void  set_profile_logging(int);
      inline int   profile_logging_setting(void) const;
      
      inline int   seconds_left_battery_bios(void);
      inline int   seconds_left_battery(void);
      inline int   seconds_left_battery_adaptive(void);

      inline int   percent_battery_bios(void);
      inline int   percent_battery(void);
                  
      inline int   seconds_left_charge(void);
      inline int   seconds_left_charge_adaptive(void);

      inline int   percent_charge(void);
      
      inline int   seconds_battery_total(void);
      inline int   seconds_battery_total_adaptive(void);

      inline int   seconds_charge_total(void);
      inline int   seconds_charge_total_adaptive(void);
      
      inline int   seconds_battery_correction(void);

      inline int   seconds_charge_correction(void);
      inline int   onBattery(void);
      inline int   charging(void);
      
      inline int   valid(void) const;
      
      inline void  update(void);
};

#include "ibam.inl"