environment.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /** @file environment.h
  2. *
  3. * @brief Handle LSUP environment initialization and teardown.
  4. *
  5. * #LSUP_init() should be called before performing any other interaction with
  6. * this library.
  7. *
  8. * #LSUP_done() is called automatically on program exit (`atexit`).
  9. */
  10. #ifndef _LSUP_ENVIRONMENT_H
  11. #define _LSUP_ENVIRONMENT_H
  12. #include "term.h"
  13. #if 0
  14. /*
  15. * TODO Deprecating all non-default environments. All is needed is a NSMap
  16. * which can be created separately for in-memory graphs.
  17. */
  18. #include "store_mdb.h"
  19. /*
  20. * Data types.
  21. */
  22. /** @brief Environment structure containing global LSUP variables.
  23. *
  24. * Multiple environments may be opened within one program. One environment,
  25. * the default one, is always opened when calling #LSUP_init(), before
  26. * performing any operation with the library.
  27. *
  28. * The namespace map is used by all volatile (not LSUP_STORE_PERM) stores
  29. * associated with the environment.
  30. */
  31. typedef struct env_t {
  32. LSUP_Buffer * default_ctx; ///> Default context URI.
  33. LSUP_NSMap * nsm; ///> Namespace prefix map.
  34. } LSUP_Env;
  35. /** @brief Default environment that gets created with #LSUP_init().
  36. */
  37. extern LSUP_Env *LSUP_default_env;
  38. /** @brief Initialize default context and MDB environments.
  39. *
  40. * The ramdisk data will persist after the application is shut down, but they
  41. * will be wiped clean the next time this function is called.
  42. */
  43. LSUP_Env *
  44. LSUP_env_new (const char *default_ctx, const LSUP_NSMap *nsmap);
  45. #endif
  46. extern LSUP_NSMap *LSUP_default_nsm; /// Default namespace prefix map.
  47. extern LSUP_Term *LSUP_default_ctx; /// Default context.
  48. extern LSUP_Buffer *LSUP_default_ctx_buf; /// Serialized default context.
  49. /** @brief Initialize the default environment.
  50. *
  51. * This must be called before using the library.
  52. *
  53. * The default environment is cleaned up automatically on exit.
  54. *
  55. * This environment should suit most cases, unless an application needs to use
  56. * multiple environments and call #LSUP_env_init with specific handles. Such
  57. * other environment(s) must be freed up manually with #LSUP_env_done().
  58. */
  59. LSUP_rc
  60. LSUP_init (void);
  61. /** @brief Whether the environment is already initialized.
  62. *
  63. * @TODO Check if the default NS was inserted; this would be slower but more
  64. * accurate.
  65. */
  66. inline bool
  67. LSUP_is_init (void)
  68. { return LSUP_term_cache != NULL; }
  69. #if 0
  70. /** @brief Close an environment.
  71. *
  72. * This only needs to be done for non-default environments. The environment
  73. * handle is not freed.
  74. */
  75. void
  76. LSUP_env_free (LSUP_Env *env);
  77. #endif
  78. /** @brief Close the default environment.
  79. *
  80. * This is called by atexit(). If called before then, subsequent calls have
  81. * no effect.
  82. */
  83. void
  84. LSUP_done (void);
  85. /** TODO
  86. */
  87. LSUP_rc
  88. LSUP_env_put_id (const uint32_t key, const char *data);
  89. /** TODO
  90. */
  91. const char *
  92. LSUP_env_get_id (const uint32_t key);
  93. #endif /* _LSUP_ENVIRONMENT_H */