Commit 3687fdd3 authored by William Jon McCann's avatar William Jon McCann Committed by William Jon McCann

New class to act as a management shell.

2006-01-08  William Jon McCann  <mccann@jhu.edu>

	* src/gpm-manager.[ch]: New class to act as a management
	shell.

	* src/gpm-hal-monitor.[ch]: New class to encapsulate all
	the HAL monitoring.

	* src/gpm-screensaver.h: Add G_BEGIN_DECLS and glib includes.

	* src/gpm-notification.c (callback_actions_activated):
	Disable the actions temporarily until we can use signals
	to do this cleanly.

	* src/gpm-marshal.list: Add new signal for battery
	status changed.

	* src/gpm-main.c: Move functionality out of here and
	split into GpmManager and GpmHalMonitor.

	* src/gpm-idle.[ch]: Turn into a class for monitoring
	the session and system idle.

	* src/gpm-hal.h: Add G_BEGIN_DECLS and glib includes.

	* src/gpm-hal-callback.[ch] (signal_handler_PropertyModified)
	(signal_handler_DeviceRemoved, signal_handler_NewCapability)
	(signal_handler_Condition, gpm_hal_callback_init):
	Add user data to be returned to callbacks.

	* src/gpm-dbus-server.[ch]: Don't use gnome.h.  Don't
	export signal enum.
	* src/Makefile.am: Add new files.
	* AUTHORS: Updated.

	Refactored to support handling signals from gnome-screensaver,
	laying groundwork for DPMS management, and making HAL
	optional. Fixes #325911.
