~ubuntu-branches/debian/sid/link-monitor-applet/sid

« back to all changes in this revision

Viewing changes to build/src/lm-host.c

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2008-03-30 22:26:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080330222613-5aubcuo9mgg2n7st
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Generated by GOB (v2.0.15)   (do not edit directly) */
 
2
 
 
3
/* End world hunger, donate to the World Food Programme, http://www.wfp.org */
 
4
 
 
5
#define GOB_VERSION_MAJOR 2
 
6
#define GOB_VERSION_MINOR 0
 
7
#define GOB_VERSION_PATCHLEVEL 15
 
8
 
 
9
#define selfp (self->_priv)
 
10
 
 
11
#include "lm-host.h"
 
12
 
 
13
#include "lm-host-private.h"
 
14
 
 
15
#ifdef G_LIKELY
 
16
#define ___GOB_LIKELY(expr) G_LIKELY(expr)
 
17
#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)
 
18
#else /* ! G_LIKELY */
 
19
#define ___GOB_LIKELY(expr) (expr)
 
20
#define ___GOB_UNLIKELY(expr) (expr)
 
21
#endif /* G_LIKELY */
 
22
 
 
23
#line 51 "src/lm-host.gob"
 
24
 
 
25
#include <string.h>
 
26
#include <stdarg.h>
 
27
#include <sys/types.h>
 
28
#include <sys/socket.h>
 
29
#include <netdb.h>
 
30
#include <glib/gi18n.h>
 
31
#include "lm-util.h"
 
32
#include "lm-applet.h"
 
33
 
 
34
#ifndef HAVE_REENTRANT_RESOLVER
 
35
G_LOCK_DEFINE_STATIC(resolver);
 
36
#endif
 
37
 
 
38
/* in milliseconds */
 
39
#define MIN_TIMEOUT             100
 
40
#define DEFAULT_TIMEOUT         1000
 
41
 
 
42
#line 43 "lm-host.c"
 
43
/* self casting macros */
 
44
#define SELF(x) LM_HOST(x)
 
45
#define SELF_CONST(x) LM_HOST_CONST(x)
 
46
#define IS_SELF(x) LM_IS_HOST(x)
 
47
#define TYPE_SELF LM_TYPE_HOST
 
48
#define SELF_CLASS(x) LM_HOST_CLASS(x)
 
49
 
 
50
#define SELF_GET_CLASS(x) LM_HOST_GET_CLASS(x)
 
51
 
 
52
/* self typedefs */
 
53
typedef LMHost Self;
 
54
typedef LMHostClass SelfClass;
 
55
 
 
56
/* here are local prototypes */
 
57
static void ___object_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
 
58
static void ___object_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
 
59
#line 0 "src/lm-host.gob"
 
60
static void lm_host_init (LMHost * o);
 
61
#line 62 "lm-host.c"
 
62
#line 0 "src/lm-host.gob"
 
63
static void lm_host_class_init (LMHostClass * c);
 
64
#line 65 "lm-host.c"
 
65
#line 147 "src/lm-host.gob"
 
66
static void lm_host_set_error (LMHost * self, Error error, const char * format, ...) G_GNUC_PRINTF(3, 4);
 
67
#line 68 "lm-host.c"
 
68
#line 166 "src/lm-host.gob"
 
69
static void lm_host_clear_error (LMHost * self, Error error);
 
70
#line 71 "lm-host.c"
 
71
#line 180 "src/lm-host.gob"
 
72
static void lm_host_constructor (LMHost * self);
 
73
#line 74 "lm-host.c"
 
74
#line 191 "src/lm-host.gob"
 
75
static void lm_host_finalize (LMHost * self);
 
76
#line 77 "lm-host.c"
 
77
#line 203 "src/lm-host.gob"
 
78
static void lm_host_resolve (LMHost * self);
 
79
#line 80 "lm-host.c"
 
80
#line 214 "src/lm-host.gob"
 
81
static gpointer lm_host_resolve_thread_cb (gpointer data);
 
82
#line 83 "lm-host.c"
 
83
#line 327 "src/lm-host.gob"
 
84
static void lm_host_install_resolve_timeout (LMHost * self, int delay);
 
85
#line 86 "lm-host.c"
 
86
#line 334 "src/lm-host.gob"
 
87
static gboolean lm_host_resolve_timeout_cb (gpointer data);
 
88
#line 89 "lm-host.c"
 
89
#line 345 "src/lm-host.gob"
 
90
static void lm_host_send_echo_request (LMHost * self);
 
91
#line 92 "lm-host.c"
 
92
#line 388 "src/lm-host.gob"
 
93
static void lm_host_delay_changed_h (GObject * object, GParamSpec * pspec, gpointer user_data);
 
94
#line 95 "lm-host.c"
 
95
#line 401 "src/lm-host.gob"
 
96
static void lm_host_install_send_timeout (LMHost * self);
 
97
#line 98 "lm-host.c"
 
98
#line 412 "src/lm-host.gob"
 
99
static gboolean lm_host_send_timeout_cb (gpointer data);
 
100
#line 101 "lm-host.c"
 
101
#line 422 "src/lm-host.gob"
 
102
static gboolean lm_host_dead_timeout_cb (gpointer data);
 
103
#line 104 "lm-host.c"
 
104
 
 
105
enum {
 
106
        PROP_0,
 
107
        PROP_APPLET,
 
108
        PROP_NAME,
 
109
        PROP_RESOLVING,
 
110
        PROP_IP,
 
111
        PROP_ALIVE,
 
112
        PROP_ROUNDTRIP_TIME,
 
113
        PROP_ERROR
 
114
};
 
115
 
 
116
/* pointer to the class of our parent */
 
117
static GObjectClass *parent_class = NULL;
 
118
 
 
119
/* Short form macros */
 
120
#define self_get_resolving lm_host_get_resolving
 
121
#define self_set_resolving lm_host_set_resolving
 
122
#define self_get_alive lm_host_get_alive
 
123
#define self_set_alive lm_host_set_alive
 
124
#define self_get_roundtrip_time lm_host_get_roundtrip_time
 
125
#define self_set_roundtrip_time lm_host_set_roundtrip_time
 
126
#define self_get_error lm_host_get_error
 
127
#define self_set_error lm_host_set_error
 
128
#define self_clear_error lm_host_clear_error
 
129
#define self_resolve lm_host_resolve
 
130
#define self_resolve_thread_cb lm_host_resolve_thread_cb
 
131
#define self_install_resolve_timeout lm_host_install_resolve_timeout
 
132
#define self_resolve_timeout_cb lm_host_resolve_timeout_cb
 
133
#define self_send_echo_request lm_host_send_echo_request
 
134
#define self_delay_changed_h lm_host_delay_changed_h
 
135
#define self_install_send_timeout lm_host_install_send_timeout
 
136
#define self_send_timeout_cb lm_host_send_timeout_cb
 
137
#define self_dead_timeout_cb lm_host_dead_timeout_cb
 
138
#define self_reply_received lm_host_reply_received
 
139
GType
 
140
lm_host_get_type (void)
 
141
{
 
142
        static GType type = 0;
 
143
 
 
144
        if ___GOB_UNLIKELY(type == 0) {
 
145
                static const GTypeInfo info = {
 
146
                        sizeof (LMHostClass),
 
147
                        (GBaseInitFunc) NULL,
 
148
                        (GBaseFinalizeFunc) NULL,
 
149
                        (GClassInitFunc) lm_host_class_init,
 
150
                        (GClassFinalizeFunc) NULL,
 
151
                        NULL /* class_data */,
 
152
                        sizeof (LMHost),
 
153
                        0 /* n_preallocs */,
 
154
                        (GInstanceInitFunc) lm_host_init,
 
155
                        NULL
 
156
                };
 
157
 
 
158
                type = g_type_register_static (G_TYPE_OBJECT, "LMHost", &info, (GTypeFlags)G_TYPE_FLAG_ABSTRACT);
 
159
        }
 
160
 
 
161
        return type;
 
162
}
 
163
 
 
164
/* a macro for creating a new object of our type */
 
165
#define GET_NEW ((LMHost *)g_object_new(lm_host_get_type(), NULL))
 
166
 
 
167
/* a function for creating a new object of our type */
 
168
#include <stdarg.h>
 
169
static LMHost * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED;
 
170
static LMHost *
 
171
GET_NEW_VARG (const char *first, ...)
 
172
{
 
173
        LMHost *ret;
 
174
        va_list ap;
 
175
        va_start (ap, first);
 
176
        ret = (LMHost *)g_object_new_valist (lm_host_get_type (), first, ap);
 
177
        va_end (ap);
 
178
        return ret;
 
179
}
 
180
 
 
181
 
 
182
static GObject *
 
183
___constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
 
184
{
 
185
#define __GOB_FUNCTION__ "LM:Host::constructor"
 
186
        GObject *obj_self;
 
187
        LMHost *self;
 
188
        obj_self = G_OBJECT_CLASS (parent_class)->constructor (type, n_construct_properties, construct_properties);
 
189
        self = LM_HOST (obj_self);
 
190
#line 180 "src/lm-host.gob"
 
191
        lm_host_constructor (self);
 
192
#line 193 "lm-host.c"
 
193
        return obj_self;
 
194
}
 
195
#undef __GOB_FUNCTION__
 
196
 
 
197
 
 
198
static void
 
199
___finalize(GObject *obj_self)
 
200
{
 
201
#define __GOB_FUNCTION__ "LM:Host::finalize"
 
202
        LMHost *self G_GNUC_UNUSED = LM_HOST (obj_self);
 
203
        gpointer priv G_GNUC_UNUSED = self->_priv;
 
204
#line 191 "src/lm-host.gob"
 
205
        lm_host_finalize (self);
 
206
#line 207 "lm-host.c"
 
207
        if(G_OBJECT_CLASS(parent_class)->finalize) \
 
208
                (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self);
 
209
#line 75 "src/lm-host.gob"
 
210
        if(self->name) { g_free ((gpointer) self->name); self->name = NULL; }
 
211
#line 212 "lm-host.c"
 
212
#line 78 "src/lm-host.gob"
 
213
        if(self->_priv->addrinfo) { freeaddrinfo ((gpointer) self->_priv->addrinfo); self->_priv->addrinfo = NULL; }
 
214
#line 215 "lm-host.c"
 
215
#line 84 "src/lm-host.gob"
 
216
        if(self->ip) { g_free ((gpointer) self->ip); self->ip = NULL; }
 
217
#line 218 "lm-host.c"
 
218
#define errors (self->_priv->errors)
 
219
#define VAR errors
 
220
        {
 
221
#line 127 "src/lm-host.gob"
 
222
        
 
223
      int i;
 
224
 
 
225
      for (i = 0; i < G_N_ELEMENTS(VAR); i++)
 
226
        g_free(VAR[i]);
 
227
    }
 
228
#line 229 "lm-host.c"
 
229
        memset(&errors, 0, sizeof(errors));
 
230
#undef VAR
 
231
#undef errors
 
232
}
 
233
#undef __GOB_FUNCTION__
 
234
 
 
235
static void 
 
236
lm_host_init (LMHost * o G_GNUC_UNUSED)
 
