environment.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /** @brief Whether the environment is already initialized.
  14. *
  15. * @TODO Check if the default NS was inserted; this would be slower but more
  16. * accurate.
  17. */
  18. #define LSUP_IS_INIT (LSUP_term_cache != NULL)
  19. extern LSUP_NSMap *LSUP_default_nsm; /// Default namespace prefix map.
  20. extern LSUP_Term *LSUP_default_ctx; /// Default context.
  21. extern LSUP_Buffer *LSUP_default_ctx_buf; /// Serialized default context.
  22. /** @brief Initialize the default environment.
  23. *
  24. * This must be called before using the library.
  25. *
  26. * The default environment is cleaned up automatically on exit.
  27. *
  28. * This environment should suit most cases, unless an application needs to use
  29. * multiple environments and call #LSUP_env_init with specific handles. Such
  30. * other environment(s) must be freed up manually with #LSUP_env_done().
  31. */
  32. LSUP_rc
  33. LSUP_init (void);
  34. /** @brief Close the default environment.
  35. *
  36. * This is called by atexit(). If called before then, subsequent calls have
  37. * no effect.
  38. */
  39. void
  40. LSUP_done (void);
  41. /** TODO
  42. */
  43. LSUP_rc
  44. LSUP_env_put_id (const uint32_t key, const char *data);
  45. /** TODO
  46. */
  47. const char *
  48. LSUP_env_get_id (const uint32_t key);
  49. #endif /* _LSUP_ENVIRONMENT_H */