device: renew dhcp leases on awake for software devices
[NetworkManager.git] / src / nm-multi-index.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* NetworkManager -- Network link manager
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Copyright (C) 2015 Red Hat, Inc.
19  */
20
21 #ifndef __NM_MULTI_INDEX__
22 #define __NM_MULTI_INDEX__
23
24 #include "nm-default.h"
25
26 G_BEGIN_DECLS
27
28
29 typedef struct {
30         char _dummy;
31 } NMMultiIndexId;
32
33 typedef struct NMMultiIndex NMMultiIndex;
34
35 typedef struct {
36         GHashTableIter _iter;
37         const NMMultiIndex *_index;
38         gconstpointer _value;
39 } NMMultiIndexIter;
40
41 typedef struct {
42         union {
43                 GHashTableIter _iter;
44                 gpointer _value;
45         };
46         guint _state;
47 } NMMultiIndexIdIter;
48
49 typedef gboolean (*NMMultiIndexFuncEqual) (const NMMultiIndexId *id_a, const NMMultiIndexId *id_b);
50 typedef guint (*NMMultiIndexFuncHash) (const NMMultiIndexId *id);
51 typedef NMMultiIndexId *(*NMMultiIndexFuncClone) (const NMMultiIndexId *id);
52 typedef void (*NMMultiIndexFuncDestroy) (NMMultiIndexId *id);
53
54 typedef gboolean (*NMMultiIndexFuncForeach) (const NMMultiIndexId *id, void *const* values, guint len, gpointer user_data);
55
56
57 NMMultiIndex *nm_multi_index_new (NMMultiIndexFuncHash hash_fcn,
58                                   NMMultiIndexFuncEqual equal_fcn,
59                                   NMMultiIndexFuncClone clone_fcn,
60                                   NMMultiIndexFuncDestroy destroy_fcn);
61
62 void nm_multi_index_free (NMMultiIndex *index);
63
64 gboolean nm_multi_index_add (NMMultiIndex *index,
65                              const NMMultiIndexId *id,
66                              gconstpointer value);
67
68 gboolean nm_multi_index_remove (NMMultiIndex *index,
69                                 const NMMultiIndexId *id,
70                                 gconstpointer value);
71
72 gboolean nm_multi_index_move (NMMultiIndex *index,
73                               const NMMultiIndexId *id_old,
74                               const NMMultiIndexId *id_new,
75                               gconstpointer value);
76
77 guint nm_multi_index_get_num_groups (const NMMultiIndex *index);
78
79 void *const*nm_multi_index_lookup (const NMMultiIndex *index,
80                                    const NMMultiIndexId *id,
81                                    guint *out_len);
82
83 gboolean nm_multi_index_contains (const NMMultiIndex *index,
84                                   const NMMultiIndexId *id,
85                                   gconstpointer value);
86
87 const NMMultiIndexId *nm_multi_index_lookup_first_by_value (const NMMultiIndex *index,
88                                                              gconstpointer value);
89
90 void nm_multi_index_foreach (const NMMultiIndex *index,
91                              gconstpointer value,
92                              NMMultiIndexFuncForeach foreach_func,
93                              gpointer user_data);
94
95 void nm_multi_index_iter_init (NMMultiIndexIter *iter,
96                                const NMMultiIndex *index,
97                                gconstpointer value);
98 gboolean nm_multi_index_iter_next (NMMultiIndexIter *iter,
99                                    const NMMultiIndexId **out_id,
100                                    void *const**out_values,
101                                    guint *out_len);
102
103 void nm_multi_index_id_iter_init (NMMultiIndexIdIter *iter,
104                                   const NMMultiIndex *index,
105                                   const NMMultiIndexId *id);
106 gboolean nm_multi_index_id_iter_next (NMMultiIndexIdIter *iter,
107                                       void **out_value);
108
109 G_END_DECLS
110
111 #endif /* __NM_MULTI_INDEX__ */
112