config.h (1511B)
1 #ifndef LQ_CONFIG_H_ 2 #define LQ_CONFIG_H_ 3 4 #ifndef LQ_CONFIG_MEMCAP 5 #define LQ_CONFIG_MEMCAP 65536 6 #endif 7 8 #ifndef LQ_CONFIG_MAX 9 #define LQ_CONFIG_MAX 128 10 #endif 11 12 #include "lq/mem.h" 13 14 /** 15 * Core configuration keys. 16 */ 17 enum lq_config_core_e { 18 LQ_CFG_DIR_BASE, ///< Base working directory. 19 LQ_CFG_DIR_CONFIG, ///< Configurations directory. 20 LQ_CFG_DIR_DATA, ///< Data directory. 21 LQ_CFG_DIR_CACHE, ///< Cache directory. 22 LQ_CFG_LAST, ///< Start of subsystem defined configuration keys. 23 }; 24 25 26 /** 27 * \brief Initialize the instance-wide config singleton. 28 * 29 * @return ERR_OK on success. 30 */ 31 int lq_config_init(); 32 33 /** 34 * \brief Register a configuration key/value pair. 35 * 36 * \param[in] Type of value to be stored under key. 37 * \param[in] Configuration key. 38 * \return ERR_OK on success. 39 */ 40 int lq_config_register(enum lq_typ_e typ, const char *name); 41 42 /** 43 * \brief Set value for a configuration key. 44 * 45 * \param[in] Configuration key. 46 * \param[in] Value to set. Must correspond to the previously registered value type. 47 * \return ERR_OK on success. 48 * 49 * \see lq_config_register 50 */ 51 int lq_config_set(int k, void *v); 52 53 /** 54 * \brief Retrieve a value stored under a configuration key. 55 * 56 * \param[in] Configuration key. 57 * \param[out] Pointer to value write location. Must be sufficient to hold the registered value type. 58 * \return ERR_OK on success. 59 * 60 * \see lq_config_register 61 */ 62 int lq_config_get(int k, void **r); 63 64 /** 65 * \brief Release configuration resources. 66 */ 67 void lq_config_free(); 68 69 #endif