summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2019-12-02 20:47:01 +0000
committerAlastair Poole <netstar@gmail.com>2019-12-02 20:47:01 +0000
commit389e9bfb02d39caf0c9e26ebc3f50d591704c387 (patch)
treed8c69c18b24c298547fd726d850fadf17e46430d
parent6b70114c6d19d74374bc7c5b614279a724dce561 (diff)
batman: FreeBSD and OpenBSD (sysctl)HEADmaster
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.
-rw-r--r--src/modules/sysinfo/batman/batman.c9
-rw-r--r--src/modules/sysinfo/batman/batman.h2
-rw-r--r--src/modules/sysinfo/batman/batman_sysctl.c51
3 files changed, 52 insertions, 10 deletions
diff --git a/src/modules/sysinfo/batman/batman.c b/src/modules/sysinfo/batman/batman.c
index 9a9858a..8a28f78 100644
--- a/src/modules/sysinfo/batman/batman.c
+++ b/src/modules/sysinfo/batman/batman.c
@@ -359,7 +359,7 @@ _batman_device_update(Instance *inst)
359static Eina_Bool 359static Eina_Bool
360_screensaver_on(void *data) 360_screensaver_on(void *data)
361{ 361{
362#if defined(HAVE_EEZE) 362#if defined(HAVE_EEZE) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
363 Instance *inst = data; 363 Instance *inst = data;
364#else 364#else
365 (void)data; 365 (void)data;
@@ -368,7 +368,7 @@ _screensaver_on(void *data)
368#if defined(HAVE_EEZE) 368#if defined(HAVE_EEZE)
369 _batman_udev_stop(inst); 369 _batman_udev_stop(inst);
370#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) 370#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
371 _batman_sysctl_stop(); 371 _batman_sysctl_stop(inst);
372#elif defined(upower) 372#elif defined(upower)
373 _batman_upower_stop(); 373 _batman_upower_stop();
374#else 374#else
@@ -583,7 +583,7 @@ _batman_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
583#if defined(HAVE_EEZE) 583#if defined(HAVE_EEZE)
584 _batman_udev_stop(inst); 584 _batman_udev_stop(inst);
585#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) 585#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
586 _batman_sysctl_stop(); 586 _batman_sysctl_stop(inst);
587#elif defined(upower) 587#elif defined(upower)
588 _batman_upower_stop(); 588 _batman_upower_stop();
589#else 589#else
@@ -616,8 +616,7 @@ sysinfo_batman_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNU
616#if defined(HAVE_EEZE) 616#if defined(HAVE_EEZE)
617 _batman_udev_stop(inst); 617 _batman_udev_stop(inst);
618#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) 618#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
619 (void)inst; 619 _batman_sysctl_stop(inst);
620 _batman_sysctl_stop();
621#elif defined(upower) 620#elif defined(upower)
622 (void)inst; 621 (void)inst;
623 _batman_upower_stop(); 622 _batman_upower_stop();
diff --git a/src/modules/sysinfo/batman/batman.h b/src/modules/sysinfo/batman/batman.h
index 31085a8..92b6247 100644
--- a/src/modules/sysinfo/batman/batman.h
+++ b/src/modules/sysinfo/batman/batman.h
@@ -104,7 +104,7 @@ EINTERNvoid _batman_upower_stop(void);
104#else 104#else
105/* in batman_sysctl.c */ 105/* in batman_sysctl.c */
106EINTERN int _batman_sysctl_start(Instance *inst); 106EINTERN int _batman_sysctl_start(Instance *inst);
107EINTERN void _batman_sysctl_stop(void); 107EINTERN void _batman_sysctl_stop(Instance *inst);
108/* end batman_sysctl.c */ 108/* end batman_sysctl.c */
109#endif 109#endif
110 110
diff --git a/src/modules/sysinfo/batman/batman_sysctl.c b/src/modules/sysinfo/batman/batman_sysctl.c
index a912c30..4279031 100644
--- a/src/modules/sysinfo/batman/batman_sysctl.c
+++ b/src/modules/sysinfo/batman/batman_sysctl.c
@@ -152,10 +152,45 @@ _batman_sysctl_start(Instance *inst)
152} 152}
153 153
154void 154void
155_batman_sysctl_stop(void) 155_batman_sysctl_stop(Instance *inst)
156{ 156{
157 Instance *child;
158 Eina_List *l;
157 Battery *bat; 159 Battery *bat;
158 Ac_Adapter *ac; 160 Ac_Adapter *ac;
161 int bat_num = 0;
162
163 /* This is a dummy battery we return here. */
164 if (inst->cfg->batman.have_battery != 1)
165 {
166 return;
167 }
168
169 /* If this is NOT the last batman gadget then we return before
170 * freeing everything. This is NOT optimal but is allows us to have
171 * many gadgets and share the same data between multiple batman
172 * gadget instances. The instance will be deleted.
173 */
174
175 EINA_LIST_FOREACH(sysinfo_instances, l, child)
176 {
177 if (inst->cfg->esm == E_SYSINFO_MODULE_BATMAN ||
178 inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
179 {
180 bat_num++;
181 if (child == inst)
182 {
183 bat_num--;
184 break;
185 }
186 }
187 }
188
189 /* This is not the last batman gadget. */
190 if (bat_num > 0) return;
191
192 /* We have no batman or sysinfo gadgets remaining. We can safely
193 remove these batteries and adapters. */
159 194
160 EINA_LIST_FREE(batman_device_ac_adapters, ac) 195 EINA_LIST_FREE(batman_device_ac_adapters, ac)
161 { 196 {
@@ -178,11 +213,18 @@ _batman_sysctl_stop(void)
178 213
179#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) 214#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
180static Eina_Bool 215static Eina_Bool
181_batman_sysctl_battery_update_poll(void *data) 216_batman_sysctl_battery_update_poll(void *data EINA_UNUSED)
182{ 217{
183 Instance *inst = data; 218 Eina_List *l;
219 Instance *inst;
184 220
185 _batman_sysctl_battery_update(inst); 221 /* We need to ensure we update both batman and sysinfo instances. */
222 EINA_LIST_FOREACH(sysinfo_instances, l, inst)
223 {
224 if (inst->cfg->esm == E_SYSINFO_MODULE_BATMAN ||
225 inst->cfg->esm == E_SYSINFO_MODULE_SYSINFO)
226 _batman_sysctl_battery_update(inst);
227 }
186 228
187 return EINA_TRUE; 229 return EINA_TRUE;
188} 230}
@@ -204,6 +246,7 @@ _batman_sysctl_battery_update(Instance *inst)
204 size_t len; 246 size_t len;
205 int value, fd, i = 0; 247 int value, fd, i = 0;
206#endif 248#endif
249
207 EINA_LIST_FOREACH(batman_device_batteries, l, bat) 250 EINA_LIST_FOREACH(batman_device_batteries, l, bat)
208 { 251 {
209 /* update the poller interval */ 252 /* update the poller interval */