File: bonobo-progressive.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (255 lines) | stat: -rw-r--r-- 8,794 bytes parent folder | download | duplicates (2)
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/**
 * Bonobo::ProgressiveDataSink
 *
 * Author:
 *   Nat Friedman (nat@nat.org)
 *
 * Copyright 1999 Helix Code, Inc.
 */

#include <config.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkmarshal.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-progressive.h>

#define PARENT_TYPE BONOBO_X_OBJECT_TYPE

static void
impl_Bonobo_ProgressiveDataSink_start (PortableServer_Servant servant,
				       CORBA_Environment     *ev)
{
	BonoboObject *object = bonobo_object_from_servant (servant);
	BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
	int result;

	if (psink->start_fn != NULL)
		result = (*psink->start_fn) (psink, psink->closure);
	else {
		GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
		BonoboProgressiveDataSinkClass *class = BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);

		result = (*class->start_fn) (psink);
	}

	if (result != 0)
		g_warning ("FIXME: should report an exception");
}

static void
impl_Bonobo_ProgressiveDataSink_end (PortableServer_Servant servant,
				     CORBA_Environment     *ev)
{
	BonoboObject *object = bonobo_object_from_servant (servant);
	BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
	int result;

	if (psink->end_fn != NULL)
		result = (*psink->end_fn) (psink, psink->closure);
	else {
		GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
		BonoboProgressiveDataSinkClass *class = BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);

		result = (*class->end_fn) (psink);
	}

	if (result != 0)
		g_warning ("FIXME: should report an exception");
}

static void
impl_Bonobo_ProgressiveDataSink_addData (PortableServer_Servant                 servant,
					 const Bonobo_ProgressiveDataSink_iobuf *buffer,
					 CORBA_Environment                      *ev)
{
	BonoboObject *object = bonobo_object_from_servant (servant);
	BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
	int result;

	if (psink->add_data_fn != NULL)
		result = (*psink->add_data_fn) (psink,
						buffer,
						psink->closure);
	else {
		GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
		BonoboProgressiveDataSinkClass *class =
			BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);

		result = (*class->add_data_fn) (psink, buffer);
	}

	if (result != 0)
		g_warning ("FIXME: should report an exception");
}

static void
impl_Bonobo_ProgressiveDataSink_setSize (PortableServer_Servant servant,
					 CORBA_long             count,
					 CORBA_Environment     *ev)
{
	BonoboObject *object = bonobo_object_from_servant (servant);
	BonoboProgressiveDataSink *psink = BONOBO_PROGRESSIVE_DATA_SINK (object);
	int result;

	if (psink->set_size_fn != NULL)
		result = (*psink->set_size_fn) (psink,
						count,
						psink->closure);
	else {
		GtkObjectClass *oc = GTK_OBJECT (psink)->klass;
		BonoboProgressiveDataSinkClass *class =
			BONOBO_PROGRESSIVE_DATA_SINK_CLASS (oc);

		result = (*class->set_size_fn) (psink, count);
	}

	if (result != 0)
		g_warning ("FIXME: should report an exception");
}

static void
bonobo_progressive_data_sink_destroy (GtkObject *object)
{
}

static int
bonobo_progressive_data_sink_start_end_nop (BonoboProgressiveDataSink *psink)
{
	return 0;
}

static int
bonobo_progressive_data_sink_add_data_nop (BonoboProgressiveDataSink *psink,
					  const Bonobo_ProgressiveDataSink_iobuf *buffer)
{
	return 0;
}

static int
bonobo_progressive_data_sink_set_size_nop (BonoboProgressiveDataSink *psink,
					  const CORBA_long count)
{
	return 0;
}

static void
bonobo_progressive_data_sink_class_init (BonoboProgressiveDataSinkClass *klass)
{
	GtkObjectClass *object_class = (GtkObjectClass *) klass;
	POA_Bonobo_ProgressiveDataSink__epv *epv = &klass->epv;

	/* Override and initialize methods */
	object_class->destroy = bonobo_progressive_data_sink_destroy;

	klass->start_fn    = bonobo_progressive_data_sink_start_end_nop;
	klass->end_fn      = bonobo_progressive_data_sink_start_end_nop;
	klass->add_data_fn = bonobo_progressive_data_sink_add_data_nop;
	klass->set_size_fn = bonobo_progressive_data_sink_set_size_nop;

	epv->start   = impl_Bonobo_ProgressiveDataSink_start;
	epv->end     = impl_Bonobo_ProgressiveDataSink_end;
	epv->addData = impl_Bonobo_ProgressiveDataSink_addData;
	epv->setSize = impl_Bonobo_ProgressiveDataSink_setSize;
}

