2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include <libbonobo.h>
26 #include <cspi/spi-private.h>
29 /* TODO: factor/wrap Bonobo_Stream dependency to cspi/bonobo */
31 struct StreamCacheItem {
37 streams_equal_func (gconstpointer a, gconstpointer b)
39 const struct StreamCacheItem *c1 = a, *c2 = b;
40 return CORBA_Object_is_equivalent (c1->stream, c2->stream, cspi_ev ());
44 stream_cache_item_free (gpointer a)
46 struct StreamCacheItem *cache_item = a;
48 cspi_release_unref (cache_item->stream);
49 SPI_freeString (cache_item->mimetype);
53 static GHashTable *streams = NULL;
59 streams = g_hash_table_new_full (g_direct_hash, streams_equal_func,
60 NULL, stream_cache_item_free);
65 accessible_bonobo_stream_client_seek (const Bonobo_Stream stream,
67 Bonobo_Stream_SeekType seek_type,
68 CORBA_Environment *opt_ev)
70 Bonobo_StorageInfo *info;
71 CORBA_Environment *ev, temp_ev;
72 CORBA_long ret_offset;
75 CORBA_exception_init (&temp_ev);
80 ret_offset = Bonobo_Stream_seek (stream, offset, seek_type, ev);
85 CORBA_exception_free (&temp_ev);
90 /* internal use only, declared in cspi-private.h */
92 cspi_streams_close_all (void)
96 g_hash_table_destroy (streams);
102 * AccessibleStreamableContent_ref:
103 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to
106 * Increment the reference count for an #AccessibleStreamableContent object.
110 AccessibleStreamableContent_ref (AccessibleStreamableContent *obj)
112 cspi_object_ref (obj);
116 * AccessibleStreamableContent_unref:
117 * @obj: a pointer to the #AccessibleStreamableContent implementor
118 * on which to operate.
120 * Decrement the reference count for an #AccessibleStreamableContent object.
124 AccessibleStreamableContent_unref (AccessibleStreamableContent *obj)
126 cspi_object_unref (obj);
130 * AccessibleStreamableContent_getContentTypes:
131 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
133 * Get a list of strings containing the content mimetypes available from an
134 * #AccessibleStreamableContent implementor.
136 * Returns: an array of strings, terminated by a NULL string, specifying the
137 * mimetypes for which the streamed content is available.
142 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
144 Accessibility_StringSeq *mimeseq;
145 char **content_types;
148 mimeseq = Accessibility_StreamableContent_getContentTypes (CSPI_OBJREF (obj),
150 cspi_return_val_if_ev ("getContentTypes", NULL);
152 content_types = g_new0 (char *, mimeseq->_length + 1);
153 for (i = 0; i < mimeseq->_length; ++i)
154 content_types[i] = CORBA_string_dup (mimeseq->_buffer[i]);
155 content_types [mimeseq->_length] = NULL;
156 CORBA_free (mimeseq);
158 return content_types;
162 AccessibleStreamableContent_freeContentTypesList (AccessibleStreamableContent *obj,
163 char **content_types)
168 while (content_types[i])
170 g_free (content_types[i]);
173 g_free (content_types);
178 * AccessibleStreamableContent_open:
179 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
180 * @content_type: a string specifying the content type to retrieve (should match one
181 * of the return strings from #AccessibleStreamableContent_getContentTypes ()).
183 * Open a streaming connection to an AccessibleStreamableContent implementor,
184 * of a particular content type
186 * Returns: #TRUE if successful, #FALSE if unsuccessful.
190 AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
191 const char *content_type)
193 Bonobo_Stream stream;
194 struct StreamCacheItem *cache;
195 stream = Accessibility_StreamableContent_getContent (CSPI_OBJREF (obj),
198 cspi_return_val_if_ev ("getContent", FALSE);
200 if (stream != CORBA_OBJECT_NIL) {
201 cache = g_new0 (struct StreamCacheItem, 1);
202 cache->stream = stream;
203 cache->mimetype = CORBA_string_dup (content_type);
204 g_hash_table_replace (get_streams (), stream, cache);
211 * AccessibleStreamableContent_close:
212 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
214 * Close the current streaming connection to an AccessibleStreamableContent implementor.
215 * This must be called before any subsequent AccessibleStreamableContent_open
216 * calls on the same object.
218 * Returns: #TRUE if successful, #FALSE if unsuccessful.
222 AccessibleStreamableContent_close (AccessibleStreamableContent *obj)
224 if (CSPI_OBJREF (obj) != CORBA_OBJECT_NIL) {
225 if (g_hash_table_remove (get_streams (), CSPI_OBJREF (obj)))
232 * AccessibleStreamableContent_seek:
233 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
234 * @offset: a long int specifying the offset into the stream.
235 * @seek_type: an enum indicating the seek offset type, may be SEEK_SET,
236 * SEEK_CUR, SEEK_END (as in the lseek() libc command).
238 * Cause the current streamable content connection (obtained via
239 * #AccessibleStreamableContent_open()) to seek to a particular offset in the
242 * Returns: #TRUE if successful, #FALSE if unsuccessful.
246 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
248 AccessibleStreamableContentSeekType seek_type)
250 Bonobo_Stream stream;
251 long int ret_offset = 0;
252 struct StreamCacheItem *cached;
253 Bonobo_Stream_SeekType bonobo_seek_type;
255 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
258 stream = cached->stream;
259 if (stream != CORBA_OBJECT_NIL)
263 case SPI_STREAM_SEEK_SET:
264 bonobo_seek_type = Bonobo_Stream_SeekSet;
266 case SPI_STREAM_SEEK_END:
267 bonobo_seek_type = Bonobo_Stream_SeekEnd;
269 case SPI_STREAM_SEEK_CUR:
271 bonobo_seek_type = Bonobo_Stream_SeekCur;
274 /* bonobo-client doesn't wrap seek yet, so we have to. */
275 ret_offset = accessible_bonobo_stream_client_seek (stream, offset,
276 seek_type, cspi_ev ());
277 cspi_return_val_if_ev ("seek", FALSE);
284 * AccessibleStreamableContent_read:
285 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
286 * @buff: a pointer to a buffer into which the resulting bytes read from the stream
288 * @nbytes: a long integer indicating the number of bytes to read/write.
289 * @read_type: currently unused, specifies behavior of reads for streamed content
290 * if blocking is not allowed, etc.
292 * Copy (read) bytes from the currently open streamable content connection
293 * to a buffer. This is a blocking API, in the sense that it does not
294 * return until the bytes have been read, or an error condition is
297 * Returns: an integer indicating the number of bytes read, or -1 on error.
301 AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
304 unsigned int read_type)
306 Bonobo_Stream stream;
307 struct StreamCacheItem *cached;
308 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
312 stream = cached->stream;
313 if (stream != CORBA_OBJECT_NIL)
316 mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
317 cspi_return_val_if_ev ("read", FALSE);
320 memcpy (buff, mem, len_read);
322 if ((nbytes == -1) || (len_read == nbytes))