km_my_con.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. * Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /*! \file
  24. * \brief DB_MYSQL :: Core
  25. * \ref my_con.c
  26. * \ingroup db_mysql
  27. * Module: \ref db_mysql
  28. */
  29. #ifndef KM_MY_CON_H
  30. #define KM_MY_CON_H
  31. #include "../../lib/srdb1/db_pool.h"
  32. #include "../../lib/srdb1/db_id.h"
  33. #include <time.h>
  34. #include <mysql/mysql.h>
  35. struct my_con {
  36. struct db_id* id; /*!< Connection identifier */
  37. unsigned int ref; /*!< Reference count */
  38. struct pool_con* next; /*!< Next connection in the pool */
  39. MYSQL* con; /*!< Connection representation */
  40. time_t timestamp; /*!< Timestamp of last query */
  41. };
  42. /*
  43. * Some convenience wrappers
  44. */
  45. #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->con)
  46. #define CON_TIMESTAMP(db_con) (((struct my_con*)((db_con)->tail))->timestamp)
  47. /*! \brief
  48. * Create a new connection structure,
  49. * open the MySQL connection and set reference count to 1
  50. */
  51. struct my_con* db_mysql_new_connection(const struct db_id* id);
  52. /*! \brief
  53. * Close the connection and release memory
  54. */
  55. void db_mysql_free_connection(struct pool_con* con);
  56. #endif /* KM_MY_CON_H */