diff --git a/Makefile b/Makefile index bf69f63..6dad537 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ INSTALLER_SRCS := $(wildcard $(INSTALLER_SRC)/*.c) TOML_SRCS := $(TOML)/toml.c ifeq ($(OS), Windows_NT) - LINKED_LIBS := -lWs2_32 -ldxgi -ldxguid -lole32 + LINKED_LIBS := -lWs2_32 -ldxgi -ldxguid -lole32 -lpsapi else ifeq ($(shell uname), Linux) LINKED_LIBS := endif diff --git a/src/config_loader.c b/src/config_loader.c index 1ab6836..e7639e8 100644 --- a/src/config_loader.c +++ b/src/config_loader.c @@ -48,18 +48,28 @@ result_t* open_config() { config_details_t get_details_from_config(toml_table_t* config) { // set initial defaults config_details_t config_details = (config_details_t) { - .server_config.hostname = BENJI_DEFAULT_SERVER_HOSTNAME, - .server_config.port = BENJI_DEFAULT_SERVER_PORT + .server_config_details.hostname = BENJI_DEFAULT_SERVER_HOSTNAME, + .server_config_details.port = BENJI_DEFAULT_SERVER_PORT, }; toml_table_t* server_table = toml_table_table(config, "server"); + toml_table_t* telemetry_table = toml_table_table(config, "telemetry"); if (server_table) { toml_value_t hostname = toml_table_string(server_table, "hostname"); toml_value_t port = toml_table_int(server_table, "port"); - config_details.server_config.hostname = hostname.ok ? hostname.u.s : BENJI_DEFAULT_SERVER_HOSTNAME; - config_details.server_config.port = port.ok ? port.u.i : BENJI_DEFAULT_SERVER_PORT; + if (hostname.ok) { + config_details.server_config_details.hostname = hostname.u.s; + } + + if (port.ok) { + config_details.server_config_details.port = port.u.i; + } + } + + if (telemetry_table) { + // TODO: add values here } return config_details; diff --git a/src/include/config_loader.h b/src/include/config_loader.h index caa36ab..793b247 100644 --- a/src/include/config_loader.h +++ b/src/include/config_loader.h @@ -23,11 +23,19 @@ #define BENJI_DEFAULT_SERVER_PORT (8000) #endif +#ifndef BENJI_DEFAULT_MAX_PROCESSES + #define BENJI_DEFAULT_MAX_PROCESSES (10) +#endif + typedef struct _BENJI_CONFIG_DETAILS { - struct _BENJI_SERVER_CONFIG { + struct _BENJI_SERVER_CONFIG_DETAILS { const char* hostname; uint16_t port; // 1-65535 - } server_config; + } server_config_details; + + struct _TELEMETRY_CONFIG_DETAILS { + // TODO: add values here + } telemetry_config_details; } config_details_t; result_t* open_config(); diff --git a/src/include/service.h b/src/include/service.h index 34e0939..a441ab9 100644 --- a/src/include/service.h +++ b/src/include/service.h @@ -19,10 +19,10 @@ #endif #endif -static struct _BENJI_SERVER_INFO { +static struct _BENJI_SERVER_CONFIG { const char* hostname; uint16_t port; -} server_info; +} server_config; static BENJI_SOCKET server_socket; @@ -41,7 +41,8 @@ static BENJI_SOCKET server_socket; /* TODO: add linux stuff */ #endif -// prolly the closest anything in this project will get to a constructor -void collect_server_details(config_details_t config_details); +// mock constructors +void collect_server_config_details(config_details_t config_details); +void collect_telemetry_config_details(config_details_t config_details); #endif \ No newline at end of file diff --git a/src/include/telemetry/cpu_telemetry.h b/src/include/telemetry/cpu_telemetry.h index 509e8c8..ca90606 100644 --- a/src/include/telemetry/cpu_telemetry.h +++ b/src/include/telemetry/cpu_telemetry.h @@ -1,21 +1,20 @@ #ifndef __BENJI_CPU_TELEMETRY_H #define __BENJI_CPU_TELEMETRY_H +#if defined(_WIN32) + #include + #include +#endif + #ifndef BENJI_USE_SYSTEM_TELEMETRY_UTILS #define BENJI_USE_SYSTEM_TELEMETRY_UTILS #endif #include "../utils.h" -#include "../map.h" #include "../result.h" #include "telemetry_base.h" -#if defined(_WIN32) - #include - #include -#endif - #ifndef BENJI_CPUID_BUFFER_LENGTH #define BENJI_CPUID_BUFFER_LENGTH (4) #endif diff --git a/src/include/telemetry/processes_telemetry.h b/src/include/telemetry/processes_telemetry.h new file mode 100644 index 0000000..0b2cb4d --- /dev/null +++ b/src/include/telemetry/processes_telemetry.h @@ -0,0 +1,44 @@ +#ifndef __BENJI_PROCESSES_TELEMETRY_H +#define __BENJI_PROCESSES_TELEMETRY_H + +#include + +#ifndef BENJI_USE_SYSTEM_TELEMETRY_UTILS + #define BENJI_USE_SYSTEM_TELEMETRY_UTILS +#endif + +#include "../utils.h" +#include "../result.h" + +#include "telemetry_base.h" + +#ifndef BENJI_PROCESSES_FIELDS + #define BENJI_PROCESSES_FIELDS(_field_getter_impl) \ + _field_getter_impl(processes, names) \ + _field_getter_impl(processes, pids) \ + _field_getter_impl(processes, parent_pids) \ + _field_getter_impl(processes, cpu_usages) \ + _field_getter_impl(processes, gpu_usages) \ + _field_getter_impl(processes, ram_usages) \ + _field_getter_impl(processes, disk_usages) \ + _field_getter_impl(processes, network_usages) +#endif + +BENJI_CREATE_TELEMETRY_STRUCT(PROCESSES, processes, + size_t processes_count; + + char* names; + size_t* pids; + size_t* parent_pids; + double* cpu_usages; // percent between 0.0 and 1.0 + double* gpu_usages; // percent between 0.0 and 1.0 + double* ram_usages; // percent between 0.0 and 1.0 + double* disk_usages; // percent between 0.0 and 1.0 + double* network_usages; // percent between 0.0 and 1.0 +) + +BENJI_CREATE_TELEMETRY_BASE(processes) + +BENJI_PROCESSES_FIELDS(BENJI_CREATE_TELEMETRY_GETTER_IMPL) + +#endif \ No newline at end of file diff --git a/src/include/telemetry/telemetry_base.h b/src/include/telemetry/telemetry_base.h index a61fa29..e7fbc8f 100644 --- a/src/include/telemetry/telemetry_base.h +++ b/src/include/telemetry/telemetry_base.h @@ -1,6 +1,8 @@ #ifndef __BENJI_TELEMETRY_BASE_H #define __BENJI_TELEMETRY_BASE_H +#include + #include "../result.h" #ifndef BENJI_CREATE_TELEMETRY_STRUCT @@ -49,4 +51,8 @@ } while (false); #endif +static struct _BENJI_TELEMETRY_CONFIG { + // TODO: add values here +} telemetry_config; + #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 5602113..e220fb2 100644 --- a/src/main.c +++ b/src/main.c @@ -21,11 +21,10 @@ int main(int argc, const char* argv[]) { config_details_t config_details = get_details_from_config(toml_config); - toml_free(toml_config); + collect_server_config_details(config_details); + collect_telemetry_config_details(config_details); - #ifdef _WIN32 - collect_server_details(config_details); - #endif + toml_free(toml_config); #if defined(_WIN32) winsock_init(); diff --git a/src/service.c b/src/service.c index 1727177..12011d3 100644 --- a/src/service.c +++ b/src/service.c @@ -1,4 +1,3 @@ - #include "include/service.h" #if defined(_WIN32) @@ -30,7 +29,7 @@ return; } - result_t* server_socket_result = server_init(server_info.hostname, server_info.port); + result_t* server_socket_result = server_init(server_config.hostname, server_config.port); if (server_socket_result->is_error) { result_error_payload_t server_socket_result_error = result_unwrap_error(server_socket_result); @@ -145,7 +144,11 @@ /* TODO: add linux stuff */ #endif -void collect_server_details(config_details_t config_details) { - server_info.hostname = config_details.server_config.hostname; - server_info.port = config_details.server_config.port; +void collect_server_config_details(config_details_t config_details) { + server_config.hostname = config_details.server_config_details.hostname; + server_config.port = config_details.server_config_details.port; +} + +void collect_telemetry_config_details(config_details_t config_details) { + // TODO: add values } \ No newline at end of file