static void
bonobo_progressive_data_sink_init (GtkObject *object)
{
	/* nothing to do */
}

BONOBO_X_TYPE_FUNC_FULL (BonoboProgressiveDataSink, 
			   Bonobo_ProgressiveDataSink,
			   PARENT_TYPE,
			   bonobo_progressive_data_sink);

/**
 * bonobo_progressive_data_sink_construct:
 * @psink: The #BonoboProgressiveDataSink object to initialize.
 * @corba_psink: The CORBA object for the #Bonobo_ProgressiveDataSink interface.
 * @start_fn: A callback which is invoked when the #start method is
 * called on the interface.  The #start method is used to indicate that
 * a new set of data is being loaded into the #Bonobo_ProgressiveDataSink interface.
 * @end_fn: A callback which is invoked when the #end method is called
 * on the interface.  The #end method is called after the entire data transmission
 * is complete.
 * @add_data_fn: A callback which is invoked when the #add_data method is called
 * on the interface.  This method is called whenever new data is available for
 * the current transmission.  The new data is passed as an argument to the method
 * @set_size_fn: A callback which is invoked when the #set_size method is called
 * on the interface.  The #set_size method is used by the caller to specify
 * the total size of the current transmission.  This method may be used
 * at any point after #start has been called.  Objects implementing #Bonobo_ProgressiveDataSink
 * may want to use this to know what percentage of the data has been received.
 * @closure: A closure which pis passed to all the callback functions.
 *
 * This function initializes @psink with the CORBA interface
 * provided in @corba_psink and the callback functions
 * specified by @start_fn, @end_fn, @add_data_fn and @set_size_fn.
 * 
 * Returns: the initialized BonoboProgressiveDataSink object.
 */
BonoboProgressiveDataSink *
bonobo_progressive_data_sink_construct (BonoboProgressiveDataSink         *psink,
					BonoboProgressiveDataSinkStartFn   start_fn,
					BonoboProgressiveDataSinkEndFn     end_fn,
					BonoboProgressiveDataSinkAddDataFn add_data_fn,
					BonoboProgressiveDataSinkSetSizeFn set_size_fn,
					void                              *closure)
{
	g_return_val_if_fail (psink != NULL, NULL);
	g_return_val_if_fail (BONOBO_IS_PROGRESSIVE_DATA_SINK (psink), NULL);

	psink->start_fn = start_fn;
	psink->end_fn = end_fn;
	psink->add_data_fn = add_data_fn;
	psink->set_size_fn = set_size_fn;

	psink->closure = closure;

	return psink;
} 

/**
 * bonobo_progressive_data_sink_new:
 * @start_fn: A callback which is invoked when the #start method is
 * called on the interface.  The #start method is used to indicate that
 * a new set of data is being loaded into the #Bonobo_ProgressiveDataSink interface.
 * @end_fn: A callback which is invoked when the #end method is called
 * on the interface.  The #end method is called after the entire data transmission
 * is complete.
 * @add_data_fn: A callback which is invoked when the #add_data method is called
 * on the interface.  This method is called whenever new data is available for
 * the current transmission.  The new data is passed as an argument to the method
 * @set_size_fn: A callback which is invoked when the #set_size method is called
 * on the interface.  The #set_size method is used by the caller to specify
 * the total size of the current transmission.  This method may be used
 * at any point after #start has been called.  Objects implementing #Bonobo_ProgressiveDataSink
 * may want to use this to know what percentage of the data has been received.
 * @closure: A closure which pis passed to all the callback functions.
 *
 * This function creates a new BonoboProgressiveDataSink object and the
 * corresponding CORBA interface object.  The new object is
 * initialized with the callback functionss specified by @start_fn,
 * @end_fn, @add_data_fn and @set_size_fn.
 * 
 * Returns: the newly-constructed BonoboProgressiveDataSink object.
 */
BonoboProgressiveDataSink *
bonobo_progressive_data_sink_new (BonoboProgressiveDataSinkStartFn   start_fn,
				  BonoboProgressiveDataSinkEndFn     end_fn,
				  BonoboProgressiveDataSinkAddDataFn add_data_fn,
				  BonoboProgressiveDataSinkSetSizeFn set_size_fn,
				  void                              *closure)
{
	BonoboProgressiveDataSink *psink;

	psink = gtk_type_new (bonobo_progressive_data_sink_get_type ());

	bonobo_progressive_data_sink_construct (psink, start_fn,
						end_fn, add_data_fn,
						set_size_fn, closure);

	return psink;
}