summaryrefslogtreecommitdiff
path: root/src/libstrongswan/database/database_factory.h
blob: 8875adad78206b22c1b1196100ff385f8694c252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (C) 2008 Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, 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.
 */

/**
 * @defgroup database_factory database_factory
 * @{ @ingroup database
 */

#ifndef DATABASE_FACTORY_H_
#define DATABASE_FACTORY_H_

typedef struct database_factory_t database_factory_t;

#include <database/database.h>

/**
 * Generic database construction function.
 *
 * @param uri			implementation specific connection URI
 */
typedef database_t*(*database_constructor_t)(char *uri);

/**
 * Create instances of database connections using registered constructors.
 */
struct database_factory_t {

	/**
	 * Create a database connection instance.
	 *
	 * @param uri		implementation specific connection URI
	 * @return			database_t instance, NULL if not supported/failed
	 */
	database_t* (*create)(database_factory_t *this, char *uri);
	
	/**
	 * Register a database constructor.
	 *
	 * @param create	database constructor to register
	 */
	void (*add_database)(database_factory_t *this, database_constructor_t create);
	
	/**
	 * Unregister a previously registered database constructor.
	 *
	 * @param create	database constructor to unregister
	 */
	void (*remove_database)(database_factory_t *this, database_constructor_t create);
	
	/**
     * Destroy a database_factory instance.
     */
    void (*destroy)(database_factory_t *this);
};

/**
 * Create a database_factory instance.
 */
database_factory_t *database_factory_create();

#endif /** DATABASE_FACTORY_H_ @}*/