device: renew dhcp leases on awake for software devices
[NetworkManager.git] / src / nm-connection-provider.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details:
12  *
13  * Copyright (C) 2012 Red Hat, Inc.
14  */
15
16 #ifndef __NETWORKMANAGER_CONNECTION_PROVIDER_H__
17 #define __NETWORKMANAGER_CONNECTION_PROVIDER_H__
18
19 #include <nm-connection.h>
20
21 #include "nm-default.h"
22
23 #define NM_TYPE_CONNECTION_PROVIDER               (nm_connection_provider_get_type ())
24 #define NM_CONNECTION_PROVIDER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_PROVIDER, NMConnectionProvider))
25 #define NM_IS_CONNECTION_PROVIDER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_PROVIDER))
26 #define NM_CONNECTION_PROVIDER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_CONNECTION_PROVIDER, NMConnectionProviderInterface))
27
28 #define NM_CP_SIGNAL_CONNECTION_ADDED        "cp-connection-added"
29 #define NM_CP_SIGNAL_CONNECTION_UPDATED      "cp-connection-updated"
30 #define NM_CP_SIGNAL_CONNECTION_REMOVED      "cp-connection-removed"
31
32
33 /**
34  * NMConnectionFilterFunc:
35  * @provider: The provider requesting the filtering
36  * @connection: the connection to be filtered
37  * @func_data: the caller-provided data pointer
38  *
39  * Returns: %TRUE to allow the connection, %FALSE to ignore it
40  */
41 typedef gboolean (*NMConnectionFilterFunc) (NMConnectionProvider *provider,
42                                             NMConnection *connection,
43                                             gpointer func_data);
44
45
46 typedef struct {
47         GTypeInterface g_iface;
48
49         /* Methods */
50         GSList * (*get_best_connections) (NMConnectionProvider *self,
51                                           guint max_requested,
52                                           const char *ctype1,
53                                           const char *ctype2,
54                                           NMConnectionFilterFunc func,
55                                           gpointer func_data);
56
57         const GSList * (*get_connections) (NMConnectionProvider *self);
58
59         NMConnection * (*add_connection) (NMConnectionProvider *self,
60                                           NMConnection *connection,
61                                           gboolean save_to_disk,
62                                           GError **error);
63
64         NMConnection * (*get_connection_by_uuid) (NMConnectionProvider *self,
65                                                   const char *uuid);
66
67         /* Signals */
68         void (*connection_added)   (NMConnectionProvider *self, NMConnection *connection);
69
70         void (*connection_updated) (NMConnectionProvider *self, NMConnection *connection);
71
72         void (*connection_removed) (NMConnectionProvider *self, NMConnection *connection);
73
74 } NMConnectionProviderInterface;
75
76 GType nm_connection_provider_get_type (void);
77
78 /**
79  * nm_connection_provider_get:
80  *
81  * Returns: the global #NMConnectionProvider
82  */
83 NMConnectionProvider *nm_connection_provider_get (void);
84
85 /**
86  * nm_connection_provider_get_best_connections:
87  * @self: the #NMConnectionProvider
88  * @max_requested: if non-zero, the maximum number of connections to return
89  * @ctype1: an #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) to
90  *   filter connections against
91  * @ctype2: a second #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME)
92  *   to filter connections against
93  * @func: caller-supplied function for filtering connections
94  * @func_data: caller-supplied data passed to @func
95  *
96  * Returns: a #GSList of #NMConnection objects in sorted order representing the
97  *   "best" or highest-priority connections filtered by @ctype1 and/or @ctype2,
98  *   and/or @func.  Caller is responsible for freeing the returned #GSList, but
99  *   the contained values do not need to be unreffed.
100  */
101 GSList *nm_connection_provider_get_best_connections (NMConnectionProvider *self,
102                                                      guint max_requested,
103                                                      const char *ctype1,
104                                                      const char *ctype2,
105                                                      NMConnectionFilterFunc func,
106                                                      gpointer func_data);
107
108 /**
109  * nm_connection_provider_get_connections:
110  * @self: the #NMConnectionProvider
111  *
112  * Returns: a #GSList of #NMConnection objects representing all known
113  *   connections.  Returned list is owned by the connection provider and must
114  *   not be freed.
115  */
116 const GSList *nm_connection_provider_get_connections (NMConnectionProvider *self);
117
118 /**
119  * nm_connection_provider_add_connection:
120  * @self: the #NMConnectionProvider
121  * @connection: the connection to be added
122  * @save_to_disk: whether to store the connection on disk
123  * @error: returns any error if adding fails
124  *
125  * returns: a newly added #NMConnection.
126  */
127 NMConnection *nm_connection_provider_add_connection (NMConnectionProvider *self,
128                                                      NMConnection *connection,
129                                                      gboolean save_to_disk,
130                                                      GError **error);
131
132 NMConnection *nm_connection_provider_get_connection_by_uuid (NMConnectionProvider *self,
133                                                              const char *uuid);
134
135 #endif /* __NETWORKMANAGER_CONNECTION_PROVIDER_H__ */