Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
gnome-battery-bench
Commits
5f7d876f
Commit
5f7d876f
authored
Mar 17, 2017
by
Christian Kellner
Browse files
Power supply: make battery_discover generic
That is, also return GbbMains, and rename it to gbb_power_supply_discover.
parent
7f0b3bac
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/power-supply.c
View file @
5f7d876f
...
...
@@ -100,6 +100,50 @@ gbb_power_supply_init(GbbPowerSupply *ps)
{
}
GList
*
gbb_power_supply_discover
()
{
GUdevClient
*
client
;
GList
*
devices
;
GList
*
l
;
GList
*
supplies
=
NULL
;
client
=
g_udev_client_new
(
NULL
);
devices
=
g_udev_client_query_by_subsystem
(
client
,
"power_supply"
);
for
(
l
=
devices
;
l
!=
NULL
;
l
=
l
->
next
)
{
GUdevDevice
*
device
=
l
->
data
;
const
gchar
*
dev_type
;
dev_type
=
g_udev_device_get_sysfs_attr
(
device
,
"type"
);
if
(
dev_type
==
NULL
)
{
continue
;
}
if
(
g_str_equal
(
dev_type
,
"Battery"
))
{
GObject
*
bat
=
g_object_new
(
GBB_TYPE_BATTERY
,
"udev-device"
,
device
,
NULL
);
supplies
=
g_list_prepend
(
supplies
,
bat
);
}
else
if
(
g_str_equal
(
dev_type
,
"Mains"
))
{
GObject
*
msn
=
g_object_new
(
GBB_TYPE_MAINS
,
"udev-device"
,
device
,
NULL
);
supplies
=
g_list_prepend
(
supplies
,
msn
);
}
else
{
g_warning
(
"Unknown power supply type '%s'. Skipping."
,
dev_type
);
}
}
g_list_free_full
(
devices
,
(
GDestroyNotify
)
g_object_unref
);
g_object_unref
(
client
);
return
supplies
;
}
/* ************************************************************************** */
struct
_GbbBattery
{
...
...
@@ -391,41 +435,6 @@ energy_design_initialize(GbbBattery *bat)
}
}
GList
*
gbb_battery_discover
()
{
GUdevClient
*
client
;
GList
*
devices
;
GList
*
l
;
GList
*
supplies
=
NULL
;
client
=
g_udev_client_new
(
NULL
);
devices
=
g_udev_client_query_by_subsystem
(
client
,
"power_supply"
);
for
(
l
=
devices
;
l
!=
NULL
;
l
=
l
->
next
)
{
GUdevDevice
*
device
=
l
->
data
;
const
gchar
*
dev_type
;
dev_type
=
g_udev_device_get_sysfs_attr
(
device
,
"type"
);
if
(
dev_type
==
NULL
)
{
continue
;
}
g_print
(
"Type: %s
\n
"
,
dev_type
);
if
(
g_str_equal
(
dev_type
,
"Battery"
))
{
GObject
*
bat
=
g_object_new
(
GBB_TYPE_BATTERY
,
"udev-device"
,
device
,
NULL
);
supplies
=
g_list_prepend
(
supplies
,
bat
);
}
}
g_list_free_full
(
devices
,
(
GDestroyNotify
)
g_object_unref
);
return
supplies
;
}
double
gbb_battery_poll
(
GbbBattery
*
bat
)
{
...
...
src/power-supply.h
View file @
5f7d876f
...
...
@@ -15,12 +15,14 @@ struct _GbbPowerSupplyClass
gpointer
padding
[
13
];
};
GList
*
gbb_power_supply_discover
(
void
);
/* ************************************************************************** */
#define GBB_TYPE_BATTERY gbb_battery_get_type()
G_DECLARE_FINAL_TYPE
(
GbbBattery
,
gbb_battery
,
GBB
,
BATTERY
,
GbbPowerSupply
)
GList
*
gbb_battery_discover
(
void
);
double
gbb_battery_poll
(
GbbBattery
*
);
/* ************************************************************************** */
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment