// Generated by gtkmmproc -- DO NOT MODIFY!


#include <giomm/dbusproxy.h>
#include <giomm/private/dbusproxy_p.h>

// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-

/* Copyright (C) 2010 The giomm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gio/gio.h>
#include <giomm/asyncresult.h>
#include <giomm/dbusconnection.h>
#include <giomm/dbusintrospection.h>
#include <giomm/slot_async.h>

namespace Gio
{

DBusProxy::DBusProxy(const Glib::RefPtr<DBusConnection>& connection,
  DBusProxyFlags flags, const Glib::RefPtr<DBusInterfaceInfo>& info,
  const Glib::ustring& name, const Glib::ustring& object_path,
  const Glib::ustring& interface_name, const SlotAsyncReady& slot,
  const Glib::RefPtr<Cancellable>& cancellable)
:
// Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Glib::Object(Glib::ConstructParams(dbusproxy_class_.init(), "g-connection",Glib::unwrap(connection),"g-flags",static_cast<GDBusProxyFlags>(flags),"g-interface-info",Glib::unwrap(info),"name",(name.empty() ? 0 : name.c_str()),"g-object-path",(object_path.empty() ? 0 : object_path.c_str()),"g-interface-name",(interface_name.empty() ? 0 : interface_name.c_str()), static_cast<char*>(0)))
{
  init_async(slot, cancellable);
}

DBusProxy::DBusProxy(const Glib::RefPtr<DBusConnection>& connection,
  DBusProxyFlags flags, const Glib::RefPtr<DBusInterfaceInfo>& info,
  const Glib::ustring& name, const Glib::ustring& object_path,
  const Glib::ustring& interface_name,
  const Glib::RefPtr<Cancellable>& cancellable)
:
// Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Glib::Object(Glib::ConstructParams(dbusproxy_class_.init(), "g-connection",Glib::unwrap(connection),"g-flags",static_cast<GDBusProxyFlags>(flags),"g-interface-info",Glib::unwrap(info),"name",(name.empty() ? 0 : name.c_str()),"g-object-path",(object_path.empty() ? 0 : object_path.c_str()),"g-interface-name",(interface_name.empty() ? 0 : interface_name.c_str()), static_cast<char*>(0)))
{
  init(cancellable);
}

DBusProxy::DBusProxy(BusType bus_type, DBusProxyFlags flags,
  const Glib::RefPtr<DBusInterfaceInfo>& info, const Glib::ustring& name,
  const Glib::ustring& object_path, const Glib::ustring& interface_name,
  const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable)
:
// Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Glib::Object(Glib::ConstructParams(dbusproxy_class_.init(), "g-bus-type",static_cast<GBusType>(bus_type),"g-flags",static_cast<GDBusProxyFlags>(flags),"g-interface-info",Glib::unwrap(info),"name",(name.empty() ? 0 : name.c_str()),"g-object-path",(object_path.empty() ? 0 : object_path.c_str()),"g-interface-name",(interface_name.empty() ? 0 : interface_name.c_str()), static_cast<char*>(0)))
{
  init_async(slot, cancellable);
}

DBusProxy::DBusProxy(BusType bus_type, DBusProxyFlags flags,
  const Glib::RefPtr<DBusInterfaceInfo>& info, const Glib::ustring& name,
  const Glib::ustring& object_path, const Glib::ustring& interface_name,
  const Glib::RefPtr<Cancellable>& cancellable)
:
// Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Glib::Object(Glib::ConstructParams(dbusproxy_class_.init(), "g-bus-type",static_cast<GBusType>(bus_type),"g-flags",static_cast<GDBusProxyFlags>(flags),"g-interface-info",Glib::unwrap(info),"name",(name.empty() ? 0 : name.c_str()),"g-object-path",(object_path.empty() ? 0 : object_path.c_str()),"g-interface-name",(interface_name.empty() ? 0 : interface_name.c_str()), static_cast<char*>(0)))
{
  init(cancellable);
}

void DBusProxy::create(const Glib::RefPtr<DBusConnection>& connection,
  DBusProxyFlags flags, const Glib::RefPtr<DBusInterfaceInfo>& info,
  const Glib::ustring& name, const Glib::ustring& object_path,
  const Glib::ustring& interface_name,
  const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable)
{
  // Create the proxy, taking an extra reference without returning it.  The
  // extra reference is taken so the proxy is not destroyed when it goes out
  // of scope.  The finished proxy will be returned in the slot by calling
  // create_finish().
  Glib::RefPtr<DBusProxy>(new DBusProxy(connection, flags, info, name,
    object_path, interface_name, slot, cancellable))->reference();
}

Glib::RefPtr<DBusProxy>
DBusProxy::create(const Glib::RefPtr<DBusConnection>& connection,
  DBusProxyFlags flags, const Glib::RefPtr<DBusInterfaceInfo>& info,
  const Glib::ustring& name, const Glib::ustring& object_path,
  const Glib::ustring& interface_name,
  const Glib::RefPtr<Cancellable>& cancellable)
{
  return Glib::RefPtr<DBusProxy>(new DBusProxy(connection, flags, info, name,
    object_path, interface_name, cancellable));
}

void DBusProxy::create_for_bus(BusType bus_type, DBusProxyFlags flags,
  const Glib::RefPtr<DBusInterfaceInfo>& info, const Glib::ustring& name,
  const Glib::ustring& object_path, const Glib::ustring& interface_name,
  const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable)
{
  // Create the proxy, taking an extra reference without returning it.  The
  // extra reference is taken so the proxy is not destroyed when it goes out
  // of scope.  The finished proxy will be returned in the slot by calling
  // create_finish().
  Glib::RefPtr<DBusProxy>(new DBusProxy(bus_type, flags, info, name,
    object_path, interface_name, slot, cancellable))->reference();
}

Glib::RefPtr<DBusProxy> DBusProxy::create_for_bus(BusType bus_type,
  DBusProxyFlags flags, const Glib::RefPtr<DBusInterfaceInfo>& info,
  const Glib::ustring& name, const Glib::ustring& object_path,
  const Glib::ustring& interface_name,
  const Glib::RefPtr<Cancellable>& cancellable)
{
  return Glib::RefPtr<DBusProxy>(new DBusProxy(bus_type, flags, info, name,
    object_path, interface_name, cancellable));
}

void DBusProxy::get_cached_property(Glib::VariantBase& property,
  const Glib::ustring& property_name) const
{
  GVariant* const g_variant =
    g_dbus_proxy_get_cached_property(const_cast<GDBusProxy*>(gobj()),
    property_name.c_str());

  property.init(g_variant, false /* no extra reference needed */);
}

