예제 #1
0
gboolean battery_os_init()
{
	GDir *directory = 0;
	GError *error = NULL;
	const char *entryname;

	battery_os_free();

	directory = g_dir_open("/sys/class/power_supply", 0, &error);
	RETURN_ON_ERROR(error);

	while ((entryname = g_dir_read_name(directory))) {
		enum psy_type type = power_supply_get_type(entryname);

		switch (type) {
		case PSY_BATTERY:
			add_battery(entryname);
			break;
		case PSY_MAINS:
			add_mains(entryname);
			break;
		default:
			break;
		}
	}

	g_dir_close(directory);

	uevent_register_notifier(&psy_change);
	uevent_register_notifier(&psy_plug);

	return batteries != NULL;
}
예제 #2
0
파일: linux.c 프로젝트: BunsenLabs/tint2
gboolean battery_os_init()
{
    GDir *directory = 0;
    GError *error = NULL;
    const char *entryname;

    battery_os_free();

    gchar *dir_path = g_build_filename(battery_sys_prefix, "/sys/class/power_supply", NULL);
    directory = g_dir_open(dir_path, 0, &error);
    g_free(dir_path);
    RETURN_ON_ERROR(error);

    while ((entryname = g_dir_read_name(directory))) {
        fprintf(stderr, GREEN "tint2: Found power device %s" RESET "\n", entryname);
        enum psy_type type = power_supply_get_type(entryname);

        switch (type) {
        case PSY_BATTERY:
            add_battery(entryname);
            break;
        case PSY_MAINS:
            add_mains(entryname);
            break;
        default:
            break;
        }
    }

    g_dir_close(directory);

    uevent_register_notifier(&psy_change);
    uevent_register_notifier(&psy_plug);

    return batteries != NULL;
}