"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.74.0/untracked/gio/giomm/asyncinitable.cc" (19 Sep 2022, 9722 Bytes) of package /linux/misc/glibmm-2.74.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "asyncinitable.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 2.73.2_vs_2.74.0 or 2.72.1_vs_2.74.0.

    1 // Generated by gmmproc 2.74.0 -- DO NOT MODIFY!
    2 
    3 
    4 #include <glibmm.h>
    5 
    6 #include <giomm/asyncinitable.h>
    7 #include <giomm/private/asyncinitable_p.h>
    8 
    9 
   10 /* Copyright (C) 2010 The giomm Development Team
   11  *
   12  * This library is free software; you can redistribute it and/or
   13  * modify it under the terms of the GNU Lesser General Public
   14  * License as published by the Free Software Foundation; either
   15  * version 2.1 of the License, or (at your option) any later version.
   16  *
   17  * This library is distributed in the hope that it will be useful,
   18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20  * Lesser General Public License for more details.
   21  *
   22  * You should have received a copy of the GNU Lesser General Public
   23  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
   24  */
   25 
   26 #include <gio/gio.h>
   27 #include <glibmm/error.h>
   28 #include <glibmm/exceptionhandler.h>
   29 #include <giomm/cancellable.h>
   30 #include <giomm/slot_async.h>
   31 
   32 namespace Gio
   33 {
   34 
   35 void
   36 AsyncInitable::init_async(
   37   const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority)
   38 {
   39   // Create a copy of the slot.
   40   // A pointer to it will be passed through the callback's data parameter
   41   // and deleted in the callback.
   42   auto slot_copy = new SlotAsyncReady(slot);
   43 
   44   g_async_initable_init_async(
   45     gobj(), io_priority, Glib::unwrap(cancellable), &SignalProxy_async_callback, slot_copy);
   46 }
   47 
   48 void
   49 AsyncInitable::init_async(const SlotAsyncReady& slot, int io_priority)
   50 {
   51   // Create a copy of the slot.
   52   // A pointer to it will be passed through the callback's data parameter
   53   // and deleted in the callback.
   54   auto slot_copy = new SlotAsyncReady(slot);
   55 
   56   g_async_initable_init_async(gobj(), io_priority, nullptr, &SignalProxy_async_callback, slot_copy);
   57 }
   58 
   59 void
   60 AsyncInitable_Class::init_async_vfunc_callback(GAsyncInitable* self, int io_priority,
   61   GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
   62 {
   63   const auto obj_base =
   64     static_cast<Glib::ObjectBase*>(Glib::ObjectBase::_get_current_wrapper((GObject*)self));
   65 
   66   // Non-gtkmmproc-generated custom classes implicitly call the default
   67   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
   68   // generated classes can use this optimisation, which avoids the unnecessary
   69   // parameter conversions if there is no possibility of the virtual function
   70   // being overridden:
   71   if (obj_base && obj_base->is_derived_())
   72   {
   73     const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
   74     if (obj) // This can be nullptr during destruction.
   75     {
   76       try // Trap C++ exceptions which would normally be lost because this is a C callback.
   77       {
   78         // Get the slot.
   79         Gio::SlotAsyncReady* the_slot = static_cast<Gio::SlotAsyncReady*>(user_data);
   80 
   81         // Call the virtual member method, which derived classes might override.
   82         obj->init_async_vfunc(*the_slot, Glib::wrap(cancellable, true), io_priority);
   83         return;
   84       }
   85       catch (...)
   86       {
   87         Glib::exception_handlers_invoke();
   88       }
   89     }
   90   }
   91 
   92   const auto base = static_cast<BaseClassType*>(
   93     g_type_interface_peek_parent( // Get the parent interface of the interface (The original
   94                                   // underlying C interface).
   95       g_type_interface_peek(
   96         G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
   97       ));
   98 
   99   // Call the original underlying C function:
  100   if (base && base->init_async)
  101     (*base->init_async)(self, io_priority, cancellable, callback, user_data);
  102 }
  103 void
  104 Gio::AsyncInitable::init_async_vfunc(
  105   const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority)
  106 {
  107   const auto base = static_cast<BaseClassType*>(
  108     g_type_interface_peek_parent( // Get the parent interface of the interface (The original
  109                                   // underlying C interface).
  110       g_type_interface_peek(
  111         G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
  112       ));
  113 
  114   if (base && base->init_async)
  115   {
  116     (*base->init_async)(gobj(), io_priority, const_cast<GCancellable*>(Glib::unwrap(cancellable)),
  117       &SignalProxy_async_callback, const_cast<SlotAsyncReady*>(&slot));
  118   }
  119 }
  120 gboolean
  121 AsyncInitable_Class::init_finish_vfunc_callback(
  122   GAsyncInitable* self, GAsyncResult* res, GError** error)
  123 {
  124   const auto obj_base =
  125     static_cast<Glib::ObjectBase*>(Glib::ObjectBase::_get_current_wrapper((GObject*)self));
  126 
  127   // Non-gtkmmproc-generated custom classes implicitly call the default
  128   // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  129   // generated classes can use this optimisation, which avoids the unnecessary
  130   // parameter conversions if there is no possibility of the virtual function
  131   // being overridden:
  132   if (obj_base && obj_base->is_derived_())
  133   {
  134     const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
  135     if (obj) // This can be nullptr during destruction.
  136     {
  137       try // Trap C++ exceptions which would normally be lost because this is a C callback.
  138       {
  139         // Call the virtual member method, which derived classes might override.
  140         return static_cast<int>(obj->init_finish_vfunc(Glib::wrap(res, true)));
  141       }
  142       catch (...)
  143       {
  144         Glib::exception_handlers_invoke();
  145       }
  146     }
  147   }
  148 
  149   const auto base = static_cast<BaseClassType*>(
  150     g_type_interface_peek_parent( // Get the parent interface of the interface (The original
  151                                   // underlying C interface).
  152       g_type_interface_peek(
  153         G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
  154       ));
  155 
  156   // Call the original underlying C function:
  157   if (base && base->init_finish)
  158     return (*base->init_finish)(self, res, error);
  159 
  160   using RType = gboolean;
  161   return RType();
  162 }
  163 bool
  164 Gio::AsyncInitable::init_finish_vfunc(const Glib::RefPtr<AsyncResult>& res)
  165 {
  166   const auto base = static_cast<BaseClassType*>(
  167     g_type_interface_peek_parent( // Get the parent interface of the interface (The original
  168                                   // underlying C interface).
  169       g_type_interface_peek(
  170         G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
  171       ));
  172 
  173   if (base && base->init_finish)
  174   {
  175     GError* gerror = nullptr;
  176 
  177     bool const result = (*base->init_finish)(gobj(), Glib::unwrap(res), &gerror);
  178 
  179     if (gerror)
  180       ::Glib::Error::throw_exception(gerror);
  181 
  182     return result;
  183   }
  184 
  185   using RType = bool;
  186   return RType();
  187 }
  188 
  189 } // namespace Gio
  190 
  191 namespace
  192 {
  193 } // anonymous namespace
  194 
  195 
  196 namespace Glib
  197 {
  198 
  199 Glib::RefPtr<Gio::AsyncInitable> wrap(GAsyncInitable* object, bool take_copy)
  200 {
  201   return Glib::make_refptr_for_instance<Gio::AsyncInitable>( dynamic_cast<Gio::AsyncInitable*> (Glib::wrap_auto_interface<Gio::AsyncInitable> ((GObject*)(object), take_copy)) );
  202   //We use dynamic_cast<> in case of multiple inheritance.
  203 }
  204 
  205 } // namespace Glib
  206 
  207 
  208 namespace Gio
  209 {
  210 
  211 
  212 /* The *_Class implementation: */
  213 
  214 const Glib::Interface_Class& AsyncInitable_Class::init()
  215 {
  216   if(!gtype_) // create the GType if necessary
  217   {
  218     // Glib::Interface_Class has to know the interface init function
  219     // in order to add interfaces to implementing types.
  220     class_init_func_ = &AsyncInitable_Class::iface_init_function;
  221 
  222     // We can not derive from another interface, and it is not necessary anyway.
  223     gtype_ = g_async_initable_get_type();
  224   }
  225 
  226   return *this;
  227 }
  228 
  229 void AsyncInitable_Class::iface_init_function(void* g_iface, void*)
  230 {
  231   const auto klass = static_cast<BaseClassType*>(g_iface);
  232 
  233   //This is just to avoid an "unused variable" warning when there are no vfuncs or signal handlers to connect.
  234   //This is a temporary fix until I find out why I can not seem to derive a GtkFileChooser interface. murrayc
  235   g_assert(klass != nullptr);
  236 
  237   klass->init_async = &init_async_vfunc_callback;
  238   klass->init_finish = &init_finish_vfunc_callback;
  239   
  240 }
  241 
  242 
  243 Glib::ObjectBase* AsyncInitable_Class::wrap_new(GObject* object)
  244 {
  245   return new AsyncInitable((GAsyncInitable*)(object));
  246 }
  247 
  248 
  249 /* The implementation: */
  250 
  251 AsyncInitable::AsyncInitable()
  252 :
  253   Glib::Interface(asyncinitable_class_.init())
  254 {}
  255 
  256 AsyncInitable::AsyncInitable(GAsyncInitable* castitem)
  257 :
  258   Glib::Interface((GObject*)(castitem))
  259 {}
  260 
  261 AsyncInitable::AsyncInitable(const Glib::Interface_Class& interface_class)
  262 : Glib::Interface(interface_class)
  263 {
  264 }
  265 
  266 AsyncInitable::AsyncInitable(AsyncInitable&& src) noexcept
  267 : Glib::Interface(std::move(src))
  268 {}
  269 
  270 AsyncInitable& AsyncInitable::operator=(AsyncInitable&& src) noexcept
  271 {
  272   Glib::Interface::operator=(std::move(src));
  273   return *this;
  274 }
  275 
  276 AsyncInitable::~AsyncInitable() noexcept
  277 {}
  278 
  279 // static
  280 void AsyncInitable::add_interface(GType gtype_implementer)
  281 {
  282   asyncinitable_class_.init().add_interface(gtype_implementer);
  283 }
  284 
  285 AsyncInitable::CppClassType AsyncInitable::asyncinitable_class_; // initialize static member
  286 
  287 GType AsyncInitable::get_type()
  288 {
  289   return asyncinitable_class_.init().get_type();
  290 }
  291 
  292 
  293 GType AsyncInitable::get_base_type()
  294 {
  295   return g_async_initable_get_type();
  296 }
  297 
  298 
  299 bool AsyncInitable::init_finish(const Glib::RefPtr<AsyncResult>& res)
  300 {
  301   GError* gerror = nullptr;
  302   auto retvalue = g_async_initable_init_finish(gobj(), Glib::unwrap(res), &(gerror));
  303   if(gerror)
  304     ::Glib::Error::throw_exception(gerror);
  305   return retvalue;
  306 }
  307 
  308 Glib::RefPtr<Glib::Object> AsyncInitable::create_finish(const Glib::RefPtr<AsyncResult>& res)
  309 {
  310   GError* gerror = nullptr;
  311   auto retvalue = Glib::wrap(g_async_initable_new_finish(gobj(), Glib::unwrap(res), &(gerror)));
  312   if(gerror)
  313     ::Glib::Error::throw_exception(gerror);
  314   return retvalue;
  315 }
  316 
  317 
  318 } // namespace Gio
  319 
  320