libmp/include/ctx.h

98 lines
4.7 KiB
C

#pragma once
#include "database.h"
#include "types.h"
#include <stdbool.h>
typedef struct lm_ctx {
lm_database_t *db; // package database
lm_pool_t *pools; // pool list
char *root; // root path for package installtion
char *temp; // temp path
char *data; // package database path
const char *version; // libmp version (read-only)
} lm_ctx_t;
typedef struct lm_ctx_resolve_list {
lm_pkg_t *resolving;
lm_pkg_t *packages;
lm_pkg_t *cur;
size_t count;
} lm_ctx_resolve_list_t;
typedef struct lm_ctx_update_list {
lm_pkg_t **packages;
size_t count;
size_t index;
} lm_ctx_update_list_t;
/* ###################
## ctx callbacks ##
################### */
typedef bool (*lm_ctx_database_callback_t)(lm_ctx_t *ctx, lm_pkg_t *pkg, void *data);
typedef bool (*lm_ctx_download_callback_t)(lm_ctx_t *ctx, lm_pkg_t *pkg, size_t current, size_t total, void *data);
typedef bool (*lm_ctx_install_callback_t)(
lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data);
typedef bool (*lm_ctx_sync_callback_t)(
lm_ctx_t *ctx, lm_pool_t *pool, bool status, size_t current, size_t total, void *data);
typedef lm_ctx_install_callback_t lm_ctx_remove_callback_t;
typedef lm_ctx_install_callback_t lm_ctx_check_callback_t;
/* ###############
## ctx stuff ##
############### */
void lm_ctx_init(lm_ctx_t *ctx);
bool lm_ctx_set_data(lm_ctx_t *ctx, char *dir);
bool lm_ctx_set_root(lm_ctx_t *ctx, char *dir);
bool lm_ctx_set_temp(lm_ctx_t *ctx, char *dir);
void lm_ctx_free(lm_ctx_t *ctx);
/* ####################
## main fucntions ##
#################### */
lm_pkg_t *lm_ctx_find(lm_ctx_t *ctx, char *name, char *version); // find package by name (and version)
lm_ctx_resolve_list_t *lm_ctx_resolve(
lm_ctx_t *ctx, lm_pkg_t *pkg); // resolves a package and returns a list of packages to install
lm_pkg_t *lm_ctx_resolve_next(lm_ctx_t *ctx, lm_ctx_resolve_list_t *list); // returns the next package in the list
void lm_ctx_resolve_free(
lm_ctx_t *ctx, lm_ctx_resolve_list_t *list); // frees the resolved list returned by lm_ctx_resolve
lm_ctx_update_list_t *lm_ctx_update(lm_ctx_t *ctx); // returns a list of packages to update
lm_pkg_t *lm_ctx_update_next(lm_ctx_t *ctx, lm_ctx_update_list_t *list); // returns the next package in the list
void lm_ctx_update_free(lm_ctx_t *ctx, lm_ctx_update_list_t *list); // frees the update list returned by lm_ctx_update
bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t callback,
void *data); // downloads a single package if its not already downloaded
bool lm_ctx_install(
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t callback, void *data); // installs/updates a single package
bool lm_ctx_remove(
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callback, void *data); // removes a single package
bool lm_ctx_check(
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback, void *data); // checks a single package
bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools
bool lm_ctx_serve(lm_ctx_t *ctx, char *add, uint8_t threads); // serves all the pools
/* ####################
## pool fucntions ##
#################### */
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url); // add a pool to the ctx pool list
bool lm_ctx_pool_del(lm_ctx_t *ctx, char *name); // remove a pool from the ctx pool list
void lm_ctx_pool_clear(lm_ctx_t *ctx); // clear all the pools in the ctx pool list
bool lm_ctx_pool_serve(
lm_ctx_t *ctx, char *addr, uint8_t threads); // serve all the pools on a MPTP server hosted at the given address
void lm_ctx_pool_test(lm_ctx_t *ctx); // test (ping) all the pool connetions
void lm_ctx_pool_get_info(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
void *data); // get pool info of all the pools in the ctx list
void lm_ctx_pool_get_list(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
void *data); // get pool list of all the pools in the ctx list
/* ########################
## database fucntions ##
######################## */
bool lm_ctx_database_init(lm_ctx_t *ctx); // init ctx database (if not already present)
bool lm_ctx_database_is_installed(lm_ctx_t *ctx, lm_pkg_t *pkg, bool check_version); // check if a package is installed
bool lm_ctx_database_find(lm_ctx_t *ctx, lm_pkg_t *pkg, char *name); // find a package by name
bool lm_ctx_database_foreach(
lm_ctx_t *ctx, lm_ctx_database_callback_t callback, void *data); // loop for each package in the database