void DBusProxy::call(const Glib::ustring& method_name,
  int timeout_msec, const SlotAsyncReady& slot, DBusCallFlags flags,
  const Glib::VariantBase& parameters,
  const Glib::RefPtr<Cancellable>& cancellable)
{
  // Create a copy of the slot.
  // A pointer to it will be passed through the callback's data parameter
  // and deleted in the callback.
  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);

  g_dbus_proxy_call(gobj(), method_name.c_str(),
    const_cast<GVariant*>(parameters.gobj()),
    static_cast<GDBusCallFlags>(flags), timeout_msec,
    Glib::unwrap(cancellable), &SignalProxy_async_callback, slot_copy);
}

void DBusProxy::call_finish(Glib::VariantBase& ret, const Glib::RefPtr<AsyncResult>& res)
{
  GError *g_error = 0;

  GVariant* const g_variant =
    g_dbus_proxy_call_finish(gobj(), Glib::unwrap(res), &g_error);

  if(g_error)
    ::Glib::Error::throw_exception(g_error);

  ret.init(g_variant, false /* don't take extra reference */);
}

void DBusProxy::call_sync(Glib::VariantBase& result,
  const Glib::ustring& method_name, int timeout_msec, DBusCallFlags flags,
  const Glib::VariantBase& parameters, 
  const Glib::RefPtr<Cancellable>& cancellable)
{
  GError *g_error = 0;

  GVariant* const g_variant =
    g_dbus_proxy_call_sync(gobj(), method_name.c_str(), 
    const_cast<GVariant*>(parameters.gobj()),
    static_cast<GDBusCallFlags>(flags), timeout_msec,
    Glib::unwrap(cancellable), &g_error);

  if(g_error)
    ::Glib::Error::throw_exception(g_error);

  result.init(g_variant, false /* don't take extra reference */);
}

} // namespace Gio

namespace
{


static void DBusProxy_signal_signal_callback(GDBusProxy* self, const gchar* p0,const gchar* p1,GVariant* p2,void* data)
{
  using namespace Gio;
  typedef sigc::slot< void,const Glib::ustring&,const Glib::ustring&,const Glib::VariantBase& > SlotType;

  // Do not try to call a signal on a disassociated wrapper.
  if(Glib::ObjectBase::_get_current_wrapper((GObject*) self))
  {
    #ifdef GLIBMM_EXCEPTIONS_ENABLED
    try
    {
    #endif //GLIBMM_EXCEPTIONS_ENABLED
      if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data))
        (*static_cast<SlotType*>(slot))(Glib::convert_const_gchar_ptr_to_ustring(p0)
, Glib::convert_const_gchar_ptr_to_ustring(p1)
, Glib::wrap(p2, true)
);
    #ifdef GLIBMM_EXCEPTIONS_ENABLED
    }
    catch(...)
    {
      Glib::exception_handlers_invoke();
    }
    #endif //GLIBMM_EXCEPTIONS_ENABLED
  }
}

