aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-component-listener.c
blob: 1e7027f33d2c6a82900b87789ea9a472c0c3b98b (plain) (blame)
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Component listener.
 *
 * Author:
 *   Rodrigo Moya <rodrigo@ximian.com>
 *
 * Copyright 2002, Ximian, Inc.
 */

#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-object.h>
#include "e-component-listener.h"
#include <libgnome/gnome-i18n.h>

#define PARENT_TYPE GTK_TYPE_OBJECT

struct _EComponentListenerPrivate {
    Bonobo_Unknown component;
};

static void e_component_listener_class_init (EComponentListenerClass *klass);
static void e_component_listener_init       (EComponentListener *cl, EComponentListenerClass *klass);
static void e_component_listener_finalize   (GObject *object);

static GObjectClass *parent_class = NULL;
static GList *watched_connections = NULL;

enum {
    COMPONENT_DIED,
    LAST_SIGNAL
};

static guint comp_listener_signals[LAST_SIGNAL];

static void
connection_listen_cb (gpointer object, gpointer user_data)
{
    GList *l, *next = NULL;
    EComponentListener *cl;

    for (l = watched_connections; l != NULL; l = next) {
        next = l->next;
        cl = l->data;

        switch (ORBit_small_get_connection_status (cl->priv->component)) {
        case ORBIT_CONNECTION_DISCONNECTED :
            watched_connections = g_list_delete_link (watched_connections, l);

            g_object_ref (cl);
            g_signal_emit (cl, comp_listener_signals[COMPONENT_DIED], 0);
            cl->priv->component = CORBA_OBJECT_NIL;
            g_object_unref (cl);
            break;
        default :
            break;
        }
    }
}