237
{
 
238
#define __GOB_FUNCTION__ "LM:Host::init"
 
239
        o->_priv = G_TYPE_INSTANCE_GET_PRIVATE(o,LM_TYPE_HOST,LMHostPrivate);
 
240
}
 
241
#undef __GOB_FUNCTION__
 
242
static void 
 
243
lm_host_class_init (LMHostClass * c G_GNUC_UNUSED)
 
244
{
 
245
#define __GOB_FUNCTION__ "LM:Host::class_init"
 
246
        GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;
 
247
 
 
248
        g_type_class_add_private(c,sizeof(LMHostPrivate));
 
249
 
 
250
        parent_class = g_type_class_ref (G_TYPE_OBJECT);
 
251
 
 
252
        g_object_class->constructor = ___constructor;
 
253
        g_object_class->finalize = ___finalize;
 
254
        g_object_class->get_property = ___object_get_property;
 
255
        g_object_class->set_property = ___object_set_property;
 
256
    {
 
257
        GParamSpec   *param_spec;
 
258
 
 
259
        param_spec = g_param_spec_pointer
 
260
                ("applet" /* name */,
 
261
                 NULL /* nick */,
 
262
                 NULL /* blurb */,
 
263
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
264
        g_object_class_install_property (g_object_class,
 
265
                PROP_APPLET,
 
266
                param_spec);
 
267
        param_spec = g_param_spec_string
 
268
                ("name" /* name */,
 
269
                 NULL /* nick */,
 
270
                 NULL /* blurb */,
 
271
                 NULL /* default_value */,
 
272
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
273
        g_object_class_install_property (g_object_class,
 
274
                PROP_NAME,
 
275
                param_spec);
 
276
        param_spec = g_param_spec_boolean
 
277
                ("resolving" /* name */,
 
278
                 NULL /* nick */,
 
279
                 NULL /* blurb */,
 
280
                 FALSE /* default_value */,
 
281
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE));
 
282
        g_object_class_install_property (g_object_class,
 
283
                PROP_RESOLVING,
 
284
                param_spec);
 
285
        param_spec = g_param_spec_string
 
286
                ("ip" /* name */,
 
287
                 NULL /* nick */,
 
288
                 NULL /* blurb */,
 
289
                 NULL /* default_value */,
 
290
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE));
 
291
        g_object_class_install_property (g_object_class,
 
292
                PROP_IP,
 
293
                param_spec);
 
294
        param_spec = g_param_spec_boolean
 
295
                ("alive" /* name */,
 
296
                 NULL /* nick */,
 
297
                 NULL /* blurb */,
 
298
                 FALSE /* default_value */,
 
299
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE));
 
300
        g_object_class_install_property (g_object_class,
 
301
                PROP_ALIVE,
 
302
                param_spec);
 
303
        param_spec = g_param_spec_int64
 
304
                ("roundtrip_time" /* name */,
 
305
                 NULL /* nick */,
 
306
                 NULL /* blurb */,
 
307
                 G_MININT64 /* minimum */,
 
308
                 G_MAXINT64 /* maximum */,
 
309
                 0 /* default_value */,
 
310
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE));
 
311
        g_object_class_install_property (g_object_class,
 
312
                PROP_ROUNDTRIP_TIME,
 
313
                param_spec);
 
314
        param_spec = g_param_spec_string
 
315
                ("error" /* name */,
 
316
                 NULL /* nick */,
 
317
                 NULL /* blurb */,
 
318
                 NULL /* default_value */,
 
319
                 (GParamFlags)(G_PARAM_READABLE));
 
320
        g_object_class_install_property (g_object_class,
 
321
                PROP_ERROR,
 
322
                param_spec);
 
323
    }
 
324
}
 
325
#undef __GOB_FUNCTION__
 
326
 
 
327
static void
 
328
___object_set_property (GObject *object,
 
329
        guint property_id,
 
330
        const GValue *VAL G_GNUC_UNUSED,
 
331
        GParamSpec *pspec G_GNUC_UNUSED)
 
332
#define __GOB_FUNCTION__ "LM:Host::set_property"
 
333
{
 
334
        LMHost *self G_GNUC_UNUSED;
 
335
 
 
336
        self = LM_HOST (object);
 
337
 
 
338
        switch (property_id) {
 
339
        case PROP_APPLET:
 
340
                {
 
341
#line 73 "src/lm-host.gob"
 
342
self->applet = g_value_get_pointer (VAL);
 
343
#line 344 "lm-host.c"
 
344
                }
 
345
                break;
 
346
        case PROP_NAME:
 
347
                {
 
348
#line 76 "src/lm-host.gob"
 
349
{ char *old = self->name; self->name = g_value_dup_string (VAL); g_free (old); }
 
350
#line 351 "lm-host.c"
 
351
                }
 
352
                break;
 
353
        case PROP_RESOLVING:
 
354
                {
 
355
#line 82 "src/lm-host.gob"
 
356
self->resolving = g_value_get_boolean (VAL);
 
357
#line 358 "lm-host.c"
 
358
                }
 
359
                break;
 
360
        case PROP_IP:
 
361
                {
 
362
#line 85 "src/lm-host.gob"
 
363
{ char *old = self->ip; self->ip = g_value_dup_string (VAL); g_free (old); }
 
364
#line 365 "lm-host.c"
 
365
                }
 
366
                break;
 
367
        case PROP_ALIVE:
 
368
                {
 
369
#line 93 "src/lm-host.gob"
 
370
self->alive = g_value_get_boolean (VAL);
 
371
#line 372 "lm-host.c"
 
372
                }
 
373
                break;
 
374
        case PROP_ROUNDTRIP_TIME:
 
375
                {
 
376
#line 104 "src/lm-host.gob"
 
377
 
 
378
      self->last_received_ticks = lm_get_ticks();
 
379
      lm_source_clear(&selfp->dead_timeout_id);
 
380
 
 
381
      self->roundtrip_time = g_value_get_int64(VAL);
 
382
      if (self->roundtrip_time > selfp->max_roundtrip_time)
 
383
        selfp->max_roundtrip_time = self->roundtrip_time;
 
384
 
 
385
      self_set_alive(self, TRUE);
 
386
    
 
387
#line 388 "lm-host.c"
 
388
                }
 
389
                break;
 
390
        default:
 
391
/* Apparently in g++ this is needed, glib is b0rk */
 
392
#ifndef __PRETTY_FUNCTION__
 
393
#  undef G_STRLOC
 
394
#  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
 
395
#endif
 
396
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
397
                break;
 
398
        }
 
399
}
 