static const Glib::SignalProxyInfo DBusProxy_signal_signal_info =
{
  "g-signal",
  (GCallback) &DBusProxy_signal_signal_callback,
  (GCallback) &DBusProxy_signal_signal_callback
};


} // anonymous namespace


namespace Glib
{

Glib::RefPtr<Gio::DBusProxy> wrap(GDBusProxy* object, bool take_copy)
{
  return Glib::RefPtr<Gio::DBusProxy>( dynamic_cast<Gio::DBusProxy*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
  //We use dynamic_cast<> in case of multiple inheritance.
}

} /* namespace Glib */


namespace Gio
{


/* The *_Class implementation: */

const Glib::Class& DBusProxy_Class::init()
{
  if(!gtype_) // create the GType if necessary
  {
    // Glib::Class has to know the class init function to clone custom types.
    class_init_func_ = &DBusProxy_Class::class_init_function;

    // This is actually just optimized away, apparently with no harm.
    // Make sure that the parent type has been created.
    //CppClassParent::CppObjectType::get_type();

    // Create the wrapper type, with the same class/instance size as the base type.
    register_derived_type(g_dbus_proxy_get_type());

    // Add derived versions of interfaces, if the C type implements any interfaces:

  }

  return *this;
}


void DBusProxy_Class::class_init_function(void* g_class, void* class_data)
{
  BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
  CppClassParent::class_init_function(klass, class_data);


  klass->g_signal = &g_signal_callback;
}


void DBusProxy_Class::g_signal_callback(GDBusProxy* self, const gchar* p0, const gchar* p1, GVariant* p2)
{
  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
      #endif //GLIBMM_EXCEPTIONS_ENABLED
        // Call the virtual member method, which derived classes might override.
        obj->on_signal(Glib::convert_const_gchar_ptr_to_ustring(p0)
, Glib::convert_const_gchar_ptr_to_ustring(p1)
, Glib::wrap(p2, true)
);
        return;
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
      #endif //GLIBMM_EXCEPTIONS_ENABLED
    }
  }
  
  BaseClassType *const base = static_cast<BaseClassType*>(
        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
    );

  // Call the original underlying C function:
  if(base && base->g_signal)
    (*base->g_signal)(self, p0, p1, p2);
}


Glib::ObjectBase* DBusProxy_Class::wrap_new(GObject* object)
{
  return new DBusProxy((GDBusProxy*)object);
}


/* The implementation: */

GDBusProxy* DBusProxy::gobj_copy()
{
  reference();
  return gobj();
}

DBusProxy::DBusProxy(const Glib::ConstructParams& construct_params)
:
  Glib::Object(construct_params)
{

}

DBusProxy::DBusProxy(GDBusProxy* castitem)
:
  Glib::Object((GObject*)(castitem))
{}


DBusProxy::~DBusProxy()
{}


DBusProxy::CppClassType DBusProxy::dbusproxy_class_; // initialize static member

GType DBusProxy::get_type()
{
  return dbusproxy_class_.init().get_type();
}


GType DBusProxy::get_base_type()
{
  return g_dbus_proxy_get_type();
}


Glib::RefPtr<DBusProxy> DBusProxy::create_finish(const Glib::RefPtr<AsyncResult>& result)
{
  GError* gerror = 0;
  Glib::RefPtr<DBusProxy> retvalue = Glib::wrap(g_dbus_proxy_new_finish(Glib::unwrap(result), &(gerror)));

  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;
}


Glib::RefPtr<DBusProxy> DBusProxy::create_for_bus_finish(const Glib::RefPtr<AsyncResult>& result)
{
  GError* gerror = 0;
  Glib::RefPtr<DBusProxy> retvalue = Glib::wrap(g_dbus_proxy_new_for_bus_finish(Glib::unwrap(result), &(gerror)));

  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;
}


DBusProxyFlags DBusProxy::get_flags() const
{
  return ((DBusProxyFlags)(g_dbus_proxy_get_flags(const_cast<GDBusProxy*>(gobj()))));
}

Glib::RefPtr<DBusConnection> DBusProxy::get_connection()
{
  return Glib::wrap(g_dbus_proxy_get_connection(gobj()));
}

Glib::RefPtr<const DBusConnection> DBusProxy::get_connection() const
{
  return Glib::wrap(g_dbus_proxy_get_connection(const_cast<GDBusProxy*>(gobj())));
}

Glib::ustring DBusProxy::get_name() const
{
  return Glib::convert_const_gchar_ptr_to_ustring(g_dbus_proxy_get_name(const_cast<GDBusProxy*>(gobj())));
}

