#ifndef _XCECD_DB_H #define _XCECD_DB_H #include "sqlite3.h" #include "xcecd_utils.h" #include "xcecd_worker_utils.h" #include #include typedef struct sqlite3 xcecd_db_t; /** * @brief Initialize the database * * @param db Pointer to the database structure * @param db_path Path to the database file * @return true if success, false if failed */ bool xcecd_db_init(xcecd_db_t** db, const char* db_path); /** * @brief close the database * @param db Pointer to the database structure */ void xcecd_db_close(xcecd_db_t* db); /** * @brief Insert a worker into the database * * @param db Pointer to the database structure * @param worker_pid PID of the worker * @param worker_status Status of the worker * @param job_id Job ID associated with the worker * @param job_status Status of the job associated with the worker * @return true if success, false if failed */ bool xcecd_db_insert_worker(xcecd_db_t* db, int worker_pid, int worker_status, uint64_t job_id, int job_status); /** * @brief Update a worker in the database * * @param db Pointer to the database structure * @param worker_pid PID of the worker * @param worker_status Status of the worker * @param job_status Status of the job associated with the worker * @return true if success, false if failed */ bool xcecd_db_update_worker(sqlite3* db, int worker_pid, int worker_status, int job_status); /** * @brief Delete a worker from the database * * @param db Pointer to the database structure * @param worker_pid PID of the worker * @return true if success, false if failed */ bool xcecd_db_delete_worker(xcecd_db_t* db, int worker_pid); /** * @brief Get a worker from the database * * @param db Pointer to the database structure * @param worker_pid PID of the worker * @return worker status if success, -1 if failed */ int xcecd_db_get_worker(xcecd_db_t* db, int worker_pid); /** * @brief Get running workers from the database * * @param db Pointer to the database structure * @return Pointer to the worker list (db->worker_list) if success, NULL if * failed */ bool xcecd_db_get_running_workers(xcecd_db_t* db, xcecd_worker_t** worker_list); /** * @brief Check if the database is available * @param db Pointer to the database structure * @param db_path Path to the database file * @return void and directly exit if the database is not available */ void xcecd_db_is_available(xcecd_db_t* db, const char* db_path); #endif