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_release (gpointer a)
48 bonobo_object_release_unref (a, &ev);
52 stream_cache_item_free (gpointer a)
54 struct StreamCacheItem *cache_item = a;
57 bonobo_object_release_unref (cache_item->stream, &ev);
58 SPI_freeString (cache_item->mimetype);
63 static GHashTable *streams = NULL;
68 if (streams == NULL) {
69 streams = g_hash_table_new_full (g_direct_hash, streams_equal_func,
70 stream_release, stream_cache_item_free);
75 /* internal use only, declared in cspi-private.h */
77 cspi_streams_close_all (void)
81 g_hash_table_destroy (streams);
87 * AccessibleStreamableContent_ref:
88 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to
91 * Increment the reference count for an #AccessibleStreamableContent object.
95 AccessibleStreamableContent_ref (AccessibleStreamableContent *obj)
97 cspi_object_ref (obj);
101 * AccessibleStreamableContent_unref:
102 * @obj: a pointer to the #AccessibleStreamableContent implementor
103 * on which to operate.
105 * Decrement the reference count for an #AccessibleStreamableContent object.
109 AccessibleStreamableContent_unref (AccessibleStreamableContent *obj)
111 cspi_object_unref (obj);
115 * AccessibleStreamableContent_getContentTypes:
116 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
118 * Get a list of strings containing the content mimetypes available from an
119 * #AccessibleStreamableContent implementor.
121 * Returns: an array of strings, terminated by a NULL string, specifying the
122 * mimetypes for which the streamed content is available.
126 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
128 Accessibility_StringSeq *mimeseq;
129 char **content_types;
132 mimeseq = Accessibility_StreamableContent_getContentTypes (CSPI_OBJREF (obj),
135 content_types = g_new0 (char *, mimeseq->_length + 1);
136 for (i = 0; i < mimeseq->_length; ++i) {
137 content_types[i] = CORBA_string_dup (mimeseq->_buffer[i]);
139 content_types [mimeseq->_length] = NULL;
140 CORBA_free (mimeseq);
142 return content_types;
146 * AccessibleStreamableContent_open:
147 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
148 * @content_type: a string specifying the content type to retrieve (should match one
149 * of the return strings from #AccessibleStreamableContent_getContentTypes ()).
151 * Open a streaming connection to an AccessibleStreamableContent implementor,
152 * of a particular content type
154 * Returns: #TRUE if successful, #FALSE if unsuccessful.
158 AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
159 const char *content_type)
161 Bonobo_Stream stream;
162 struct StreamCacheItem *cache;
163 stream = Accessibility_StreamableContent_getContent (CSPI_OBJREF (obj),
166 if (stream != CORBA_OBJECT_NIL) {
167 cache = g_new0 (struct StreamCacheItem, 1);
168 cache->stream = stream;
169 cache->mimetype = CORBA_string_dup (content_type);
170 g_hash_table_replace (get_streams (), stream, cache);
177 * AccessibleStreamableContent_close:
178 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
180 * Close the current streaming connection to an AccessibleStreamableContent implementor.
181 * This must be called before any subsequent AccessibleStreamableContent_open
182 * calls on the same object.
184 * Returns: #TRUE if successful, #FALSE if unsuccessful.
188 AccessibleStreamableContent_close (AccessibleStreamableContent *obj)
190 if (CSPI_OBJREF (obj) != CORBA_OBJECT_NIL) {
191 if (g_hash_table_remove (get_streams (), CSPI_OBJREF (obj)))
198 * AccessibleStreamableContent_seek:
199 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
200 * @offset: a long int specifying the offset into the stream.
201 * @seek_type: an enum indicating the seek offset type, may be SEEK_SET,
202 * SEEK_CUR, SEEK_END (as in the lseek() libc command).
204 * Cause the current streamable content connection (obtained via
205 * #AccessibleStreamableContent_open()) to seek to a particular offset in the
208 * Returns: #TRUE if successful, #FALSE if unsuccessful.
212 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
214 unsigned int seek_type)
216 /* currently Bonobo_Stream does not appear to support seek operations */
221 * AccessibleStreamableContent_read:
222 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
223 * @buff: a pointer to a buffer into which the resulting bytes read from the stream
225 * @nbytes: a long integer indicating the number of bytes to read/write.
226 * @read_type: currently unused, specifies behavior of reads for streamed content
227 * if blocking is not allowed, etc.
229 * Copy (read) bytes from the currently open streamable content connection
232 * Returns: an integer indicating the number of bytes read, or -1 on error.
236 AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
239 unsigned int read_type)
241 Bonobo_Stream stream;
242 struct StreamCacheItem *cached;
243 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
246 stream = cached->stream;
247 if (stream != CORBA_OBJECT_NIL) {
249 mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
250 if (mem) memcpy (buff, mem, len_read);
251 if (mem && ((nbytes == -1) || (len_read == nbytes)))