srdb2/db_pool.h

00001 /* 
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2005 iptel.org
00005  * Copyright (C) 2006-2007 iptelorg GmbH
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser 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  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028 
00029 #ifndef _DB_POOL_H
00030 #define _DB_POOL_H  1
00031 
00036 #include "db_drv.h"
00037 #include "db_uri.h"
00038 #include "../../list.h"
00039 #include <sys/types.h>
00040 
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif /* __cplusplus */
00045 
00046 
00047 /*
00048  * This is a stub that contains all attributes
00049  * that pool members must have, it is not really
00050  * used, real connection structures are created
00051  * by database backends. All such structures (
00052  * created by the backends) must have these
00053  * attributes.
00054  */
00055 typedef struct db_pool_entry {
00056         db_drv_t drv_gen;  /* Generic part of the driver specific data */
00057         SLIST_ENTRY(db_pool_entry) next;
00058         db_uri_t* uri;     /* Pointer to the URI representing the connection */
00059         unsigned int ref;  /* Reference count */
00060 } db_pool_entry_t;
00061 
00062 
00063 int db_pool_entry_init(struct db_pool_entry *entry, void* free_func, db_uri_t* uri);
00064 void db_pool_entry_free(struct db_pool_entry* entry);   
00065 
00066 
00067 /*
00068  * Search the pool for a connection with
00069  * the identifier equal to id, NULL is returned
00070  * when no connection is found
00071  */
00072 struct db_pool_entry* db_pool_get(db_uri_t* uri);
00073 
00074 
00075 /*
00076  * Insert a new connection into the pool
00077  */
00078 void db_pool_put(struct db_pool_entry* entry);
00079 
00080 
00081 /*
00082  * Release connection from the pool, the function
00083  * would return 1 when if the connection is not
00084  * referenced anymore and thus can be closed and
00085  * deleted by the backend. The function returns
00086  * 0 if the connection should still be kept open
00087  * because some other module is still using it.
00088  * The function returns -1 if the connection is
00089  * not in the pool.
00090  */
00091 int db_pool_remove(struct db_pool_entry* entry);
00092 
00093 #ifdef __cplusplus
00094 }
00095 #endif /* __cplusplus */
00096 
00099 #endif /* _DB_POOL_H */