1 /***************************************************************************
2  *
3  * hal-system-lcd-get-brightness-sunos.c : Get LCD brightness
4  *
5  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
6  * Use is subject to license terms.
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  **************************************************************************/
11 
12 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15 
16 #include <errno.h>
17 #include <string.h>
18 #include <strings.h>
19 #include <ctype.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <sys/ioctl.h>
23 #include <fcntl.h>
24 #include <unistd.h>
25 #include "../../hald/util.h"
26 #include <sys/acpi_drv.h>
27 
28 int
main(int argc,char * argv[])29 main(int argc, char *argv[])
30 {
31 	struct acpi_drv_output_status status;
32 	int fd = -1;
33 	char *udi;
34 	char device_file[HAL_PATH_MAX] = "/devices";
35 	char *devfs_path;
36 
37 	if ((udi = getenv("UDI")) == NULL) {
38 		return (-1);
39 	}
40 	if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
41 		return (-1);
42 	}
43 
44 	strlcat(device_file, devfs_path, HAL_PATH_MAX);
45 	fprintf(stderr, "Getting brightness on %s (udi=%s)",
46 	    device_file, udi);
47 	if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
48 		fprintf(stderr, "Cannot open %s: %s", device_file,
49 		    strerror(errno));
50 		return (-1);
51 	}
52 
53 	bzero(&status, sizeof (status));
54 	if (ioctl(fd, ACPI_DRV_IOC_STATUS, &status) < 0) {
55 		close(fd);
56 		return (-1);
57 	} else {
58 		close(fd);
59 		return (status.cur_level_index);
60 	}
61 }
62