1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * gsf-output-bonobo.c: bonobo based output
5 * Copyright (C) 2002-2003 Dom Lachowicz (cinamod@hotmail.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2.1 of the GNU Lesser General Public
9 * License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 #include <gsf-config.h>
23 #include <gsf-gnome/gsf-output-bonobo.h>
24 #include <bonobo/bonobo-exception.h>
25 #include <bonobo/bonobo-persist-stream.h>
26 #include <gsf/gsf-output-impl.h>
27 #include <gsf/gsf-impl-utils.h>
29 struct _GsfOutputBonobo {
31 Bonobo_Stream stream ;
35 GsfOutputClass output_class;
36 } GsfOutputBonoboClass;
39 * gsf_output_bonobo_new :
40 * @stream : non-%NULL bonobo stream
41 * @err : optionally %NULL.
43 * Returns: a new file or %NULL.
46 gsf_output_bonobo_new (Bonobo_Stream const stream, G_GNUC_UNUSED GError **err)
50 res = g_object_new (GSF_OUTPUT_BONOBO_TYPE, NULL);
51 if (G_UNLIKELY (NULL == res)) return NULL;
55 return GSF_OUTPUT (res);
59 gsf_output_bonobo_close (GsfOutput *output)
61 GsfOutputBonobo *bonobo = GSF_OUTPUT_BONOBO (output);
64 if (bonobo->stream != NULL) {
65 bonobo->stream = NULL;
73 gsf_output_bonobo_seek (GsfOutput *output, gsf_off_t offset,
76 GsfOutputBonobo const *bonobo = GSF_OUTPUT_BONOBO (output);
77 Bonobo_Stream_SeekType bwhence = 0; /* make compiler shut up */
81 g_return_val_if_fail (bonobo->stream != CORBA_OBJECT_NIL,
82 gsf_output_set_error (output, 0, "missing stream"));
85 case G_SEEK_SET : bwhence = Bonobo_Stream_SeekSet; break;
86 case G_SEEK_CUR : bwhence = Bonobo_Stream_SeekCur; break;
87 case G_SEEK_END : bwhence = Bonobo_Stream_SeekEnd; break;
89 break; /*checked in GsfOutput wrapper */
92 CORBA_exception_init (&ev);
93 pos = Bonobo_Stream_seek
94 (bonobo->stream, offset, bwhence, &ev);
95 if (BONOBO_EX (&ev)) {
96 gsf_output_set_error (output, 0,
97 "%s", bonobo_exception_get_text (&ev));
98 CORBA_exception_free (&ev);
105 gsf_output_bonobo_write (GsfOutput *output,
107 guint8 const *buffer)
109 GsfOutputBonobo *bonobo = GSF_OUTPUT_BONOBO (output);
110 Bonobo_Stream_iobuf *bsobuf;
111 CORBA_Environment ev;
113 g_return_val_if_fail (bonobo != NULL, FALSE);
114 g_return_val_if_fail (bonobo->stream != NULL, FALSE);
116 bsobuf = Bonobo_Stream_iobuf__alloc ();
117 bsobuf->_buffer = (CORBA_octet*)buffer;
118 bsobuf->_length = num_bytes;
120 CORBA_exception_init (&ev);
121 Bonobo_Stream_write (bonobo->stream, bsobuf, &ev);
122 if (BONOBO_EX (&ev)) {
123 g_warning ("%s", bonobo_exception_get_text (&ev));
124 CORBA_exception_free (&ev);
132 gsf_output_bonobo_finalize (GObject *obj)
134 GObjectClass *parent_class;
135 GsfOutput *output = (GsfOutput *)obj;
137 gsf_output_bonobo_close (output);
139 parent_class = g_type_class_peek (GSF_OUTPUT_TYPE);
140 if (parent_class && parent_class->finalize)
141 parent_class->finalize (obj);
145 gsf_output_bonobo_init (GObject *obj)
147 GsfOutputBonobo *stream = GSF_OUTPUT_BONOBO (obj);
149 stream->stream = NULL;
153 gsf_output_bonobo_class_init (GObjectClass *gobject_class)
155 GsfOutputClass *output_class = GSF_OUTPUT_CLASS (gobject_class);
157 gobject_class->finalize = gsf_output_bonobo_finalize;
158 output_class->Close = gsf_output_bonobo_close;
159 output_class->Seek = gsf_output_bonobo_seek;
160 output_class->Write = gsf_output_bonobo_write;
163 GSF_CLASS (GsfOutputBonobo, gsf_output_bonobo,
164 gsf_output_bonobo_class_init, gsf_output_bonobo_init, GSF_OUTPUT_TYPE)