/** @file environment.h * * @brief Handle LSUP environment initialization and teardown. * * #LSUP_init() should be called before performing any other interaction with * this library. * * #LSUP_done() is called automatically on program exit (`atexit`). */ #ifndef _LSUP_ENVIRONMENT_H #define _LSUP_ENVIRONMENT_H #include "term.h" #if 0 /* * TODO Deprecating all non-default environments. All is needed is a NSMap * which can be created separately for in-memory graphs. */ #include "store_mdb.h" /* * Data types. */ /** @brief Environment structure containing global LSUP variables. * * Multiple environments may be opened within one program. One environment, * the default one, is always opened when calling #LSUP_init(), before * performing any operation with the library. * * The namespace map is used by all volatile (not LSUP_STORE_PERM) stores * associated with the environment. */ typedef struct env_t { LSUP_Buffer * default_ctx; ///> Default context URI. LSUP_NSMap * nsm; ///> Namespace prefix map. } LSUP_Env; /** @brief Default environment that gets created with #LSUP_init(). */ extern LSUP_Env *LSUP_default_env; /** @brief Initialize default context and MDB environments. * * The ramdisk data will persist after the application is shut down, but they * will be wiped clean the next time this function is called. */ LSUP_Env * LSUP_env_new (const char *default_ctx, const LSUP_NSMap *nsmap); #endif extern LSUP_NSMap *LSUP_default_nsm; /// Default namespace prefix map. extern LSUP_Term *LSUP_default_ctx; /// Default context. extern LSUP_Buffer *LSUP_default_ctx_buf; /// Serialized default context. /** @brief Initialize the default environment. * * This must be called before using the library. * * The default environment is cleaned up automatically on exit. * * This environment should suit most cases, unless an application needs to use * multiple environments and call #LSUP_env_init with specific handles. Such * other environment(s) must be freed up manually with #LSUP_env_done(). */ LSUP_rc LSUP_init (void); /** @brief Whether the environment is already initialized. * * @TODO Check if the default NS was inserted; this would be slower but more * accurate. */ inline bool LSUP_is_init (void) { return LSUP_term_cache != NULL; } #if 0 /** @brief Close an environment. * * This only needs to be done for non-default environments. The environment * handle is not freed. */ void LSUP_env_free (LSUP_Env *env); #endif /** @brief Close the default environment. * * This is called by atexit(). If called before then, subsequent calls have * no effect. */ void LSUP_done (void); /** TODO */ LSUP_rc LSUP_env_put_id (const uint32_t key, const char *data); /** TODO */ const char * LSUP_env_get_id (const uint32_t key); #endif /* _LSUP_ENVIRONMENT_H */