80
80
pci->bus_no_present = libhal_device_property_exists (halctx, hal_device_udi,
81
81
"usb_device.bus_number", &err);
82
if (dbus_error_is_set (&err))
83
if (dbus_error_is_set (&err)) {
83
84
HAL_ERROR (("Error: [%s]/[%s]", err.name, err.message));
85
dbus_error_free (&err);
85
88
if (pci->bus_no_present)
86
89
pci->bus_no = libhal_device_get_property_int (halctx, hal_device_udi,
87
90
"usb_device.bus_number", &err);
92
LIBHAL_FREE_DBUS_ERROR (&err);
89
93
pci->port_no_present = libhal_device_property_exists (halctx, hal_device_udi,
90
94
"usb_device.linux.device_number", &err);
96
LIBHAL_FREE_DBUS_ERROR (&err);
91
97
if (pci->port_no_present)
92
98
pci->port_no = libhal_device_get_property_int (halctx, hal_device_udi,
93
99
"usb_device.linux.device_number", &err);
101
LIBHAL_FREE_DBUS_ERROR (&err);
95
102
pci->csr_is_dual_present = libhal_device_property_exists (halctx, hal_device_udi,
96
103
"battery.csr.is_dual", &err);
105
LIBHAL_FREE_DBUS_ERROR (&err);
97
106
if (pci->csr_is_dual_present)
98
107
pci->csr_is_dual = libhal_device_get_property_bool (halctx, hal_device_udi,
99
108
"battery.csr.is_dual", &err);
110
LIBHAL_FREE_DBUS_ERROR (&err);
101
111
pci->current_charge_present = libhal_device_property_exists (halctx, hal_device_udi,
102
112
"battery.charge_level.current", &err);
114
LIBHAL_FREE_DBUS_ERROR (&err);
103
115
if (pci->current_charge_present)
104
116
pci->current_charge = libhal_device_get_property_int (halctx, hal_device_udi,
105
117
"battery.charge_level.current", &err);
119
LIBHAL_FREE_DBUS_ERROR (&err);
151
164
HAL_DEBUG (("Charge level: %d->%d", pci->current_charge, current_charge));
152
165
if (current_charge != pci->current_charge) {
153
pci->current_charge = current_charge; dbus_error_init (&err);
166
pci->current_charge = current_charge;
167
dbus_error_init (&err);
154
169
libhal_device_set_property_int (halctx, hal_device_udi,
155
170
"battery.charge_level.current", current_charge, &err);
171
LIBHAL_FREE_DBUS_ERROR (&err);
156
173
if (current_charge != 0) {
157
174
percentage = (100.0 / 7.0) * current_charge;
158
175
libhal_device_set_property_int (halctx, hal_device_udi,
161
178
libhal_device_remove_property(halctx, hal_device_udi,
162
179
"battery.charge_level.percentage", &err);
182
LIBHAL_FREE_DBUS_ERROR (&err);
167
186
perror ("Writing to USB device");
168
189
usb_close (handle);
188
209
for (curr_bus = usb_busses; curr_bus != NULL; curr_bus = curr_bus->next) {
189
210
struct usb_device *curr_device;
190
211
/* dbg ("Checking bus: [%s]", curr_bus->dirname); */
191
if (g_strcasecmp (LUdirname, curr_bus->dirname))
212
if (g_ascii_strcasecmp (LUdirname, curr_bus->dirname))
194
215
for (curr_device = curr_bus->devices; curr_device != NULL;
195
216
curr_device = curr_device->next) {
196
217
/* dbg ("Checking port: [%s]", curr_device->filename); */
197
if (g_strcasecmp (LUfname, curr_device->filename))
218
if (g_ascii_strcasecmp (LUfname, curr_device->filename))
199
220
HAL_DEBUG (("Matched device: [%s][%s][%04X:%04X]", curr_bus->dirname,
200
221
curr_device->filename,
282
304
dbus_error_init (&err);
283
305
if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
284
306
HAL_ERROR (("Cannot connect to hald"));
289
312
/* update_properties */
290
dbus_error_init (&err);
291
313
libhal_device_set_property_bool (halctx, device_udi,
292
314
"battery.present", TRUE, &err);
316
LIBHAL_FREE_DBUS_ERROR (&err);
293
317
if (!libhal_device_property_exists (halctx, device_udi,
294
"battery.is_rechargeable", &err))
318
"battery.is_rechargeable", &err)) {
319
LIBHAL_FREE_DBUS_ERROR (&err);
295
320
libhal_device_set_property_bool (halctx, device_udi,
296
321
"battery.is_rechargeable", FALSE, &err);
324
LIBHAL_FREE_DBUS_ERROR (&err);
297
325
libhal_device_set_property_int (halctx, device_udi,
298
326
"battery.charge_level.design", 7, &err);
327
LIBHAL_FREE_DBUS_ERROR (&err);
299
328
libhal_device_set_property_int (halctx, device_udi,
300
329
"battery.charge_level.last_full", 7, &err);
330
LIBHAL_FREE_DBUS_ERROR (&err);
301
331
libhal_device_set_property_string (halctx, device_udi,
302
332
"info.category", "battery", &err);
333
LIBHAL_FREE_DBUS_ERROR (&err);
303
334
libhal_device_set_property_string (halctx, device_udi,
304
335
"battery.command_interface", "csr", &err);
317
348
check_all_batteries (NULL);
319
350
/* only add capability when initial charge_level key has been set */
320
dbus_error_init (&err);
351
LIBHAL_FREE_DBUS_ERROR (&err);
321
352
libhal_device_add_capability (halctx, device_udi, "battery", &err);
323
dbus_error_init (&err);
354
LIBHAL_FREE_DBUS_ERROR (&err);
324
355
if (!libhal_device_addon_is_ready (halctx, device_udi, &err)) {
328
360
hal_set_proc_title ("hald-addon-usb-csr: listening on '%s'",
336
368
g_timeout_add (1000L * TIMEOUT, check_all_batteries, NULL);
338
370
g_main_loop_run (main_loop);
340
libhal_ctx_shutdown (halctx, &err);
341
HAL_ERROR (("** Addon exits normally"));
374
HAL_DEBUG (("An error occured, exiting cleanly"));
376
LIBHAL_FREE_DBUS_ERROR (&err);
378
if (halctx != NULL) {
379
libhal_ctx_shutdown (halctx, &err);
380
LIBHAL_FREE_DBUS_ERROR (&err);
381
libhal_ctx_free (halctx);