glibmm: Gio::AsyncResult Class Reference

# Gio::AsyncResult Class Reference

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

`#include <giomm/asyncresult.h>`

Inheritance diagram for Gio::AsyncResult:
[legend]

List of all members.

## Public Member Functions

virtual | ~AsyncResult ()
GAsyncResult* | gobj ()
| Provides access to the underlying C GObject.
const GAsyncResult* | gobj () const
| Provides access to the underlying C GObject.
Glib::RefPtr< Glib::Object > | get_source_object ()
| Gets the source object from a AsyncResult.
Glib::RefPtr< const Glib::Object > | get_source_object () const
| Gets the source object from a AsyncResult.
Glib::RefPtr< Glib::ObjectBase > | get_source_object_base ()
Glib::RefPtr< const Glib::ObjectBase > | get_source_object_base () const
virtual Glib::RefPtr < Glib::ObjectBase > | get_source_object_vfunc ()

## Static Public Member Functions

static void | add_interface (GType gtype_implementer)

## Related Functions

(Note that these are not member functions.)
Glib::RefPtr< Gio::AsyncResult > | wrap (GAsyncResult* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## 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 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 with the object the function was called for, and 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.

Example of a typical asynchronous operation flow:

     void _theoretical_frobnitz_async(const Glib::RefPtr<Theoretical>& t,                                   const SlotAsyncReady& slot);

     gboolean _theoretical_frobnitz_finish(const Glib::RefPtr<Theoretical>& t,
                                           const Glib::RefPtr<AsyncResult>& result);

     static void  on_frobnitz_result(Glib::RefPtr<AsyncResult>& result)
     {

       Glib::RefPtr<Glib::Object> source_object = result->get_source_object();
       bool success = _theoretical_frobnitz_finish(source_object, res);

       if (success)
         std::cout << "Hurray" << std::endl;
       else      std::cout << "Uh oh!" << std::endl;

       ...
     }

     int main (int argc, void *argv[])
     {
        ...

        _theoretical_frobnitz_async (theoretical_data,                                  sigc::ptr_fun(&on_frobnitz_result) );

        ...
     }

The async function could also take an optional Glib::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 result is a ERROR_CANCELLED error.

Some ascynchronous operations are implemented using synchronous calls. These are run in a separate GThread, but otherwise they are sent to the Main Event Loop and processed in an idle function. So, if you truly need asynchronous operations, make sure to initialize GThread.

Since glibmm 2.16:

## Constructor & Destructor Documentation

virtual Gio::AsyncResult::~AsyncResult | ( |  | ) | `[virtual]`

## Member Function Documentation

static void Gio::AsyncResult::add_interface | ( | GType | gtype_implementer | ) | `[static]`

Glib::RefPtr<const Glib::Object> Gio::AsyncResult::get_source_object | ( |  | ) | const

Gets the source object from a AsyncResult.

Deprecated:
  Use get_source_object_base()

Returns:
  A new reference to the source object for the res, or `0` if there is none.

Glib::RefPtr<Glib::Object> Gio::AsyncResult::get_source_object | ( |  | ) |

Gets the source object from a AsyncResult.

Deprecated:
  Use get_source_object_base()

Returns:
  A new reference to the source object for the res, or `0` if there is none.

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

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

virtual Glib::RefPtr<Glib::ObjectBase> Gio::AsyncResult::get_source_object_vfunc | ( |  | ) | `[virtual]`

const GAsyncResult* Gio::AsyncResult::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::Interface.

GAsyncResult* Gio::AsyncResult::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::Interface.

## Friends And Related Function Documentation

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.