#pragma once #include "database.h" #include "types.h" #include 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; lm_pkg_t *cur; size_t count; } lm_ctx_update_list_t; typedef enum lm_ctx_sync_state { SYNC_DOWNLOADING_INFO = 0, SYNC_INFO_SUCCESS = 1, SYNC_INFO_FAIL = 2, SYNC_DOWNLOADING_LIST = 3, SYNC_LIST_SUCCESS = 4, SYNC_LIST_FAIL = 5, } lm_ctx_sync_state_t; typedef enum lm_ctx_update_state { UPDATE_REMOVE = 0, UPDATE_INSTALL = 1, } lm_ctx_update_state_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, bool is_archive, 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_update_callback_t)( lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_update_state_t state, 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, lm_ctx_sync_state_t state, size_t current, size_t total, void *data); typedef bool (*lm_ctx_ping_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, 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_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_resolve_list_t *list); // returns the next package in the list void lm_ctx_resolve_free(lm_ctx_resolve_list_t *list); // frees the resolved list returned by lm_ctx_resolve lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx); // get a list of packages to update lm_pkg_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list); // get the next package in the update list void lm_ctx_update_list_free(lm_ctx_update_list_t *list); // free the update list bool lm_ctx_update(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_update_callback_t callback, void *data); // returns a list of packages to 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 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 size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools void lm_ctx_ping(lm_ctx_t *ctx, lm_ctx_ping_callback_t callback, void *data); // pings all the pools bool lm_ctx_serve(lm_ctx_t *ctx, char *addr, uint8_t threads); // serves all the pools /* #################### ## pool fucntions ## #################### */ lm_pkg_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name, char *version); // find a package in ctx pool list 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 lm_pool_t *lm_ctx_pool_by_name(lm_ctx_t *ctx, char *name); // find pool by name lm_pool_t *lm_ctx_pool_by_url(lm_ctx_t *ctx, char *host, char *path); // find pool by URL /* ######################## ## 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, char *version); // find a package by name bool lm_ctx_database_next(lm_ctx_t *ctx, lm_pkg_t *pkg); // load the next package into pkg pointer bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_pkg_t *pkg); // free the used next pointers