src/lib/srdb2/db_pool.h
18c6ca66
 /* 
  * Copyright (C) 2001-2005 iptel.org
c949f162
  * Copyright (C) 2006-2007 iptelorg GmbH
18c6ca66
  *
8d8cea81
  * This file is part of Kamailio, a free SIP server.
18c6ca66
  *
8d8cea81
  * Kamailio is free software; you can redistribute it and/or modify
18c6ca66
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
8d8cea81
  * Kamailio is distributed in the hope that it will be useful,
18c6ca66
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18c6ca66
  */
 
 #ifndef _DB_POOL_H
c949f162
 #define _DB_POOL_H  1
18c6ca66
 
0f7f49b2
 /** \ingroup DB_API 
  * @{ 
  */
 
c949f162
 #include "db_drv.h"
 #include "db_uri.h"
cf83221d
 #include "../../core/list.h"
b4f5cb26
 #include <sys/types.h>
 
c949f162
 
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
18c6ca66
 
 
 /*
  * This is a stub that contains all attributes
  * that pool members must have, it is not really
  * used, real connection structures are created
  * by database backends. All such structures (
  * created by the backends) must have these
  * attributes.
  */
c949f162
 typedef struct db_pool_entry {
 	db_drv_t drv_gen;  /* Generic part of the driver specific data */
 	SLIST_ENTRY(db_pool_entry) next;
 	db_uri_t* uri;     /* Pointer to the URI representing the connection */
 	unsigned int ref;  /* Reference count */
 } db_pool_entry_t;
 
 
 int db_pool_entry_init(struct db_pool_entry *entry, void* free_func, db_uri_t* uri);
 void db_pool_entry_free(struct db_pool_entry* entry);	
18c6ca66
 
 
 /*
  * Search the pool for a connection with
  * the identifier equal to id, NULL is returned
  * when no connection is found
  */
c949f162
 struct db_pool_entry* db_pool_get(db_uri_t* uri);
18c6ca66
 
 
 /*
  * Insert a new connection into the pool
  */
c949f162
 void db_pool_put(struct db_pool_entry* entry);
18c6ca66
 
 
 /*
  * Release connection from the pool, the function
  * would return 1 when if the connection is not
  * referenced anymore and thus can be closed and
  * deleted by the backend. The function returns
  * 0 if the connection should still be kept open
  * because some other module is still using it.
  * The function returns -1 if the connection is
  * not in the pool.
  */
c949f162
 int db_pool_remove(struct db_pool_entry* entry);
18c6ca66
 
c949f162
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
18c6ca66
 
0f7f49b2
 /** @} */
 
c949f162
 #endif /* _DB_POOL_H */