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.
24 #include <cspi/spi-private.h>
27 /* TODO: factor/wrap Bonobo_Stream dependency to cspi/bonobo */
29 struct StreamCacheItem {
35 streams_equal_func (gconstpointer a, gconstpointer b)
37 const struct StreamCacheItem *c1 = a, *c2 = b;
38 return CORBA_Object_is_equivalent (c1->stream, c2->stream, cspi_ev ());
42 stream_release (gpointer a)
44 bonobo_object_release_unref (a);
48 stream_cache_item_free (gpointer a)
50 struct StreamCacheItem *cache_item = a;
52 bonobo_object_release_unref (cache_item->stream);
53 SPI_freeString (cache_item->mimetype);
58 static GHashTable *streams = NULL;
63 if (streams == NULL) {
64 streams = g_hash_table_new_full (g_direct_hash, streams_equal_func,
65 stream_release, stream_cache_item_free);
70 /* internal use only, declared in cspi-private.h */
72 cspi_streams_close_all (void)
74 g_hash_table_destroy (get_streams ());
78 * AccessibleStreamableContent_ref:
79 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to
82 * Increment the reference count for an #AccessibleStreamableContent object.
86 AccessibleStreamableContent_ref (AccessibleStreamableContent *obj)
88 cspi_object_ref (obj);
92 * AccessibleStreamableContent_unref:
93 * @obj: a pointer to the #AccessibleStreamableContent implementor
94 * on which to operate.
96 * Decrement the reference count for an #AccessibleStreamableContent object.
100 AccessibleStreamableContent_unref (AccessibleStreamableContent *obj)
102 cspi_object_unref (obj);
106 * AccessibleStreamableContent_getContentTypes:
107 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
109 * Get a list of strings containing the content mimetypes available from an
110 * #AccessibleStreamableContent implementor.
112 * Returns: an array of strings, terminated by a NULL string, specifying the
113 * mimetypes for which the streamed content is available.
117 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
119 Accessibility_StringSeq *mimeseq;
120 char **content_types;
123 mimeseq = Accessibility_StreamableContent_getContentTypes (CSPI_OBJREF (obj),
126 content_types = g_new0 (char *, mimeseq->_length + 1);
127 for (i = 0; i < mimeseq->_length; ++i) {
128 content_types[i] = CORBA_string_dup (mimeseq->_buffer[i]);
130 content_types [mimeseq->_length] = NULL;
131 CORBA_free (mimeseq);
133 return content_types;
137 * AccessibleStreamableContent_open:
138 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
139 * @content_type: a string specifying the content type to retrieve (should match one
140 * of the return strings from #AccessibleStreamableContent_getContentTypes ()).
142 * Open a streaming connection to an AccessibleStreamableContent implementor,
143 * of a particular content type
145 * Returns: #TRUE if successful, #FALSE if unsuccessful.
149 AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
150 const char *content_type)
152 Bonobo_Stream stream;
153 struct StreamCacheItem *cache;
154 stream = Accessibility_StreamableContent_getContent (CSPI_OBJREF (obj),
157 if (stream != CORBA_OBJECT_NIL) {
158 cache = g_new0 (struct StreamCacheItem, 1);
159 cache->stream = stream;
160 cache->mimetype = CORBA_string_dup (content_type);
161 g_hash_table_replace (get_streams (), stream, cache);
168 * AccessibleStreamableContent_close:
169 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
171 * Close the current streaming connection to an AccessibleStreamableContent implementor.
172 * This must be called before any subsequent AccessibleStreamableContent_open
173 * calls on the same object.
175 * Returns: #TRUE if successful, #FALSE if unsuccessful.
179 AccessibleStreamableContent_close (AccessibleStreamableContent *obj)
181 if (CSPI_OBJREF (obj) != CORBA_OBJECT_NIL) {
182 if (g_hash_table_remove (get_streams (), CSPI_OBJREF (obj)))
189 * AccessibleStreamableContent_seek:
190 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
191 * @offset: a long int specifying the offset into the stream.
192 * @seek_type: an enum indicating the seek offset type, may be SEEK_SET,
193 * SEEK_CUR, SEEK_END (as in the lseek() libc command).
195 * Cause the current streamable content connection (obtained via
196 * #AccessibleStreamableContent_open()) to seek to a particular offset in the
199 * Returns: #TRUE if successful, #FALSE if unsuccessful.
203 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
205 unsigned int seek_type)
207 /* currently Bonobo_Stream does not appear to support seek operations */
212 * AccessibleStreamableContent_read:
213 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
214 * @buff: a pointer to a buffer into which the resulting bytes read from the stream
216 * @nbytes: a long integer indicating the number of bytes to read/write.
217 * @read_type: currently unused, specifies behavior of reads for streamed content
218 * if blocking is not allowed, etc.
220 * Copy (read) bytes from the currently open streamable content connection
223 * Returns: an integer indicating the number of bytes read, or -1 on error.
227 AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
230 unsigned int read_type)
232 Bonobo_Stream stream;
233 struct StreamCacheItem *cached;
234 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
237 stream = cached->stream;
238 if (stream != CORBA_OBJECT_NIL) {
240 mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
241 if (mem) memcpy (buff, mem, len_read);
242 if (mem && ((nbytes == -1) || (len_read == nbytes)))