mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
lib: add tc_readable_set_data()
This commit is contained in:
parent
d719832f1c
commit
455ccf2610
@ -15,7 +15,10 @@ extern "C" {
|
|||||||
#define TC_ASSIGNABLE (1)
|
#define TC_ASSIGNABLE (1)
|
||||||
#define TC_READABLE (1 << 1)
|
#define TC_READABLE (1 << 1)
|
||||||
#define TC_INTERFACE (1 << 2)
|
#define TC_INTERFACE (1 << 2)
|
||||||
|
|
||||||
|
#define TC_READABLE_DYNAMIC (1)
|
||||||
|
#define TC_READABLE_STATIC (1 << 1)
|
||||||
|
|
||||||
// Categories for modules.
|
// Categories for modules.
|
||||||
enum tc_module_category {
|
enum tc_module_category {
|
||||||
TC_CATEGORY_ASSIGNABLE,
|
TC_CATEGORY_ASSIGNABLE,
|
||||||
@ -41,6 +44,11 @@ enum tc_module_category {
|
|||||||
// Maximum argument count for "overloaded" functions
|
// Maximum argument count for "overloaded" functions
|
||||||
#define TC_MAX_FUNCTION_ARGC 16
|
#define TC_MAX_FUNCTION_ARGC 16
|
||||||
|
|
||||||
|
union module_data_callback_t {
|
||||||
|
tc_readable_module_data_t (*readable_data)();
|
||||||
|
tc_assignable_module_data_t (*assignable_data)();
|
||||||
|
};
|
||||||
|
|
||||||
// Tagged union for category specific data
|
// Tagged union for category specific data
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t category;
|
uint64_t category;
|
||||||
@ -84,6 +92,11 @@ tc_module_t *tc_module_find(enum tc_module_category category, const char *name);
|
|||||||
// Try to return all module handles matching 'category'. The return value needs to be freed in addition to tc_module_close()
|
// Try to return all module handles matching 'category'. The return value needs to be freed in addition to tc_module_close()
|
||||||
tc_module_t **tc_module_find_all_from_category(enum tc_module_category category, uint16_t *count);
|
tc_module_t **tc_module_find_all_from_category(enum tc_module_category category, uint16_t *count);
|
||||||
|
|
||||||
|
// Convenience functions
|
||||||
|
tc_module_category_info_t tc_module_category_info_create(uint64_t mask, uint16_t num_categories, const tc_module_category_data_t *categories);
|
||||||
|
|
||||||
|
tc_module_category_data_t tc_module_category_data_create(uint64_t category, union module_data_callback_t u);
|
||||||
|
|
||||||
// Close the module after successful find
|
// Close the module after successful find
|
||||||
void tc_module_close(tc_module_t *module);
|
void tc_module_close(tc_module_t *module);
|
||||||
|
|
||||||
|
@ -36,8 +36,10 @@ typedef struct tc_readable_node_t_ {
|
|||||||
|
|
||||||
// Master data structure loaded by module loader
|
// Master data structure loaded by module loader
|
||||||
typedef struct {
|
typedef struct {
|
||||||
tc_readable_node_t *root_node;
|
uint64_t category_mask; // Which types of readable (dynamic or static) are implemented
|
||||||
const char *(*sha256_hash)(const tc_readable_node_t*); // Callback to get a unique hash for a node
|
tc_readable_node_t *root_static_node;
|
||||||
|
tc_readable_node_t *root_node;
|
||||||
|
const char *(*sha256_hash)(const tc_readable_node_t*); // Callback to get a unique hash for a node
|
||||||
} tc_readable_module_data_t;
|
} tc_readable_module_data_t;
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
@ -53,6 +55,9 @@ int8_t tc_readable_node_add_child(tc_readable_node_t *parent, tc_readable_node_t
|
|||||||
// Convinience function for creating a new node and adding it to parent
|
// Convinience function for creating a new node and adding it to parent
|
||||||
tc_readable_node_t *tc_readable_node_add_new_child(tc_readable_node_t *parent);
|
tc_readable_node_t *tc_readable_node_add_new_child(tc_readable_node_t *parent);
|
||||||
|
|
||||||
|
// Set node data
|
||||||
|
void tc_readable_node_set_data(tc_readable_node_t *node, const char *name, const char *unit);
|
||||||
|
|
||||||
// Create a tc_readable_result from data, data type and validity. Avoids boilerplate in returning values from readable nodes.
|
// Create a tc_readable_result from data, data type and validity. Avoids boilerplate in returning values from readable nodes.
|
||||||
tc_readable_result_t tc_readable_result_create(enum tc_data_types type, void *data, bool valid);
|
tc_readable_result_t tc_readable_result_create(enum tc_data_types type, void *data, bool valid);
|
||||||
|
|
||||||
|
@ -50,6 +50,11 @@ tc_readable_node_t *tc_readable_node_add_new_child(tc_readable_node_t *parent) {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tc_readable_node_set_data(tc_readable_node_t *node, const char *name, const char *unit) {
|
||||||
|
node->name = name;
|
||||||
|
node->unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
tc_readable_result_t tc_readable_result_create(enum tc_data_types type, void *data, bool valid) {
|
tc_readable_result_t tc_readable_result_create(enum tc_data_types type, void *data, bool valid) {
|
||||||
tc_readable_result_t res;
|
tc_readable_result_t res;
|
||||||
res.valid = valid;
|
res.valid = valid;
|
||||||
|
Loading…
Reference in New Issue
Block a user