400
#undef __GOB_FUNCTION__
 
401
 
 
402
static void
 
403
___object_get_property (GObject *object,
 
404
        guint property_id,
 
405
        GValue *VAL G_GNUC_UNUSED,
 
406
        GParamSpec *pspec G_GNUC_UNUSED)
 
407
#define __GOB_FUNCTION__ "LM:Host::get_property"
 
408
{
 
409
        LMHost *self G_GNUC_UNUSED;
 
410
 
 
411
        self = LM_HOST (object);
 
412
 
 
413
        switch (property_id) {
 
414
        case PROP_APPLET:
 
415
                {
 
416
#line 73 "src/lm-host.gob"
 
417
g_value_set_pointer (VAL, self->applet);
 
418
#line 419 "lm-host.c"
 
419
                }
 
420
                break;
 
421
        case PROP_NAME:
 
422
                {
 
423
#line 76 "src/lm-host.gob"
 
424
g_value_set_string (VAL, self->name);
 
425
#line 426 "lm-host.c"
 
426
                }
 
427
                break;
 
428
        case PROP_RESOLVING:
 
429
                {
 
430
#line 82 "src/lm-host.gob"
 
431
g_value_set_boolean (VAL, self->resolving);
 
432
#line 433 "lm-host.c"
 
433
                }
 
434
                break;
 
435
        case PROP_IP:
 
436
                {
 
437
#line 85 "src/lm-host.gob"
 
438
g_value_set_string (VAL, self->ip);
 
439
#line 440 "lm-host.c"
 
440
                }
 
441
                break;
 
442
        case PROP_ALIVE:
 
443
                {
 
444
#line 93 "src/lm-host.gob"
 
445
g_value_set_boolean (VAL, self->alive);
 
446
#line 447 "lm-host.c"
 
447
                }
 
448
                break;
 
449
        case PROP_ROUNDTRIP_TIME:
 
450
                {
 
451
#line 115 "src/lm-host.gob"
 
452
 
 
453
      g_value_set_int64(VAL, self->roundtrip_time);
 
454
    
 
455
#line 456 "lm-host.c"
 
456
                }
 
457
                break;
 
458
        case PROP_ERROR:
 
459
                {
 
460
#line 121 "src/lm-host.gob"
 
461
 
 
462
      g_value_set_string(VAL, self_get_error(self));
 
463
    
 
464
#line 465 "lm-host.c"
 
465
                }
 
466
                break;
 
467
        default:
 
468
/* Apparently in g++ this is needed, glib is b0rk */
 
469
#ifndef __PRETTY_FUNCTION__
 
470
#  undef G_STRLOC
 
471
#  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
 
472
#endif
 
473
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
474
                break;
 
475
        }
 
476
}
 
477
#undef __GOB_FUNCTION__
 
478
 
 
479
 
 
480
 
 
481
#line 82 "src/lm-host.gob"
 
482
gboolean 
 
483
lm_host_get_resolving (LMHost * self)
 
484
{
 
485
#line 486 "lm-host.c"
 
486
#define __GOB_FUNCTION__ "LM:Host::get_resolving"
 
487
{
 
488
#line 82 "src/lm-host.gob"
 
489
                gboolean val; g_object_get (G_OBJECT (self), "resolving", &val, NULL); return val;
 
490
}}
 
491
#line 492 "lm-host.c"
 
492
#undef __GOB_FUNCTION__
 
493
 
 
494
#line 82 "src/lm-host.gob"
 
495
void 
 
496
lm_host_set_resolving (LMHost * self, gboolean val)
 
497
{
 
498
#line 499 "lm-host.c"
 
499
#define __GOB_FUNCTION__ "LM:Host::set_resolving"
 
500
{
 
501
#line 82 "src/lm-host.gob"
 
502
                g_object_set (G_OBJECT (self), "resolving", val, NULL);
 
503
}}
 
504
#line 505 "lm-host.c"
 
505
#undef __GOB_FUNCTION__
 
506
 
 
507
#line 93 "src/lm-host.gob"
 
508
gboolean 
 
509
lm_host_get_alive (LMHost * self)
 
510
{
 
511
#line 512 "lm-host.c"
 
512
#define __GOB_FUNCTION__ "LM:Host::get_alive"
 
513
{
 
514
#line 93 "src/lm-host.gob"
 
515
                gboolean val; g_object_get (G_OBJECT (self), "alive", &val, NULL); return val;
 
516
}}
 
517
#line 518 "lm-host.c"
 
518
#undef __GOB_FUNCTION__
 
519
 
 
520
#line 93 "src/lm-host.gob"
 
521
void 
 
522
lm_host_set_alive (LMHost * self, gboolean val)
 
