Make in-memory pool thread-safe.
[strongswan.git] / src / libhydra / attributes / mem_pool.h
1 /*
2 * Copyright (C) 2010 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup mem_pool mem_pool
18 * @{ @ingroup attributes
19 */
20
21 #ifndef MEM_POOL_H
22 #define MEM_POOL_H
23
24 typedef struct mem_pool_t mem_pool_t;
25
26 #include <utils/host.h>
27 #include <utils/identification.h>
28
29 /**
30 * An in-memory IP address pool.
31 */
32 struct mem_pool_t {
33
34 /**
35 * Get the name of this pool.
36 *
37 * @return the name of this pool
38 */
39 const char* (*get_name)(mem_pool_t *this);
40
41 /**
42 * Get the size (i.e. number of addresses) of this pool.
43 *
44 * @return the size of this pool
45 */
46 u_int (*get_size)(mem_pool_t *this);
47
48 /**
49 * Get the number of online leases.
50 *
51 * @return the number of offline leases
52 */
53 u_int (*get_online)(mem_pool_t *this);
54
55 /**
56 * Get the number of offline leases.
57 *
58 * @return the number of online leases
59 */
60 u_int (*get_offline)(mem_pool_t *this);
61
62 /**
63 * Acquire an address for the given id from this pool.
64 *
65 * @param id the id to acquire an address for
66 * @param requested acquire this address, if possible
67 * @return the acquired address
68 */
69 host_t* (*acquire_address)(mem_pool_t *this, identification_t *id,
70 host_t *requested);
71
72 /**
73 * Release a previously acquired address.
74 *
75 * @param address the address to release
76 * @param id the id the address was assigned to
77 * @return TRUE, if the lease was found
78 */
79 bool (*release_address)(mem_pool_t *this, host_t *address,
80 identification_t *id);
81
82 /**
83 * Create an enumerator over the leases of this pool.
84 *
85 * Enumerator enumerates over
86 * identification_t *id, host_t *address, bool online
87 *
88 * @return enumerator
89 */
90 enumerator_t* (*create_lease_enumerator)(mem_pool_t *this);
91
92 /**
93 * Destroy a mem_pool_t instance.
94 */
95 void (*destroy)(mem_pool_t *this);
96 };
97
98 /**
99 * Create an in-memory IP address pool.
100 *
101 * An empty pool just returns the requested address.
102 *
103 * @param name name of this pool
104 * @param base base address of this pool, NULL to create an empty pool
105 * @param bits net mask
106 */
107 mem_pool_t *mem_pool_create(char *name, host_t *base, int bits);
108
109 #endif /** MEM_POOL_H_ @} */
110