summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2021-08-11 21:26:38 +0100
committerAlastair Poole <netstar@gmail.com>2021-08-11 21:26:38 +0100
commit793e7fcd079c0858ce3ab63f8972eb2999817934 (patch)
tree95eb0863a49bd0de1b5936d5a8f9ad4b24f88c38
parent4a5e8507593f6a3302e166db8a7fbdcf87e29286 (diff)
blindmin: blind system admin...
:) install festival
-rw-r--r--src/bin/examples/blindmin.c252
-rw-r--r--src/bin/examples/meson.build12
2 files changed, 264 insertions, 0 deletions
diff --git a/src/bin/examples/blindmin.c b/src/bin/examples/blindmin.c
new file mode 100644
index 0000000..04e135c
--- /dev/null
+++ b/src/bin/examples/blindmin.c
@@ -0,0 +1,252 @@
1#include "Enigmatic_Client.h"
2#include <Elementary.h>
3
4#define NOISY 0
5
6static Ecore_Exe *exe = NULL;
7
8static void
9cb_event_change(Enigmatic_Client *client, Snapshot *s, void *data)
10{
11 char buf[32];
12 struct tm tm_out;
13 time_t t = (time_t) s->time;
14
15 /*
16 localtime_r((time_t *) &t, &tm_out);
17 strftime(buf, sizeof(buf) - 1, "%Y-%m-%d %H:%M:%S", &tm_out);
18
19 printf("%s\n", buf);
20
21 Eina_List *l;
22 Cpu_Core *core;
23
24 EINA_LIST_FOREACH(s->cores, l, core)
25 printf("%s\t=> %i%% => %i => %iC\n", core->name, core->percent, core->freq, core->temp);
26
27 printf("Total: %"PRIu64" Used: %"PRIu64" Buffered: %"PRIu64" Cached: %"PRIu64" Shared: %"PRIu64" Swap Total %"PRIu64" Swap Used: %"PRIu64"\n",
28 (s->meminfo.total >> 10), (s->meminfo.used >> 10), (s->meminfo.buffered >> 10),
29 (s->meminfo.cached >> 10), (s->meminfo.shared >> 10), (s->meminfo.swap_total >> 10), (s->meminfo.swap_used >> 10));
30 for (int i = 0; i < s->meminfo.video_count; i++)
31 printf("Video: (%i) Total: %"PRIu64" Used: %"PRIu64"\n", i, s->meminfo.video[i].total, s->meminfo.video[i].used);
32
33 Sensor *sensor;
34 EINA_LIST_FOREACH(s->sensors, l, sensor)
35 {
36 printf("%s.%s %1.1f", sensor->name, sensor->child_name, sensor->value);
37 if (sensor->type == THERMAL) printf("C\n");
38 else printf("RPM\n");
39 }
40
41 Battery *battery;
42 EINA_LIST_FOREACH(s->batteries, l, battery)
43 printf("%s => %1.1f%% => %i of %i\n", battery->name, battery->percent, battery->charge_current, battery->charge_full);
44
45 printf("AC: [%i]\n", s->power);
46
47 Network_Interface *iface;
48 EINA_LIST_FOREACH(s->network_interfaces, l, iface)
49 printf("%s => %"PRIu64" => %"PRIu64"\n", iface->name, iface->total_in, iface->total_out);
50
51 File_System *fs;
52 EINA_LIST_FOREACH(s->file_systems, l, fs)
53 printf("%s on %s => %"PRIu64" of %"PRIu64"\n", fs->mount, fs->path, (fs->usage.used >> 10), (fs->usage.total >> 10));
54
55#if NOISY
56 Proc_Stubby *proc;
57 EINA_LIST_FOREACH(s->processes, l, proc)
58 printf("pid: %i cmd %s pri: %i nthreads: %i mem: %"PRIu64" cpu: %i%%\n",
59 proc->pid, proc->path, proc->priority, proc->numthreads, proc->mem_size >> 10, proc->cpu_usage);
60#endif
61 */
62}
63
64static void
65send_speech(const char *fmt, ...)
66{
67 char buf[4096];
68 char text[8192];
69 va_list ap;
70
71 va_start(ap, fmt);
72 vsnprintf(buf, sizeof(buf), fmt, ap);
73 va_end(ap);
74 snprintf(text, sizeof(text), "(SayText \"%s\")\n", buf);
75 ecore_exe_send(exe, text, strlen(text));
76}
77
78static void
79cb_cpu_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
80{
81 Cpu_Core *core = event->data;
82 send_speech("add %s => %i\n", core->name, core->id);
83}
84
85static void
86cb_cpu_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
87{
88 Cpu_Core *core = event->data;
89 send_speech("del %s => %i\n", core->name, core->id);
90}
91
92static void
93cb_battery_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
94{
95 Battery *bat = event->data;
96 send_speech("add %s\n", bat->name);
97}
98
99static void
100cb_battery_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
101{
102 Battery *bat = event->data;
103 send_speech("del %s\n", bat->name);
104}
105
106static void
107cb_power_supply_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
108{
109 Eina_Bool *power = event->data;
110 send_speech("power supply add %i\n", *power);
111}
112
113static void
114cb_power_supply_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
115{
116 Eina_Bool *power = event->data;
117 send_speech("power supply gone %i\n", *power);
118}
119
120static void
121cb_sensor_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
122{
123 Sensor *sensor = event->data;
124 send_speech("add %s.%s\n", sensor->name, sensor->child_name);
125}
126
127static void
128cb_sensor_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
129{
130 Sensor *sensor = event->data;
131 send_speech("del %s.%s\n", sensor->name, sensor->child_name);
132}
133
134static void
135cb_network_iface_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
136{
137 Network_Interface *iface = event->data;
138 send_speech("add %s\n", iface->name);
139}
140
141static void
142cb_network_iface_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
143{
144 Network_Interface *iface = event->data;
145 send_speech("del %s\n", iface->name);
146}
147
148static void
149cb_file_system_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
150{
151 File_System *fs = event->data;
152 send_speech("add %s => %s\n", fs->mount, fs->path);
153}
154
155static void
156cb_file_system_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
157{
158 File_System *fs = event->data;
159 send_speech("del %s => %s\n", fs->mount, fs->path);
160}
161
162static void
163cb_process_add(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
164{
165 Proc_Stubby *proc = event->data;
166 //send_speech("add %i => %s\n", proc->pid, proc->command);
167}
168
169static void
170cb_process_del(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
171{
172 Proc_Stubby *proc = event->data;
173// send_speech("del %i => %s\n", proc->pid, proc->command);
174}
175
176static void
177cb_recording_delay(Enigmatic_Client *client, Enigmatic_Client_Event *event, void *data)
178{
179 int *delay = event->data;
180 printf("gap %i => total %i secs\n", event->time, *delay);
181}
182
183static void
184cb_event_change_init(Enigmatic_Client *client, Snapshot *s, void *data)
185{
186 client_event_callback_add(client, EVENT_CPU_ADD, cb_cpu_add, NULL);
187 client_event_callback_add(client, EVENT_CPU_DEL, cb_cpu_del, NULL);
188 client_event_callback_add(client, EVENT_BATTERY_ADD, cb_battery_add, NULL);
189 client_event_callback_add(client, EVENT_BATTERY_DEL, cb_battery_del, NULL);
190 client_event_callback_add(client, EVENT_POWER_SUPPLY_ADD, cb_power_supply_add, NULL);
191 client_event_callback_add(client, EVENT_POWER_SUPPLY_DEL, cb_power_supply_del, NULL);
192 client_event_callback_add(client, EVENT_SENSOR_ADD, cb_sensor_add, NULL);
193 client_event_callback_add(client, EVENT_SENSOR_DEL, cb_sensor_del, NULL);
194 client_event_callback_add(client, EVENT_NETWORK_IFACE_ADD, cb_network_iface_add, NULL);
195 client_event_callback_add(client, EVENT_NETWORK_IFACE_DEL, cb_network_iface_del, NULL);
196 client_event_callback_add(client, EVENT_FILE_SYSTEM_ADD, cb_file_system_add, NULL);
197 client_event_callback_add(client, EVENT_FILE_SYSTEM_DEL, cb_file_system_del, NULL);
198 client_event_callback_add(client, EVENT_PROCESS_ADD, cb_process_add, NULL);
199 client_event_callback_add(client, EVENT_PROCESS_DEL, cb_process_del, NULL);
200 client_event_callback_add(client, EVENT_RECORD_DELAY, cb_recording_delay, NULL);
201}
202
203static void
204monitor(void)
205{
206 Enigmatic_Client *client = client_open();
207 EINA_SAFETY_ON_NULL_RETURN(client);
208
209 enigmatic_launch();
210
211 client_monitor_add(client, cb_event_change_init, cb_event_change, NULL);
212
213 ecore_main_loop_begin();
214
215 enigmatic_terminate();
216
217 client_del(client);
218}
219
220static Eina_Bool
221stdout_handler(void *data, int type EINA_UNUSED, void *event)
222{
223 Ecore_Exe_Event_Data *ev;
224
225 ev = event;
226
227 if (!ev || !ev->size) return 1;
228 if (ev->exe != exe) return 1;
229
230 for (int i = 0; ev->lines[i].line != NULL; i++)
231 {
232 Ecore_Exe_Event_Data_Line *line = &ev->lines[i];
233 //printf("%s\n", line->line);
234 }
235 return 1;
236}
237
238int
239elm_main(int argc, char **argv)
240{
241 exe = ecore_exe_pipe_run("festival -i", ECORE_EXE_PIPE_WRITE | ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_READ_LINE_BUFFERED |
242 ECORE_EXE_PIPE_ERROR | ECORE_EXE_PIPE_ERROR_LINE_BUFFERED, NULL);
243
244 ecore_event_handler_add(ECORE_EXE_EVENT_DATA, stdout_handler, NULL);
245 ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, stdout_handler, NULL);
246
247 monitor();
248
249 return 0;
250}
251
252ELM_MAIN();
diff --git a/src/bin/examples/meson.build b/src/bin/examples/meson.build
index 57cdd6a..e2d3353 100644
--- a/src/bin/examples/meson.build
+++ b/src/bin/examples/meson.build
@@ -16,3 +16,15 @@ executable('cpeew', src_cpu,
16 install : true) 16 install : true)
17 17
18 18
19src_blind = []
20src_blind += src_client
21src_blind += files([
22 'blindmin.c',
23])
24
25executable('blindmin', src_blind,
26 include_directories : [ inc, inc_client ],
27 dependencies : [ dep_client, dep_elm ],
28 link_with : lz4_lib,
29 gui_app : false,
30 install : true)