environment.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "store_mdb.h"
  8. /*
  9. * Data types.
  10. */
  11. /** @brief Environment structure containing "global" LSUP variables.
  12. *
  13. * Multiple environments may be opened within one program. One environment,
  14. * the default one, must always be opened before performing any operation with
  15. * the library.
  16. */
  17. typedef struct env_t {
  18. LSUP_Buffer * default_ctx; // Default context URI.
  19. LSUP_MDBStore * mdb_store; // MDB permanent store handle.
  20. LSUP_MDBStore * mdb_store_ramdisk; // MDB RAM disk store handle.
  21. LSUP_NSMap * nsm; // Namespace prefix map.
  22. } LSUP_Env;
  23. /** @brief Environment variable that gets passed around.
  24. */
  25. extern LSUP_Env *LSUP_default_env;
  26. /** @brief Initialize default context and MDB environments.
  27. *
  28. * The ramdisk data will persist after the application is shut down, but they
  29. * will be wiped clean the next time this function is called.
  30. */
  31. LSUP_Env *
  32. LSUP_env_new (
  33. const char *default_ctx, const char *mdb_path,
  34. const LSUP_NSMap *nsmap);
  35. /** @brief Initialize the default environment.
  36. *
  37. * This must be called before using the library.
  38. *
  39. * The default environment is cleaned up automatically on exit.
  40. *
  41. * This environment should suit most cases, unless an application needs to use
  42. * multiple environments and call #LSUP_env_init with specific handles. Such
  43. * other environment(s) must be freed up manually with #LSUP_env_done().
  44. */
  45. LSUP_rc
  46. LSUP_init (void);
  47. /** @brief Close an environment.
  48. *
  49. * This only needs to be done for non-default environments. The environment
  50. * handle is not freed.
  51. */
  52. void
  53. LSUP_env_free (LSUP_Env *env);
  54. /** @brief Close the defailt environment.
  55. *
  56. * This is called by atexit(). If called before then, subsequent calls have
  57. * no effect.
  58. */
  59. void LSUP_done (void);
  60. LSUP_rc
  61. LSUP_env_push_id (LSUP_Env *env, const uint32_t key, const char *data);
  62. const char *
  63. LSUP_env_get_id (LSUP_Env *env, const uint32_t key);
  64. #endif /* _LSUP_ENVIRONMENT_H */