00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef POWERSAVE_POWERLIB_H
00026 #define POWERSAVE_POWERLIB_H
00027
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034
00035 #include <stdio.h>
00036 #include <syslog.h>
00037 #include <stdint.h>
00038
00053 #define MAX_FILE_PATH 512
00054
00056 #define MAX_LINE_SIZE 1024
00057
00059 #define MAX_BATTERIES 4
00060
00062 #define MAX_BAT_CHAR_LEN 200
00063
00064 #define MAX_THERMAL_ACTIVE 10
00065
00067 #define NO_ACPI_ERROR -20
00068
00070 #define NO_MODULE_ERROR -10
00071
00073 #define NO_DEVICE_ERROR -5
00074
00076 #define MAX_SUPPORTED_CPUS 32
00077
00082 #define UNKNOWN -1
00083
00085 #define CHARG_STATE_UNKNOWN 0
00086
00087 #define CHARG_STATE_CHARGING 1
00088
00089 #define CHARG_STATE_DISCHARGING 2
00090
00091 #define CHARG_STATE_CHARG_DISCHARG (CHARG_STATE_CHARGING | CHARG_STATE_DISCHARGING)
00092
00094 #define ACPI_S1 1
00095
00096 #define ACPI_S2 2
00097
00098 #define ACPI_S3 4
00099
00100 #define ACPI_S3_BIOS 8
00101
00102 #define ACPI_S4 16
00103
00104 #define ACPI_S4_BIOS 32
00105
00106 #define APM_STANDBY 64
00107
00108 #define APM_SUSPEND 128
00109
00110
00111 #ifdef POWERSAVE_DEBUG
00112 #define DBG_ERR 1
00113 #define DBG_WARN 2
00114 #define DBG_DIAG 4
00115 #define DBG_INFO 8
00116 #define DBG_DEBUG 16
00117
00118 extern int DEBUG_LEVEL;
00119 #ifdef USE_SYSLOG
00120 static int syslog_open = 0;
00121 #define pDebug(level, string, args...) \
00122 do{\
00123 if (!syslog_open){ \
00124 openlog("[powersave]",0 , LOG_DAEMON); \
00125 syslog_open = 1; \
00126 } \
00127 if (DEBUG_LEVEL & DBG_ERR & level){ \
00128 syslog(LOG_ERR, "ERROR (%s:%d) "string, __FUNCTION__, __LINE__, ## args); \
00129 }else if (DEBUG_LEVEL & DBG_WARN & level) { \
00130 syslog(LOG_WARNING, "WARNING (%s:%d) "string, __FUNCTION__, __LINE__, ## args); \
00131 }else if (DEBUG_LEVEL & DBG_DIAG & level) { \
00132 syslog(LOG_NOTICE, "DIAG (%s:%d) "string, __FUNCTION__, __LINE__, ## args); \
00133 }else if (DEBUG_LEVEL & DBG_INFO & level) {\
00134 syslog(LOG_INFO, "Info (%s:%d) "string, __FUNCTION__, __LINE__, ## args); \
00135 }else if (DEBUG_LEVEL & DBG_DEBUG & level) {\
00136 syslog(LOG_INFO, "Debug (%s:%d) "string, __FUNCTION__, __LINE__, ## args); \
00137 } \
00138 }while(0);
00139 #else
00140 #define pDebug(level, string, args...) \
00141 do{\
00142 if (DEBUG_LEVEL & DBG_ERR & level){ \
00143 fprintf(stderr, "ERROR (%s:%d) "string"\n", __FUNCTION__, __LINE__, ## args); \
00144 }else if (DEBUG_LEVEL & DBG_WARN & level) { \
00145 fprintf(stderr, "WARNING (%s:%d) "string"\n", __FUNCTION__, __LINE__, ## args); \
00146 }else if (DEBUG_LEVEL & DBG_DIAG & level) { \
00147 printf("DIAG (%s:%d) "string"\n", __FUNCTION__, __LINE__, ## args); \
00148 }else if (DEBUG_LEVEL & DBG_INFO & level) {\
00149 printf("Info "string"\n", ## args); \
00150 }else {\
00151 printf("Debug "string"\n", ## args); \
00152 } \
00153 }while(0);
00154
00155 #endif
00156 #else
00157 #define pDebug(level, string, args...) do {} while (0);
00158 #endif
00159
00161 enum BATTERY_PRESENT { PRESENT_YES = 0, PRESENT_NO };
00162
00164 enum CAPACITY_UNIT { WATT_H = 0, AMP };
00165
00167 enum BATTERY_TECH { TECH_NON_RECHARGEABLE = 0, TECH_RECHARGEABLE };
00168
00173 enum CAPACITY_STATE { STATE_OK, STATE_CRIT, STATE_LOW, STATE_WARN };
00174
00176 enum AC_ADAPTER_STATE { AC_UNKNOWN, AC_ONLINE, AC_OFFLINE };
00177
00179 enum DISK_MODE { DISK_FULL_ON, DISK_STANDBY, DISK_SLEEP };
00180
00182 enum LID_STATE { LID_OPEN, LID_CLOSED };
00183
00185 enum ISACPI { NOT_SUPPORTED = -1, APM, ACPI };
00186
00192 enum THERM_MODE { OK, ACTIVE, PASSIVE, HOT, CRITICAL };
00193
00195 enum _COOLING_POLICY { COOLING_MODE_ACTIVE = 0, COOLING_MODE_PASSIVE };
00196
00198 typedef struct BatteryGeneral {
00200 int remaining_percent;
00201
00204 int remaining_minutes;
00205
00213 int charging_state;
00214 } BatteryGeneral;
00215
00220 typedef struct BatteryDetailed {
00222 int present;
00223
00224
00225 int design_capacity;
00226 int last_full_capacity;
00227 int battery_technology;
00228 int design_voltage;
00229 int design_capacity_warning;
00230 int design_capacity_low;
00231 int capacity_granularity_1;
00232 int capacity_granularity_2;
00233 char model_number[MAX_BAT_CHAR_LEN + 1];
00234 char serial_number[MAX_BAT_CHAR_LEN + 1];
00235 char battery_type[MAX_BAT_CHAR_LEN + 1];
00236 char OEM_info[MAX_BAT_CHAR_LEN + 1];
00237
00238
00239 int power_unit;
00240 int capacity_state;
00241 int charging_state;
00242 int present_rate;
00243 int remaining_capacity;
00244 int present_voltage;
00245
00246
00247 int alarm_limit;
00248 } BatteryDetailed;
00249
00251 typedef struct ThermalDev {
00252 int present;
00253 int temperature;
00254
00255 int cooling_mode;
00256 int polling_frequency;
00257 int critical;
00258 int hot;
00259 int passive;
00260 int active[MAX_THERMAL_ACTIVE];
00261
00262 int state;
00263 int tc1;
00264 int tc2;
00265 int tsp;
00266 } ThermalDev;
00267
00279 int getBatteriesInfo(BatteryGeneral * bat);
00280
00289 int getBatteryInfo(const int no, BatteryGeneral *battery_info);
00290
00295 int numBatteries(void);
00296
00315 int getBatteryDetailedInfo(const int no, BatteryDetailed * bd);
00316
00321 int setBatteryAlarm(const int percent);
00322
00327 int getLidState(void);
00328
00341 int getThrottlingInfo(int *num_states, int *current_state);
00342
00351 int setThrottlingPercent(const int percent);
00352
00367 int getThrottlingInfoCPU(const int cpu, int *num_states, int *current_state);
00368
00381 int setThrottlingStateCPU(const int cpu, const int state);
00382
00392 int setThrottlingPercentCPU(const int cpu, const int percent);
00393
00400 int getThermalZonesNum(void);
00401
00414 int getThermalZoneTemp(const int zone);
00415
00428 int getThermalZoneState(int zone);
00429
00443 int getThermalZone(const int zone, ThermalDev * td);
00444
00457 int setThermalTrippoints(const int zone, const ThermalDev td);
00458
00471 int setCoolingMode(const int device_num, const int mode);
00472
00479 int getFanNum(void);
00480
00496 int getFanStatus(const int device_num);
00497
00507 int getACAdapterStatus(void);
00508
00521 float getRealProcessorSpeed(void);
00522
00535 int calcCPULoad(const int consider_nice);
00536
00543 int getCPULoad(const int cpu);
00544
00551 void freeCPULoadData(void);
00552
00557 int getCPUCount(void);
00558
00565 int64_t getSupportedSleepStates(void);
00566
00572 int checkACPI(void);
00573
00592 void setDebugLevel(const int dbg);
00593
00594 #ifdef __cplusplus
00595 }
00596 #endif
00597
00598 #endif
00599