db_pool.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2005 iptel.org
  5. * Copyright (C) 2007-2008 1&1 Internet AG
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Kamailio 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. * Kamailio is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /**
  24. * \file lib/srdb1/db_pool.h
  25. * \brief Functions for managing a pool of database connections.
  26. * \ingroup db1
  27. */
  28. #ifndef _DB1_POOL_H
  29. #define _DB1_POOL_H
  30. #include "db_id.h"
  31. #include "db_con.h"
  32. /**
  33. * This is a stub that contains all attributes
  34. * that pool members must have, it is not really
  35. * used, real connection structures are created
  36. * by database backends. All such structures (
  37. * created by the backends) must have these
  38. * attributes.
  39. */
  40. struct pool_con {
  41. struct db_id* id; /**< Connection identifier */
  42. unsigned int ref; /**< Reference count */
  43. struct pool_con* next; /**< Next element in the pool */
  44. };
  45. /**
  46. * Search the pool for a connection with the identifier equal to
  47. * the id.
  48. * \param id searched id
  49. * \return the connection if it could be found, NULL otherwise
  50. */
  51. struct pool_con* pool_get(const struct db_id* id);
  52. /**
  53. * Insert a new connection into the pool.
  54. * \param con the inserted connection
  55. */
  56. void pool_insert(struct pool_con* con);
  57. /**
  58. * Release a connection from the pool, the function
  59. * would return 1 when if the connection is not
  60. * referenced anymore and thus can be closed and
  61. * deleted by the backend. The function returns
  62. * 0 if the connection should still be kept open
  63. * because some other module is still using it.
  64. * The function returns -1 if the connection is
  65. * not in the pool.
  66. * \param con connection that should be removed
  67. * \return 1 if the connection can be freed, 0 if it can't be freed, -1 if not found
  68. */
  69. int pool_remove(struct pool_con* con);
  70. #endif /* _DB1_POOL_H */