18861N/Adiff -Nrup gkrellm-2.3.2.mod.2/server/Makefile gkrellm-2.3.2.mod.3/server/Makefile
18861N/A--- gkrellm-2.3.2.mod.2/server/Makefile 2008-10-09 19:02:59.728948000 +0800
18861N/A+++ gkrellm-2.3.2.mod.3/server/Makefile 2008-10-09 19:59:59.877475000 +0800
18861N/A@@ -56,10 +56,15 @@ GKRELLMD_INCLUDES = gkrellmd.h $(SHARED_
18861N/A PKG_INCLUDE = `$(PKG_CONFIG) --cflags glib-2.0 gthread-2.0`
18861N/A PKG_LIB = `$(PKG_CONFIG) --libs glib-2.0 gmodule-2.0 gthread-2.0`
18861N/A
18861N/A+HAL_CFLAGS = -DDBUS_API_SUBJECT_TO_CHANGE -I/usr/include/hal -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
18861N/A+HAL_LIBS = -lhal -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0
18861N/A+DBUS_CFLAGS = -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
18861N/A+DBUS_LIBS = -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0
18861N/A+
18861N/A GLIB12_INCLUDE = `glib-config --cflags`
18861N/A GLIB12_LIB = `glib-config --libs glib gmodule`
18861N/A
18861N/A-FLAGS = -O2 $(PKG_INCLUDE)
18861N/A+FLAGS = -O2 $(PKG_INCLUDE) $(HAL_CFLAGS) $(DBUS_CFLAGS)
18861N/A
18861N/A ifeq ($(glib12),1)
18861N/A FLAGS = -O2 $(GLIB12_INCLUDE)
18861N/A@@ -69,7 +74,7 @@ ifeq ($(glib12),yes)
18861N/A endif
18861N/A FLAGS += $(GTOP_INCLUDE) $(PTHREAD_INC) -I.. -I$(SHARED_PATH) -DGKRELLM_SERVER
18861N/A
18861N/A-LIBS = $(PKG_LIB)
18861N/A+LIBS = $(PKG_LIB) $(HAL_LIBS) $(DBUS_LIBS)
18861N/A ifeq ($(glib12),1)
18861N/A LIBS = $(GLIB12_LIB)
18861N/A endif
18861N/Adiff -Nrup gkrellm-2.3.2.mod.2/src/Makefile gkrellm-2.3.2.mod.3/src/Makefile
18861N/A--- gkrellm-2.3.2.mod.2/src/Makefile 2008-10-09 19:02:59.824263000 +0800
18861N/A+++ gkrellm-2.3.2.mod.3/src/Makefile 2008-10-09 20:02:19.048732000 +0800
18861N/A@@ -87,10 +87,18 @@ GKRELLM_INCLUDES = gkrellm.h gkrellm-pub
18861N/A PKG_INCLUDE = `$(PKG_CONFIG) --cflags gtk+-2.0 gthread-2.0`
18861N/A PKG_LIB = `$(PKG_CONFIG) --libs gtk+-2.0 gthread-2.0`
18861N/A
18861N/A-FLAGS = -O2 -I.. -I$(SHARED_PATH) $(PKG_INCLUDE) $(GTOP_INCLUDE) $(PTHREAD_INC) \
18861N/A+HAL_CFLAGS = -DDBUS_API_SUBJECT_TO_CHANGE -I/usr/include/hal -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
18861N/A+HAL_LIBS = -lhal -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0
18861N/A+DBUS_CFLAGS = -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
18861N/A+DBUS_LIBS = -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0
18861N/A+
18861N/A+FLAGS = -I.. -I$(SHARED_PATH) $(PKG_INCLUDE) $(GTOP_INCLUDE) $(PTHREAD_INC) $(HAL_CFLAGS) $(DBUS_CFLAGS)\
18861N/A+
18861N/A+
18861N/A+FLAGS = -O2 -I.. -I$(SHARED_PATH) $(PKG_INCLUDE) $(GTOP_INCLUDE) $(PTHREAD_INC) $(HAL_CFLAGS) $(DBUS_CFLAGS) \
18861N/A ${NTLM_INCLUDES} -DGKRELLM_CLIENT
18861N/A
18861N/A-LIBS = $(PKG_LIB) $(GTOP_LIBS) $(SMC_LIBS) $(SYS_LIBS) $(SSL_LIBS) $(SENSORS_LIBS) \
18861N/A+LIBS = $(PKG_LIB) $(GTOP_LIBS) $(SMC_LIBS) $(SYS_LIBS) $(SSL_LIBS) $(SENSORS_LIBS) $(HAL_LIBS) $(DBUS_LIBS) -lnsl \
18861N/A $(NTLM_LIBS) $(X11_LIBS)
18861N/A
18861N/A ifeq ($(debug),1)
18861N/A--- gkrellm-2.3.2.mod.2/src/sysdeps/solaris.c 2008-10-09 19:02:59.823558000 +0800
18861N/A+++ gkrellm-2.3.2.mod.3/src/sysdeps/solaris.c 2008-10-22 20:33:19.630950000 +0800
18861N/A@@ -998,18 +998,218 @@ gkrellm_sys_fs_init(void)
18861N/A
18861N/A /* ===================================================================== */
18861N/A /* Battery monitor interface */
18861N/A+
18861N/A+#include <libhal.h>
18861N/A+#include <dbus/dbus-glib-lowlevel.h>
18861N/A+#include <glib.h>
18861N/A+
18861N/A+static void
18861N/A+device_removed_callback( LibHalContext *ctx, const char *udi )
18861N/A+{
18861N/A+ return;
18861N/A+}
18861N/A+
18861N/A+static void
18861N/A+device_added_callback( LibHalContext *ctx, const char *udi )
18861N/A+{
18861N/A+ return;
18861N/A+}
18861N/A+
18861N/A void
18861N/A gkrellm_sys_battery_read_data(void)
18861N/A {
18861N/A- }
18861N/A+ DBusConnection *connection;
18861N/A+ LibHalContext *ctx;
18861N/A+ DBusError error;
18861N/A+ char **devices;
18861N/A+ gint i, num;
18861N/A+ char * key;
18861N/A+ const char *udi; /* device name seen by HAL */
18861N/A+ /* We need to know if we are on AC power or not. Eventually, we can look
18861N/A+ * at the AC adaptor HAL devices to determine that. For now, we assume that
18861N/A+ * if any battery is discharging then we must not be on AC power. Else, by
18861N/A+ * default, we must be on AC.
18861N/A+ */
18861N/A+ gboolean on_line = TRUE;
18861N/A+
18861N/A+ gboolean available; /* the device's battery is/isn't attached */
18861N/A+ gboolean charging; /* If the battery is charged by AC */
18861N/A+ gboolean discharging; /* If the battery is used */
18861N/A+ gint remaining_time; /* remaining time in second gotten from HAL */
18861N/A+ gint current_charge_total = 0, full_capacity_total = 0;
18861N/A+ gint current_level, full_level;
18861N/A+ gint time_left; /* how many time left for battery */
18861N/A+ gint percent; /* used percent */
18861N/A+
18861N/A+ dbus_error_init( &error );
18861N/A+
18861N/A+ if( (connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error )) == NULL )
18861N/A+ {
18861N/A+ dbus_error_free( &error );
18861N/A+ return;
18861N/A+ }
18861N/A+
18861N/A+ if( (ctx = libhal_ctx_new()) == NULL )
18861N/A+ {
18861N/A+ dbus_set_error( &error, _("HAL error"), _("Could not create libhal_ctx") );
18861N/A+ dbus_error_free( &error );
18861N/A+ return;
18861N/A+ }
18861N/A
18861N/A-gboolean
18861N/A-gkrellm_sys_battery_init()
18861N/A- {
18861N/A- return FALSE;
18861N/A- }
18861N/A+ libhal_ctx_set_dbus_connection( ctx, connection );
18861N/A+ libhal_ctx_set_device_added( ctx, device_added_callback );
18861N/A+ libhal_ctx_set_device_removed( ctx, device_removed_callback );
18861N/A+
18861N/A+ if( libhal_ctx_init( ctx, &error ) == 0 )
18861N/A+ {
18861N/A+ libhal_ctx_free( ctx );
18861N/A+ dbus_error_free( &error );
18861N/A+ return;
18861N/A+ }
18861N/A+
18861N/A+ devices = libhal_find_device_by_capability( ctx, "battery", &num, &error );
18861N/A
18861N/A+ if( devices == NULL )
18861N/A+ {
18861N/A+ libhal_ctx_shutdown( ctx, NULL );
18861N/A+ libhal_ctx_free( ctx );
18861N/A+ dbus_error_free( &error );
18861N/A+ return;
18861N/A+ }
18861N/A
18861N/A+ /* FIXME: for now, if 0 battery devices are present on first scan, then fail.
18861N/A+ * This allows fallover to the legacy (ACPI, APM, etc) backends if the
18861N/A+ * installed version of HAL doesn't know about batteries. This check should
18861N/A+ * be removed at some point in the future (maybe circa GNOME 2.13..).
18861N/A+ */
18861N/A+ if( num == 0 )
18861N/A+ {
18861N/A+
18861N/A+ dbus_free_string_array( devices );
18861N/A+ dbus_set_error( &error, _("HAL error"), _("No batteries found") );
18861N/A+ libhal_ctx_shutdown( ctx, NULL );
18861N/A+ libhal_ctx_free( ctx );
18861N/A+ dbus_error_free( &error );
18861N/A+
18861N/A+ return;
18861N/A+ }
18861N/A+
18861N/A+ for( i = 0; i < num; i++ )
18861N/A+ {
18861N/A+ char *type = libhal_device_get_property_string( ctx, devices[i],
18861N/A+ "battery.type",
18861N/A+ &error );
18861N/A+ if( type )
18861N/A+ {
18861N/A+ /* We only track 'primary' batteries (ie: to avoid monitoring
18861N/A+ * batteries in cordless mice or UPSes etc.)
18861N/A+ */
18861N/A+ if( !strcmp( type, "primary" ) ){
18861N/A+
18861N/A+ udi = devices[i];
18861N/A+
18861N/A+ key = g_strdup("battery.charge_level.current"); // current charge
18861N/A+ current_level = libhal_device_get_property_int( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ key = g_strdup("battery.charge_level.last_full"); // maximum charge
18861N/A+ full_level = libhal_device_get_property_int( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ key = g_strdup("battery.present"); /* the device's battery is/isn't attached */
18861N/A+ available = libhal_device_get_property_bool( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ if (!available)
18861N/A+ {
18861N/A+ /* Either no battery is present or something has gone horribly wrong.
18861N/A+ * In either case we must return that the composite battery is not
18861N/A+ * present.
18861N/A+ */
18861N/A+ available = FALSE;
18861N/A+ percent = 0;
18861N/A+ time_left = -1;
18861N/A+ on_line = TRUE;
18861N/A+ charging = FALSE;
18861N/A+ gkrellm_battery_assign_data(i, available, on_line, charging, percent, time_left);
18861N/A+
18861N/A+ dbus_free_string_array( devices );
18861N/A+ libhal_ctx_shutdown( ctx, NULL );
18861N/A+ libhal_ctx_free( ctx );
18861N/A+ dbus_error_free( &error );
18861N/A+ return ;
18861N/A+ }
18861N/A+
18861N/A+ key = "battery.rechargeable.is_discharging"; /* the battery is being used */
18861N/A+ discharging = libhal_device_get_property_bool( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ key = g_strdup("battery.rechargeable.is_charging");
18861N/A+ charging = libhal_device_get_property_bool( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ key = g_strdup("battery.charge_level.rate");// shows the percent charged
18861N/A+ percent = libhal_device_get_property_int( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ key = g_strdup("battery.remaining_time"); // the remaining charge time or remaining battery time
18861N/A+ remaining_time = libhal_device_get_property_int( ctx, udi, key, &error );
18861N/A+ g_free(key);
18861N/A+
18861N/A+ /* In the case of exactly one battery, report the time remaining figure
18861N/A+ * from HAL directly since it might have come from an authorative source
18861N/A+ * (ie: the PMU or APM subsystem).
18861N/A+ *
18861N/A+ * HAL gives remaining time in seconds with a 0 to mean that the
18861N/A+ * remaining time is unknown. we uses minutes and -1 for
18861N/A+ * unknown time remaining.
18861N/A+ */
18861N/A+
18861N/A+ if( remaining_time == 0 )
18861N/A+ time_left = -1;
18861N/A+ else
18861N/A+ time_left = (remaining_time + 30) / 60;
18861N/A+
18861N/A+
18861N/A+ /* At least one battery is discharging -> we're not on AC. */
18861N/A+ if( discharging )
18861N/A+ {
18861N/A+ on_line = FALSE; /* AC is on-line? */
18861N/A+ charging = FALSE;
18861N/A+ }
18861N/A+
18861N/A+ current_charge_total += current_level;
18861N/A+ full_capacity_total += full_level;
18861N/A+
18861N/A+ /* As per above, overall charge is:
18861N/A+ *
18861N/A+ * Sum( Current charges ) / Sum( Full Capacities )
18861N/A+ */
18861N/A+ percent = ( ((double) current_charge_total) /
18861N/A+ ((double) full_capacity_total) ) * 100.0 + 0.5;
18861N/A+
18861N/A+
18861N/A+ gkrellm_battery_assign_data(i, available, on_line, charging, percent, time_left);
18861N/A+
18861N/A+ libhal_free_string( type );
18861N/A+ }
18861N/A+ } // end of if (type)
18861N/A+ } // end of for
18861N/A+
18861N/A+ dbus_free_string_array( devices );
18861N/A+
18861N/A+ libhal_ctx_shutdown( ctx, NULL );
18861N/A+ libhal_ctx_free( ctx );
18861N/A+ dbus_error_free( &error );
18861N/A+ return ;
18861N/A+ }
18861N/A+
18861N/A+gboolean
18861N/A+gkrellm_sys_battery_init()
18861N/A+ {
18861N/A+ return TRUE;
18861N/A+ }
18861N/A+
18861N/A /* ===================================================================== */
18861N/A /* Uptime monitor interface */
18861N/A