environment.h 2.2 KB

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