523
{
 
524
#line 525 "lm-host.c"
 
525
#define __GOB_FUNCTION__ "LM:Host::set_alive"
 
526
{
 
527
#line 93 "src/lm-host.gob"
 
528
                g_object_set (G_OBJECT (self), "alive", val, NULL);
 
529
}}
 
530
#line 531 "lm-host.c"
 
531
#undef __GOB_FUNCTION__
 
532
 
 
533
#line 115 "src/lm-host.gob"
 
534
LMTimeSpan 
 
535
lm_host_get_roundtrip_time (LMHost * self)
 
536
{
 
537
#line 538 "lm-host.c"
 
538
#define __GOB_FUNCTION__ "LM:Host::get_roundtrip_time"
 
539
{
 
540
#line 102 "src/lm-host.gob"
 
541
                LMTimeSpan val; g_object_get (G_OBJECT (self), "roundtrip_time", &val, NULL); return val;
 
542
}}
 
543
#line 544 "lm-host.c"
 
544
#undef __GOB_FUNCTION__
 
545
 
 
546
#line 104 "src/lm-host.gob"
 
547
void 
 
548
lm_host_set_roundtrip_time (LMHost * self, LMTimeSpan val)
 
549
{
 
550
#line 551 "lm-host.c"
 
551
#define __GOB_FUNCTION__ "LM:Host::set_roundtrip_time"
 
552
{
 
553
#line 102 "src/lm-host.gob"
 
554
                g_object_set (G_OBJECT (self), "roundtrip_time", val, NULL);
 
555
}}
 
556
#line 557 "lm-host.c"
 
557
#undef __GOB_FUNCTION__
 
558
 
 
559
#line 134 "src/lm-host.gob"
 
560
const char * 
 
561
lm_host_get_error (LMHost * self)
 
562
{
 
563
#line 564 "lm-host.c"
 
564
#define __GOB_FUNCTION__ "LM:Host::get_error"
 
565
#line 134 "src/lm-host.gob"
 
566
        g_return_val_if_fail (self != NULL, (const char * )0);
 
567
#line 134 "src/lm-host.gob"
 
568
        g_return_val_if_fail (LM_IS_HOST (self), (const char * )0);
 
569
#line 570 "lm-host.c"
 
570
{
 
571
#line 136 "src/lm-host.gob"
 
572
        
 
573
    int i;
 
574
 
 
575
    for (i = 0; i < G_N_ELEMENTS(selfp->errors); i++)
 
576
      if (selfp->errors[i])
 
577
        return selfp->errors[i];
 
578
 
 
579
    return NULL;
 
580
  }}
 
581
#line 582 "lm-host.c"
 
582
#undef __GOB_FUNCTION__
 
583
 
 
584
#line 147 "src/lm-host.gob"
 
585
static void 
 
586
lm_host_set_error (LMHost * self, Error error, const char * format, ...)
 
587
{
 
588
#line 589 "lm-host.c"
 
589
#define __GOB_FUNCTION__ "LM:Host::set_error"
 
590
#line 147 "src/lm-host.gob"
 
591
        g_return_if_fail (self != NULL);
 
592
#line 147 "src/lm-host.gob"
 
593
        g_return_if_fail (LM_IS_HOST (self));
 
594
#line 147 "src/lm-host.gob"
 
595
        g_return_if_fail (format != NULL);
 
596
#line 597 "lm-host.c"
 
597
{
 
598
#line 149 "src/lm-host.gob"
 
599
        
 
600
    va_list args;
 
601
    char *msg;
 
602
 
 
603
    va_start(args, format);
 
604
    msg = g_strdup_vprintf(format, args);
 
605
    va_end(args);
 
606
 
 
607
    g_free(selfp->errors[error]);
 
608
    selfp->errors[error] = msg;
 
609
 
 
610
    lm_source_clear(&selfp->dead_timeout_id);
 
611
    self_set_alive(self, FALSE);
 
612
 
 
613
    g_object_notify(G_OBJECT(self), "error");
 
614
  }}
 
615
#line 616 "lm-host.c"
 
616
#undef __GOB_FUNCTION__
 
617
 
 
618
#line 166 "src/lm-host.gob"
 
619
static void 
 
620
lm_host_clear_error (LMHost * self, Error error)
 
621
{
 
622
#line 623 "lm-host.c"
 
623
#define __GOB_FUNCTION__ "LM:Host::clear_error"
 
624
#line 166 "src/lm-host.gob"
 
625
        g_return_if_fail (self != NULL);
 
626
#line 166 "src/lm-host.gob"
 
627
        g_return_if_fail (LM_IS_HOST (self));
 
628
#line 629 "lm-host.c"
 
629
{
 
630
#line 168 "src/lm-host.gob"
 
631
        
 
632
    if (! selfp->errors[error])
 
633
      return;
 
634
 
 
635
    g_free(selfp->errors[error]);
 
636
    selfp->errors[error] = NULL;
 
637
 
 
638
    g_object_notify(G_OBJECT(self), "error");
 
639
  }}
 
640
#line 641 "lm-host.c"
 
641
#undef __GOB_FUNCTION__
 
642
 
 
643
#line 180 "src/lm-host.gob"
 
644
static void 
 
645
lm_host_constructor (LMHost * self)
 
646
{
 
647
#line 648 "lm-host.c"
 
648
#define __GOB_FUNCTION__ "LM:Host::constructor"
 
649
{
 
650
#line 181 "src/lm-host.gob"
 
651
        
 
652
    selfp->host_id = lm_shell_allocate_host_id(lm_shell, self);
 
653
 
 
654
    lm_g_object_connect(self, self->applet,
 
655
                        "signal::notify::delay", self_delay_changed_h, self,
 
656
                        NULL);
 
657
 
 
658
    self_resolve(self);
 
659
  }}
 
