kdb.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /** @file kdb.h
  2. *
  3. * @brief Klish db
  4. */
  5. #ifndef _klish_kdb_h
  6. #define _klish_kdb_h
  7. #include <stdint.h>
  8. #include <faux/ini.h>
  9. #include <faux/error.h>
  10. #include <klish/kscheme.h>
  11. // Current API version
  12. #define KDB_MAJOR 1
  13. #define KDB_MINOR 0
  14. // Shared object filename template. Insert db ID or db "name" field
  15. // instead "%s". Consider db ID as an "internal native name". The "name"
  16. // field can differ from ID and it's just used within scheme to refer db.
  17. // Consider it as alias of ID.
  18. #define KDB_SONAME_FMT "kdb_%s.so"
  19. // db's API version symbols
  20. // One byte (uint8_t) for major and one byte for minor numbers
  21. #define KDB_MAJOR_FMT "kdb_%s_major"
  22. #define KDB_MINOR_FMT "kdb_%s_minor"
  23. // db's init and fini functions
  24. // Init and fini functions can be not defined
  25. #define KDB_INIT_FMT "kdb_%s_init"
  26. #define KDB_FINI_FMT "kdb_%s_fini"
  27. // db's load and deploy functions
  28. // One of these function must be non-NULL else plugin has no usefull functions
  29. #define KDB_LOAD_FMT "kdb_%s_load_scheme"
  30. #define KDB_DEPLOY_FMT "kdb_%s_deploy_scheme"
  31. typedef struct kdb_s kdb_t;
  32. // DB plugin's entry points
  33. typedef bool_t (*kdb_init_fn)(kdb_t *db);
  34. typedef bool_t (*kdb_fini_fn)(kdb_t *db);
  35. typedef bool_t (*kdb_load_fn)(kdb_t *db, kscheme_t *scheme);
  36. typedef bool_t (*kdb_deploy_fn)(kdb_t *db, const kscheme_t *scheme);
  37. C_DECL_BEGIN
  38. kdb_t *kdb_new(const char *name, const char *file);
  39. void kdb_free(kdb_t *db);
  40. const char *kdb_name(const kdb_t *db);
  41. const char *kdb_file(const kdb_t *db);
  42. faux_ini_t *kdb_ini(const kdb_t *db);
  43. bool_t kdb_set_ini(kdb_t *db, faux_ini_t *ini);
  44. uint8_t kdb_major(const kdb_t *db);
  45. // static bool_t kdb_set_major(kdb_t *db, uint8_t major);
  46. uint8_t kdb_minor(const kdb_t *db);
  47. // static bool_t kdb_set_minor(kdb_t *db, uint8_t minor);
  48. void *kdb_udata(const kdb_t *db);
  49. bool_t kdb_set_udata(kdb_t *db, void *udata);
  50. faux_error_t *kdb_error(const kdb_t *db);
  51. bool_t kdb_load_plugin(kdb_t *db);
  52. bool_t kdb_init(kdb_t *db);
  53. bool_t kdb_fini(kdb_t *db);
  54. bool_t kdb_load_scheme(kdb_t *db, kscheme_t *scheme);
  55. bool_t kdb_deploy_scheme(kdb_t *db, const kscheme_t *scheme);
  56. bool_t kdb_has_init_fn(const kdb_t *db);
  57. bool_t kdb_has_fini_fn(const kdb_t *db);
  58. bool_t kdb_has_load_fn(const kdb_t *db);
  59. bool_t kdb_has_deploy_fn(const kdb_t *db);
  60. C_DECL_END
  61. #endif // _klish_kdb_h