2024-02-19 16:01:53 +01:00
# pragma once
# include "utils.h"
2024-02-28 17:50:27 +01:00
# include "config.h"
2024-02-19 16:01:53 +01:00
2024-02-28 17:50:27 +01:00
/// @brief The maximum length of a container identifier.
# define MAX_CONTAINER_IDENTIFIER_LENGTH 64
2024-02-19 16:01:53 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Checks whether the specified container identifier is valid. This call will return an error with a message describing the problem if the identifier is invalid.
/// @param identifier The identifier to check.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t check_container_identifier ( const char * identifier ) ;
2024-02-19 20:03:30 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Checks whether the specified container exists.
/// @param _exists The pointer to where the result should be stored.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container to check.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t check_container_exists ( bool * _exists , const config_t * config , const char * identifier ) ;
2024-02-19 16:01:53 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Returns the path of the container pool directory.
/// @param _path The pointer to where the path should be stored. The caller is responsible for freeing the memory.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t get_container_pool_path ( char * * _path , const config_t * config ) ;
2024-02-19 20:03:30 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Returns the path of the specified container.
/// @param _path The pointer to where the path should be stored. The caller is responsible for freeing the memory.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container.
/// @return The result of the operation.
result_t get_container_path ( char * * _path , const config_t * config , const char * identifier ) ;
2024-02-19 16:01:53 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Adds a new root container to the pool, with the specified identifier and size.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container to add.
2024-02-19 20:03:30 +01:00
/// @param size The size of the container to add, in bytes.
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t add_root_container ( const config_t * config , const char * identifier , size_t size ) ;
2024-02-19 20:03:30 +01:00
2024-02-29 10:58:47 +01:00
/// @brief Adds a new backed container to the pool, with the specified identifier and image.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container to add.
2024-02-29 10:58:47 +01:00
/// @param image The identifier of the image to use.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-29 10:58:47 +01:00
result_t add_backed_container ( const config_t * config , const char * identifier , const char * image ) ;
2024-02-19 16:01:53 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Removes the specified container from the pool.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container to remove.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t remove_container ( const config_t * config , const char * identifier ) ;
2024-02-19 20:03:30 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Resets the specified container to its original state.
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container to reset.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t reset_container ( const config_t * config , const char * identifier ) ;
2024-02-19 20:23:26 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Trims the specified container.
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param identifier The identifier of the container to trim.
2024-02-19 20:23:26 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t trim_container ( const config_t * config , const char * identifier ) ;
2024-02-20 14:54:04 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Lists the containers in the pool.
/// @param _identifiers The pointer to where the list of identifiers should be stored. The caller is responsible for freeing the strings and the array.
/// @param _count The pointer to where the count of identifiers should be stored.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t list_containers ( char * * * _identifiers , size_t * _count , const config_t * config ) ;
2024-02-20 14:54:04 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Returns the available space in the pool.
/// @param _space The pointer to where the available space should be stored, in bytes.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t get_container_pool_space ( size_t * _space , const config_t * config ) ;
2024-02-20 14:54:04 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Find the oldest container in the pool.
/// @param _identifier The pointer to where the identifier of the oldest container should be stored.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t find_oldest_container ( char * * _identifier , const config_t * config ) ;
2024-02-20 14:54:04 +01:00
2024-02-29 09:50:28 +01:00
/// @brief Reserves the specified space in the pool by removing the oldest containers.
2024-02-28 17:50:27 +01:00
/// @param config The program configuration to use.
2024-02-29 09:50:28 +01:00
/// @param space The space to reserve, in bytes.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-29 09:50:28 +01:00
result_t reserve_container_pool_space ( const config_t * config , size_t space ) ;