nm-setting-team-port.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #include "nm-default.h"
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include <stdlib.h>
  24. #include <dbus/dbus-glib.h>
  25. #include "nm-setting-team-port.h"
  26. #include "nm-utils.h"
  27. #include "nm-utils-private.h"
  28. #include "nm-setting-private.h"
  29. /**
  30. * SECTION:nm-setting-team-port
  31. * @short_description: Describes connection properties for team ports
  32. * @include: nm-setting-team-port.h
  33. *
  34. * The #NMSettingTeamPort object is a #NMSetting subclass that describes
  35. * optional properties that apply to team ports.
  36. *
  37. * Since: 0.9.10
  38. **/
  39. /**
  40. * nm_setting_team_port_error_quark:
  41. *
  42. * Registers an error quark for #NMSettingTeamPort if necessary.
  43. *
  44. * Returns: the error quark used for #NMSettingTeamPort errors.
  45. *
  46. * Since: 0.9.10
  47. **/
  48. GQuark
  49. nm_setting_team_port_error_quark (void)
  50. {
  51. static GQuark quark;
  52. if (G_UNLIKELY (!quark))
  53. quark = g_quark_from_static_string ("nm-setting-team-port-error-quark");
  54. return quark;
  55. }
  56. G_DEFINE_TYPE_WITH_CODE (NMSettingTeamPort, nm_setting_team_port, NM_TYPE_SETTING,
  57. _nm_register_setting (NM_SETTING_TEAM_PORT_SETTING_NAME,
  58. g_define_type_id,
  59. 3,
  60. NM_SETTING_TEAM_PORT_ERROR))
  61. NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM_PORT)
  62. #define NM_SETTING_TEAM_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortPrivate))
  63. typedef struct {
  64. char *config;
  65. } NMSettingTeamPortPrivate;
  66. enum {
  67. PROP_0,
  68. PROP_CONFIG,
  69. LAST_PROP
  70. };
  71. /**
  72. * nm_setting_team_port_new:
  73. *
  74. * Creates a new #NMSettingTeamPort object with default values.
  75. *
  76. * Returns: (transfer full): the new empty #NMSettingTeamPort object
  77. *
  78. * Since: 0.9.10
  79. **/
  80. NMSetting *
  81. nm_setting_team_port_new (void)
  82. {
  83. return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM_PORT, NULL);
  84. }
  85. /**
  86. * nm_setting_team_port_get_config:
  87. * @setting: the #NMSettingTeamPort
  88. *
  89. * Returns: the #NMSettingTeamPort:config property of the setting
  90. *
  91. * Since: 0.9.10
  92. **/
  93. const char *
  94. nm_setting_team_port_get_config (NMSettingTeamPort *setting)
  95. {
  96. g_return_val_if_fail (NM_IS_SETTING_TEAM_PORT (setting), NULL);
  97. return NM_SETTING_TEAM_PORT_GET_PRIVATE (setting)->config;
  98. }
  99. static gboolean
  100. verify (NMSetting *setting, GSList *all_settings, GError **error)
  101. {
  102. return TRUE;
  103. }
  104. static void
  105. nm_setting_team_port_init (NMSettingTeamPort *setting)
  106. {
  107. }
  108. static void
  109. set_property (GObject *object, guint prop_id,
  110. const GValue *value, GParamSpec *pspec)
  111. {
  112. NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
  113. switch (prop_id) {
  114. case PROP_CONFIG:
  115. g_free (priv->config);
  116. priv->config = g_value_dup_string (value);
  117. break;
  118. default:
  119. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  120. break;
  121. }
  122. }
  123. static void
  124. get_property (GObject *object, guint prop_id,
  125. GValue *value, GParamSpec *pspec)
  126. {
  127. NMSettingTeamPort *setting = NM_SETTING_TEAM_PORT (object);
  128. switch (prop_id) {
  129. case PROP_CONFIG:
  130. g_value_set_string (value, nm_setting_team_port_get_config (setting));
  131. break;
  132. default:
  133. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  134. break;
  135. }
  136. }
  137. static void
  138. finalize (GObject *object)
  139. {
  140. NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
  141. g_free (priv->config);
  142. G_OBJECT_CLASS (nm_setting_team_port_parent_class)->finalize (object);
  143. }
  144. static void
  145. nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
  146. {
  147. GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
  148. NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
  149. g_type_class_add_private (setting_class, sizeof (NMSettingTeamPortPrivate));
  150. /* virtual methods */
  151. object_class->set_property = set_property;
  152. object_class->get_property = get_property;
  153. object_class->finalize = finalize;
  154. parent_class->verify = verify;
  155. /* Properties */
  156. /**
  157. * NMSettingTeamPort:config:
  158. *
  159. * The JSON configuration for the team port. The property should contain raw
  160. * JSON configuration data suitable for teamd, because the value is passed
  161. * directly to teamd. If not specified, the default configuration is
  162. * used. See man teamd.conf for the format details.
  163. **/
  164. g_object_class_install_property
  165. (object_class, PROP_CONFIG,
  166. g_param_spec_string (NM_SETTING_TEAM_PORT_CONFIG, "", "",
  167. NULL,
  168. G_PARAM_READWRITE |
  169. NM_SETTING_PARAM_INFERRABLE |
  170. G_PARAM_STATIC_STRINGS));
  171. }