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)
76 g_hash_table_destroy (streams);
82 * AccessibleStreamableContent_ref:
83 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to
86 * Increment the reference count for an #AccessibleStreamableContent object.
90 AccessibleStreamableContent_ref (AccessibleStreamableContent *obj)
92 cspi_object_ref (obj);
96 * AccessibleStreamableContent_unref:
97 * @obj: a pointer to the #AccessibleStreamableContent implementor
98 * on which to operate.
100 * Decrement the reference count for an #AccessibleStreamableContent object.
104 AccessibleStreamableContent_unref (AccessibleStreamableContent *obj)
106 cspi_object_unref (obj);
110 * AccessibleStreamableContent_getContentTypes:
111 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
113 * Get a list of strings containing the content mimetypes available from an
114 * #AccessibleStreamableContent implementor.
116 * Returns: an array of strings, terminated by a NULL string, specifying the
117 * mimetypes for which the streamed content is available.
121 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
123 Accessibility_StringSeq *mimeseq;
124 char **content_types;
127 mimeseq = Accessibility_StreamableContent_getContentTypes (CSPI_OBJREF (obj),
130 content_types = g_new0 (char *, mimeseq->_length + 1);
131 for (i = 0; i < mimeseq->_length; ++i) {
132 content_types[i] = CORBA_string_dup (mimeseq->_buffer[i]);
134 content_types [mimeseq->_length] = NULL;
135 CORBA_free (mimeseq);
137 return content_types;
141 * AccessibleStreamableContent_open:
142 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
143 * @content_type: a string specifying the content type to retrieve (should match one
144 * of the return strings from #AccessibleStreamableContent_getContentTypes ()).
146 * Open a streaming connection to an AccessibleStreamableContent implementor,
147 * of a particular content type
149 * Returns: #TRUE if successful, #FALSE if unsuccessful.
153 AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
154 const char *content_type)
156 Bonobo_Stream stream;
157 struct StreamCacheItem *cache;
158 stream = Accessibility_StreamableContent_getContent (CSPI_OBJREF (obj),
161 if (stream != CORBA_OBJECT_NIL) {
162 cache = g_new0 (struct StreamCacheItem, 1);
163 cache->stream = stream;
164 cache->mimetype = CORBA_string_dup (content_type);
165 g_hash_table_replace (get_streams (), stream, cache);
172 * AccessibleStreamableContent_close:
173 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
175 * Close the current streaming connection to an AccessibleStreamableContent implementor.
176 * This must be called before any subsequent AccessibleStreamableContent_open
177 * calls on the same object.
179 * Returns: #TRUE if successful, #FALSE if unsuccessful.
183 AccessibleStreamableContent_close (AccessibleStreamableContent *obj)
185 if (CSPI_OBJREF (obj) != CORBA_OBJECT_NIL) {
186 if (g_hash_table_remove (get_streams (), CSPI_OBJREF (obj)))
193 * AccessibleStreamableContent_seek:
194 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
195 * @offset: a long int specifying the offset into the stream.
196 * @seek_type: an enum indicating the seek offset type, may be SEEK_SET,
197 * SEEK_CUR, SEEK_END (as in the lseek() libc command).
199 * Cause the current streamable content connection (obtained via
200 * #AccessibleStreamableContent_open()) to seek to a particular offset in the
203 * Returns: #TRUE if successful, #FALSE if unsuccessful.
207 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
209 unsigned int seek_type)
211 /* currently Bonobo_Stream does not appear to support seek operations */
216 * AccessibleStreamableContent_read:
217 * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
218 * @buff: a pointer to a buffer into which the resulting bytes read from the stream
220 * @nbytes: a long integer indicating the number of bytes to read/write.
221 * @read_type: currently unused, specifies behavior of reads for streamed content
222 * if blocking is not allowed, etc.
224 * Copy (read) bytes from the currently open streamable content connection
227 * Returns: an integer indicating the number of bytes read, or -1 on error.
231 AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
234 unsigned int read_type)
236 Bonobo_Stream stream;
237 struct StreamCacheItem *cached;
238 cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
241 stream = cached->stream;
242 if (stream != CORBA_OBJECT_NIL) {
244 mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
245 if (mem) memcpy (buff, mem, len_read);
246 if (mem && ((nbytes == -1) || (len_read == nbytes)))