source: trunk/third/bonobo/bonobo/bonobo-progressive.c @ 15579

Revision 15579, 8.6 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15578, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/**
3 * Bonobo::ProgressiveDataSink
4 *
5 * Author:
6 *   Nat Friedman (nat@nat.org)
7 *
8 * Copyright 1999 Helix Code, Inc.
9 */
10
11#include <config.h>
12#include <gtk/gtksignal.h>
13#include <gtk/gtkmarshal.h>
14#include <bonobo/bonobo-exception.h>
15#include <bonobo/bonobo-progressive.h>
16
17#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
18
19static void
20impl_Bonobo_ProgressiveDataSink_start (PortableServer_Servant servant,
21                                       CORBA_Environment     *ev)
22{
23        BonoboObject *object = bonobo_object_from_servant (servant);
24        BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
25        int result;
26
27        if (psink->start_fn != NULL)
28                result = (*psink->start_fn) (psink, psink->closure);
29        else {
30                GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
31                BonoboProgressiveDataSinkClass *class = BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);
32
33                result = (*class->start_fn) (psink);
34        }
35
36        if (result != 0)
37                g_warning ("FIXME: should report an exception");
38}
39
40static void
41impl_Bonobo_ProgressiveDataSink_end (PortableServer_Servant servant,
42                                     CORBA_Environment     *ev)
43{
44        BonoboObject *object = bonobo_object_from_servant (servant);
45        BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
46        int result;
47
48        if (psink->end_fn != NULL)
49                result = (*psink->end_fn) (psink, psink->closure);
50        else {
51                GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
52                BonoboProgressiveDataSinkClass *class = BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);
53
54                result = (*class->end_fn) (psink);
55        }
56
57        if (result != 0)
58                g_warning ("FIXME: should report an exception");
59}
60
61static void
62impl_Bonobo_ProgressiveDataSink_addData (PortableServer_Servant                 servant,
63                                         const Bonobo_ProgressiveDataSink_iobuf *buffer,
64                                         CORBA_Environment                      *ev)
65{
66        BonoboObject *object = bonobo_object_from_servant (servant);
67        BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
68        int result;
69
70        if (psink->add_data_fn != NULL)
71                result = (*psink->add_data_fn) (psink,
72                                                buffer,
73                                                psink->closure);
74        else {
75                GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
76                BonoboProgressiveDataSinkClass *class =
77                        BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);
78
79                result = (*class->add_data_fn) (psink, buffer);
80        }
81
82        if (result != 0)
83                g_warning ("FIXME: should report an exception");
84}
85
86static void
87impl_Bonobo_ProgressiveDataSink_setSize (PortableServer_Servant servant,
88                                         CORBA_long             count,
89                                         CORBA_Environment     *ev)
90{
91        BonoboObject *object = bonobo_object_from_servant (servant);
92        BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
93        int result;
94
95        if (psink->set_size_fn != NULL)
96                result = (*psink->set_size_fn) (psink,
97                                                count,
98                                                psink->closure);
99        else {
100                GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
101                BonoboProgressiveDataSinkClass *class =
102                        BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);
103
104                result = (*class->set_size_fn) (psink, count);
105        }
106
107        if (result != 0)
108                g_warning ("FIXME: should report an exception");
109}
110
111static void
112bonobo_progressive_data_sink_destroy (GtkObject *object)
113{
114}
115
116static int
117bonobo_progressive_data_sink_start_end_nop (BonoboProgressiveDataSink *psink)
118{
119        return 0;
120}
121
122static int
123bonobo_progressive_data_sink_add_data_nop (BonoboProgressiveDataSink *psink,
124                                          const Bonobo_ProgressiveDataSink_iobuf *buffer)
125{
126        return 0;
127}
128
129static int
130bonobo_progressive_data_sink_set_size_nop (BonoboProgressiveDataSink *psink,
131                                          const CORBA_long count)
132{
133        return 0;
134}
135
136static void
137bonobo_progressive_data_sink_class_init (BonoboProgressiveDataSinkClass *klass)
138{
139        GtkObjectClass *object_class = (GtkObjectClass *) klass;
140        POA_Bonobo_ProgressiveDataSink__epv *epv = &klass->epv;
141
142        /* Override and initialize methods */
143        object_class->destroy = bonobo_progressive_data_sink_destroy;
144
145        klass->start_fn    = bonobo_progressive_data_sink_start_end_nop;
146        klass->end_fn      = bonobo_progressive_data_sink_start_end_nop;
147        klass->add_data_fn = bonobo_progressive_data_sink_add_data_nop;
148        klass->set_size_fn = bonobo_progressive_data_sink_set_size_nop;
149
150        epv->start   = impl_Bonobo_ProgressiveDataSink_start;
151        epv->end     = impl_Bonobo_ProgressiveDataSink_end;
152        epv->addData = impl_Bonobo_ProgressiveDataSink_addData;
153        epv->setSize = impl_Bonobo_ProgressiveDataSink_setSize;
154}
155
156static void
157bonobo_progressive_data_sink_init (GtkObject *object)
158{
159        /* nothing to do */
160}
161
162BONOBO_X_TYPE_FUNC_FULL (BonoboProgressiveDataSink,
163                           Bonobo_ProgressiveDataSink,
164                           PARENT_TYPE,
165                           bonobo_progressive_data_sink);
166
167/**
168 * bonobo_progressive_data_sink_construct:
169 * @psink: The #BonoboProgressiveDataSink object to initialize.
170 * @corba_psink: The CORBA object for the #Bonobo_ProgressiveDataSink interface.
171 * @start_fn: A callback which is invoked when the #start method is
172 * called on the interface.  The #start method is used to indicate that
173 * a new set of data is being loaded into the #Bonobo_ProgressiveDataSink interface.
174 * @end_fn: A callback which is invoked when the #end method is called
175 * on the interface.  The #end method is called after the entire data transmission
176 * is complete.
177 * @add_data_fn: A callback which is invoked when the #add_data method is called
178 * on the interface.  This method is called whenever new data is available for
179 * the current transmission.  The new data is passed as an argument to the method
180 * @set_size_fn: A callback which is invoked when the #set_size method is called
181 * on the interface.  The #set_size method is used by the caller to specify
182 * the total size of the current transmission.  This method may be used
183 * at any point after #start has been called.  Objects implementing #Bonobo_ProgressiveDataSink
184 * may want to use this to know what percentage of the data has been received.
185 * @closure: A closure which pis passed to all the callback functions.
186 *
187 * This function initializes @psink with the CORBA interface
188 * provided in @corba_psink and the callback functions
189 * specified by @start_fn, @end_fn, @add_data_fn and @set_size_fn.
190 *
191 * Returns: the initialized BonoboProgressiveDataSink object.
192 */
193BonoboProgressiveDataSink *
194bonobo_progressive_data_sink_construct (BonoboProgressiveDataSink         *psink,
195                                        BonoboProgressiveDataSinkStartFn   start_fn,
196                                        BonoboProgressiveDataSinkEndFn     end_fn,
197                                        BonoboProgressiveDataSinkAddDataFn add_data_fn,
198                                        BonoboProgressiveDataSinkSetSizeFn set_size_fn,
199                                        void                              *closure)
200{
201        g_return_val_if_fail (psink != NULL, NULL);
202        g_return_val_if_fail (BONOBO_IS_PROGRESSIVE_DATA_SINK (psink), NULL);
203
204        psink->start_fn = start_fn;
205        psink->end_fn = end_fn;
206        psink->add_data_fn = add_data_fn;
207        psink->set_size_fn = set_size_fn;
208
209        psink->closure = closure;
210
211        return psink;
212}
213
214/**
215 * bonobo_progressive_data_sink_new:
216 * @start_fn: A callback which is invoked when the #start method is
217 * called on the interface.  The #start method is used to indicate that
218 * a new set of data is being loaded into the #Bonobo_ProgressiveDataSink interface.
219 * @end_fn: A callback which is invoked when the #end method is called
220 * on the interface.  The #end method is called after the entire data transmission
221 * is complete.
222 * @add_data_fn: A callback which is invoked when the #add_data method is called
223 * on the interface.  This method is called whenever new data is available for
224 * the current transmission.  The new data is passed as an argument to the method
225 * @set_size_fn: A callback which is invoked when the #set_size method is called
226 * on the interface.  The #set_size method is used by the caller to specify
227 * the total size of the current transmission.  This method may be used
228 * at any point after #start has been called.  Objects implementing #Bonobo_ProgressiveDataSink
229 * may want to use this to know what percentage of the data has been received.
230 * @closure: A closure which pis passed to all the callback functions.
231 *
232 * This function creates a new BonoboProgressiveDataSink object and the
233 * corresponding CORBA interface object.  The new object is
234 * initialized with the callback functionss specified by @start_fn,
235 * @end_fn, @add_data_fn and @set_size_fn.
236 *
237 * Returns: the newly-constructed BonoboProgressiveDataSink object.
238 */
239BonoboProgressiveDataSink *
240bonobo_progressive_data_sink_new (BonoboProgressiveDataSinkStartFn   start_fn,
241                                  BonoboProgressiveDataSinkEndFn     end_fn,
242                                  BonoboProgressiveDataSinkAddDataFn add_data_fn,
243                                  BonoboProgressiveDataSinkSetSizeFn set_size_fn,
244                                  void                              *closure)
245{
246        BonoboProgressiveDataSink *psink;
247
248        psink = gtk_type_new (bonobo_progressive_data_sink_get_type ());
249
250        bonobo_progressive_data_sink_construct (psink, start_fn,
251                                                end_fn, add_data_fn,
252                                                set_size_fn, closure);
253
254        return psink;
255}
Note: See TracBrowser for help on using the repository browser.