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 CORBA_Environment *ev, temp_ev;
71 CORBA_long ret_offset;
74 CORBA_exception_init (&temp_ev);
79 ret_offset = Bonobo_Stream_seek (stream, offset, seek_type, ev);
84 CORBA_exception_free (&temp_ev);
89 /* internal use only, declared in cspi-private.h */
91 cspi_streams_close_all (void)
95 g_hash_table_destroy (streams);
101 * AccessibleStreamableContent_ref:
102 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to
105 * 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.
125 AccessibleStreamableContent_unref (AccessibleStreamableContent *obj)
127 cspi_object_unref (obj);
131 * AccessibleStreamableContent_getContentTypes:
132 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
134 * Get a list of strings containing the content mimetypes available from an
135 * #AccessibleStreamableContent implementor.
139 * Returns: an array of strings, terminated by a NULL string, specifying the
140 * mimetypes for which the streamed content is available.
145 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
147 Accessibility_StringSeq *mimeseq;
148 char **content_types;
151 mimeseq = Accessibility_StreamableContent_getContentTypes (CSPI_OBJREF (obj),
153 cspi_return_val_if_ev ("getContentTypes", NULL);
155 content_types = g_new0 (char *, mimeseq->_length + 1);
156 for (i = 0; i < mimeseq->_length; ++i)
157 content_types[i] = CORBA_string_dup (mimeseq->_buffer[i]);
158 content_types [mimeseq->_length] = NULL;
159 CORBA_free (mimeseq);
161 return content_types;
164 * AccessibleStreamableContent_freeContentTypesList:
165 * @obj: the AccessibleStreamableContent implementor on which to operate.
166 * @content_types: a list of content types previously returned by
167 * #AccessibleStreamableContent_getContentTypes.
169 * Free the memory associated with a call to #AccessibleStreamableContent_getContentTypes, once
170 * the result has been used.
175 AccessibleStreamableContent_freeContentTypesList (AccessibleStreamableContent *obj,
176 char **content_types)
181 while (content_types[i])
183 g_free (content_types[i]);
186 g_free (content_types);
191 * AccessibleStreamableContent_open:
192 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
193 * @content_type: a string specifying the content type to retrieve (should match one
194 * of the return strings from #AccessibleStreamableContent_getContentTypes ()).
196 * Open a streaming connection to an AccessibleStreamableContent implementor,
197 * of a particular content type
201 * Returns: #TRUE if successful, #FALSE if unsuccessful.
205 AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
206 const char *content_type)
208 Bonobo_Stream stream;
209 struct StreamCacheItem *cache;
210 stream = Accessibility_StreamableContent_getContent (CSPI_OBJREF (obj),
213 cspi_return_val_if_ev ("getContent", FALSE);
215 if (stream != CORBA_OBJECT_NIL) {
216 cache = g_new0 (struct StreamCacheItem, 1);
217 cache->stream = stream;
218 cache->mimetype = CORBA_string_dup (content_type);
219 g_hash_table_replace (get_streams (), stream, cache);
226 * AccessibleStreamableContent_close:
227 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
229 * Close the current streaming connection to an AccessibleStreamableContent implementor.
230 * This must be called before any subsequent AccessibleStreamableContent_open
231 * calls on the same object.
235 * Returns: #TRUE if successful, #FALSE if unsuccessful.
239 AccessibleStreamableContent_close (AccessibleStreamableContent *obj)
241 if (CSPI_OBJREF (obj) != CORBA_OBJECT_NIL) {
242 if (g_hash_table_remove (get_streams (), CSPI_OBJREF (obj)))
249 * AccessibleStreamableContent_seek:
250 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
251 * @offset: a long int specifying the offset into the stream.
252 * @seek_type: an enum indicating the seek offset type, may be SEEK_SET,
253 * SEEK_CUR, SEEK_END (as in the lseek() libc command).
255 * Cause the current streamable content connection (obtained via
256 * #AccessibleStreamableContent_open()) to seek to a particular offset in the
261 * Returns: #TRUE if successful, #FALSE if unsuccessful.
265 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
267 AccessibleStreamableContentSeekType seek_type)
269 Bonobo_Stream stream;
270 long int ret_offset = 0;
271 struct StreamCacheItem *cached;
272 Bonobo_Stream_SeekType bonobo_seek_type;
274 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
277 stream = cached->stream;
278 if (stream != CORBA_OBJECT_NIL)
281 case SPI_STREAM_SEEK_SET:
282 bonobo_seek_type = Bonobo_Stream_SeekSet;
284 case SPI_STREAM_SEEK_END:
285 bonobo_seek_type = Bonobo_Stream_SeekEnd;
287 case SPI_STREAM_SEEK_CUR:
289 bonobo_seek_type = Bonobo_Stream_SeekCur;
292 /* bonobo-client doesn't wrap seek yet, so we have to. */
293 ret_offset = accessible_bonobo_stream_client_seek (stream, offset,
294 bonobo_seek_type, cspi_ev ());
295 cspi_return_val_if_ev ("seek", FALSE);
302 * AccessibleStreamableContent_read:
303 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
304 * @buff: a pointer to a buffer into which the resulting bytes read from the stream
306 * @nbytes: a long integer indicating the number of bytes to read/write.
307 * @read_type: currently unused, specifies behavior of reads for streamed content
308 * if blocking is not allowed, etc.
310 * Copy (read) bytes from the currently open streamable content connection
311 * to a buffer. This is a blocking API, in the sense that it does not
312 * return until the bytes have been read, or an error condition is
317 * Returns: an integer indicating the number of bytes read, or -1 on error.
321 AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
324 unsigned int read_type)
326 Bonobo_Stream stream;
327 struct StreamCacheItem *cached;
328 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
332 stream = cached->stream;
333 if (stream != CORBA_OBJECT_NIL)
336 mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
337 cspi_return_val_if_ev ("read", FALSE);
340 memcpy (buff, mem, len_read);
342 if ((nbytes == -1) || (len_read == nbytes))