1 #Copyright (C) 2008 Codethink Ltd
4 #modify it under the terms of the GNU Lesser General Public
5 #License version 2 as published by the Free Software Foundation.
7 #This program is distributed in the hope that it will be useful,
8 #but WITHOUT ANY WARRANTY; without even the implied warranty of
9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 #GNU General Public License for more details.
11 #You should have received a copy of the GNU Lesser General Public License
12 #along with this program; if not, write to the Free Software
13 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 from base import BaseProxy, Enum
17 from factory import accessible_factory
24 #------------------------------------------------------------------------------
26 class ContentStream(BaseProxy):
28 An interface by which the requested data from a StreamableContent
29 object may be read by the client.
32 def close(self, *args, **kwargs):
34 close the stream and release associated resources. A client should
35 not perform further operations on a StreamableContent::Stream
36 object after closing it.
38 func = self.get_dbus_method("close")
39 return func(*args, **kwargs)
41 def read(self, *args, **kwargs):
43 Request/read a specified amount of data from a Stream.
44 @return the number of bytes actually read into the client buffer.
46 func = self.get_dbus_method("read")
47 return func(*args, **kwargs)
49 def seek(self, *args, **kwargs):
51 Seek to a specified position in the Stream.
53 an offset specifying the requested position in the stream, relative
54 to the SeekType specified in whence.
56 a SeekType specifying the reference point from which the seek
57 offset is calculated. Some forms of seek are not supported by
58 certain implementations of Stream, in which case a NotSupported
59 exception will be raised.
60 @return the actual resulting offset, if no exception was raised.
62 func = self.get_dbus_method("seek")
63 return func(*args, **kwargs)
65 class IOError(Exception):
68 class NoPermission(Exception):
71 class NotSupported(Exception):
76 Specifies the meaning of a seek 'offset'. Not all SeekTypes are
77 supported by all StreamableContent data sources, for instance
78 some streams may not support seeking from the beginning or other
79 types of 'backwards' seeks.
87 SEEK_CURRENT = SeekType(1)
88 SEEK_END = SeekType(2)
89 SEEK_SET = SeekType(0)
91 #------------------------------------------------------------------------------
93 class StreamableContent(BaseProxy):
95 An interface whereby an object allows its backing content to
96 be streamed to clients. Negotiation of content type is allowed.
97 Clients may examine the backing data and transform, convert,
98 or parse the content in order to present it in an alternate form
102 def getContent(self, *args, **kwargs):
104 DEPRECATED, use getStream instead.
106 func = self.get_dbus_method("getContent")
107 return func(*args, **kwargs)
109 def getContentTypes(self, *args, **kwargs):
112 @return the list of available mimetypes for this object's content.
114 func = self.get_dbus_method("getContentTypes")
115 return func(*args, **kwargs)
117 def getStream(self, *args, **kwargs):
119 Retrieve this object's content, in a format appropriate to a
120 requested mimetype, as a ContentStream instance.
122 a string specifying the desired mimetype for the content stream.
123 @return a Stream whose mimetype matches contentType, if available,
126 func = self.get_dbus_method("getStream")
127 return func(*args, **kwargs)
129 def getURI(self, *args, **kwargs):
131 Get a URI pointing to the content of the specified type, if such
132 a URI can be obtained. Not all streamable content providers have
135 a string specifying the desired mimetype for the content stream.
136 If NULL, then a URI for the default content type will be returned,
138 @return a string which constitutes a URI for a stream of the
139 specified content type, or NULL if no such URI can be obtained.
141 func = self.get_dbus_method("getURI")
142 return func(*args, **kwargs)
144 # Register the accessible class with the factory.
145 accessible_factory.register_accessible_class(interfaces.ATSPI_STREAMABLE_CONTENT, StreamableContent)
147 #END----------------------------------------------------------------------------