660
#line 661 "lm-host.c"
 
661
#undef __GOB_FUNCTION__
 
662
 
 
663
#line 191 "src/lm-host.gob"
 
664
static void 
 
665
lm_host_finalize (LMHost * self)
 
666
{
 
667
#line 668 "lm-host.c"
 
668
#define __GOB_FUNCTION__ "LM:Host::finalize"
 
669
{
 
670
#line 192 "src/lm-host.gob"
 
671
        
 
672
    if (selfp->resolve_timeout_id)
 
673
      g_source_remove(selfp->resolve_timeout_id);
 
674
    if (selfp->send_timeout_id)
 
675
      g_source_remove(selfp->send_timeout_id);
 
676
    if (selfp->dead_timeout_id)
 
677
      g_source_remove(selfp->dead_timeout_id);
 
678
 
 
679
    lm_shell_deallocate_host_id(lm_shell, selfp->host_id);
 
680
  }}
 
681
#line 682 "lm-host.c"
 
682
#undef __GOB_FUNCTION__
 
683
 
 
684
#line 203 "src/lm-host.gob"
 
685
static void 
 
686
lm_host_resolve (LMHost * self)
 
687
{
 
688
#line 689 "lm-host.c"
 
689
#define __GOB_FUNCTION__ "LM:Host::resolve"
 
690
#line 203 "src/lm-host.gob"
 
691
        g_return_if_fail (self != NULL);
 
692
#line 203 "src/lm-host.gob"
 
693
        g_return_if_fail (LM_IS_HOST (self));
 
694
#line 695 "lm-host.c"
 
695
{
 
696
#line 205 "src/lm-host.gob"
 
697
        
 
698
    g_return_if_fail(self->resolving == FALSE);
 
699
 
 
700
    self_set_resolving(self, TRUE);
 
701
 
 
702
    g_object_ref(self);
 
703
    lm_thread_create(self_resolve_thread_cb, self);
 
704
  }}
 
705
#line 706 "lm-host.c"
 
706
#undef __GOB_FUNCTION__
 
707
 
 
708
#line 214 "src/lm-host.gob"
 
709
static gpointer 
 
710
lm_host_resolve_thread_cb (gpointer data)
 
711
{
 
712
#line 713 "lm-host.c"
 
713
#define __GOB_FUNCTION__ "LM:Host::resolve_thread_cb"
 
714
{
 
715
#line 216 "src/lm-host.gob"
 
716
        
 
717
    Self *self = data;
 
718
    struct addrinfo hints;
 
719
    struct addrinfo *addrinfo;
 
720
    char *ip = NULL;
 
721
    int status;
 
722
 
 
723
    memset(&hints, 0, sizeof(hints));
 
724
#if WITH_IPV6
 
725
    hints.ai_family = PF_UNSPEC;
 
726
#else
 
727
    hints.ai_family = PF_INET;
 
728
#endif /* WITH_IPV6 */
 
729
    hints.ai_socktype = SOCK_RAW;
 
730
 
 
731
#ifndef HAVE_REENTRANT_RESOLVER
 
732
    G_LOCK(resolver);
 
733
#endif
 
734
    status = getaddrinfo(self->name, NULL, &hints, &addrinfo);
 
735
#ifndef HAVE_REENTRANT_RESOLVER
 
736
    G_UNLOCK(resolver);
 
737
#endif
 
738
 
 
739
    if (status == 0)
 
740
      {
 
741
        char buf[NI_MAXHOST];
 
742
        int name_status;
 
743
 
 
744
#ifndef HAVE_REENTRANT_RESOLVER
 
745
        G_LOCK(resolver);
 
746
#endif
 
747
        name_status = getnameinfo(addrinfo->ai_addr,
 
748
                                  addrinfo->ai_addrlen,
 
749
                                  buf,
 
750
                                  sizeof(buf),
 
751
                                  NULL,
 
752
                                  0,
 
753
                                  NI_NUMERICHOST);
 
754
#ifndef HAVE_REENTRANT_RESOLVER
 
755
        G_UNLOCK(resolver);
 
756
#endif
 
757
 
 
758
        if (name_status == 0)
 
759
          ip = g_strdup(buf);
 
760
      }
 
761
    else
 
762
      addrinfo = NULL;
 
763
 
 
764
    GDK_THREADS_ENTER();
 
765
 
 
766
    self_set_resolving(self, FALSE);
 
767
 
 
768
    if (selfp->addrinfo)
 
769
      freeaddrinfo(selfp->addrinfo);
 
770
    selfp->addrinfo = addrinfo;
 
771
 
 
772
    g_free(self->ip);
 
773
    self->ip = g_strdup(ip);
 
774
    g_object_notify(G_OBJECT(self), "ip");
 
775
 
 
776
    if (selfp->addrinfo)
 
777
      {
 
778
        selfp->sock = lm_shell_get_socket(lm_shell, selfp->addrinfo->ai_family);
 
779
        if (selfp->sock)
 
780
          {
 
781
            if (! selfp->sock->init_error)
 
782
              {
 
783
                /* complete success */
 
784
                self_clear_error(self, ERROR_RESOLVE);
 
785
 
 
786
                if (! selfp->send_timeout_id)
 
787
                  {
 
788
                    self_send_echo_request(self);       /* send first packet */
 
789
                    self_install_send_timeout(self);    /* install send loop */
 
790
                  }
 
791
              }
 
792
            else
 
793
              self_set_error(self, ERROR_RESOLVE, _("socket could not be initialized: %s"), selfp->sock->init_error);
 
794
          }
 
795
        else
 
796
          self_set_error(self, ERROR_RESOLVE, _("unsupported address family"));
 
797
 
 
798
        /* DNS success (even if no socket), refresh in one hour */
 
799
        self_install_resolve_timeout(self, 3600 * 1000);
 
800
      }
 
801
    else
 
802
      {
 
803
        selfp->sock = NULL;
 
804
        self_set_error(self, ERROR_RESOLVE, _("unable to resolve hostname: %s"), gai_strerror(status));
 
805
 
 
806
        /* DNS failure, retry in 10 seconds */
 
807
        self_install_resolve_timeout(self, 10 * 1000);
 
808
      }
 
809
 
 
810
    /* if an error was installed above, remove the send timeout */
 
811
    if (selfp->errors[ERROR_RESOLVE])
 
812
      lm_source_clear(&selfp->send_timeout_id);
 
813
 
 
814
    g_object_unref(self);
 
815
 
 
816
    /*
 
817
     * A note on gdk_flush(): as advised in the GDK threads
 
818
     * documentation, we only call gdk_flush() from a thread other
 
819
     * than our main thread.
 
820
     */
 
821
    gdk_flush();
 
822
    GDK_THREADS_LEAVE();
 
823
 
 
824
    return NULL;
 
825
  }}
 
