db_pool.h

Go to the documentation of this file.
00001 /* 
00002  * $Id: db_pool.h 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Copyright (C) 2001-2005 iptel.org
00005  * Copyright (C) 2007-2008 1&1 Internet AG
00006  *
00007  * This file is part of Kamailio, a free SIP server.
00008  *
00009  * Kamailio is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * Kamailio is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License 
00020  * along with this program; if not, write to the Free Software 
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00024 /**
00025  * \file db/db_pool.h
00026  * \brief Functions for managing a pool of database connections.
00027  * \ingroup db
00028  */
00029 
00030 #ifndef _DB_POOL_H
00031 #define _DB_POOL_H
00032 
00033 #include "db_id.h"
00034 #include "db_con.h"
00035 
00036 
00037 /**
00038  * This is a stub that contains all attributes
00039  * that pool members must have, it is not really
00040  * used, real connection structures are created
00041  * by database backends. All such structures (
00042  * created by the backends) must have these
00043  * attributes.
00044  */
00045 struct pool_con {
00046    struct db_id* id;        /**< Connection identifier */
00047    unsigned int ref;        /**< Reference count */
00048    struct pool_con* next;   /**< Next element in the pool */
00049 };
00050 
00051 
00052 /**
00053  * Search the pool for a connection with the identifier equal to
00054  * the id.
00055  * \param id searched id
00056  * \return the connection if it could be found, NULL otherwise
00057  */
00058 struct pool_con* pool_get(const struct db_id* id);
00059 
00060 
00061 /**
00062  * Insert a new connection into the pool.
00063  * \param con the inserted connection 
00064  */
00065 void pool_insert(struct pool_con* con);
00066 
00067 
00068 /**
00069  * Release a connection from the pool, the function
00070  * would return 1 when if the connection is not
00071  * referenced anymore and thus can be closed and
00072  * deleted by the backend. The function returns
00073  * 0 if the connection should still be kept open
00074  * because some other module is still using it.
00075  * The function returns -1 if the connection is
00076  * not in the pool.
00077  * \param con connection that should be removed
00078  * \return 1 if the connection can be freed, 0 if it can't be freed, -1 if not found
00079  */
00080 int pool_remove(struct pool_con* con);
00081 
00082 
00083 #endif /* _POOL_H */

Generated on Tue May 22 14:00:25 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6