db_pool.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2005 iptel.org
  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_POOL_H
  29. #define _DB_POOL_H 1
  30. /** \ingroup DB_API
  31. * @{
  32. */
  33. #include "db_drv.h"
  34. #include "db_uri.h"
  35. #include "../../list.h"
  36. #include <sys/types.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif /* __cplusplus */
  40. /*
  41. * This is a stub that contains all attributes
  42. * that pool members must have, it is not really
  43. * used, real connection structures are created
  44. * by database backends. All such structures (
  45. * created by the backends) must have these
  46. * attributes.
  47. */
  48. typedef struct db_pool_entry {
  49. db_drv_t drv_gen; /* Generic part of the driver specific data */
  50. SLIST_ENTRY(db_pool_entry) next;
  51. db_uri_t* uri; /* Pointer to the URI representing the connection */
  52. unsigned int ref; /* Reference count */
  53. } db_pool_entry_t;
  54. int db_pool_entry_init(struct db_pool_entry *entry, void* free_func, db_uri_t* uri);
  55. void db_pool_entry_free(struct db_pool_entry* entry);
  56. /*
  57. * Search the pool for a connection with
  58. * the identifier equal to id, NULL is returned
  59. * when no connection is found
  60. */
  61. struct db_pool_entry* db_pool_get(db_uri_t* uri);
  62. /*
  63. * Insert a new connection into the pool
  64. */
  65. void db_pool_put(struct db_pool_entry* entry);
  66. /*
  67. * Release connection from the pool, the function
  68. * would return 1 when if the connection is not
  69. * referenced anymore and thus can be closed and
  70. * deleted by the backend. The function returns
  71. * 0 if the connection should still be kept open
  72. * because some other module is still using it.
  73. * The function returns -1 if the connection is
  74. * not in the pool.
  75. */
  76. int db_pool_remove(struct db_pool_entry* entry);
  77. #ifdef __cplusplus
  78. }
  79. #endif /* __cplusplus */
  80. /** @} */
  81. #endif /* _DB_POOL_H */