826
#line 827 "lm-host.c"
 
827
#undef __GOB_FUNCTION__
 
828
 
 
829
#line 327 "src/lm-host.gob"
 
830
static void 
 
831
lm_host_install_resolve_timeout (LMHost * self, int delay)
 
832
{
 
833
#line 834 "lm-host.c"
 
834
#define __GOB_FUNCTION__ "LM:Host::install_resolve_timeout"
 
835
#line 327 "src/lm-host.gob"
 
836
        g_return_if_fail (self != NULL);
 
837
#line 327 "src/lm-host.gob"
 
838
        g_return_if_fail (LM_IS_HOST (self));
 
839
#line 840 "lm-host.c"
 
840
{
 
841
#line 329 "src/lm-host.gob"
 
842
        
 
843
    g_return_if_fail(selfp->resolve_timeout_id == 0);
 
844
    selfp->resolve_timeout_id = gdk_threads_add_timeout(delay, self_resolve_timeout_cb, self);
 
845
  }}
 
846
#line 847 "lm-host.c"
 
847
#undef __GOB_FUNCTION__
 
848
 
 
849
#line 334 "src/lm-host.gob"
 
850
static gboolean 
 
851
lm_host_resolve_timeout_cb (gpointer data)
 
852
{
 
853
#line 854 "lm-host.c"
 
854
#define __GOB_FUNCTION__ "LM:Host::resolve_timeout_cb"
 
855
{
 
856
#line 336 "src/lm-host.gob"
 
857
        
 
858
    Self *self = data;
 
859
 
 
860
    self_resolve(self);
 
861
 
 
862
    selfp->resolve_timeout_id = 0;
 
863
    return FALSE;               /* remove source */
 
864
  }}
 
865
#line 866 "lm-host.c"
 
866
#undef __GOB_FUNCTION__
 
867
 
 
868
#line 345 "src/lm-host.gob"
 
869
static void 
 
870
lm_host_send_echo_request (LMHost * self)
 
871
{
 
872
#line 873 "lm-host.c"
 
873
#define __GOB_FUNCTION__ "LM:Host::send_echo_request"
 
874
#line 345 "src/lm-host.gob"
 
875
        g_return_if_fail (self != NULL);
 
876
#line 345 "src/lm-host.gob"
 
877
        g_return_if_fail (LM_IS_HOST (self));
 
878
#line 879 "lm-host.c"
 
879
{
 
880
#line 347 "src/lm-host.gob"
 
881
        
 
882
    GError *err = NULL;
 
883
 
 
884
    g_return_if_fail(selfp->sock != NULL);
 
885
    g_return_if_fail(selfp->sock->init_error == NULL);
 
886
    g_return_if_fail(selfp->addrinfo != NULL);
 
887
 
 
888
    if (lm_icmp_send_echo_request(selfp->sock, selfp->addrinfo, selfp->host_id, selfp->sent_seq, &err))
 
889
      {
 
890
        RequestInfo *req;
 
891
 
 
892
        req = &selfp->requests[selfp->sent_seq];
 
893
        req->sent_time = lm_get_ticks();
 
894
 
 
895
        selfp->sent_seq++;
 
896
 
 
897
        self_clear_error(self, ERROR_SEND);
 
898
 
 
899
        if (! selfp->dead_timeout_id)
 
900
          {
 
901
            int timeout;
 
902
 
 
903
            if (selfp->max_roundtrip_time > 0)
 
904
              {
 
905
                timeout = (selfp->max_roundtrip_time / 1000) * 2;
 
906
                if (timeout < MIN_TIMEOUT)
 
907
                  timeout = MIN_TIMEOUT;
 
908
              }
 
909
            else
 
910
              timeout = DEFAULT_TIMEOUT;
 
911
 
 
912
            selfp->dead_timeout_id = gdk_threads_add_timeout(timeout, self_dead_timeout_cb, self);
 
913
          }
 
914
      }
 
915
    else
 
916
      {
 
917
        self_set_error(self, ERROR_SEND, _("unable to send echo request: %s"), err->message);
 
918
        g_error_free(err);
 
919
      }
 
920
  }}
 
921
#line 922 "lm-host.c"
 
922
#undef __GOB_FUNCTION__
 
923
 
 
924
#line 388 "src/lm-host.gob"
 
925
static void 
 
926
lm_host_delay_changed_h (GObject * object, GParamSpec * pspec, gpointer user_data)
 
