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
|
/***************************************************************************
* *
* Powersave Daemon *
* *
* Copyright (C) 2004,2005 SUSE Linux Products GmbH *
* *
* 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 you *
* 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., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "powerlib.h"
int quiet = 0;
void usage()
{
fprintf(stderr, "Usage: on_ac_power [-q]\n\n\
returns 0 if on AC power or unable to determine ac state\n\
returns 1 if on battery power\n\
-q: quiet mode\n");
}
void get_args(int argc, char **argv)
{
int option_index = 0;
struct option opts[] = {
{"quiet", 0, 0, 'q'},
{"help", 0, 0, 'h'},
{NULL, 0, 0, 0},
};
while (1) {
int i = getopt_long(argc, argv, "hq", opts, &option_index);
if (i == -1) {
break;
}
switch (i) {
case 'h':
usage();
exit(0);
break;
case 'q':
quiet = 1;
break;
default:
break;
}
}
}
int main(int argc, char **argv)
{
int status;
get_args(argc, argv);
status = getACAdapterStatus();
if (status == AC_OFFLINE) {
if (!quiet)
fprintf(stdout, "OFFLINE\n");
return 1;
} else {
if (!quiet)
fprintf(stdout, "ONLINE\n");
return 0;
}
}
|