batman: FreeBSD and OpenBSD (sysctl)

After the work on the sysinfo gadgets for Linux the BSD variant
code was a little bit of an afterthought. These changes provide
us with unlimited battery/sysinfo gadgets and reliable status
for our battery or batteries and our power supply.

This patch allows us to add and remove (many) batman gadgets to
the desktop without negatively affecting existing instances.
It also takes into account additional sysinfo gadgets that include
a batman instance.

Iterating through the existing array of sysinfo gadgets to find
multiple instances and apply changes it not ideal but it does
not affect the Linux code, and keeps this change relatively
simple.

Tested on FreeBSD and OpenBSD with various hardware setups.
Thanks to Peter2121 (Quelrond) for his testing.

There is work to now improve batman's Linux behaviour to match that
of the behaviour on BSD systems.
This commit is contained in:
Alastair Poole 2019-12-02 20:47:01 +00:00
parent 6b70114c6d
commit 389e9bfb02
3 changed files with 52 additions and 10 deletions

View File

@ -359,7 +359,7 @@ _batman_device_update(Instance *inst)
static Eina_Bool
_screensaver_on(void *data)
{
#if defined(HAVE_EEZE)
#if defined(HAVE_EEZE) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
Instance *inst = data;
#else
(void)data;
@ -368,7 +368,7 @@ _screensaver_on(void *data)
#if defined(HAVE_EEZE)
_batman_udev_stop(inst);
#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
_batman_sysctl_stop();
_batman_sysctl_stop(inst);
#elif defined(upower)
_batman_upower_stop();
#else
@ -583,7 +583,7 @@ _batman_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
#if defined(HAVE_EEZE)
_batman_udev_stop(inst);
#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
_batman_sysctl_stop();
_batman_sysctl_stop(inst);
#elif defined(upower)
_batman_upower_stop();
#else
@ -616,8 +616,7 @@ sysinfo_batman_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNU
#if defined(HAVE_EEZE)
_batman_udev_stop(inst);
#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
(void)inst;
_batman_sysctl_stop();
_batman_sysctl_stop(inst);
#elif defined(upower)
(void)inst;
_batman_upower_stop();

View File

@ -104,7 +104,7 @@ EINTERNvoid _batman_upower_stop(void);
#else
/* in batman_sysctl.c */
EINTERN int _batman_sysctl_start(Instance *inst);
EINTERN void _batman_sysctl_stop(void);
EINTERN void _batman_sysctl_stop(Instance *inst);
/* end batman_sysctl.c */
#endif

View File

@ -152,10 +152,45 @@ _batman_sysctl_start(Instance *inst)
}
void
_batman_sysctl_stop(void)
_batman_sysctl_stop(Instance *inst)
{
Instance *child;
Eina_List *l;
Battery *bat;
Ac_Adapter *ac;
int bat_num = 0;
/* This is a dummy battery we return here. */
if (inst->cfg->batman.have_battery != 1)
{
return;
}
/* If this is NOT the last batman gadget then we return before
* freeing everything. This is NOT optimal but is allows us to have
* many gadgets and share the same data between multiple batman
* gadget instances. The instance will be deleted.
*/
EINA_LIST_FOREACH(sysinfo_instances, l, child)
{
if (inst->cfg->esm == E_SYSINFO_MODULE_BATMAN ||
inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
{
bat_num++;
if (child == inst)
{
bat_num--;
break;
}
}
}
/* This is not the last batman gadget. */
if (bat_num > 0) return;
/* We have no batman or sysinfo gadgets remaining. We can safely
remove these batteries and adapters. */
EINA_LIST_FREE(batman_device_ac_adapters, ac)
{
@ -178,11 +213,18 @@ _batman_sysctl_stop(void)
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
static Eina_Bool
_batman_sysctl_battery_update_poll(void *data)
_batman_sysctl_battery_update_poll(void *data EINA_UNUSED)
{
Instance *inst = data;
Eina_List *l;
Instance *inst;
_batman_sysctl_battery_update(inst);
/* We need to ensure we update both batman and sysinfo instances. */
EINA_LIST_FOREACH(sysinfo_instances, l, inst)
{
if (inst->cfg->esm == E_SYSINFO_MODULE_BATMAN ||
inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
_batman_sysctl_battery_update(inst);
}
return EINA_TRUE;
}
@ -204,6 +246,7 @@ _batman_sysctl_battery_update(Instance *inst)
size_t len;
int value, fd, i = 0;
#endif
EINA_LIST_FOREACH(batman_device_batteries, l, bat)
{
/* update the poller interval */