~ubuntu-branches/ubuntu/maverick/hal/maverick

« back to all changes in this revision

Viewing changes to hald/linux/pmu.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • mto: (1.5.1 sid)
  • mto: This revision was merged to the branch mainline in revision 90.
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <unistd.h>
32
32
 
33
33
#include "../device_info.h"
 
34
#include "../device_pm.h"
34
35
#include "../hald_dbus.h"
35
36
#include "../logger.h"
36
37
#include "../util.h"
78
79
        const char *path;
79
80
        int flags;
80
81
        int last_full;
81
 
        int remaining_time;
82
 
        int remaining_percentage;
83
82
 
84
83
        path = hal_device_property_get_string (d, "linux.pmu_path");
85
84
        if (path == NULL)
107
106
                hal_device_property_set_bool (d, "battery.rechargeable.is_charging", flags & PMU_BATT_CHARGING);
108
107
                /* we're discharging if, and only if, we are not plugged into the wall */
109
108
                {
110
 
                        char buf[HAL_PATH_MAX];
111
 
                        snprintf (buf, sizeof (buf), "%s/pmu/info", get_hal_proc_path ());
112
 
                        hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", buf, "", 
 
109
                        hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", "/proc/pmu/info", "", 
113
110
                                                          "AC Power", 0, "0", FALSE);
114
111
                }
115
112
 
130
127
                last_full = hal_device_property_get_int (d, "battery.charge_level.last_full");
131
128
 
132
129
                /* TODO: could read some pmu file? */
133
 
                remaining_time = util_compute_time_remaining (
134
 
                                        hal_device_get_udi (d),
135
 
                                        hal_device_property_get_int (d, "battery.charge_level.rate"),
136
 
                                        current,
137
 
                                        last_full,
138
 
                                        hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
139
 
                                        hal_device_property_get_bool (d, "battery.rechargeable.is_charging"),
140
 
                                        hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"));
141
 
                remaining_percentage = util_compute_percentage_charge (hal_device_get_udi (d), current, last_full);
142
 
                /*
143
 
                 * Only set keys if no error (signified with negative return value)
144
 
                 * Scrict checking is needed to ensure that the values presented by HAL
145
 
                 * are 100% acurate.
146
 
                 */
147
 
                if (remaining_time > 0)
148
 
                        hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
149
 
                else
150
 
                        hal_device_property_remove (d, "battery.remaining_time");
151
 
                if (remaining_percentage > 0)
152
 
                        hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
153
 
                else
154
 
                        hal_device_property_remove (d, "battery.charge_level.percentage");
 
130
                device_pm_calculate_time (d);
 
131
                device_pm_calculate_percentage (d);
155
132
 
156
133
                device_property_atomic_update_end ();
157
134
        } else {
158
135
                device_property_atomic_update_begin ();
159
 
                hal_device_property_remove (d, "battery.is_rechargeable");
160
 
                hal_device_property_remove (d, "battery.rechargeable.is_charging");
161
 
                hal_device_property_remove (d, "battery.rechargeable.is_discharging");
162
 
                /*hal_device_property_remove (d, "battery.charge_level.unit");*/
163
 
                hal_device_property_remove (d, "battery.charge_level.current");
164
 
                hal_device_property_remove (d, "battery.charge_level.last_full");
165
 
                hal_device_property_remove (d, "battery.charge_level.design");
 
136
                device_pm_remove_optional_props (d);
166
137
                device_property_atomic_update_end ();           
167
138
        }
168
139
 
331
302
{
332
303
        gboolean ret;
333
304
        HalDevice *computer;
334
 
        gchar path[HAL_PATH_MAX];
335
305
        GError *error;
336
306
        GDir *dir;
337
307
        gboolean has_battery_bays;
355
325
        hal_device_property_set_string (computer, "power_management.type", "pmu");
356
326
 
357
327
        /* AC Adapter */
358
 
        snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
359
 
        pmu_synthesize_item (path, PMU_TYPE_AC_ADAPTER);
 
328
        pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_AC_ADAPTER);
360
329
 
361
330
        error = NULL;
362
 
        snprintf (path, sizeof (path), "%s/pmu", get_hal_proc_path ());
363
 
        dir = g_dir_open (path, 0, &error);
 
331
        dir = g_dir_open ("/proc/pmu", 0, &error);
364
332
        if (dir != NULL) {
365
333
                const gchar *f;
366
334
                while ((f = g_dir_read_name (dir)) != NULL) {
367
335
                        gchar buf[HAL_PATH_MAX];
368
336
                        int battery_num;
369
337
 
370
 
                        snprintf (buf, sizeof (buf), "%s/pmu/%s", get_hal_proc_path (), f);
 
338
                        snprintf (buf, sizeof (buf), "/proc/pmu/%s", f);
371
339
                        if (sscanf (f, "battery_%d", &battery_num) == 1) {
372
340
                                has_battery_bays = TRUE;
373
341
                                pmu_synthesize_item (buf, PMU_TYPE_BATTERY);
375
343
                        
376
344
                }
377
345
        } else {
378
 
                HAL_ERROR (("Couldn't open %s: %s", path, error->message));
 
346
                HAL_ERROR (("Couldn't open /proc/pmu/info: %s", error->message));
379
347
                g_error_free (error);
380
348
        }
381
349
 
387
355
         */
388
356
        if (has_battery_bays) {
389
357
                /* Add lid button */
390
 
                snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
391
 
                pmu_synthesize_item (path, PMU_TYPE_LID_BUTTON);
 
358
                pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_LID_BUTTON);
392
359
 
393
360
                /* Add Laptop Panel */
394
 
                snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
395
 
                pmu_synthesize_item (path, PMU_TYPE_LAPTOP_PANEL);
 
361
                pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_LAPTOP_PANEL);
396
362
        }
397
363
 
398
364
        /* setup timer for things that we need to poll */