db_ctx.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG FOKUS
  5. * Copyright (C) 2006-2007 iptelorg GmbH
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #ifndef _DB_CTX_H
  29. #define _DB_CTX_H 1
  30. /** \ingroup DB_API
  31. * @{
  32. */
  33. #include "db_drv.h"
  34. #include "db_gen.h"
  35. #include "db_con.h"
  36. #include "../../str.h"
  37. #include "../../list.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif /* __cplusplus */
  41. struct db_ctx;
  42. /* This structure is stored in a linked list inside db_ctx
  43. * and is used to lookup driver-specific data based on module
  44. * name. A driver can have multiple connections in a context but
  45. * it should have only one structure attached to db_ctx structure
  46. * (which will be shared by all the connections of that driver in
  47. * db_ctx.
  48. */
  49. struct db_ctx_data {
  50. str module;
  51. db_drv_t* data;
  52. SLIST_ENTRY(db_ctx_data) next;
  53. };
  54. typedef struct db_ctx {
  55. db_gen_t gen; /* Generic data common for all DB API structures */
  56. str id; /* Text id of the context */
  57. int con_n; /* Number of connections in the context */
  58. SLIST_HEAD(, db_ctx_data) data;
  59. struct db_con* con[DB_PAYLOAD_MAX];
  60. } db_ctx_t;
  61. /*
  62. * Create a new database context
  63. */
  64. struct db_ctx* db_ctx(const char* id);
  65. /* Remove the database context structure
  66. * from the linked list and free all memory
  67. * used by the structure
  68. */
  69. void db_ctx_free(struct db_ctx* ctx);
  70. /*
  71. * Add a new database to database context
  72. */
  73. int db_add_db(struct db_ctx* ctx, const char* uri);
  74. /*
  75. * Attempt to connect all connections in the
  76. * context
  77. */
  78. int db_connect(struct db_ctx* ctx);
  79. /*
  80. * Disconnect all database connections in the
  81. * context
  82. */
  83. void db_disconnect(struct db_ctx* ctx);
  84. #ifdef __cplusplus
  85. }
  86. #endif /* __cplusplus */
  87. /** @} */
  88. #endif /* _DB_CTX_H */