- /* Get the name of the device.. */
- ps_value = NULL;
- if (CFDictionaryGetValueIfPresent (ps_dict,
- CFSTR (kIOPSNameKey),
- &ps_value))
- {
- if (CFGetTypeID (ps_value) != CFStringGetTypeID ())
- {
- if (!CFStringGetCString (ps_value,
- name, 128,
- kCFStringEncodingASCII))
- continue;
- }
- else
- {
- DBG ("kIOPSNameKey: Not a CFStringGetTypeID");
- }
- DBG ("Original string: `%s'", name);
- }
- else
+ if (*ret_voltage == INVALID_VALUE)
+ {
+ temp_double = dict_get_double (ps_dict,
+ kIOPSVoltageKey);
+ if (temp_double != INVALID_VALUE)
+ *ret_voltage = temp_double / 1000.0;
+ }
+ }
+
+ CFRelease(ps_array);
+ CFRelease(ps_raw);
+}
+#endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+
+#if HAVE_IOKIT_IOKITLIB_H
+static void get_via_generic_iokit (double *ret_charge,
+ double *ret_current,
+ double *ret_voltage)
+{
+ kern_return_t status;
+ io_iterator_t iterator;
+ io_object_t io_obj;
+
+ CFDictionaryRef bat_root_dict;
+ CFArrayRef bat_info_arry;
+ CFIndex bat_info_arry_len;
+ CFIndex bat_info_arry_pos;
+ CFDictionaryRef bat_info_dict;
+
+ double temp_double;
+
+ status = IOServiceGetMatchingServices (kIOMasterPortDefault,
+ IOServiceNameMatching ("battery"),
+ &iterator);
+ if (status != kIOReturnSuccess)
+ {
+ DBG ("IOServiceGetMatchingServices failed.");
+ return;
+ }
+
+ while ((io_obj = IOIteratorNext (iterator)))
+ {
+ status = IORegistryEntryCreateCFProperties (io_obj,
+ (CFMutableDictionaryRef *) &bat_root_dict,
+ kCFAllocatorDefault,
+ kNilOptions);
+ if (status != kIOReturnSuccess)
+ {
+ DBG ("IORegistryEntryCreateCFProperties failed.");
+ continue;
+ }
+
+ bat_info_arry = (CFArrayRef) CFDictionaryGetValue (bat_root_dict,
+ CFSTR ("IOBatteryInfo"));
+ if (bat_info_arry == NULL)
+ {
+ CFRelease (bat_root_dict);
+ continue;
+ }
+ bat_info_arry_len = CFArrayGetCount (bat_info_arry);
+
+ for (bat_info_arry_pos = 0;
+ bat_info_arry_pos < bat_info_arry_len;
+ bat_info_arry_pos++)
+ {
+ bat_info_dict = (CFDictionaryRef) CFArrayGetValueAtIndex (bat_info_arry, bat_info_arry_pos);
+
+ if (*ret_current == INVALID_VALUE)