Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions include/api/groq.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ extern "C" {

#include "base.h"

/**
* \brief Default model optimized for fast CLI usage.
*/
#define GROQ_DEFAULT_MODEL "llama-3.1-8b-instant"

/**
* \brief Queries Groq to analyze the provided hardware telemetry.
* \param[in] hardware_json The JSON representation of the system/hardware.
* \param[in] user_prompt The user's specific question or command.
* \return true on successful API request and parsing, false otherwise.
*/
bool groq_analyze_hardware(const char *hardware_json, const char *user_prompt);

#ifdef __cplusplus
Expand Down
27 changes: 2 additions & 25 deletions include/api/http.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file http.h
* \brief Generic HTTP networking subsystem using libcurl.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -13,30 +8,12 @@ extern "C" {
#include <stddef.h>
#include <curl/curl.h>

/**
* \struct HttpResponse
* \brief Buffer to store the dynamically allocated raw string response from an HTTP request.
*/
typedef struct {
char *data; /**< Null-terminated string containing the HTTP response body */
size_t size; /**< Size of the response data in bytes (excluding null terminator) */
char *data;
size_t size;
} HttpResponse;

/**
* \brief Performs a blocking HTTP POST request.
* \param[in] url The target endpoint URL.
* \param[in] headers A linked list of HTTP headers (e.g., Authorization, Content-Type).
* \param[in] payload The raw string payload to send in the body of the request.
* \param[out] out_response Pointer to an HttpResponse struct to hold the result.
* The caller MUST call http_free_response() on success to avoid leaks.
* \return true if the network request succeeded (CURLE_OK), false otherwise.
*/
bool http_post(const char *url, struct curl_slist *headers, const char *payload, HttpResponse *out_response);

/**
* \brief Safely frees the dynamically allocated memory inside an HttpResponse.
* \param[in,out] response Pointer to the HttpResponse to clean up.
*/
void http_free_response(HttpResponse *response);

#ifdef __cplusplus
Expand Down
21 changes: 16 additions & 5 deletions include/base.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file base.h
* \brief Header file for base module.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -23,6 +18,22 @@ extern "C" {

#define STR_OR_UNK(s) ((s) ? (s) : "<unknown>")

#define DEFINE_FREE_ARRAY(func_name, item_type, free_item_fn) \
void func_name(item_type **items, int count) \
{ \
if (items == NULL) { \
return; \
} \
\
for (int i = 0; i < count; i++) { \
if (items[i] != NULL) { \
free_item_fn(items[i]); \
} \
} \
\
free(items); \
} \

#ifdef __cplusplus
}
#endif /* __cplusplus */
24 changes: 0 additions & 24 deletions include/battery.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file battery.h
* \brief Header file for battery module.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -12,10 +7,6 @@ extern "C" {
#include <inttypes.h>
#include <cJSON.h>

/**
* \struct BATTERY
* \brief Structure to hold battery metrics and vendor information.
*/
typedef struct {
uint16_t capacity;
float voltage_min_design;
Expand All @@ -33,23 +24,8 @@ typedef struct {
char *serial;
} BATTERY;

/**
* \brief Discovers and parses battery information from /sys/class/power_supply.
* \return Pointer to a newly allocated BATTERY struct, or NULL on failure.
*/
BATTERY *battery_get_info(void);

/**
* \brief Deep-frees a BATTERY structure and its internal strings.
* \param[in] battery Pointer to the structure to free.
*/
void free_battery(BATTERY *battery);

/**
* \brief Converts a BATTERY structure to a cJSON object.
* \param[in] battery Pointer to the BATTERY structure.
* \return Pointer to a cJSON object (caller must delete).
*/
cJSON *battery_to_json_obj(const BATTERY *battery);

#ifdef __cplusplus
Expand Down
9 changes: 0 additions & 9 deletions include/cpu.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file cpu.h
* \brief Header file for cpu module.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -12,10 +7,6 @@ extern "C" {
#include <stdint.h>
#include <cJSON.h>

/**
* \struct CPU
* \brief Structure to hold CPU metrics and vendor information.
*/
typedef struct {
char *vendor_id;
char *model_name;
Expand Down
51 changes: 0 additions & 51 deletions include/display.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file display.h
* \brief Header file for display module.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -18,60 +13,14 @@ extern "C" {
#include "storage.h"
#include "network.h"

/**
* \brief Displays OS information to the console.
* \param[in] os Pointer to the OS structure.
*/
void display_os(const OS *os);

/**
* \brief Displays CPU information to the console.
* \param[in] cpu Pointer to the CPU structure.
*/
void display_cpu(const CPU *cpu);

/**
* \brief Displays RAM information to the console.
* \param[in] ram Pointer to the RAM structure.
*/
void display_ram(const RAM *ram);

/**
* \brief Displays information for all GPUs to the console.
* \param[in] gpus Array of pointers to GPU structures.
* \param[in] count Number of GPUs in the array.
*/
void display_gpus(GPU **gpus, int count);

/**
* \brief Displays Battery information to the console.
* \param[in] battery Pointer to the BATTERY structure.
*/
void display_battery(const BATTERY *battery);

/**
* \brief Displays Mainboard information to the console.
* \param[in] mainboard Pointer to the MAINBOARD structure.
*/
void display_mainboard(const MAINBOARD *mainboard);

/**
* \brief Displays information for all Storage devices to the console.
* \param[in] storages Array of pointers to STORAGE structures.
* \param[in] count Number of storages in the array.
*/
void display_storages(STORAGE **storages, int count);

/**
* \brief Displays information for all Network interfaces to the console.
* \param[in] networks Array of pointers to Network structures.
* \param[in] count Number of networks in the array.
*/
void display_networks(Network **networks, int count);

/**
* \brief Clears the terminal screen and resets cursor position using ANSI codes.
*/
void display_clear(void);

#ifdef __cplusplus
Expand Down
23 changes: 4 additions & 19 deletions include/file.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file file.h
* \brief Header file for file module.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -11,23 +6,13 @@ extern "C" {

#include <stdbool.h>

/**
* \brief Reads a file into a dynamically allocated string, stripping specified characters.
* \param[in] filename Path to the file to read.
* \param[in] exclude Characters to strip out from the file content.
* \param[in] verbose If true, prints warning messages on failure.
* \return A null-terminated dynamically allocated string, or NULL on error.
*/
char *file_read_stripped(const char *filename, const char *exclude, bool verbose);

/**
* \brief Writes a string to a file.
* \param[in] filename Path to the file to write.
* \param[in] data String data to write.
* \return true on success, false on failure.
*/
bool file_write_string(const char *filename, const char *data);

typedef void *(*sysfs_parse_fn)(const char *entry_name);
void **sysfs_enumerate(const char *dir_path, sysfs_parse_fn parse_fn, int max_items, int *out_count);
char *sysfs_read_attr_fmt(const char *exclude, const char *fmt, ...);

#ifdef __cplusplus
}
#endif /* __cplusplus */
28 changes: 0 additions & 28 deletions include/gpu.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file gpu.h
* \brief Header file for gpu module.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -14,7 +9,6 @@ extern "C" {

#define MAX_GPUS 16

/* GPU Vendor IDs (PCI hex codes) */
#define PCI_VENDOR_NVIDIA "0x10de"
#define PCI_VENDOR_INTEL "0x8086"
#define PCI_VENDOR_AMD "0x1002"
Expand All @@ -37,31 +31,9 @@ typedef struct {
char *pci_slot_name;
} GPU;

/**
* \brief Discovers all GPUs in the system via sysfs.
* \param[out] count Pointer to an integer where the number of GPUs will be stored.
* \return A dynamically allocated array of GPU pointers, or NULL on failure.
*/
GPU **gpu_get_all(int *count);

/**
* \brief Frees a single GPU structure and all its internal strings.
* \param[in] gpu Pointer to the GPU structure to free.
*/
void free_gpu(GPU *gpu);

/**
* \brief Frees an array of GPU pointers and the array itself.
* \param[in] gpus Array of GPU pointers to free.
* \param[in] count Number of GPUs in the array.
*/
void free_gpus(GPU **gpus, int count);

/**
* \brief Converts a GPU structure to a cJSON object.
* \param[in] gpu Pointer to the GPU structure.
* \return Pointer to a cJSON object (caller must delete).
*/
cJSON *gpu_to_json_obj(const GPU *gpu);

#ifdef __cplusplus
Expand Down
20 changes: 0 additions & 20 deletions include/io.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file io.h
* \brief Header file for string parsing utilities.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -11,22 +6,7 @@ extern "C" {

#include "base.h"

/**
* \brief Searches a source string for a key and returns the associated value.
* \param[in] source The source string to search.
* \param[in] search The key string to find.
* \param[in] delim Delimiter characters to find the end of the value.
* \return Dynamically allocated string (caller must free), or NULL if not found.
*/
char *str_find_value(const char *source, const char *search, const char *delim);

/**
* \brief Searches a source string for a key and returns the value as a double.
* \param[in] source The source string to search.
* \param[in] search The key string to find.
* \param[in] delim Delimiter characters to find the end of the value.
* \return Value as a double, or 0.0 if not found.
*/
double str_parse_value(const char *source, const char *search, const char *delim);

#ifdef __cplusplus
Expand Down
24 changes: 0 additions & 24 deletions include/mainboard.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* \file mainboard.h
* \brief Header file for mainboard/system DMI discovery.
*/

#pragma once

#ifdef __cplusplus
Expand All @@ -11,10 +6,6 @@ extern "C" {

#include <cJSON.h>

/**
* \struct MAINBOARD
* \brief Structure to hold system and motherboard DMI information.
*/
typedef struct {
char *sys_vendor;
char *product_name;
Expand All @@ -25,23 +16,8 @@ typedef struct {
char *serial;
} MAINBOARD;

/**
* \brief Discovers and parses Mainboard/System information from sysfs DMI data.
* \return Pointer to a newly allocated MAINBOARD struct, or NULL on failure.
*/
MAINBOARD *mainboard_get_info(void);

/**
* \brief Deep-frees a MAINBOARD structure and its internal strings.
* \param[in] mainboard Pointer to the MAINBOARD structure to free.
*/
void free_mainboard(MAINBOARD *mainboard);

/**
* \brief Converts a MAINBOARD structure to a cJSON object.
* \param[in] mainboard Pointer to the MAINBOARD structure.
* \return Pointer to a cJSON object (caller must delete).
*/
cJSON *mainboard_to_json_obj(const MAINBOARD *mainboard);

#ifdef __cplusplus
Expand Down
Loading
Loading