device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-util / nm-setting-team-port.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library 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 GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the
15  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301 USA.
17  *
18  * Copyright 2013 Jiri Pirko <jiri@resnulli.us>
19  */
20
21 #include "nm-default.h"
22
23 #include <string.h>
24 #include <ctype.h>
25 #include <stdlib.h>
26 #include <dbus/dbus-glib.h>
27
28 #include "nm-setting-team-port.h"
29 #include "nm-utils.h"
30 #include "nm-utils-private.h"
31 #include "nm-setting-private.h"
32
33 /**
34  * SECTION:nm-setting-team-port
35  * @short_description: Describes connection properties for team ports
36  * @include: nm-setting-team-port.h
37  *
38  * The #NMSettingTeamPort object is a #NMSetting subclass that describes
39  * optional properties that apply to team ports.
40  *
41  * Since: 0.9.10
42  **/
43
44 /**
45  * nm_setting_team_port_error_quark:
46  *
47  * Registers an error quark for #NMSettingTeamPort if necessary.
48  *
49  * Returns: the error quark used for #NMSettingTeamPort errors.
50  *
51  * Since: 0.9.10
52  **/
53 GQuark
54 nm_setting_team_port_error_quark (void)
55 {
56         static GQuark quark;
57
58         if (G_UNLIKELY (!quark))
59                 quark = g_quark_from_static_string ("nm-setting-team-port-error-quark");
60         return quark;
61 }
62
63 G_DEFINE_TYPE_WITH_CODE (NMSettingTeamPort, nm_setting_team_port, NM_TYPE_SETTING,
64                          _nm_register_setting (NM_SETTING_TEAM_PORT_SETTING_NAME,
65                                                g_define_type_id,
66                                                3,
67                                                NM_SETTING_TEAM_PORT_ERROR))
68 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM_PORT)
69
70 #define NM_SETTING_TEAM_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortPrivate))
71
72 typedef struct {
73         char *config;
74 } NMSettingTeamPortPrivate;
75
76 enum {
77         PROP_0,
78         PROP_CONFIG,
79         LAST_PROP
80 };
81
82 /**
83  * nm_setting_team_port_new:
84  *
85  * Creates a new #NMSettingTeamPort object with default values.
86  *
87  * Returns: (transfer full): the new empty #NMSettingTeamPort object
88  *
89  * Since: 0.9.10
90  **/
91 NMSetting *
92 nm_setting_team_port_new (void)
93 {
94         return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM_PORT, NULL);
95 }
96
97 /**
98  * nm_setting_team_port_get_config:
99  * @setting: the #NMSettingTeamPort
100  *
101  * Returns: the #NMSettingTeamPort:config property of the setting
102  *
103  * Since: 0.9.10
104  **/
105 const char *
106 nm_setting_team_port_get_config (NMSettingTeamPort *setting)
107 {
108         g_return_val_if_fail (NM_IS_SETTING_TEAM_PORT (setting), NULL);
109
110         return NM_SETTING_TEAM_PORT_GET_PRIVATE (setting)->config;
111 }
112
113 static gboolean
114 verify (NMSetting *setting, GSList *all_settings, GError **error)
115 {
116         return TRUE;
117 }
118
119 static void
120 nm_setting_team_port_init (NMSettingTeamPort *setting)
121 {
122 }
123
124 static void
125 set_property (GObject *object, guint prop_id,
126               const GValue *value, GParamSpec *pspec)
127 {
128         NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
129
130         switch (prop_id) {
131         case PROP_CONFIG:
132                 g_free (priv->config);
133                 priv->config = g_value_dup_string (value);
134                 break;
135         default:
136                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137                 break;
138         }
139 }
140
141 static void
142 get_property (GObject *object, guint prop_id,
143               GValue *value, GParamSpec *pspec)
144 {
145         NMSettingTeamPort *setting = NM_SETTING_TEAM_PORT (object);
146
147         switch (prop_id) {
148         case PROP_CONFIG:
149                 g_value_set_string (value, nm_setting_team_port_get_config (setting));
150                 break;
151         default:
152                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
153                 break;
154         }
155 }
156
157 static void
158 finalize (GObject *object)
159 {
160         NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
161
162         g_free (priv->config);
163
164         G_OBJECT_CLASS (nm_setting_team_port_parent_class)->finalize (object);
165 }
166
167 static void
168 nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
169 {
170         GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
171         NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
172
173         g_type_class_add_private (setting_class, sizeof (NMSettingTeamPortPrivate));
174
175         /* virtual methods */
176         object_class->set_property = set_property;
177         object_class->get_property = get_property;
178         object_class->finalize = finalize;
179         parent_class->verify       = verify;
180
181         /* Properties */
182         /**
183          * NMSettingTeamPort:config:
184          *
185          * The JSON configuration for the team port. The property should contain raw
186          * JSON configuration data suitable for teamd, because the value is passed
187          * directly to teamd. If not specified, the default configuration is
188          * used. See man teamd.conf for the format details.
189          **/
190         g_object_class_install_property
191                 (object_class, PROP_CONFIG,
192                  g_param_spec_string (NM_SETTING_TEAM_PORT_CONFIG, "", "",
193                                       NULL,
194                                       G_PARAM_READWRITE |
195                                       NM_SETTING_PARAM_INFERRABLE |
196                                       G_PARAM_STATIC_STRINGS));
197 }