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

« back to all changes in this revision

Viewing changes to build/src/lm-shell.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 <string.h> /* memset() */
 
12
 
 
13
#include "lm-shell.h"
 
14
 
 
15
#include "lm-shell-private.h"
 
16
 
 
17
#ifdef G_LIKELY
 
18
#define ___GOB_LIKELY(expr) G_LIKELY(expr)
 
19
#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)
 
20
#else /* ! G_LIKELY */
 
21
#define ___GOB_LIKELY(expr) (expr)
 
22
#define ___GOB_UNLIKELY(expr) (expr)
 
23
#endif /* G_LIKELY */
 
24
 
 
25
#line 37 "src/lm-shell.gob"
 
26
 
 
27
#include <unistd.h>
 
28
#include <fcntl.h>
 
29
#include <errno.h>
 
30
#include <glib/gi18n.h>
 
31
#include "lm-applet.h"
 
32
#include "lm-host.h"
 
33
#include "lm-util.h"
 
34
 
 
35
typedef struct
 
36
{
 
37
  LMShell               *self;
 
38
  const LMSocket        *sock;
 
39
} WatchInfo;
 
40
 
 
41
LMShell *lm_shell = NULL;
 
42
 
 
43
#line 44 "lm-shell.c"
 
44
/* self casting macros */
 
45
#define SELF(x) LM_SHELL(x)
 
46
#define SELF_CONST(x) LM_SHELL_CONST(x)
 
47
#define IS_SELF(x) LM_IS_SHELL(x)
 
48
#define TYPE_SELF LM_TYPE_SHELL
 
49
#define SELF_CLASS(x) LM_SHELL_CLASS(x)
 
50
 
 
51
#define SELF_GET_CLASS(x) LM_SHELL_GET_CLASS(x)
 
52
 
 
53
/* self typedefs */
 
54
typedef LMShell Self;
 
55
typedef LMShellClass SelfClass;
 
56
 
 
57
/* here are local prototypes */
 
58
static void ___object_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
 
59
static void ___object_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
 
60
#line 0 "src/lm-shell.gob"
 
61
static void lm_shell_init (LMShell * o);
 
62
#line 63 "lm-shell.c"
 
63
#line 0 "src/lm-shell.gob"
 
64
static void lm_shell_class_init (LMShellClass * c);
 
65
#line 66 "lm-shell.c"
 
66
#line 80 "src/lm-shell.gob"
 
67
static void lm_shell_constructor (LMShell * self);
 
68
#line 69 "lm-shell.c"
 
69
#line 98 "src/lm-shell.gob"
 
70
static void lm_shell_init_socket (LMShell * self, LMSocket * sock);
 
71
#line 72 "lm-shell.c"
 
72
#line 123 "src/lm-shell.gob"
 
73
static gboolean lm_shell_socket_watch_cb (GIOChannel * source, GIOCondition condition, gpointer data);
 
74
#line 75 "lm-shell.c"
 
75
#line 146 "src/lm-shell.gob"
 
76
static LMHost * lm_shell_get_host (LMShell * self, int host_id);
 
77
#line 78 "lm-shell.c"
 
78
 
 
79
enum {
 
80
        PROP_0,
 
81
        PROP_SOCKETS,
 
82
        PROP_HOST_COUNT
 
83
};
 
84
 
 
85
/* pointer to the class of our parent */
 
86
static GObjectClass *parent_class = NULL;
 
87
 
 
88
/* Short form macros */
 
89
#define self_get_host_count lm_shell_get_host_count
 
90
#define self_init_socket lm_shell_init_socket
 
91
#define self_socket_watch_cb lm_shell_socket_watch_cb
 
92
#define self_get_host lm_shell_get_host
 
93
#define self_allocate_host_id lm_shell_allocate_host_id
 
94
#define self_deallocate_host_id lm_shell_deallocate_host_id
 
95
#define self_get_socket lm_shell_get_socket
 
96
#define self_new lm_shell_new
 
97
GType
 
98
lm_shell_get_type (void)
 
