environment.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /*
  20. * External variables.
  21. */
  22. extern LSUP_NSMap *LSUP_default_nsm; /// Default namespace prefix map.
  23. extern LSUP_Term *LSUP_default_ctx; /// Default context.
  24. extern LSUP_Buffer *LSUP_default_ctx_buf; /// Serialized default context.
  25. /** @brief Initialize the default environment.
  26. *
  27. * This must be called before using the library.
  28. *
  29. * The default environment is cleaned up automatically on exit.
  30. *
  31. * This environment should suit most cases, unless an application needs to use
  32. * multiple environments and call #LSUP_env_init with specific handles. Such
  33. * other environment(s) must be freed up manually with #LSUP_env_done().
  34. */
  35. LSUP_rc
  36. LSUP_init (void);
  37. /** @brief Close the default environment.
  38. *
  39. * This is called by atexit(). If called before then, subsequent calls have
  40. * no effect.
  41. */
  42. void
  43. LSUP_done (void);
  44. /** TODO
  45. */
  46. LSUP_rc
  47. LSUP_env_put_id (const uint32_t key, const char *data);
  48. /** TODO
  49. */
  50. const char *
  51. LSUP_env_get_id (const uint32_t key);
  52. #endif /* _LSUP_ENVIRONMENT_H */