927
{
 
928
#line 929 "lm-host.c"
 
929
#define __GOB_FUNCTION__ "LM:Host::delay_changed_h"
 
930
{
 
931
#line 390 "src/lm-host.gob"
 
932
        
 
933
    Self *self = user_data;
 
934
 
 
935
    if (selfp->send_timeout_id)
 
936
      {
 
937
        lm_source_clear(&selfp->send_timeout_id);
 
938
        self_install_send_timeout(self);
 
939
      }
 
940
    /* else we cannot send packets: do not install the send timeout */
 
941
  }}
 
942
#line 943 "lm-host.c"
 
943
#undef __GOB_FUNCTION__
 
944
 
 
945
#line 401 "src/lm-host.gob"
 
946
static void 
 
947
lm_host_install_send_timeout (LMHost * self)
 
948
{
 
949
#line 950 "lm-host.c"
 
950
#define __GOB_FUNCTION__ "LM:Host::install_send_timeout"
 
951
#line 401 "src/lm-host.gob"
 
952
        g_return_if_fail (self != NULL);
 
953
#line 401 "src/lm-host.gob"
 
954
        g_return_if_fail (LM_IS_HOST (self));
 
955
#line 956 "lm-host.c"
 
956
{
 
957
#line 403 "src/lm-host.gob"
 
958
        
 
959
    g_return_if_fail(selfp->send_timeout_id == 0);
 
960
    g_return_if_fail(selfp->sock != NULL);
 
961
    g_return_if_fail(selfp->sock->init_error == NULL);
 
962
    g_return_if_fail(selfp->addrinfo != NULL);
 
963
 
 
964
    selfp->send_timeout_id = gdk_threads_add_timeout(self->applet->delay, self_send_timeout_cb, self);
 
965
  }}
 
966
#line 967 "lm-host.c"
 
967
#undef __GOB_FUNCTION__
 
968
 
 
969
#line 412 "src/lm-host.gob"
 
970
static gboolean 
 
971
lm_host_send_timeout_cb (gpointer data)
 
972
{
 
973
#line 974 "lm-host.c"
 
974
#define __GOB_FUNCTION__ "LM:Host::send_timeout_cb"
 
975
{
 
976
#line 414 "src/lm-host.gob"
 
977
        
 
978
    Self *self = data;
 
979
 
 
980
    self_send_echo_request(self);
 
981
 
 
982
    return TRUE;                /* keep source */
 
983
  }}
 
984
#line 985 "lm-host.c"
 
985
#undef __GOB_FUNCTION__
 
986
 
 
987
#line 422 "src/lm-host.gob"
 
988
static gboolean 
 
989
lm_host_dead_timeout_cb (gpointer data)
 
990
{
 
991
#line 992 "lm-host.c"
 
992
#define __GOB_FUNCTION__ "LM:Host::dead_timeout_cb"
 
993
{
 
994
#line 424 "src/lm-host.gob"
 
995
        
 
996
    Self *self = data;
 
997
 
 
998
    self_set_alive(self, FALSE);
 
999
 
 
1000
    selfp->dead_timeout_id = 0;
 
1001
    return FALSE;               /* remove source */
 
1002
  }}
 
1003
#line 1004 "lm-host.c"
 
1004
#undef __GOB_FUNCTION__
 
1005
 
 
1006
#line 433 "src/lm-host.gob"
 
1007
void 
 
1008
lm_host_reply_received (LMHost * self, const LMICMPReply * reply)
 
1009
{
 
1010
#line 1011 "lm-host.c"
 
1011
#define __GOB_FUNCTION__ "LM:Host::reply_received"
 
1012
#line 433 "src/lm-host.gob"
 
1013
        g_return_if_fail (self != NULL);
 
1014
#line 433 "src/lm-host.gob"
 
1015
        g_return_if_fail (LM_IS_HOST (self));
 
1016
#line 433 "src/lm-host.gob"
 
1017
        g_return_if_fail (reply != NULL);
 
1018
#line 1019 "lm-host.c"
 
1019
{
 
1020
#line 435 "src/lm-host.gob"
 
1021
        
 
1022
    RequestInfo *req;
 
1023
 
 
1024
    /*
 
1025
     * If there is no send timeout, an error (DNS or socket) has
 
1026
     * occurred and we are unable to send packets: ignore this reply,
 
1027
     * otherwise we would set alive back to TRUE.
 
1028
     */
 
1029
    if (! selfp->send_timeout_id)
 
1030
      return;
 
1031
 
 
1032
    req = &selfp->requests[reply->seq];
 
1033
    if (! req->sent_time)
 
1034
      return; /* no matching request, ignore */
 
1035
 
 
1036
    if (reply->received_time < req->sent_time)
 
1037
      /*
 
1038
       * Negative roundtrip-time: this should not normally happen
 
1039
       * since we use a monotonic clock source, but it is possible
 
1040
       * that the OS improperly implements it, or that the monitored
 
1041
       * host returns garbage, etc. Acknowledge the reply but
 
1042
       * otherwise ignore it.
 
1043
       */
 
1044
      goto end;
 
1045
 
 
1046
    if (reply->error)
 
1047
      self_set_error(self, ERROR_RECEIVE, "%s", reply->error);
 
1048
    else
 
1049
      {
 
1050
        self_clear_error(self, ERROR_RECEIVE);
 
1051
        self_set_roundtrip_time(self, reply->received_time - req->sent_time);
 
1052
      }
 
1053
 
 
1054
  end:
 
1055
    /* we have matched the request, clear it */
 
1056
    req->sent_time = 0;
 
1057
  }}
 
1058
#line 1059 "lm-host.c"
 
1059
#undef __GOB_FUNCTION__