99
{
 
100
        static GType type = 0;
 
101
 
 
102
        if ___GOB_UNLIKELY(type == 0) {
 
103
                static const GTypeInfo info = {
 
104
                        sizeof (LMShellClass),
 
105
                        (GBaseInitFunc) NULL,
 
106
                        (GBaseFinalizeFunc) NULL,
 
107
                        (GClassInitFunc) lm_shell_class_init,
 
108
                        (GClassFinalizeFunc) NULL,
 
109
                        NULL /* class_data */,
 
110
                        sizeof (LMShell),
 
111
                        0 /* n_preallocs */,
 
112
                        (GInstanceInitFunc) lm_shell_init,
 
113
                        NULL
 
114
                };
 
115
 
 
116
                type = g_type_register_static (G_TYPE_OBJECT, "LMShell", &info, (GTypeFlags)0);
 
117
        }
 
118
 
 
119
        return type;
 
120
}
 
121
 
 
122
/* a macro for creating a new object of our type */
 
123
#define GET_NEW ((LMShell *)g_object_new(lm_shell_get_type(), NULL))
 
124
 
 
125
/* a function for creating a new object of our type */
 
126
#include <stdarg.h>
 
127
static LMShell * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED;
 
128
static LMShell *
 
129
GET_NEW_VARG (const char *first, ...)
 
130
{
 
131
        LMShell *ret;
 
132
        va_list ap;
 
133
        va_start (ap, first);
 
134
        ret = (LMShell *)g_object_new_valist (lm_shell_get_type (), first, ap);
 
135
        va_end (ap);
 
136
        return ret;
 
137
}
 
138
 
 
139
 
 
140
static GObject *
 
141
___constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
 
142
{
 
143
#define __GOB_FUNCTION__ "LM:Shell::constructor"
 
144
        GObject *obj_self;
 
145
        LMShell *self;
 
146
        obj_self = G_OBJECT_CLASS (parent_class)->constructor (type, n_construct_properties, construct_properties);
 
147
        self = LM_SHELL (obj_self);
 
148
#line 80 "src/lm-shell.gob"
 
149
        lm_shell_constructor (self);
 
150
#line 151 "lm-shell.c"
 
151
        return obj_self;
 
152
}
 
153
#undef __GOB_FUNCTION__
 
154
 
 
155
 
 
156
static void
 
157
___finalize(GObject *obj_self)
 
158
{
 
159
#define __GOB_FUNCTION__ "LM:Shell::finalize"
 
160
        LMShell *self G_GNUC_UNUSED = LM_SHELL (obj_self);
 
161
        gpointer priv G_GNUC_UNUSED = self->_priv;
 
162
        if(G_OBJECT_CLASS(parent_class)->finalize) \
 
163
                (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self);
 
164
}
 
165
#undef __GOB_FUNCTION__
 
166
 
 
167
static void 
 
168
lm_shell_init (LMShell * o G_GNUC_UNUSED)
 
169
{
 
170
#define __GOB_FUNCTION__ "LM:Shell::init"
 
171
        o->_priv = G_TYPE_INSTANCE_GET_PRIVATE(o,LM_TYPE_SHELL,LMShellPrivate);
 
172
}
 
173
#undef __GOB_FUNCTION__
 
174
static void 
 
175
lm_shell_class_init (LMShellClass * c G_GNUC_UNUSED)
 
