glibmm: Gio::AsyncResult Class Reference

glibmm 2.89.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gio::AsyncResult Class Reference

Provides a base class for implementing asynchronous function results. More...

`#include <giomm/asyncresult.h>`

Inheritance diagram for Gio::AsyncResult:
[legend]

## Public Member Functions
| AsyncResult (AsyncResult && src) noexcept
AsyncResult & | operator= (AsyncResult && src) noexcept
| ~AsyncResult () noexcept override
GAsyncResult * | gobj ()
| Provides access to the underlying C GObject.
const GAsyncResult * | gobj () const
| Provides access to the underlying C GObject.
Glib::RefPtr< Glib::ObjectBase > | get_source_object_base ()
Glib::RefPtr< const Glib::ObjectBase > | get_source_object_base () const
bool | is_tagged (gpointer source_tag) const
| Checks if res has the given source_tag (generally a function pointer indicating the function res was created by).
Public Member Functions inherited from Glib::Interface
| Interface ()
| A Default constructor.
| Interface (Interface && src) noexcept
Interface & | operator= (Interface && src) noexcept
| Interface (const Glib::Interface_Class & interface_class)
| Called by constructors of derived classes.
| Interface (GObject * castitem)
| Called by constructors of derived classes.
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
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.
template<class PropertyType>
PropertyType | get_property (const Glib::ustring & property_name) const
| You probably want to use a specific property_*() accessor method instead.
sigc::connection | 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.
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
| You can use the signal_changed() signal of the property proxy instead.
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 ()
| Provides access to the underlying C GObject.
const GObject * | gobj () const
| Provides access to the underlying C GObject.
GObject * | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access.
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const

## Static Public Member Functions
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.

## Protected Member Functions
| AsyncResult ()
| You should derive from this class to use it.
virtual Glib::RefPtr< Glib::ObjectBase > | get_source_object_vfunc ()
virtual bool | is_tagged_vfunc (gpointer source_tag)
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.
| ObjectBase (ObjectBase && src) noexcept
ObjectBase & | operator= (ObjectBase && src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject * castitem)
void | initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)

## Related Symbols
(Note that these are not member symbols.)
using | SlotAsyncReady = sigc::slot<void(Glib::RefPtr<AsyncResult>&)>
| A function that will be called when an asynchronous operation within GIO has been completed.
Glib::RefPtr< Gio::AsyncResult > | wrap (GAsyncResult * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Additional Inherited Members
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

Provides a base class for implementing asynchronous function results.

Asynchronous operations are broken up into two separate operations which are chained together by a SlotAsyncReady. To begin an asynchronous operation, provide a SlotAsyncReady to the asynchronous function. This callback will be triggered when the operation has completed, and will be passed an AsyncResult instance (an instance of a class that implements the AsyncResult interface) filled with the details of the operation's success or failure, the object the asynchronous function was started for and any error codes returned. The asynchronous callback function is then expected to call the corresponding "_finish()" function of the object the async function was called for, with the AsyncResult instance.

The purpose of the "_finish()" function is to take the generic result of type AsyncResult and return the specific result that the operation in question yields (e.g. a FileEnumerator for an "enumerate children" operation). If the result or error status of the operation is not needed, there is no need to call the "_finish()" function and GIO will take care of cleaning up the result and error information after the SlotAsyncReady returns. You may also store the AsyncResult and call "_finish()" later. However, the "_finish()" function may be called at most once.

Example of a typical asynchronous operation flow:

class Theoretical : public Glib::Object
{
public:
Glib::RefPtr<Theoretical> create();
void frobnitz_async(const Gio::SlotAsyncReady& slot);
Glib::ustring frobnitz_finish(const Glib::RefPtr<Gio::AsyncResult>& result);
// ...
};
// ...
namespace
{
Glib::RefPtr<Theoretical> theoretical;
void on_frobnitz_ready(Glib::RefPtr<Gio::AsyncResult>& result)
{
try
{
Glib::ustring s = theoretical->frobnitz_finish(result);
std::cout << s << std::endl;
}
catch (const Glib::Error& err)
{
std::cerr << err.what() << std::endl;
}
// ...
}
} // anonymous namespace
int main(int argc, void* argv[])
{
// ...
theoretical = Theoretical::create();
theoretical->frobnitz_async(sigc::ptr_fun(&on_frobnitz_ready));
// ...
}
std::endl
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
std::cerr
ostream cerr
std::cout
ostream cout
Glib::Error
Definition error.h:29
Glib::Error::what
const char * what() const noexcept override
Glib::Object
Definition object.h:89
Glib::ustring
Glib::ustring has much the same interface as std::string, but contains Unicode characters encoded as ...
Definition ustring.h:336
Glib::RefPtr
std::shared_ptr< T_CppObject > RefPtr
RefPtr<> is a reference-counting shared smartpointer.
Definition refptr.h:81
sigc::ptr_fun
decltype(auto) ptr_fun(T_return(*func)(T_args...))

The async function could also take an optional Gio::Cancellable object, allowing the calling function to cancel the asynchronous operation.

The callback for an asynchronous operation is called only once, and is always called, even in the case of a cancelled operation. On cancellation the "_finish()" function will throw a Gio::Error exception with a Gio::Error::CANCELLED error code.

Since glibmm 2.16

## Constructor & Destructor Documentation

## ◆ AsyncResult() [1/2]

Gio::AsyncResult::AsyncResult | ( |  | ) |
| protected

You should derive from this class to use it.

## ◆ AsyncResult() [2/2]

Gio::AsyncResult::AsyncResult | ( | AsyncResult && | src | ) |
| noexcept

## ◆ ~AsyncResult()

Gio::AsyncResult::~AsyncResult | ( |  | ) |
| overridenoexcept

## Member Function Documentation

## ◆ add_interface()

void Gio::AsyncResult::add_interface | ( | GType | gtype_implementer | ) |
| static

## ◆ get_source_object_base() [1/2]

Glib::RefPtr< Glib::ObjectBase > Gio::AsyncResult::get_source_object_base | ( |  | ) |

## ◆ get_source_object_base() [2/2]

Glib::RefPtr< const Glib::ObjectBase > Gio::AsyncResult::get_source_object_base | ( |  | ) | const

## ◆ get_source_object_vfunc()

virtual Glib::RefPtr< Glib::ObjectBase > Gio::AsyncResult::get_source_object_vfunc | ( |  | ) |
| protectedvirtual

## ◆ get_type()

GType Gio::AsyncResult::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GAsyncResult * Gio::AsyncResult::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GAsyncResult * Gio::AsyncResult::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ is_tagged()

bool Gio::AsyncResult::is_tagged | ( | gpointer | source_tag | ) | const

Checks if res has the given source_tag (generally a function pointer indicating the function res was created by).

Since glibmm 2.34

Parameters

  source_tag | An application-defined tag.

Returns
  true if res has the indicated source_tag, false if not.

## ◆ is_tagged_vfunc()

virtual bool Gio::AsyncResult::is_tagged_vfunc | ( | gpointer | source_tag | ) |
| protectedvirtual

## ◆ operator=()

AsyncResult & Gio::AsyncResult::operator= | ( | AsyncResult && | src | ) |
| noexcept

## Friends And Related Symbol Documentation

## ◆ SlotAsyncReady

using SlotAsyncReady = sigc::slot<void(Glib::RefPtr<AsyncResult>&)>
| related

A function that will be called when an asynchronous operation within GIO has been completed.

Parameters

  result | The asynchronous function's results.

For instance,

void on_async_ready(Glib::RefPtr<Gio::AsyncResult>& result);

Since glibmm 2.16

## ◆ wrap()

Glib::RefPtr< Gio::AsyncResult > wrap | ( | GAsyncResult * | object,
|  | bool | take_copy = false )
| related

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

Parameters

  object | The C instance.
  take_copy | False 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.