示例#1
0
文件: battery.c 项目: alhazred/onarm
gboolean
ac_adapter_update(LibHalContext *ctx, const char *udi, int fd)
{
	LibHalChangeSet *cs;
	DBusError error;

	HAL_DEBUG(("ac_adapter_update() enter"));
	dbus_error_init(&error);
	if (!libhal_device_query_capability(ctx, udi, "ac_adapter", &error)) {
		my_dbus_error_free(&error);
		libhal_device_add_capability(ctx, udi, "ac_adapter", &error);
		if ((cs = libhal_device_new_changeset(udi)) == NULL) {
			my_dbus_error_free(&error);
			return (FALSE);
		}
		libhal_changeset_set_property_string(cs, "info.product",
		    "AC Adapter");
		libhal_changeset_set_property_string(cs, "info.category",
		    "ac_adapter");
		my_dbus_error_free(&error);
		libhal_device_commit_changeset(ctx, cs, &error);
		libhal_device_free_changeset(cs);
	}
	ac_adapter_present(ctx, udi, fd);
	battery_update_all(ctx);

	my_dbus_error_free(&error);
	HAL_DEBUG(("ac_adapter_update() exit"));
	return (TRUE);
}
示例#2
0
static void
set_fstyp_properties (LibHalContext *ctx, const char *udi, const char *fstype, nvlist_t *fsattr)
{
	char buf[256];
	DBusError error;
	char *uuid = NULL;
	char *label_orig = NULL;
	char *label = NULL;
	int  err;
	LibHalChangeSet *cs;

	dbus_error_init (&error);

	if ((cs = libhal_device_new_changeset (udi)) == NULL) {
		return;
	}

	libhal_changeset_set_property_string (cs, "volume.fsusage", "filesystem");
	libhal_changeset_set_property_string (cs, "volume.fstype", fstype);

	/* label */
	(void) nvlist_lookup_string(fsattr, "gen_volume_label", &label_orig);
	if (label_orig != NULL) {
		label = rtrim_copy(label_orig, 0);
	}
	/* Check if label is utf8 format */
	if ((label != NULL) && (label[0] != '\0') &&
	    (u8_validate(label, strlen(label), (char **)NULL,
	    U8_VALIDATE_ENTIRE, &err) != -1)) {
	        libhal_changeset_set_property_string (cs, "volume.label", label);
	        libhal_changeset_set_property_string (cs, "info.product", label);
	} else {
		libhal_changeset_set_property_string (cs, "volume.label", "");
		snprintf (buf, sizeof (buf), "Volume (%s)", fstype);
		libhal_changeset_set_property_string (cs, "info.product", buf);
	}
	free(label);

	/* uuid */
	if (nvlist_lookup_string(fsattr, "gen_uuid", &uuid) == 0) {
		libhal_changeset_set_property_string (cs, "volume.uuid", uuid);
	} else {
		libhal_changeset_set_property_string (cs, "volume.uuid", "");
	}

	libhal_device_commit_changeset (ctx, cs, &error);
	libhal_device_free_changeset (cs);

	my_dbus_error_free (&error);
}
示例#3
0
static dbus_bool_t
probe_disc (int fd, LibHalContext *ctx, const char *udi, dbus_bool_t *has_data,
    dbus_bool_t *has_audio)
{
	DBusError error;
	disc_info_t di;
	int profile;
	dbus_bool_t is_blank, is_appendable, is_rewritable;
	char *disc_type = "cd_rom";
	uint64_t capacity = 0;
	int i;
	LibHalChangeSet *cs;

	dbus_error_init (&error);

	if (get_disc_info (fd, &di)) {
		is_blank = (di.disc_status == 0);
		is_appendable = (di.disc_status == 1);
		is_rewritable = (di.erasable != 0);
	} else {
		is_blank = is_appendable = is_rewritable = FALSE;
	}

	if (get_current_profile (fd, &profile)) {
		switch (profile) {
		case 0x08: /* CD-ROM */
			disc_type = "cd_rom";
			break;
		case 0x09: /* CD-R */
			disc_type = "cd_r";
			break;
		case 0x0A: /* CD-RW */
			disc_type = "cd_rw";
			is_rewritable = TRUE;
			break;
		case 0x10: /* DVD-ROM */
			disc_type = "dvd_rom";
			break;
		case 0x11: /* DVD-R Sequential */
			disc_type = "dvd_r";
			break;
		case 0x12: /* DVD-RAM */
			disc_type = "dvd_ram";
			is_rewritable = TRUE;
			break;
		case 0x13: /* DVD-RW Restricted Overwrite */
			disc_type = "dvd_rw";
			is_rewritable = TRUE;
			break;
		case 0x14: /* DVD-RW Sequential */
			disc_type = "dvd_rw";
			is_rewritable = TRUE;
			break;
		case 0x1A: /* DVD+RW */
			disc_type = "dvd_plus_rw";
			is_rewritable = TRUE;
			break;
		case 0x1B: /* DVD+R */
			disc_type = "dvd_plus_r";
			break;
		case 0x2B: /* DVD+R Double Layer */
                        disc_type = "dvd_plus_r_dl";
			break;
		case 0x40: /* BD-ROM */
                        disc_type = "bd_rom";
			break;
		case 0x41: /* BD-R Sequential */
                        disc_type = "bd_r";
			break;
		case 0x42: /* BD-R Random */
                        disc_type = "bd_r";
			break;
		case 0x43: /* BD-RE */
                        disc_type = "bd_re";
			is_rewritable = TRUE;
			break;
		case 0x50: /* HD DVD-ROM */
                        disc_type = "hddvd_rom";
			break;
		case 0x51: /* HD DVD-R */
                        disc_type = "hddvd_r";
			break;
		case 0x52: /* HD DVD-Rewritable */
                        disc_type = "hddvd_rw";
			is_rewritable = TRUE;
			break;
		}

		(void) get_disc_capacity_for_profile(fd, profile, &capacity);
	}

	*has_audio = *has_data = FALSE;
	if (!is_blank) {
		uchar_t	smalltoc[12];
		size_t	toc_size;
		uchar_t	*toc, *p;

		/*
		 * XXX for some reason CDROMREADTOCENTRY fails on video DVDs,
		 * but extracting the toc directly works okay.
		 */
        	if (!read_toc(fd, 0, 1, 4, smalltoc)) {
                	HAL_DEBUG(("read_toc failed"));
			*has_data = B_TRUE; /* probe for fs anyway */
        	} else {
        		toc_size = smalltoc[0] * 256 + smalltoc[1] + 2;
        		toc = (uchar_t *)calloc(1, toc_size);
        		if (toc == NULL || !read_toc(fd, 0, 1, toc_size, toc)) {
                		HAL_DEBUG (("read_toc again failed"));
        		} else {
        			for (p = &toc[4]; p < (toc + toc_size); p += 8) {
					/* skip leadout */
                			if (p[2] == 0xAA) {
						continue;
					}
					if (p[1] & 4) {
						*has_data = B_TRUE;
					} else {
						*has_audio = B_TRUE;
					}
        			}
			}
			free(toc);
		}
	}

	if ((cs = libhal_device_new_changeset (udi)) == NULL) {
		return (FALSE);
	}
	libhal_changeset_set_property_string (cs, "volume.disc.type", disc_type);
	libhal_changeset_set_property_bool (cs, "volume.disc.is_blank", is_blank);
	libhal_changeset_set_property_bool (cs, "volume.disc.has_audio", *has_audio);
	libhal_changeset_set_property_bool (cs, "volume.disc.has_data", *has_data);
	libhal_changeset_set_property_bool (cs, "volume.disc.is_appendable", is_appendable);
	libhal_changeset_set_property_bool (cs, "volume.disc.is_rewritable", is_rewritable);
	libhal_changeset_set_property_uint64 (cs, "volume.disc.capacity", capacity);

	libhal_changeset_set_property_bool (cs, "volume.disc.is_videodvd", FALSE);
	libhal_changeset_set_property_bool (cs, "volume.disc.is_vcd", FALSE);
	libhal_changeset_set_property_bool (cs, "volume.disc.is_svcd", FALSE);

	libhal_device_commit_changeset (ctx, cs, &error);
	libhal_device_free_changeset (cs);

out:
	my_dbus_error_free (&error);

	return (TRUE);
}
示例#4
0
文件: battery.c 项目: alhazred/onarm
static gboolean
battery_static_update(LibHalContext *ctx, const char *udi, int fd)
{
	const char *technology;
	int reporting_design;
	int reporting_warning;
	int reporting_low;
	int reporting_gran1;
	int reporting_gran2;
	int voltage_design;
	char reporting_unit[10];
	acpi_bif_t bif;
	LibHalChangeSet *cs;
	DBusError error;

	HAL_DEBUG(("battery_static_update() enter"));
	bzero(&bif, sizeof (bif));
	if (ioctl(fd, BATT_IOC_INFO, &bif) < 0) {
		return (FALSE);
	}
	if ((cs = libhal_device_new_changeset(udi)) == NULL) {
		HAL_DEBUG(("Cannot allocate changeset"));
		return (FALSE);
	}

	libhal_changeset_set_property_string(cs, "battery.vendor",
	    bif.bif_oem_info);
	technology = bif.bif_type;
	if (technology != NULL) {
		libhal_changeset_set_property_string(cs,
		    "battery.reporting.technology", technology);
		libhal_changeset_set_property_string(cs, "battery.technology",
		    util_get_battery_technology(technology));
	}
	libhal_changeset_set_property_string(cs, "battery.serial",
	    bif.bif_serial);
	libhal_changeset_set_property_string(cs, "battery.model",
	    bif.bif_model);

	if (bif.bif_unit) {
		libhal_changeset_set_property_string(cs,
		    "battery.reporting.unit", "mAh");
		strlcpy(reporting_unit, "mAh", sizeof (reporting_unit));
	} else {
		libhal_changeset_set_property_string(cs,
		    "battery.reporting.unit", "mWh");
		strlcpy(reporting_unit, "mWh", sizeof (reporting_unit));
	}
	libhal_changeset_set_property_int(cs, "battery.reporting.last_full",
	    bif.bif_last_cap);
	libhal_changeset_set_property_int(cs, "battery.reporting.design",
	    bif.bif_design_cap);
	reporting_design = bif.bif_design_cap;
	libhal_changeset_set_property_int(cs, "battery.reporting.warning",
	    bif.bif_warn_cap);
	reporting_warning = bif.bif_warn_cap;
	libhal_changeset_set_property_int(cs, "battery.reporting.low",
	    bif.bif_low_cap);
	reporting_low = bif.bif_low_cap;
	libhal_changeset_set_property_int(cs,
	    "battery.reporting.granularity_1", bif.bif_gran1_cap);
	reporting_gran1 = bif.bif_gran1_cap;
	libhal_changeset_set_property_int(cs,
	    "battery.reporting.granularity_2", bif.bif_gran2_cap);
	reporting_gran2 = bif.bif_gran2_cap;
	libhal_changeset_set_property_int(cs, "battery.voltage.design",
	    bif.bif_voltage);
	voltage_design = bif.bif_voltage;

	if (reporting_unit && strcmp(reporting_unit, "mAh") == 0) {
		/* convert to mWh */
		libhal_changeset_set_property_string(cs,
		    "battery.charge_level.unit", "mWh");
		libhal_changeset_set_property_int(cs,
		    "battery.charge_level.design",
		    (reporting_design * voltage_design) / 1000);
		libhal_changeset_set_property_int(cs,
		    "battery.charge_level.warning",
		    (reporting_warning * voltage_design) / 1000);
		libhal_changeset_set_property_int(cs,
		    "battery.charge_level.low",
		    (reporting_low * voltage_design) / 1000);
		libhal_changeset_set_property_int(cs,
		    "battery.charge_level.granularity_1",
		    (reporting_gran1 * voltage_design) / 1000);
		libhal_changeset_set_property_int(cs,
		    "battery.charge_level.granularity_2",
		    (reporting_gran2 * voltage_design) / 1000);
	} else {
		if (reporting_unit && strcmp(reporting_unit, "mWh") == 0) {
			libhal_changeset_set_property_string(cs,
			    "battery.charge_level.unit", "mWh");
		}
		libhal_changeset_set_property_int(cs,
                    "battery.charge_level.design", reporting_design);
                libhal_changeset_set_property_int(cs,
                    "battery.charge_level.warning", reporting_warning);
                libhal_changeset_set_property_int(cs,
                    "battery.charge_level.low", reporting_low);
                libhal_changeset_set_property_int(cs,
                    "battery.charge_level.granularity_1", reporting_gran1);
                libhal_changeset_set_property_int(cs,
                    "battery.charge_level.granularity_2", reporting_gran2);
	}
		

	dbus_error_init(&error);
	libhal_device_commit_changeset(ctx, cs, &error);
	libhal_device_free_changeset(cs);
	my_dbus_error_free(&error);
	HAL_DEBUG(("battery_static_update() exit"));
	return (TRUE);
}