File: oobs-ntpserver.c

package info (click to toggle)
liboobs 3.0.0-4.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,284 kB
  • sloc: sh: 10,131; ansic: 9,920; makefile: 176; xml: 1
file content (200 lines) | stat: -rw-r--r-- 5,353 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* Copyright (C) 2005 Carlos Garnacho
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 * Authors: Carlos Garnacho Parro  <carlosg@gnome.org>
 */

#include <glib-object.h>
#include "oobs-ntpserver.h"

/**
 * SECTION:oobs-ntpserver
 * @title: OobsNTPServer
 * @short_description: Object that represents an individual NTP server
 * @see_also: #OobsNTPConfig
 **/

#define OOBS_NTP_SERVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OOBS_TYPE_NTP_SERVER, OobsNTPServerPrivate))

typedef struct _OobsNTPServerPrivate OobsNTPServerPrivate;

struct _OobsNTPServerPrivate {
  gchar *hostname;
};

static void oobs_ntp_server_class_init (OobsNTPServerClass *class);
static void oobs_ntp_server_init       (OobsNTPServer      *ntp_server);
static void oobs_ntp_server_finalize   (GObject            *object);

static void oobs_ntp_server_set_property (GObject      *object,
					  guint         prop_id,
					  const GValue *value,
					  GParamSpec   *pspec);
static void oobs_ntp_server_get_property (GObject      *object,
					  guint         prop_id,
					  GValue       *value,
					  GParamSpec   *pspec);
enum
{
  PROP_0,
  PROP_HOSTNAME,
};

G_DEFINE_TYPE (OobsNTPServer, oobs_ntp_server, G_TYPE_OBJECT);

static void
oobs_ntp_server_class_init (OobsNTPServerClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);

  object_class->set_property = oobs_ntp_server_set_property;
  object_class->get_property = oobs_ntp_server_get_property;
  object_class->finalize     = oobs_ntp_server_finalize;

  g_object_class_install_property (object_class,
				   PROP_HOSTNAME,
				   g_param_spec_string ("hostname",
							"Hostname",
							"Server hostname",
							NULL,
							G_PARAM_READWRITE));
  g_type_class_add_private (object_class,
			    sizeof (OobsNTPServerPrivate));
}

static void
oobs_ntp_server_init (OobsNTPServer *ntp_server)
{
  OobsNTPServerPrivate *priv;

  g_return_if_fail (OOBS_IS_NTP_SERVER (ntp_server));

  priv = OOBS_NTP_SERVER_GET_PRIVATE (ntp_server);
  priv->hostname = NULL;
  ntp_server->_priv = priv;
}

static void
oobs_ntp_server_set_property (GObject      *object,
			      guint         prop_id,
			      const GValue *value,
			      GParamSpec   *pspec)
{
  OobsNTPServerPrivate *priv;

  g_return_if_fail (OOBS_IS_NTP_SERVER (object));

  priv = OOBS_NTP_SERVER (object)->_priv;

  switch (prop_id)
    {
    case PROP_HOSTNAME:
      g_free (priv->hostname);
      priv->hostname = g_value_dup_string (value);
      break;
    }
}

static void
oobs_ntp_server_get_property (GObject      *object,
			      guint         prop_id,
			      GValue       *value,
			      GParamSpec   *pspec)
{
  OobsNTPServerPrivate *priv;

  g_return_if_fail (OOBS_IS_NTP_SERVER (object));

  priv = OOBS_NTP_SERVER (object)->_priv;

  switch (prop_id)
    {
    case PROP_HOSTNAME:
      g_value_set_string (value, priv->hostname);
      break;
    }
}

static void
oobs_ntp_server_finalize (GObject *object)
{
  OobsNTPServerPrivate *priv;

  g_return_if_fail (OOBS_IS_NTP_SERVER (object));

  priv = OOBS_NTP_SERVER (object)->_priv;

  if (priv)
    g_free (priv->hostname);

  if (G_OBJECT_CLASS (oobs_ntp_server_parent_class)->finalize)
    (* G_OBJECT_CLASS (oobs_ntp_server_parent_class)->finalize) (object);
}

/**
 * oobs_ntp_server_new:
 * @hostname: Hostname of the NTP server.
 * 
 * Returns a new #OobsNTPServer with hostname set to #hostname.
 * #hostname can specify an IP address too.
 * 
 * Return Value: A new #OobsNTPServer.
 **/
OobsNTPServer*
oobs_ntp_server_new (const gchar *hostname)
{
  return g_object_new (OOBS_TYPE_NTP_SERVER,
		       "hostname", hostname,
		       NULL);
}

/**
 * oobs_ntp_server_get_hostname:
 * @ntp_server: An #OobsNTPServer.
 * 
 * Returns the #OobsNTPServer hostname or IP address.
 * 
 * Return Value: A pointer to the NTP server hostname (or IP address) as a string.
 *               This string must not be freed, modified or stored.
 **/
G_CONST_RETURN gchar*
oobs_ntp_server_get_hostname (OobsNTPServer *ntp_server)
{
  OobsNTPServerPrivate *priv;

  g_return_val_if_fail (OOBS_IS_NTP_SERVER (ntp_server), NULL);

  priv = ntp_server->_priv;

  return priv->hostname;
}

/**
 * oobs_ntp_server_set_hostname:
 * @ntp_server: An #OobsNTPServer.
 * @hostname: a new hostname (or IP address) for #ntp_server.
 * 
 * Sets the hostname of #ntp_server to be #hostname.
 * #hostname can specify an IP address too.
 **/
void
oobs_ntp_server_set_hostname (OobsNTPServer *ntp_server, const gchar *hostname)
{
  g_return_if_fail (OOBS_IS_NTP_SERVER (ntp_server));

  g_object_set (G_OBJECT (ntp_server), "hostname", hostname, NULL);
}