~ubuntu-branches/ubuntu/lucid/hal/lucid-proposed

« back to all changes in this revision

Viewing changes to hald/linux/addons/addon-usb-csr.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-12-03 01:21:24 UTC
  • mto: (1.1.18 squeeze)
  • mto: This revision was merged to the branch mainline in revision 165.
  • Revision ID: james.westby@ubuntu.com-20091203012124-3573qknop973uvc2
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
 
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))
 
82
 
 
83
        if (dbus_error_is_set (&err)) {
83
84
                HAL_ERROR (("Error: [%s]/[%s]", err.name, err.message));        
 
85
                dbus_error_free (&err);
 
86
        }
84
87
 
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);
88
91
 
 
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);
 
95
 
 
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);
94
100
 
 
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);
 
104
 
 
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);
100
109
 
 
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);
 
113
 
 
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);
106
118
 
 
119
        LIBHAL_FREE_DBUS_ERROR (&err);
107
120
        return pci;
108
121
}
109
122
 
150
163
 
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);
 
168
 
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);
 
172
 
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); 
163
180
                                }
 
181
 
 
182
                                LIBHAL_FREE_DBUS_ERROR (&err);
164
183
                        }
165
184
                }
166
 
        } else
 
185
        } else {
167
186
                perror ("Writing to USB device");
 
187
        }
 
188
 
168
189
        usb_close (handle);
169
190
}
170
191
 
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))
192
213
                        continue;
193
214
 
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))
198
219
                                continue;
199
220
                        HAL_DEBUG (("Matched device: [%s][%s][%04X:%04X]", curr_bus->dirname, 
200
221
                                curr_device->filename, 
266
287
main (int argc, char *argv[])
267
288
{
268
289
        DBusError err;
 
290
        int retval = 0;
269
291
 
270
292
        hal_set_proc_title_init (argc, argv);
271
293
 
282
304
        dbus_error_init (&err);
283
305
        if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
284
306
                HAL_ERROR (("Cannot connect to hald"));
285
 
                return -3;
 
307
                retval = -3;
 
308
                goto out;
286
309
        }
287
310
 
288
311
 
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);
 
315
 
 
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);
 
322
        }
 
323
 
 
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);
305
336
 
317
348
        check_all_batteries (NULL);
318
349
 
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);
322
353
 
323
 
        dbus_error_init (&err);
 
354
        LIBHAL_FREE_DBUS_ERROR (&err);
324
355
        if (!libhal_device_addon_is_ready (halctx, device_udi, &err)) {
325
 
                return -4;
 
356
                retval = -4;
 
357
                goto out;
326
358
        }
327
359
 
328
360
        hal_set_proc_title ("hald-addon-usb-csr: listening on '%s'", 
336
368
        g_timeout_add (1000L * TIMEOUT, check_all_batteries, NULL);
337
369
#endif
338
370
        g_main_loop_run (main_loop);
339
 
 
340
 
        libhal_ctx_shutdown (halctx, &err);
341
 
        HAL_ERROR (("** Addon exits normally"));
342
371
        return 0;
 
372
 
 
373
out:
 
374
        HAL_DEBUG (("An error occured, exiting cleanly"));
 
375
 
 
376
        LIBHAL_FREE_DBUS_ERROR (&err);
 
377
 
 
378
        if (halctx != NULL) {
 
379
                libhal_ctx_shutdown (halctx, &err);
 
380
                LIBHAL_FREE_DBUS_ERROR (&err);
 
381
                libhal_ctx_free (halctx);
 
382
        }
 
383
 
 
384
        return retval;
343
385
}