glibmm  2.32.1
Public Member Functions | Related Functions
Gio::InputStream Class Reference

Base class for implementing streaming input. More...

#include <giomm/inputstream.h>

Inheritance diagram for Gio::InputStream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual ~InputStream ()
GInputStream* gobj ()
 Provides access to the underlying C GObject.
const GInputStream* gobj () const
 Provides access to the underlying C GObject.
GInputStream* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
gssize read (void* buffer, gsize count, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to read count bytes from the stream into the buffer starting at buffer.
gssize read (void* buffer, gsize count)
 Tries to read count bytes from the stream into the buffer starting at buffer.
bool read_all (void* buffer, gsize count, gsize& bytes_read, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to read count bytes from the stream into the buffer starting at buffer.
bool read_all (void* buffer, gsize count, gsize& bytes_read)
 Tries to read count bytes from the stream into the buffer starting at buffer.
gssize skip (gsize count, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to skip count bytes from the stream.
gssize skip (gsize count)
 Tries to skip count bytes from the stream.
bool close (const Glib::RefPtr< Cancellable >& cancellable)
 Closes the stream, releasing resources related to it.
bool close ()
 Closes the stream, releasing resources related to it.
void read_async (void* buffer, gsize count, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.
void read_async (void* buffer, gsize count, const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.
gssize read_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an asynchronous stream read operation.
void skip_async (gsize count, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer.
void skip_async (gsize count, const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer.
gssize skip_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a stream skip operation.
void close_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Requests an asynchronous closes of the stream, releasing resources related to it.
void close_async (const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Requests an asynchronous closes of the stream, releasing resources related to it.
gboolean close_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes closing a stream asynchronously, started from g_input_stream_close_async().
- Public Member Functions inherited from Glib::Object
void* get_data (const QueryQuark& key)
void set_data (const Quark& key, void* data)
void set_data (const Quark& key, void* data, DestroyNotify notify)
void remove_data (const QueryQuark& quark)
void* steal_data (const QueryQuark& quark)
- Public Member Functions inherited from Glib::ObjectBase
void set_property_value (const Glib::ustring& property_name, const Glib::ValueBase&value)
 You probably want to use a specific property_*() accessor method instead.
void get_property_value (const Glib::ustring& property_name, Glib::ValueBase&value) const
 You probably want to use a specific property_*() accessor method instead.
template<class PropertyType >
void set_property (const Glib::ustring& property_name, const PropertyType&value)
 You probably want to use a specific property_*() accessor method instead.
template<class PropertyType >
void get_property (const Glib::ustring& property_name, PropertyType&value) const
 You probably want to use a specific property_*() accessor method instead.
void connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void >& slot)
 You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API.
sigc::connection connect_property_changed_with_return (const Glib::ustring& property_name, const sigc::slot< void >& slot)
 You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API.
void freeze_notify ()
 Increases the freeze count on object.
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify().
virtual void reference () const
 Increment the reference count for this object.
virtual void unreference () const
 Decrement the reference count for this object.
GObject* gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access.
- Public Member Functions inherited from sigc::trackable
 trackable (const trackable &src)
trackableoperator= (const trackable &src)
void add_destroy_notify_callback (void *data, func_destroy_notify func) const
void remove_destroy_notify_callback (void *data) const
void notify_callbacks ()

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gio::InputStreamwrap (GInputStream* object, bool take_copy=false)
 A Glib::wrap() method for this object.

Additional Inherited Members

- Public Types inherited from Glib::Object
typedef void(* DestroyNotify )(gpointer data)
- Protected Member Functions inherited from Glib::Object
 Object ()
 Object (const Glib::ConstructParams& construct_params)
 Object (GObject* castitem)
virtual ~Object ()
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor.
 ObjectBase (const char* custom_type_name)
 A derived constructor always overrides this choice.
 ObjectBase (const std::type_info& custom_type_info)
 This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually.
virtual ~ObjectBase ()=0
void initialize (GObject* castitem)

Detailed Description

Base class for implementing streaming input.

Since glibmm 2.16:

Constructor & Destructor Documentation

virtual Gio::InputStream::~InputStream ( )
virtual

Member Function Documentation

bool Gio::InputStream::close ( const Glib::RefPtr< Cancellable >&  cancellable)

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will throw a Gio::Error with CLOSED. Closing a stream multiple times will not return an error.

Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still throw a Gio::Error with CLOSED for all operations. Still, it is important to check and report the error to the user.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn't block to e.g. check errors.

Parameters:
cancellableCancellable object.
Returns:
true on success, false on failure.
bool Gio::InputStream::close ( )

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will throw a Gio::Error with CLOSED. Closing a stream multiple times will not return an error.

Streams will be automatically closed when the last reference is dropped, but you might want to call this make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still throw a Gio::Error with CLOSED for all operations. Still, it is important to check and report the error to the user.

Returns:
true on success, false on failure.
void Gio::InputStream::close_async ( const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Requests an asynchronous closes of the stream, releasing resources related to it.

When the operation is finished slot will be called. You can then call close_finish() to get the result of the operation.

For behaviour details see close().

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:
slotCallback to call when the request is satisfied.
cancellableA Cancellable object.
io_priorityThe I/O priority of the request.
void Gio::InputStream::close_async ( const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Requests an asynchronous closes of the stream, releasing resources related to it.

When the operation is finished slot will be called. You can then call close_finish() to get the result of the operation.

For behaviour details see close().

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:
slotCallback to call when the request is satisfied.
io_priorityThe I/O priority of the request.
gboolean Gio::InputStream::close_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes closing a stream asynchronously, started from g_input_stream_close_async().

Parameters:
resultA AsyncResult.
Returns:
true if the stream was closed successfully.
GInputStream* Gio::InputStream::gobj ( )
inline

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

Reimplemented in Gio::BufferedInputStream, Gio::FileInputStream, Gio::DataInputStream, Gio::FilterInputStream, Gio::MemoryInputStream, and Gio::UnixInputStream.

const GInputStream* Gio::InputStream::gobj ( ) const
inline

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

Reimplemented in Gio::BufferedInputStream, Gio::FileInputStream, Gio::DataInputStream, Gio::FilterInputStream, Gio::MemoryInputStream, and Gio::UnixInputStream.

GInputStream* Gio::InputStream::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Reimplemented in Gio::BufferedInputStream, Gio::FileInputStream, Gio::DataInputStream, Gio::FilterInputStream, Gio::MemoryInputStream, and Gio::UnixInputStream.

gssize Gio::InputStream::read ( void *  buffer,
gsize  count,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to read count bytes from the stream into the buffer starting at buffer.

Will block during this read.

If count is zero returns zero and does nothing. A value of @a count
larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer is returned.
It is not an error if this is not the same as the requested size, as it
can happen e.g. near the end of a file. Zero is returned on end of file
(or if @a count is zero), but never otherwise.

The operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, a Gio::Error will be thrown with CANCELLED. If an
operation was partially finished when the operation was cancelled the
partial result will be returned, without an error.
@param buffer A buffer to read data into (which should be at least count bytes long).
@param count The number of bytes that will be read from the stream.
@param cancellable Cancellable object.
@return Number of bytes read, or -1 on error.
gssize Gio::InputStream::read ( void *  buffer,
gsize  count 
)

Tries to read count bytes from the stream into the buffer starting at buffer.

Will block during this read.

If count is zero returns zero and does nothing. A value of @a count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer is returned.
It is not an error if this is not the same as the requested size, as it
can happen e.g. near the end of a file. Zero is returned on end of file
(or if @a count is zero), but never otherwise.

On error -1 is returned.
@param buffer A buffer to read data into (which should be at least count bytes long).
@param count The number of bytes that will be read from the stream.
@return Number of bytes read, or -1 on error.
bool Gio::InputStream::read_all ( void *  buffer,
gsize  count,
gsize &  bytes_read,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to read count bytes from the stream into the buffer starting at buffer.

Will block during this read.

This function is similar to g_input_stream_read(), except it tries to
read as many bytes as requested, only stopping on an error or end of stream.

On a successful read of @a count bytes, or if we reached the end of the
stream, <tt>true</tt> is returned, and @a bytes_read is set to the number of bytes
read into @a buffer.

If there is an error during the operation <tt>false</tt> is returned and @a error
is set to indicate the error status, @a bytes_read is updated to contain
the number of bytes read into @a buffer before the error occurred.
@param buffer A buffer to read data into (which should be at least count bytes long).
@param count The number of bytes that will be read from the stream.
@param bytes_read Location to store the number of bytes that was read from the stream.
@param cancellable Optional Cancellable object, <tt>0</tt> to ignore.
@return <tt>true</tt> on success, <tt>false</tt> if there was an error.
bool Gio::InputStream::read_all ( void *  buffer,
gsize  count,
gsize &  bytes_read 
)

Tries to read count bytes from the stream into the buffer starting at buffer.

Will block during this read.

This function is similar to read(), except it tries to
read as many bytes as requested, only stopping on an error or end of stream.

On a successful read of @a count bytes, or if we reached the end of the
stream, <tt>true</tt> is returned, and @a bytes_read is set to the number of bytes
read into @a buffer .

If there is an error during the operation <tt>false</tt> is returned and a Gio::Error is thrown to indicate the error status, @a bytes_read is updated to contain
the number of bytes read into @a buffer before the error occured.
@param buffer A buffer to read data into (which should be at least count bytes long).
@param count The number of bytes that will be read from the stream.
@param bytes_read Location to store the number of bytes that was read from the stream.
@return <tt>true</tt> on success, <tt>false</tt> if there was an error.
void Gio::InputStream::read_async ( void *  buffer,
gsize  count,
const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call read_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer will be passed to the slot callback. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise.

Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:
bufferA buffer to read data into (which should be at least count bytes long).
countThe number of bytes that will be read from the stream.
slotCallback to call when the request is satisfied.
cancellableA Cancellable object.
io_priorityThe I/O priority of the request.
void Gio::InputStream::read_async ( void *  buffer,
gsize  count,
const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call read_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in a Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes read into the buffer will be passed to the slot callback. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise.

Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:
bufferA buffer to read data into (which should be at least count bytes long).
countThe number of bytes that will be read from the stream.
slotCallback to call when the request is satisfied.
io_priorityThe I/O priority of the request.
gssize Gio::InputStream::read_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes an asynchronous stream read operation.

Parameters:
resultA AsyncResult.
Returns:
Number of bytes read in, or -1 on error.
gssize Gio::InputStream::skip ( gsize  count,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to skip count bytes from the stream.

Will block during the operation.

This is identical to g_input_stream_read(), from a behaviour standpoint,
but the bytes that are skipped are not returned to the user. Some
streams have an implementation that is more efficient than reading the data.

This function is optional for inherited classes, as the default implementation
emulates it using read.

The operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, a Gio::Error will be thrown with CANCELLED. If an
operation was partially finished when the operation was cancelled the
partial result will be returned, without an error.
@param count The number of bytes that will be skipped from the stream.
@param cancellable Cancellable object.
@return Number of bytes skipped, or -1 on error.
gssize Gio::InputStream::skip ( gsize  count)

Tries to skip count bytes from the stream.

Will block during the operation.

This is identical to read(), from a behaviour standpoint,
but the bytes that are skipped are not returned to the user. Some
streams have an implementation that is more efficient than reading the data.

This function is optional for inherited classes, as the default implementation
emulates it using read.

@param count The number of bytes that will be skipped from the stream.
@return Number of bytes skipped, or -1 on error.
void Gio::InputStream::skip_async ( gsize  count,
const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call skip_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes skipped will be passed to the callback. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise.

Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:
countThe number of bytes that will be skipped from the stream.
slotCallback to call when the request is satisfied.
cancellableA Cancellable object.
io_priorityThe I/O priority of the request.
void Gio::InputStream::skip_async ( gsize  count,
const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous skip of count bytes from the stream into the buffer starting at buffer.

When the operation is finished slot will be called. You can then call skip_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes skipped will be passed to the callback. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise.

Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:
countThe number of bytes that will be skipped from the stream.
slotCallback to call when the request is satisfied.
io_priorityThe I/O priority of the request.
gssize Gio::InputStream::skip_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a stream skip operation.

Parameters:
resultA AsyncResult.
Returns:
The size of the bytes skipped, or %-1 on error.

Friends And Related Function Documentation

Glib::RefPtr< Gio::InputStream > wrap ( GInputStream *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters:
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns:
A C++ instance that wraps this C instance.