environment.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /** @file environment.h
  2. *
  3. * @brief Handle LSUP environment initialization and teardown.
  4. */
  5. #ifndef _LSUP_ENVIRONMENT_H
  6. #define _LSUP_ENVIRONMENT_H
  7. #include "term.h"
  8. #include "store_mdb.h"
  9. #include "namespace.h"
  10. typedef struct env_t {
  11. LSUP_Buffer * default_ctx; // Default context URI.
  12. LSUP_MDBStore * mdb_store; // MDB permanent store handle.
  13. LSUP_MDBStore * mdb_store_ramdisk; // MDB RAM disk store handle.
  14. LSUP_NSMap * nsm; // Namespace prefix map.
  15. } LSUP_Env;
  16. /** @brief Environment variable that gets passed around.
  17. */
  18. extern LSUP_Env *LSUP_default_env;
  19. /** @brief Initialize default context and MDB environments.
  20. *
  21. * The ramdisk data will persist after the application is shut down, but they
  22. * will be wiped clean the next time this function is called.
  23. */
  24. LSUP_Env *
  25. LSUP_env_new (
  26. const char *default_ctx, const char *mdb_path,
  27. const char *mdb_ramdisk_path, const LSUP_NSMap *nsmap);
  28. /** @brief Initialize the default environment.
  29. *
  30. * This must be called before using the library.
  31. *
  32. * The default environment is cleaned up automatically on exit.
  33. *
  34. * This environment should suit most cases, unless an application needs to use
  35. * multiple environments and call #LSUP_env_init with specific handles. Such
  36. * other environment(s) must be freed up manually with #LSUP_env_done().
  37. */
  38. LSUP_rc
  39. LSUP_init (void);
  40. /** @brief Close an environment.
  41. *
  42. * This only needs to be done for non-default environments. The environment
  43. * handle is not freed.
  44. */
  45. void
  46. LSUP_env_done (LSUP_Env *env);
  47. /** @brief Close the defailt environment.
  48. *
  49. * This is called by atexit(). If called before then, subsequent calls have
  50. * no effect.
  51. */
  52. void LSUP_done (void);
  53. #endif /* _LSUP_ENVIRONMENT_H */