Glib::ustring DBusProxy::get_name_owner() const
{
  return Glib::convert_return_gchar_ptr_to_ustring(g_dbus_proxy_get_name_owner(const_cast<GDBusProxy*>(gobj())));
}

Glib::ustring DBusProxy::get_object_path() const
{
  return Glib::convert_const_gchar_ptr_to_ustring(g_dbus_proxy_get_object_path(const_cast<GDBusProxy*>(gobj())));
}

Glib::ustring DBusProxy::get_interface_name() const
{
  return Glib::convert_const_gchar_ptr_to_ustring(g_dbus_proxy_get_interface_name(const_cast<GDBusProxy*>(gobj())));
}

int DBusProxy::get_default_timeout() const
{
  return g_dbus_proxy_get_default_timeout(const_cast<GDBusProxy*>(gobj()));
}

void DBusProxy::set_default_timeout(int timeout_msec)
{
g_dbus_proxy_set_default_timeout(gobj(), timeout_msec); 
}

void DBusProxy::set_cached_property(const Glib::ustring& property_name, const Glib::VariantBase& value)
{
g_dbus_proxy_set_cached_property(gobj(), property_name.c_str(), const_cast<GVariant*>((value).gobj())); 
}

Glib::StringArrayHandle DBusProxy::get_cached_property_names() const
{
  return Glib::StringArrayHandle(g_dbus_proxy_get_cached_property_names(const_cast<GDBusProxy*>(gobj())));
}

void DBusProxy::set_interface_info(const Glib::RefPtr<DBusInterfaceInfo>& info)
{
g_dbus_proxy_set_interface_info(gobj(), Glib::unwrap(info)); 
}

Glib::RefPtr<DBusInterfaceInfo> DBusProxy::get_interface_info()
{
  return Glib::wrap(g_dbus_proxy_get_interface_info(gobj()));
}

Glib::RefPtr<const DBusInterfaceInfo> DBusProxy::get_interface_info() const
{
  return const_cast<DBusProxy*>(this)->get_interface_info();
}


Glib::SignalProxy3< void,const Glib::ustring&,const Glib::ustring&,const Glib::VariantBase& > DBusProxy::signal_signal()
{
  return Glib::SignalProxy3< void,const Glib::ustring&,const Glib::ustring&,const Glib::VariantBase& >(this, &DBusProxy_signal_signal_info);
}


#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly< Glib::RefPtr<DBusConnection> > DBusProxy::property_g_connection() const
{
  return Glib::PropertyProxy_ReadOnly< Glib::RefPtr<DBusConnection> >(this, "g-connection");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy<int> DBusProxy::property_g_default_timeout() 
{
  return Glib::PropertyProxy<int>(this, "g-default-timeout");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly<int> DBusProxy::property_g_default_timeout() const
{
  return Glib::PropertyProxy_ReadOnly<int>(this, "g-default-timeout");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly<DBusProxyFlags> DBusProxy::property_g_flags() const
{
  return Glib::PropertyProxy_ReadOnly<DBusProxyFlags>(this, "g-flags");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy< Glib::RefPtr<DBusInterfaceInfo> > DBusProxy::property_g_interface_info() 
{
  return Glib::PropertyProxy< Glib::RefPtr<DBusInterfaceInfo> >(this, "g-interface-info");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly< Glib::RefPtr<DBusInterfaceInfo> > DBusProxy::property_g_interface_info() const
{
  return Glib::PropertyProxy_ReadOnly< Glib::RefPtr<DBusInterfaceInfo> >(this, "g-interface-info");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly<Glib::ustring> DBusProxy::property_g_interface_name() const
{
  return Glib::PropertyProxy_ReadOnly<Glib::ustring>(this, "g-interface-name");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly<Glib::ustring> DBusProxy::property_g_name() const
{
  return Glib::PropertyProxy_ReadOnly<Glib::ustring>(this, "g-name");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly<Glib::ustring> DBusProxy::property_g_name_owner() const
{
  return Glib::PropertyProxy_ReadOnly<Glib::ustring>(this, "g-name-owner");
}
#endif //GLIBMM_PROPERTIES_ENABLED

#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly<Glib::ustring> DBusProxy::property_g_object_path() const
{
  return Glib::PropertyProxy_ReadOnly<Glib::ustring>(this, "g-object-path");
}
#endif //GLIBMM_PROPERTIES_ENABLED


void Gio::DBusProxy::on_signal(const Glib::ustring& sender_name, const Glib::ustring& signal_name, const Glib::VariantBase& parameters)
{
  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
  );

  if(base && base->g_signal)
    (*base->g_signal)(gobj(),sender_name.c_str(),signal_name.c_str(),const_cast<GVariant*>((parameters).gobj()));
}


} // namespace Gio