parent 27d899fc
Richard Hughes <richard@hughsie.com>
William Jon McCann <mccann@jhu.edu>
2006-01-08 William Jon McCann <mccann@jhu.edu>
* src/gpm-manager.[ch]: New class to act as a management
shell.
* src/gpm-hal-monitor.[ch]: New class to encapsulate all
the HAL monitoring.
* src/gpm-screensaver.h: Add G_BEGIN_DECLS and glib includes.
* src/gpm-notification.c (callback_actions_activated):
Disable the actions temporarily until we can use signals
to do this cleanly.
* src/gpm-marshal.list: Add new signal for battery
status changed.
* src/gpm-main.c: Move functionality out of here and
split into GpmManager and GpmHalMonitor.
* src/gpm-idle.[ch]: Turn into a class for monitoring
the session and system idle.
* src/gpm-hal.h: Add G_BEGIN_DECLS and glib includes.
* src/gpm-hal-callback.[ch] (signal_handler_PropertyModified)
(signal_handler_DeviceRemoved, signal_handler_NewCapability)
(signal_handler_Condition, gpm_hal_callback_init):
Add user data to be returned to callbacks.
* src/gpm-dbus-server.[ch]: Don't use gnome.h. Don't
export signal enum.
* src/Makefile.am: Add new files.
* AUTHORS: Updated.
Refactored to support handling signals from gnome-screensaver,
laying groundwork for DPMS management, and making HAL
optional. Fixes #325911.
2005-01-06 Richard Hughes <richard@hughsie.com>
* data/: src/gnome-power-preferences.glade,
......
2006-01-08 William Jon McCann <mccann@jhu.edu>
* POTFILES.in: Add new files.
2006-01-07 Ilkka Tuohela <hile@iki.fi>
* fi.po: Updated Finnish translation.
......
......@@ -21,12 +21,16 @@ src/gpm-hal.c
src/gpm-hal.h
src/gpm-hal-callback.c
src/gpm-hal-callback.h
src/gpm-hal-monitor.c
src/gpm-hal-monitor.h
src/gpm-idle.c
src/gpm-idle.h
src/gpm-libnotify.c
src/gpm-libnotify.h
src/gpm-main.c
src/gpm-main.h
src/gpm-manager.c
src/gpm-manager.h
src/gpm-notification.c
src/gpm-notification.h
src/gpm-prefs.c
......
......@@ -73,6 +73,10 @@ gnome_power_manager_SOURCES = \
gpm-libnotify.c \
gpm-idle.h \
gpm-idle.c \
gpm-hal-monitor.h \
gpm-hal-monitor.c \
gpm-manager.h \
gpm-manager.c \
gpm-notification.h \
gpm-notification.c \
gpm-core.h \
......
......@@ -33,14 +33,24 @@
*/
#include <glib.h>
#include <gnome.h>
#include <dbus/dbus-glib.h>
#include "gpm-dbus-server.h"
#include "gpm-common.h"
#include "gpm-dbus-common.h"
#include "gpm-hal.h"
G_DEFINE_TYPE(GPMObject, gpm_object, G_TYPE_OBJECT)
G_DEFINE_TYPE (GPMObject, gpm_object, G_TYPE_OBJECT)
/** The dbus signal type
*/
enum
{
MAINS_CHANGED, /**< Signal mainsStatusChanged */
ACTION_ABOUT_TO_HAPPEN, /**< Signal actionAboutToHappen */
PERFORMING_ACTION, /**< Signal performingAction */
LAST_SIGNAL /**< The last signal... */
};
guint signals[LAST_SIGNAL] = { 0 };
......
......@@ -29,15 +29,11 @@
#ifndef _GPMDBUSSERVER_H
#define _GPMDBUSSERVER_H
/** The dbus signal type
*/
enum
{
MAINS_CHANGED, /**< Signal mainsStatusChanged */
ACTION_ABOUT_TO_HAPPEN, /**< Signal actionAboutToHappen */
PERFORMING_ACTION, /**< Signal performingAction */
LAST_SIGNAL /**< The last signal... */
};
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
G_BEGIN_DECLS
typedef struct GPMObject GPMObject;
typedef struct GPMObjectClass GPMObjectClass;
......@@ -47,10 +43,15 @@ GType gpm_object_get_type (void);
/** The dbus GPM GObject type
*/
struct GPMObject {GObject parent;};
struct GPMObject {
GObject parent;
};
/** The dbus GPM GObject class type
*/
struct GPMObjectClass {GObjectClass parent;};
struct GPMObjectClass {
GObjectClass parent;
};
gboolean gpm_object_register (DBusGConnection *connection);
gboolean gpm_emit_about_to_happen (const gint value);
......@@ -61,5 +62,7 @@ gboolean gpm_object_is_on_battery (GPMObject *obj, gboolean *ret, GError **error
gboolean gpm_object_is_on_ups (GPMObject *obj, gboolean *ret, GError **error);
gboolean gpm_object_is_on_ac (GPMObject *obj, gboolean *ret, GError **error);
G_END_DECLS
#endif /* _GPMDBUSSERVER_H */
/** @} */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/** @file gpm-hal-callback.c
* @brief GLIB replacement for libhal, providing callbacks
* @author Richard Hughes <richard@hughsie.com>
......@@ -45,6 +46,7 @@
HalFunctions function;
HalRegistered reg;
HalConnections proxy;
gpointer cb_user_data;
/** PropertyModified signal handler
*
......@@ -78,7 +80,7 @@ signal_handler_PropertyModified (DBusGProxy *proxy, gint type, GPtrArray *proper
key = g_value_get_string (g_value_array_get_nth (array, 0));
removed = g_value_get_boolean (g_value_array_get_nth (array, 1));
added = g_value_get_boolean (g_value_array_get_nth (array, 2));
function.device_property_modified (udi, key, removed, added);
function.device_property_modified (udi, key, removed, added, cb_user_data);
}
}
......@@ -95,7 +97,7 @@ signal_handler_DeviceRemoved (DBusGProxy *proxy, gchar *udi)
return;
}
g_debug ("gpm_hal: device removed '%s'", udi);
function.device_removed (udi);
function.device_removed (udi, cb_user_data);
}
/** NewCapability signal handler
......@@ -112,7 +114,7 @@ signal_handler_NewCapability (DBusGProxy *proxy, gchar *udi, gchar *capability)
return;
}
g_debug ("gpm_hal: new capability '%s'", udi);
function.device_new_capability (udi, capability);
function.device_new_capability (udi, capability, cb_user_data);
}
/** Condition signal handler
......@@ -131,7 +133,7 @@ signal_handler_Condition (DBusGProxy *proxy, gchar *name, gchar *details)
}
udi = dbus_g_proxy_get_path (proxy);
g_debug ("gpm_hal: condition '%s'", udi);
function.device_condition (udi, name, details);
function.device_condition (udi, name, details, cb_user_data);
}
/** Removed watch removal
......@@ -489,7 +491,7 @@ gpm_hal_method_device_condition (HalDeviceCondition callback)
* @return If we initialised callbacks okay
*/
gboolean
gpm_hal_callback_init (void)
gpm_hal_callback_init (gpointer data)
{
g_debug ("gpm_hal_callback: init");
function.device_added = NULL;
......@@ -514,6 +516,8 @@ gpm_hal_callback_init (void)
proxy.device_condition = g_ptr_array_new ();
proxy.device_property_modified = g_ptr_array_new ();
cb_user_data = data;
return TRUE;
}
......
......@@ -31,12 +31,12 @@
#include <dbus/dbus-glib.h>
typedef void (*HalDeviceAdded) (const gchar *udi);
typedef void (*HalDeviceRemoved) (const gchar *udi);
typedef void (*HalDeviceNewCapability) (const gchar *udi, const gchar *capability);
typedef void (*HalDeviceLostCapability) (const gchar *udi, const gchar *capability);
typedef void (*HalDevicePropertyModified) (const gchar *udi, const gchar *key, gboolean removed, gboolean added);
typedef void (*HalDeviceCondition) (const gchar *udi, const gchar *name, const gchar *detail);
typedef void (*HalDeviceAdded) (const gchar *udi, gpointer user_data);
typedef void (*HalDeviceRemoved) (const gchar *udi, gpointer user_data);
typedef void (*HalDeviceNewCapability) (const gchar *udi, const gchar *capability, gpointer user_data);
typedef void (*HalDeviceLostCapability) (const gchar *udi, const gchar *capability, gpointer user_data);
typedef void (*HalDevicePropertyModified) (const gchar *udi, const gchar *key, gboolean removed, gboolean added, gpointer user_data);
typedef void (*HalDeviceCondition) (const gchar *udi, const gchar *name, const gchar *detail, gpointer user_data);
typedef void (*HalNameOwnerChanged) (const gchar *name, gboolean connected);
......@@ -75,7 +75,7 @@ typedef struct {
DBusGProxy *proxy;
} UdiProxy;
gboolean gpm_hal_callback_init (void);
gboolean gpm_hal_callback_init (gpointer user_data);
gboolean gpm_hal_callback_shutdown (void);
gboolean gpm_hal_method_device_removed (HalDeviceRemoved callback);
......
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
*
* 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.
*
* Authors: William Jon McCann <mccann@jhu.edu>
*
*/
#ifndef __GPM_HAL_MONITOR_H
#define __GPM_HAL_MONITOR_H
#include <glib-object.h>
G_BEGIN_DECLS
#define GPM_TYPE_HAL_MONITOR (gpm_hal_monitor_get_type ())
#define GPM_HAL_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_HAL_MONITOR, GpmHalMonitor))
#define GPM_HAL_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_HAL_MONITOR, GpmHalMonitorClass))
#define GS_IS_HAL_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_HAL_MONITOR))
#define GS_IS_HAL_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_HAL_MONITOR))
#define GPM_HAL_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_HAL_MONITOR, GpmHalMonitorClass))
typedef struct GpmHalMonitorPrivate GpmHalMonitorPrivate;
typedef struct
{
GObject parent;
GpmHalMonitorPrivate *priv;
} GpmHalMonitor;
typedef struct
{
GObjectClass parent_class;
void (* device_added) (GpmHalMonitor *monitor);
void (* device_removed) (GpmHalMonitor *monitor);
void (* power_button) (GpmHalMonitor *monitor,
gboolean state);
void (* suspend_button) (GpmHalMonitor *monitor,
gboolean state);
void (* lid_button) (GpmHalMonitor *monitor,
gboolean state);
void (* suspend) (GpmHalMonitor *monitor);
void (* hibernate) (GpmHalMonitor *monitor);
void (* lock) (GpmHalMonitor *lock);
void (* ac_power_changed) (GpmHalMonitor *monitor,
gboolean on_ac);
void (* battery_power_changed) (GpmHalMonitor *monitor,
gint percentage,
gint64 minutes,
gboolean discharging,
gboolean primary);
} GpmHalMonitorClass;
GType gpm_hal_monitor_get_type (void);
GpmHalMonitor * gpm_hal_monitor_new (void);
gboolean gpm_hal_monitor_get_on_ac (GpmHalMonitor *monitor);
G_END_DECLS
#endif /* __GPM_HAL_MONITOR_H */
......@@ -29,6 +29,10 @@
#ifndef _GPMHAL_H
#define _GPMHAL_H
#include <glib.h>
G_BEGIN_DECLS
gboolean gpm_hal_has_power_management (void);
gboolean gpm_hal_is_running (void);
......@@ -58,5 +62,7 @@ gint gpm_hal_num_devices_of_capability (const gchar *capability);
gint gpm_hal_num_devices_of_capability_with_value (const gchar *capability, const gchar *key, const gchar *value);
void gpm_hal_free_capability (gchar **value);
G_END_DECLS
#endif /* _GPMHAL_H */
/** @} */
This diff is collapsed.
/** @file gpm-idle.h
* @brief Idle calculation routines
* @author Richard Hughes <richard@hughsie.com>
* @date 2005-10-02
*/
/*
* Licensed under the GNU General Public License Version 2
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
*
* 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 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
......@@ -18,43 +14,62 @@
*
* 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 Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @addtogroup idle
* @{
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: William Jon McCann <mccann@jhu.edu>
*
*/
#ifndef _GPMIDLE_H
#define _GPMIDLE_H
#ifndef __GPM_IDLE_H
#define __GPM_IDLE_H
/*
* How many seconds between polling?
*/
#define POLL_FREQUENCY 5
/*
* Sets the idle percent limit, i.e. how hard the computer can work
* while considered "at idle"
*/
#define IDLE_LIMIT 5
#include <glib-object.h>
/** The cached cpu statistics used to work out the difference
*
*/
typedef struct {
long unsigned user; /**< The CPU user time */
long unsigned nice; /**< The CPU nice time */
long unsigned system; /**< The CPU system time */
long unsigned idle; /**< The CPU idle time */
long unsigned total; /**< The CPU total time (uptime) */
} cpudata;
typedef void (*IdleCallback) (const gint timeout);
gboolean gpm_idle_set_callback (IdleCallback callback);
gboolean gpm_idle_update (gpointer data);
gboolean gpm_idle_set_timeout (gint timeout);
#endif /* _GPMIDLE_H */
/** @} */
G_BEGIN_DECLS
#define GPM_TYPE_IDLE (gpm_idle_get_type ())
#define GPM_IDLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_IDLE, GpmIdle))
#define GPM_IDLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_IDLE, GpmIdleClass))
#define GPM_IS_IDLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_IDLE))
#define GPM_IS_IDLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_IDLE))
#define GPM_IDLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_IDLE, GpmIdleClass))
typedef enum {
GPM_IDLE_MODE_NORMAL,
GPM_IDLE_MODE_SESSION,
GPM_IDLE_MODE_SYSTEM
} GpmIdleMode;
typedef struct GpmIdlePrivate GpmIdlePrivate;
typedef struct
{
GObject parent;
GpmIdlePrivate *priv;
} GpmIdle;
typedef struct
{
GObjectClass parent_class;
void (* changed) (GpmIdle *idle,
GpmIdleMode mode);
} GpmIdleClass;
GType gpm_idle_get_type (void);
GpmIdle * gpm_idle_new (void);
void gpm_idle_reset (GpmIdle *idle);
GpmIdleMode gpm_idle_get_mode (GpmIdle *idle);
void gpm_idle_set_mode (GpmIdle *idle,
GpmIdleMode mode);
void gpm_idle_set_session_timeout (GpmIdle *idle,
guint timeout);
void gpm_idle_set_system_timeout (GpmIdle *idle,
guint timeout);
G_END_DECLS
#endif /* __GPM_IDLE_H */
This diff is collapsed.
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
*
* 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.
*
* Authors: William Jon McCann <mccann@jhu.edu>
*
*/
#ifndef __GPM_MANAGER_H
#define __GPM_MANAGER_H
#include <glib-object.h>
G_BEGIN_DECLS
#define GPM_TYPE_MANAGER (gpm_manager_get_type ())
#define GPM_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_MANAGER, GpmManager))
#define GPM_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_MANAGER, GpmManagerClass))
#define GS_IS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_MANAGER))
#define GS_IS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_MANAGER))
#define GPM_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_MANAGER, GpmManagerClass))
typedef struct GpmManagerPrivate GpmManagerPrivate;
typedef struct
{
GObject parent;
GpmManagerPrivate *priv;
} GpmManager;
typedef struct
{
GObjectClass parent_class;
} GpmManagerClass;
GType gpm_manager_get_type (void);
GpmManager * gpm_manager_new (void);
gboolean gpm_manager_get_on_ac (GpmManager *manager);
void gpm_manager_set_on_ac (GpmManager *manager,
gboolean on_ac);
void gpm_manager_suspend (GpmManager *manager);
void gpm_manager_hibernate (GpmManager *manager);
void gpm_manager_shutdown (GpmManager *manager);
G_END_DECLS
#endif /* __GPM_MANAGER_H */
NONE:INT,BOXED
NONE:STRING,STRING
NONE:STRING
NONE:INT,LONG,BOOLEAN,BOOLEAN
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/** @file gpm-notification.c
* @brief GNOME Power Notification
* @author Richard Hughes <richard@hughsie.com>
......@@ -410,9 +411,15 @@ callback_actions_activated (GtkMenuItem *menuitem, gpointer user_data)
g_debug ("action = '%s'", action);
if (strcmp (action, "suspend") == 0) {
action_policy_do (ACTION_SUSPEND);
/* FIXME: Emit a signal instead */
/* action_policy_do (ACTION_SUSPEND); */
} else if (strcmp (action, "hibernate") == 0) {
action_policy_do (ACTION_HIBERNATE);
/* FIXME: Emit a signal instead */
/*action_policy_do (ACTION_HIBERNATE);*/
} else if (strcmp (action, "about") == 0) {
callback_about_activated ();
} else if (strcmp (action, "preferences") == 0) {
......
......@@ -25,9 +25,15 @@
#ifndef _GPM_NOTIFICATION_H
#define _GPM_NOTIFICATION_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
GtkWidget *gpm_notification_get_icon (void);
void gpm_notification_icon_destroy (void);
void gpm_notification_icon_update (void);
G_END_DECLS
#endif /* _GPM_NOTIFICATION_H */
......@@ -29,6 +29,10 @@
#ifndef _GPM_SCREENSAVER_H
#define _GPM_SCREENSAVER_H
#include <glib.h>
G_BEGIN_DECLS
#define GS_PREF_DIR "/apps/gnome-screensaver"
#define GS_PREF_DPMS_SUSPEND GS_PREF_DIR "/dpms_suspend"
#define GS_PREF_DPMS_ENABLED GS_PREF_DIR "/dpms_enabled"
......@@ -44,5 +48,7 @@ gboolean gpm_screensaver_get_idle (gint *time);
gboolean gpm_screensaver_set_dpms_timeout (gint timeout);
gboolean gpm_screensaver_enable_dpms (gboolean enable);
G_END_DECLS
#endif /* _GPMSCREENSAVER_H */
/** @} */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment