"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.63.1/gio/src/asyncinitable.hg" (4 May 2019, 5220 Bytes) of package /linux/misc/glibmm-2.63.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2010 The giomm Development Team
    2  *
    3  * This library is free software; you can redistribute it and/or
    4  * modify it under the terms of the GNU Lesser General Public
    5  * License as published by the Free Software Foundation; either
    6  * version 2.1 of the License, or (at your option) any later version.
    7  *
    8  * This library is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11  * Lesser General Public License for more details.
   12  *
   13  * You should have received a copy of the GNU Lesser General Public
   14  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
   15  */
   16 
   17 #include <glibmm/interface.h>
   18 #include <glibmm/priorities.h>
   19 #include <giomm/asyncresult.h>
   20 
   21 _DEFS(giomm,gio)
   22 _PINCLUDE(glibmm/private/interface_p.h)
   23 _PINCLUDE(gio/gio.h)
   24 
   25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   26 typedef struct _GAsyncInitableIface GAsyncInitableIface;
   27 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
   28 
   29 namespace Gio
   30 {
   31 
   32 class Cancellable;
   33 
   34 /** AsyncInitable - Asynchronously failable object initialization interface.
   35  * This is the asynchronous version of Initable; it behaves the same in all
   36  * ways except that initialization is asynchronous. For more details see the
   37  * descriptions on Initable.
   38  *
   39  * A class may implement both the Initable and AsyncInitable interfaces.
   40  *
   41  * Users of objects implementing this are not intended to use the interface
   42  * method directly; instead it will be used automatically in various ways. For
   43  * C applications you generally just call g_async_initable_new_async()
   44  * directly, or indirectly via a foo_thing_new_async() wrapper. This will call
   45  * g_async_initable_init_async() under the cover, calling back with nullptr and a
   46  * set GError on failure.
   47  */
   48 class AsyncInitable : public Glib::Interface
   49 {
   50   _CLASS_INTERFACE(AsyncInitable, GAsyncInitable, G_ASYNC_INITABLE, GAsyncInitableIface)
   51 
   52 protected:
   53   /** Starts asynchronous initialization of the object implementing the
   54    * interface. This must be done before any real use of the object after
   55    * initial construction. If the object also implements Initable you can
   56    * optionally call Gio::Initable::init() instead.
   57    *
   58    * When the initialization is finished, @a slot will be called. You can
   59    * then call init_finish() to get the result of the initialization.
   60    *
   61    * Implementations may also support cancellation. Initialization can be
   62    * cancelled by triggering the @a cancellable object from another thread. If
   63    * the operation was cancelled, the error Gio::IO_ERROR_CANCELLED will be
   64    * returned. If the object doesn't support cancellable initialization, the
   65    * error Gio::IO_ERROR_NOT_SUPPORTED will be returned.
   66    *
   67    * If this function is not called, or returns with an error, then all
   68    * operations on the object should fail, generally returning the error
   69    * Gio::IO_ERROR_NOT_INITIALIZED.
   70    *
   71    * Implementations of this method must be idempotent: i.e. multiple calls to
   72    * this function with the same argument should return the same results. Only
   73    * the first call initializes the object; further calls return the result of
   74    * the first call. This is so that it's safe to implement the singleton
   75    * pattern in the GObject constructor function.
   76    *
   77    * For classes that also support the Initable interface, the default
   78    * implementation of this method will run the Gio::Initable::init() method
   79    * in a thread, so if you want to support asynchronous initialization via
   80    * threads, just implement the AsyncInitable interface without overriding
   81    * any interface methods.
   82    *
   83    * @param io_priority The I/O priority of the operation.
   84    * @param cancellable Cancellable object to make cancellation possible.
   85    * @param slot a SlotAsyncReady to call when the request is satisfied.
   86    *
   87    * @newin{2,28}
   88    */
   89   void init_async(const SlotAsyncReady& slot,
   90     const Glib::RefPtr<Cancellable>& cancellable,
   91     int io_priority = Glib::PRIORITY_DEFAULT);
   92   _IGNORE(g_async_initable_init_async)
   93 
   94   /// Non-cancellable version of init_async().
   95   void init_async(const SlotAsyncReady& slot,
   96     int io_priority = Glib::PRIORITY_DEFAULT);
   97 
   98   _WRAP_METHOD(bool init_finish(const Glib::RefPtr<AsyncResult>& res), g_async_initable_init_finish, errthrow)
   99 
  100   _WRAP_METHOD(Glib::RefPtr<Glib::Object> create_finish(const Glib::RefPtr<AsyncResult>& res), g_async_initable_new_finish, errthrow)
  101 
  102   virtual void init_async_vfunc(const SlotAsyncReady& slot,
  103     const Glib::RefPtr<Cancellable>& cancellable,
  104     int io_priority = Glib::PRIORITY_DEFAULT);
  105 
  106   /** @throw Glib::Errror.
  107    */
  108     virtual bool init_finish_vfunc(const Glib::RefPtr<AsyncResult>& res);
  109 
  110 protected:
  111 #m4begin
  112   _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
  113   klass->init_async = &init_async_vfunc_callback;
  114   klass->init_finish = &init_finish_vfunc_callback;
  115   _SECTION(SECTION_PH_VFUNCS)
  116   static void init_async_vfunc_callback(GAsyncInitable* self,
  117     int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback,
  118     gpointer user_data);
  119   static gboolean init_finish_vfunc_callback(GAsyncInitable* self,
  120     GAsyncResult* res, GError** error);
  121   _POP()
  122 #m4end
  123 };
  124 
  125 } // namespace Gio