static void
e_component_listener_class_init (EComponentListenerClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    parent_class = g_type_class_peek_parent (klass);

    object_class->finalize = e_component_listener_finalize;
    klass->component_died = NULL;

    comp_listener_signals[COMPONENT_DIED] =
        g_signal_new ("component_died",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (EComponentListenerClass, component_died),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
}

static void
e_component_listener_init (EComponentListener *cl, EComponentListenerClass *klass)
{
    /* allocate internal structure */
    cl->priv = g_new (EComponentListenerPrivate, 1);
    cl->priv->component = CORBA_OBJECT_NIL;
}

static void
e_component_listener_finalize (GObject *object)
{
    EComponentListener *cl = (EComponentListener *) object;

    g_return_if_fail (E_IS_COMPONENT_LISTENER (cl));

    watched_connections = g_list_remove (watched_connections, cl);

    if (cl->priv->component != CORBA_OBJECT_NIL)
        cl->priv->component = CORBA_OBJECT_NIL;

    /* free memory */
    g_free (cl->priv);
    cl->priv = NULL;

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

GType
e_component_listener_get_type (void)
{
    static GType type = 0;

    if (!type) {
        static GTypeInfo info = {
                        sizeof (EComponentListenerClass),
                        (GBaseInitFunc) NULL,
                        (GBaseFinalizeFunc) NULL,
                        (GClassInitFunc) e_component_listener_class_init,
                        NULL, NULL,
                        sizeof (EComponentListener),
                        0,
                        (GInstanceInitFunc) e_component_listener_init
                };
        type = g_type_register_static (G_TYPE_OBJECT, "EComponentListener", &info, 0);
    }

    return type;
}

/**
 * e_component_listener_new
 * @comp: Component to listen for.
 *
 * Create a new #EComponentListener object, which allows to listen
 * for a given component and get notified when that component dies.
 *
 * Returns: a component listener object.
 */
EComponentListener *
e_component_listener_new (Bonobo_Unknown comp)
{
    EComponentListener *cl;

    g_return_val_if_fail (comp != NULL, NULL);

    cl = g_object_new (E_COMPONENT_LISTENER_TYPE, NULL);
    cl->priv->component = comp;

    /* watch the connection */
    ORBit_small_listen_for_broken (comp, G_CALLBACK (connection_listen_cb), cl);
    watched_connections = g_list_prepend (watched_connections, cl);

    return cl;
}

Bonobo_Unknown
e_component_listener_get_component (EComponentListener *cl)
{
    g_return_val_if_fail (E_IS_COMPONENT_LISTENER (cl), CORBA_OBJECT_NIL);
    return cl->priv->component;
}

void
e_component_listener_set_component (EComponentListener *cl, Bonobo_Unknown comp)
{
    g_return_if_fail (E_IS_COMPONENT_LISTENER (cl));

    cl->priv->component = comp;
    ORBit_small_listen_for_broken (comp, G_CALLBACK (connection_listen_cb), cl);
}
389f'>gdl178logstatsplain d---------gigi178logstatsplain d---------girara146logstatsplain d---------gnocl141logstatsplain d---------gnome-desktop-sharp20178logstatsplain d---------gnome-sharp20178logstatsplain d---------gnomemm110logstatsplain d---------gnustep-art36logstatsplain d---------gnustep-back185logstatsplain d---------gnustep-cairo36logstatsplain d---------gnustep-gui178logstatsplain d---------gnustep-xdps36logstatsplain d---------gstreamer-plugins-pango36logstatsplain d---------gtk-sharp10178logstatsplain d---------gtk-sharp20146logstatsplain d---------gtk12178logstatsplain d---------gtk20-reference73logstatsplain d---------gtk20178logstatsplain d---------gtk30-reference73logstatsplain d---------gtk30178logstatsplain d---------gtkada178logstatsplain d---------gtkdatabox178logstatsplain d---------gtkextra2178logstatsplain d---------gtkglarea146logstatsplain d---------gtkglarea2146logstatsplain d---------gtkglext146logstatsplain d---------gtkglextmm146logstatsplain d---------gtkimageview146logstatsplain d---------gtkmathview146logstatsplain d---------gtkmm12217logstatsplain d---------gtkmm20-reference110logstatsplain d---------gtkmm20178logstatsplain d---------gtkmm24-reference110logstatsplain d---------gtkmm24146logstatsplain d---------gtkmm30-reference110logstatsplain d---------gtkmm30146logstatsplain d---------gtksourceview-reference73logstatsplain d---------gtksourceview-sharp178logstatsplain d---------gtksourceview178logstatsplain d---------gtksourceview2-reference73logstatsplain d---------gtksourceview2146logstatsplain d---------gtkunique146logstatsplain d---------gtoolkit178logstatsplain d---------guile-gtk178logstatsplain d---------hippo-canvas146logstatsplain d---------hs-GLUT141logstatsplain d---------hs-OpenGL109logstatsplain d---------hs-frantk217logstatsplain d---------hs-gtk109logstatsplain d---------hs-gtk2hs73logstatsplain d---------hs-gtkglext109logstatsplain d---------hs-gtksourceview2109logstatsplain d---------hs-pango109logstatsplain d---------hs-vte109logstatsplain d---------hs-wx109logstatsplain d---------hs-wxc141logstatsplain d---------hs-wxcore141logstatsplain d---------hs-wxdirect109logstatsplain d---------irrlicht178logstatsplain d---------itk178logstatsplain d---------iwidgets178logstatsplain d---------lesstif185logstatsplain d---------libXaw146logstatsplain d---------libXmu146logstatsplain d---------libXt146logstatsplain d---------libbonoboui-reference73logstatsplain d---------libbonoboui178logstatsplain d---------libbonobouimm178logstatsplain d---------libgail-gnome109logstatsplain d---------libgdiplus141logstatsplain d---------libgnomeprintui146logstatsplain d---------libgnomeprintuimm146logstatsplain d---------libgnomeui-reference73logstatsplain d---------libgnomeui146logstatsplain d---------libgnomeuimm178logstatsplain d---------libgnomeuimm26146logstatsplain d---------libgtk-java217logstatsplain d---------libgtksourceviewmm146logstatsplain d---------libpanelappletmm146logstatsplain d---------libsexy146logstatsplain d---------libsexymm146logstatsplain d---------libwnck-reference73logstatsplain d---------libwnck146logstatsplain d---------libxaw3dxft146logstatsplain d---------libxfce4gui146logstatsplain d---------libzvt178logstatsplain d---------linux-f10-blt151logstatsplain d---------linux-f10-gtk156logstatsplain d---------linux-f10-gtk2114logstatsplain d---------linux-f10-openmotif151logstatsplain d---------linux-f10-pango114logstatsplain d---------linux-f10-qt33119logstatsplain d---------linux-f10-tk85114logstatsplain d---------linux-gtk156logstatsplain d---------linux-gtk2151logstatsplain d---------linux-openmotif151logstatsplain d---------linux-pango151logstatsplain d---------linux-qt33156logstatsplain d---------mesgui178logstatsplain d---------movingmotif178logstatsplain d---------mowitz178logstatsplain d---------neXtaw178logstatsplain d---------nucleo178logstatsplain d---------ocaml-lablgtk146logstatsplain d---------ocaml-lablgtk2178logstatsplain d---------open-motif218logstatsplain d---------otk109logstatsplain d---------p5-Alien-wxWidgets146logstatsplain d---------p5-GdkImlib178logstatsplain d---------p5-Glade2146logstatsplain d---------p5-Gnome2-Canvas146logstatsplain d---------p5-Gnome2-VFS146logstatsplain d---------p5-Gnome2146logstatsplain d---------p5-Gtk178logstatsplain d---------p5-Gtk2-Chmod146logstatsplain d---------p5-Gtk2-Ex-Dialogs146logstatsplain d---------p5-Gtk2-Ex-FormFactory146logstatsplain d---------p5-Gtk2-Ex-PodViewer146logstatsplain d---------p5-Gtk2-Ex-Simple-List146logstatsplain d---------p5-Gtk2-Ex-Utils146logstatsplain d---------p5-Gtk2-GladeXML146logstatsplain d---------p5-Gtk2-Html2146logstatsplain d---------p5-Gtk2-ImageView146logstatsplain d---------p5-Gtk2-PathButtonBar146logstatsplain d---------p5-Gtk2-TrayIcon146logstatsplain d---------p5-Gtk2146logstatsplain d---------p5-Pango146logstatsplain d---------p5-Prima178logstatsplain d---------p5-Tk-Action146logstatsplain d---------p5-Tk-Autoscroll146logstatsplain d---------p5-Tk-ColourChooser146logstatsplain d---------p5-Tk-Contrib146logstatsplain d---------p5-Tk-CursorControl146logstatsplain d---------p5-Tk-DKW178logstatsplain d---------p5-Tk-Date146logstatsplain d---------p5-Tk-DynaTabFrame146logstatsplain d---------p5-Tk-Enscript146logstatsplain d---------p5-Tk-FileDialog146logstatsplain d---------p5-Tk-FontDialog146logstatsplain d---------p5-Tk-GBARR146logstatsplain d---------p5-Tk-Getopt146logstatsplain d---------p5-Tk-HistEntry146logstatsplain d---------p5-Tk-JComboBox146logstatsplain d---------p5-Tk-ResizeButton146logstatsplain d---------p5-Tk-Role-Dialog146logstatsplain d---------p5-Tk-Role-HasWidgets146logstatsplain d---------p5-Tk-Splashscreen146logstatsplain d---------p5-Tk-Sugar146logstatsplain d---------p5-Tk-TableMatrix146logstatsplain d---------p5-Tk-ToolBar146logstatsplain d---------p5-Tk178logstatsplain d---------p5-Wx-Perl-ProcessStream146logstatsplain d---------p5-Wx178logstatsplain d---------pango-reference73logstatsplain d---------pango146logstatsplain d---------pangomm146logstatsplain d---------pangoxsl146logstatsplain d---------paragui-devel178logstatsplain d---------paragui178logstatsplain d---------phat146logstatsplain d---------plib178logstatsplain d---------pure-gtk146logstatsplain d---------pure-tk109logstatsplain d---------py-Pmw178logstatsplain d---------py-SciParam109logstatsplain d---------py-fltk146logstatsplain d---------py-gnome-desktop146logstatsplain d---------py-gnome-extras146logstatsplain d---------py-gnome2178logstatsplain d---------py-gtk178logstatsplain d---------py-gtk2178logstatsplain d---------py-gtkglext146logstatsplain d---------py-gtksourceview146logstatsplain d---------py-gui146logstatsplain d---------py-kiwi178logstatsplain d---------py-pyqwt178logstatsplain d---------py-qt178logstatsplain d---------py-qt4-gui110logstatsplain d---------py-sexy146logstatsplain d---------py-tkinter105logstatsplain d---------py-tktreectrl146logstatsplain d---------py-traitsbackendwx146logstatsplain d---------py-traitsgui178logstatsplain d---------py-vte110logstatsplain d---------py-wax146logstatsplain d---------py-wmdockapps146logstatsplain d---------py-wxPython24178logstatsplain d---------py-wxPython26-common73logstatsplain d---------py-wxPython26-unicode36logstatsplain d---------py-wxPython26178logstatsplain d---------py-wxPython28-common73logstatsplain d---------py-wxPython28-unicode36logstatsplain d---------py-wxPython28178logstatsplain d---------py-xlib178logstatsplain d---------py31-tkinter36logstatsplain d---------qscintilla146logstatsplain d---------qt33217logstatsplain d---------qt4-gui181logstatsplain d---------qt4pas146logstatsplain d---------qwt4178logstatsplain d---------qwt5-designerplugin178logstatsplain d---------qwt5178logstatsplain d---------qwt6-designerplugin141logstatsplain d---------qwt6178logstatsplain d---------renaissance146logstatsplain d---------rep-gtk2146logstatsplain d---------ruby-fox16146logstatsplain d---------ruby-goocanvas110logstatsplain d---------ruby-gstreamer110logstatsplain d---------ruby-gtk146logstatsplain d---------ruby-gtk2110logstatsplain d---------ruby-gtksourceview2110logstatsplain d---------ruby-pango110logstatsplain d---------ruby-poppler110logstatsplain d---------ruby-tk110logstatsplain d---------ruby-vte110logstatsplain d---------ruby-wx178logstatsplain d---------sakura146logstatsplain d---------scintilla178logstatsplain d---------sdl_pango178logstatsplain d---------shared-desktop-ontologies146logstatsplain d---------skinlf109logstatsplain d---------slingshot178logstatsplain d---------soqt146logstatsplain d---------swt-devel141logstatsplain d---------swt141logstatsplain d---------termit178logstatsplain d---------tile178logstatsplain d---------tix178logstatsplain d---------tk-wrapper73logstatsplain d---------tk82178logstatsplain d---------tk83178logstatsplain d---------tk84-thread36logstatsplain d---------tk84223logstatsplain d---------tk85-thread36logstatsplain d---------tk85223logstatsplain d---------tk86-thread36logstatsplain d---------tk86223logstatsplain d---------tkdnd146logstatsplain d---------tkshape178logstatsplain d---------tktable178logstatsplain d---------tktray178logstatsplain d---------tktreectrl146logstatsplain d---------unique146logstatsplain d---------v217logstatsplain d---------vdk178logstatsplain d---------vdkbuilder178logstatsplain d---------viewklass146logstatsplain d---------vte-reference73logstatsplain d---------vte178logstatsplain d---------vtkfox109logstatsplain d---------wmapp109logstatsplain d---------wxd178logstatsplain d---------wxgtk24-contrib73logstatsplain d---------wxgtk24-docs146logstatsplain d---------wxgtk24178logstatsplain d---------wxgtk26-common73logstatsplain d---------wxgtk26-contrib-common73logstatsplain d---------wxgtk26-contrib73logstatsplain d---------wxgtk26-docs109logstatsplain d---------wxgtk26-unicode-contrib73logstatsplain d---------wxgtk26-unicode73logstatsplain