176
{
 
177
#define __GOB_FUNCTION__ "LM:Shell::class_init"
 
178
        GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;
 
179
 
 
180
        g_type_class_add_private(c,sizeof(LMShellPrivate));
 
181
 
 
182
        parent_class = g_type_class_ref (G_TYPE_OBJECT);
 
183
 
 
184
        g_object_class->constructor = ___constructor;
 
185
        g_object_class->finalize = ___finalize;
 
186
        g_object_class->get_property = ___object_get_property;
 
187
        g_object_class->set_property = ___object_set_property;
 
188
    {
 
189
        GParamSpec   *param_spec;
 
190
 
 
191
        param_spec = g_param_spec_pointer
 
192
                ("sockets" /* name */,
 
193
                 NULL /* nick */,
 
194
                 NULL /* blurb */,
 
195
                 (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
196
        g_object_class_install_property (g_object_class,
 
197
                PROP_SOCKETS,
 
198
                param_spec);
 
199
        param_spec = g_param_spec_int
 
200
                ("host_count" /* name */,
 
201
                 NULL /* nick */,
 
202
                 NULL /* blurb */,
 
203
                 G_MININT /* minimum */,
 
204
                 G_MAXINT /* maximum */,
 
205
                 0 /* default_value */,
 
206
                 (GParamFlags)(G_PARAM_READABLE));
 
207
        g_object_class_install_property (g_object_class,
 
208
                PROP_HOST_COUNT,
 
209
                param_spec);
 
210
    }
 
211
}
 
212
#undef __GOB_FUNCTION__
 
213
 
 
214
static void
 
215
___object_set_property (GObject *object,
 
216
        guint property_id,
 
217
        const GValue *VAL G_GNUC_UNUSED,
 
218
        GParamSpec *pspec G_GNUC_UNUSED)
 
219
#define __GOB_FUNCTION__ "LM:Shell::set_property"
 
220
{
 
221
        LMShell *self G_GNUC_UNUSED;
 
222
 
 
223
        self = LM_SHELL (object);
 
224
 
 
225
        switch (property_id) {
 
226
        case PROP_SOCKETS:
 
227
                {
 
228
#line 60 "src/lm-shell.gob"
 
229
self->_priv->sockets = g_value_get_pointer (VAL);
 
230
#line 231 "lm-shell.c"
 
231
                }
 
232
                break;
 
233
        default:
 
234
/* Apparently in g++ this is needed, glib is b0rk */
 
235
#ifndef __PRETTY_FUNCTION__
 
236
#  undef G_STRLOC
 
237
#  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
 
238
#endif
 
239
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
240
                break;
 
241
        }
 
242
}
 
243
#undef __GOB_FUNCTION__
 
244
 
 
245
static void
 
246
___object_get_property (GObject *object,
 
247
        guint property_id,
 
248
        GValue *VAL G_GNUC_UNUSED,
 
249
        GParamSpec *pspec G_GNUC_UNUSED)
 
250
#define __GOB_FUNCTION__ "LM:Shell::get_property"
 
251
{
 
252
        LMShell *self G_GNUC_UNUSED;
 
253
 
 
254
        self = LM_SHELL (object);
 
255
 
 
256
        switch (property_id) {
 
257
        case PROP_SOCKETS:
 
258
                {
 
259
#line 60 "src/lm-shell.gob"
 
260
g_value_set_pointer (VAL, self->_priv->sockets);
 
261
#line 262 "lm-shell.c"
 
262
                }
 
263
                break;
 
264
        case PROP_HOST_COUNT:
 
265
                {
 
266
#line 69 "src/lm-shell.gob"
 
267
 
 
268
      int count = 0;
 
269
      int i;
 
270
 
 
271
      for (i = 0; i < G_N_ELEMENTS(selfp->hosts); i++)
 
272
        if (selfp->hosts[i])
 
273
          count++;
 
274
 
 
275
      g_value_set_int(VAL, count);
 
276
    
 
277
#line 278 "lm-shell.c"
 
278
                }
 
279
                break;
 
280
        default:
 
281
/* Apparently in g++ this is needed, glib is b0rk */
 
282
#ifndef __PRETTY_FUNCTION__
 
283
#  undef G_STRLOC
 
284
#  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
 
285
#endif
 
286
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
287
                break;
 
288
        }
 
289
}
 
290
#undef __GOB_FUNCTION__
 
291
 
 
292
 
 
293
 
 
294
#line 69 "src/lm-shell.gob"
 
295
gint 
 
296
lm_shell_get_host_count (LMShell * self)
 
297
{
 
298
#line 299 "lm-shell.c"
 
299
#define __GOB_FUNCTION__ "LM:Shell::get_host_count"
 
300
{
 
301
#line 67 "src/lm-shell.gob"
 
302
                gint val; g_object_get (G_OBJECT (self), "host_count", &val, NULL); return val;
 
303
}}
 
304
#line 305 "lm-shell.c"
 
305
#undef __GOB_FUNCTION__
 
306
 
 
307
#line 80 "src/lm-shell.gob"
 
308
static void 
 
309
lm_shell_constructor (LMShell * self)
 
310
{
 
311
#line 312 "lm-shell.c"
 
312
#define __GOB_FUNCTION__ "LM:Shell::constructor"
 
313
{
 
314
#line 81 "src/lm-shell.gob"
 
315
        
 
316
    GSList *l;
 
317
 
 
318
    g_assert(lm_shell == NULL);
 
319
 
 
320
    lm_shell = self;
 
321
    lm_add_weak_pointer(&lm_shell);
 
322
 
 
323
    /* unique identifier for our ICMP packets */
 
324
    self->icmp_ident = getpid() & 0xffff;
 
325
 
 
326
    LM_LIST_FOREACH(l, selfp->sockets)
 
327
      self_init_socket(self, l->data);
 
328
 
 
329
    self->tooltips = lm_tooltips_new();
 
330
  }}
 
331
#line 332 "lm-shell.c"
 
332
#undef __GOB_FUNCTION__
 
333
 
 
334
#line 98 "src/lm-shell.gob"
 
335
static void 
 
336
lm_shell_init_socket (LMShell * self, LMSocket * sock)
 
337
{
 
338
#line 339 "lm-shell.c"
 
339
#define __GOB_FUNCTION__ "LM:Shell::init_socket"
 
340
#line 98 "src/lm-shell.gob"
 
341
        g_return_if_fail (self != NULL);
 
342
#line 98 "src/lm-shell.gob"
 
343
        g_return_if_fail (LM_IS_SHELL (self));
 
344
#line 98 "src/lm-shell.gob"
 
345
        g_return_if_fail (sock != NULL);
 
346
#line 347 "lm-shell.c"
 
347
{
 
348
#line 100 "src/lm-shell.gob"
 
349
        
 
350
    if (! sock->init_error)
 
351
      {
 
352
        int flags;
 
353
 
 
354
        flags = fcntl(sock->desc, F_GETFL, 0);
 
355
        if (fcntl(sock->desc, F_SETFL, flags | O_NONBLOCK) < 0)
 
356
          sock->init_error = g_strdup_printf(_("unable to set O_NONBLOCK flag: %s"), g_strerror(errno));
 
357
        else
 
358
          {
 
359
            GIOChannel *channel;
 
360
            WatchInfo *info;
 
361
 
 
362
            info = g_new0(WatchInfo, 1);
 
363
            info->self = self;
 
364
            info->sock = sock;
 
365
 
 
366
            channel = g_io_channel_unix_new(sock->desc);
 
367
            g_io_add_watch_full(channel, G_PRIORITY_HIGH, G_IO_IN, self_socket_watch_cb, info, NULL);
 
368
          }
 
369
      }
 
370
  }}
 
371
#line 372 "lm-shell.c"
 
372
#undef __GOB_FUNCTION__
 
373
 
 
374
#line 123 "src/lm-shell.gob"
 
375
static gboolean 
 
376
lm_shell_socket_watch_cb (GIOChannel * source, GIOCondition condition, gpointer data)
 
377
{
 
378
#line 379 "lm-shell.c"
 
379
#define __GOB_FUNCTION__ "LM:Shell::socket_watch_cb"
 
380
{
 
381
#line 125 "src/lm-shell.gob"
 
382
        
 
383
    WatchInfo *info = data;
 
384
    Self *self = info->self;
 
385
    LMICMPReply reply;
 
386
 
 
387
    if (lm_icmp_reply_get(info->sock, &reply))
 
388
      {
 
389
        LMHost *host;
 
390
 
 
391
        host = self_get_host(self, reply.host_id);
 
392
        if (host)
 
393
          {
 
394
            GDK_THREADS_ENTER();
 
395
            lm_host_reply_received(host, &reply);
 
396
            GDK_THREADS_LEAVE();
 
397
          }
 
398
      }
 
399
 
 
400
    return TRUE;                /* keep source */
 
401
  }}
 
402
#line 403 "lm-shell.c"
 
403
#undef __GOB_FUNCTION__
 
404
 
 
405
#line 146 "src/lm-shell.gob"
 
406
static LMHost * 
 
407
lm_shell_get_host (LMShell * self, int host_id)
 
408
{
 
409
#line 410 "lm-shell.c"
 
410
#define __GOB_FUNCTION__ "LM:Shell::get_host"
 
411
#line 146 "src/lm-shell.gob"
 
412
        g_return_val_if_fail (self != NULL, (LMHost * )0);
 
413
#line 146 "src/lm-shell.gob"
 
414
        g_return_val_if_fail (LM_IS_SHELL (self), (LMHost * )0);
 
415
#line 146 "src/lm-shell.gob"
 
416
        g_return_val_if_fail (host_id >= 0, (LMHost * )0);
 
417
#line 146 "src/lm-shell.gob"
 
418
        g_return_val_if_fail (host_id < LM_MAX_HOSTS, (LMHost * )0);
 
419
#line 420 "lm-shell.c"
 
420
{
 
421
#line 148 "src/lm-shell.gob"
 
422
        
 
423
    return selfp->hosts[host_id];
 
424
  }}
 
425
#line 426 "lm-shell.c"
 
426
#undef __GOB_FUNCTION__
 
427
 
 
428
#line 152 "src/lm-shell.gob"
 
429
int 
 
430
lm_shell_allocate_host_id (LMShell * self, LMHost * host)
 
431
{
 
432
#line 433 "lm-shell.c"
 
433
#define __GOB_FUNCTION__ "LM:Shell::allocate_host_id"
 
434
#line 152 "src/lm-shell.gob"
 
435
        g_return_val_if_fail (self != NULL, (int )0);
 
436
#line 152 "src/lm-shell.gob"
 
437
        g_return_val_if_fail (LM_IS_SHELL (self), (int )0);
 
438
#line 152 "src/lm-shell.gob"
 
439
        g_return_val_if_fail (host != NULL, (int )0);
 
440
#line 152 "src/lm-shell.gob"
 
441
        g_return_val_if_fail (LM_IS_HOST (host), (int )0);
 
442
#line 443 "lm-shell.c"
 
443
{
 
444
#line 154 "src/lm-shell.gob"
 
445
        
 
446
    int host_id;
 
447
 
 
448
    for (host_id = 0; host_id < G_N_ELEMENTS(selfp->hosts); host_id++)
 
449
      if (! selfp->hosts[host_id])
 
450
        {
 
451
          selfp->hosts[host_id] = host;
 
452
          g_object_notify(G_OBJECT(self), "host-count");
 
453
          return host_id;
 
454
        }
 
455
 
 
456
    g_assert_not_reached();
 
457
    return -1;
 
458
  }}
 
459
#line 460 "lm-shell.c"
 
460
#undef __GOB_FUNCTION__
 
461
 
 
462
#line 169 "src/lm-shell.gob"
 
463
void 
 
464
lm_shell_deallocate_host_id (LMShell * self, int host_id)
 
465
{
 
466
#line 467 "lm-shell.c"
 
467
#define __GOB_FUNCTION__ "LM:Shell::deallocate_host_id"
 
468
#line 169 "src/lm-shell.gob"
 
469
        g_return_if_fail (self != NULL);
 
470
#line 169 "src/lm-shell.gob"
 
471
        g_return_if_fail (LM_IS_SHELL (self));
 
472
#line 473 "lm-shell.c"
 
473
{
 
474
#line 171 "src/lm-shell.gob"
 
475
        
 
476
    g_return_if_fail(selfp->hosts[host_id] != NULL);
 
477
 
 
478
    selfp->hosts[host_id] = NULL;
 
479
    g_object_notify(G_OBJECT(self), "host-count");
 
480
  }}
 
481
#line 482 "lm-shell.c"
 
482
#undef __GOB_FUNCTION__
 
483
 
 
484
#line 178 "src/lm-shell.gob"
 
485
const LMSocket * 
 
486
lm_shell_get_socket (LMShell * self, int domain)
 
487
{
 
488
#line 489 "lm-shell.c"
 
489
#define __GOB_FUNCTION__ "LM:Shell::get_socket"
 
490
#line 178 "src/lm-shell.gob"
 
491
        g_return_val_if_fail (self != NULL, (const LMSocket * )0);
 
492
#line 178 "src/lm-shell.gob"
 
493
        g_return_val_if_fail (LM_IS_SHELL (self), (const LMSocket * )0);
 
494
#line 495 "lm-shell.c"
 
495
{
 
496
#line 180 "src/lm-shell.gob"
 
497
        
 
498
    GSList *l;
 
499
 
 
500
    LM_LIST_FOREACH(l, selfp->sockets)
 
501
      {
 
502
        const LMSocket *sock = l->data;
 
503
 
 
504
        if (sock->domain == domain)
 
505
          return sock;
 
506
      }
 
507
 
 
508
    return NULL;
 
509
  }}
 
510
#line 511 "lm-shell.c"
 
511
#undef __GOB_FUNCTION__
 
512
 
 
513
#line 194 "src/lm-shell.gob"
 
514
LMShell * 
 
515
lm_shell_new (GSList * sockets)
 
516
{
 
517
#line 518 "lm-shell.c"
 
518
#define __GOB_FUNCTION__ "LM:Shell::new"
 
519
{
 
520
#line 196 "src/lm-shell.gob"
 
521
        
 
522
    return GET_NEW_VARG(LM_SHELL_PROP_SOCKETS(sockets), NULL);
 
523
  }}
 
524
#line 525 "lm-shell.c"
 
525
#undef __GOB_FUNCTION__