Made polling dependant on if the plugin is ready or not
This commit is contained in:
parent
df4c777bed
commit
317708dc1f
|
@ -3,15 +3,17 @@
|
||||||
#define _H_PLUG
|
#define _H_PLUG
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef void (*plug_init_f) ();
|
typedef void (*plug_init_f) (void);
|
||||||
typedef void (*plug_reload_f) ();
|
typedef void (*plug_reload_f) (void);
|
||||||
typedef void (*plug_poll_f) (char*, size_t);
|
typedef void (*plug_poll_f) (char*, size_t);
|
||||||
typedef void (*plug_free_f) ();
|
typedef void (*plug_free_f) (void);
|
||||||
|
|
||||||
typedef struct plug_t {
|
typedef struct plug_t {
|
||||||
char* name;
|
char* name;
|
||||||
char* version;
|
char* version;
|
||||||
|
bool is_ready;
|
||||||
} plug_t;
|
} plug_t;
|
||||||
|
|
||||||
typedef struct plug_int_t {
|
typedef struct plug_int_t {
|
||||||
|
@ -23,8 +25,8 @@ typedef struct plug_int_t {
|
||||||
} plug_int_t;
|
} plug_int_t;
|
||||||
|
|
||||||
void setup_plugins(char* plugin_path);
|
void setup_plugins(char* plugin_path);
|
||||||
char* poll_plugins();
|
char* poll_plugins(char* sep);
|
||||||
void free_plugins();
|
void free_plugins(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ void plug_init(void) {
|
||||||
printf("MODULE: ERROR: Unable to find battery\n");
|
printf("MODULE: ERROR: Unable to find battery\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PLUG.is_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plug_reload(void) { /* Unused */ }
|
void plug_reload(void) { /* Unused */ }
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "plug.h"
|
#include "plug.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
plug_t PLUG = {0};
|
plug_t PLUG = {0};
|
||||||
|
|
||||||
void plug_init(void) {
|
void plug_init(void) {
|
||||||
PLUG.name = "time";
|
PLUG.name = "time";
|
||||||
PLUG.version = "0.0.1";
|
PLUG.version = "0.0.1";
|
||||||
|
PLUG.is_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plug_reload(void) { /* Unused */ }
|
void plug_reload(void) { /* Unused */ }
|
||||||
|
|
|
@ -124,7 +124,7 @@ void setup_plugins(char* plugin_path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_plugins() {
|
void free_plugins(void) {
|
||||||
for (size_t i = 0; i < PLUGMAN.plug_count; i++) {
|
for (size_t i = 0; i < PLUGMAN.plug_count; i++) {
|
||||||
plug_int_t* plug = PLUGMAN.plugs[i];
|
plug_int_t* plug = PLUGMAN.plugs[i];
|
||||||
(plug->f_free)();
|
(plug->f_free)();
|
||||||
|
@ -146,10 +146,11 @@ char* poll_plugins(char* sep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < PLUGMAN.plug_count; i++) {
|
for (size_t i = 0; i < PLUGMAN.plug_count; i++) {
|
||||||
plug_int_t* plug = PLUGMAN.plugs[i];
|
plug_int_t* plug = PLUGMAN.plugs[i];
|
||||||
|
if (!plug->s_plug_info->is_ready) continue;
|
||||||
printf("Polling plug id %zu\n", i);
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("Polling plug id %zu\n", i);
|
||||||
size_t len = strlen(buf);
|
size_t len = strlen(buf);
|
||||||
(plug->f_poll)(buf + len, PLUG_POLL_BUF_SZ - len);
|
(plug->f_poll)(buf + len, PLUG_POLL_BUF_SZ - len);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user