// Generated by gmmproc 2.89.0 -- DO NOT MODIFY!


#include <glibmm.h>

#include <giomm/socketlistener.h>
#include <giomm/private/socketlistener_p.h>


/* Copyright (C) 2010 Jonathon Jongsma
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <gio/gio.h>
#include <giomm/slot_async.h>

using Event = Gio::SocketListener::Event;

namespace Gio
{

bool
SocketListener::add_socket(const Glib::RefPtr<Socket>& socket)
{
  GError* gerror = nullptr;
  const bool retval = g_socket_listener_add_socket(gobj(), Glib::unwrap(socket), nullptr, &gerror);

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

  return retval;
}

bool
SocketListener::add_address(const Glib::RefPtr<SocketAddress>& address, Socket::Type type,
  Socket::Protocol protocol, const Glib::RefPtr<Glib::Object>& source_object,
  Glib::RefPtr<SocketAddress>& effective_address)
{
  GError* gerror = nullptr;
  GSocketAddress* retaddr = nullptr;
  const bool retval =
    g_socket_listener_add_address(gobj(), Glib::unwrap(address), static_cast<GSocketType>(type),
      static_cast<GSocketProtocol>(protocol), Glib::unwrap(source_object), &retaddr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  if (retaddr)
    effective_address = Glib::wrap(retaddr);

  return retval;
}

bool
SocketListener::add_address(const Glib::RefPtr<SocketAddress>& address, Socket::Type type,
  Socket::Protocol protocol, Glib::RefPtr<SocketAddress>& effective_address)
{
  GError* gerror = nullptr;
  GSocketAddress* retaddr = nullptr;
  const bool retval =
    g_socket_listener_add_address(gobj(), Glib::unwrap(address), static_cast<GSocketType>(type),
      static_cast<GSocketProtocol>(protocol), nullptr, &retaddr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  if (retaddr)
    effective_address = Glib::wrap(retaddr);

  return retval;
}

bool
SocketListener::add_inet_port(guint16 port)
{
  GError* gerror = nullptr;
  const bool retvalue = g_socket_listener_add_inet_port(gobj(), port, nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;
}

guint16
SocketListener::add_any_inet_port()
{
  GError* gerror = nullptr;
  const auto retvalue = g_socket_listener_add_any_inet_port(gobj(), nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;
}

Glib::RefPtr<Socket>
SocketListener::accept_socket(
  Glib::RefPtr<Glib::Object>& source_object, const Glib::RefPtr<Cancellable>& cancellable)
{
  GError* gerror = nullptr;
  GObject* retobj = nullptr;
  auto retvalue =
    g_socket_listener_accept_socket(gobj(), &retobj, Glib::unwrap(cancellable), &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  if (retobj)
    source_object = Glib::wrap(retobj);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<Socket>
SocketListener::accept_socket(Glib::RefPtr<Glib::Object>& source_object)
{
  GError* gerror = nullptr;
  GObject* retobj = nullptr;
  auto retvalue = g_socket_listener_accept_socket(gobj(), &retobj, nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  if (retobj)
    source_object = Glib::wrap(retobj);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<Socket>
SocketListener::accept_socket(const Glib::RefPtr<Cancellable>& cancellable)
{
  GError* gerror = nullptr;
  auto retvalue =
    g_socket_listener_accept_socket(gobj(), nullptr, Glib::unwrap(cancellable), &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<Socket>
SocketListener::accept_socket()
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_accept_socket(gobj(), nullptr, nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return Glib::wrap(retvalue);
}

void
SocketListener::accept_socket_async(
  const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot)
{
  // Create a copy of the slot.
  // A pointer to it will be passed through the callback's data parameter
  // and deleted in the callback.
  auto slot_copy = new SlotAsyncReady(slot);

  g_socket_listener_accept_socket_async(
    gobj(), Glib::unwrap(cancellable), &giomm_SignalProxy_async_callback, slot_copy);
}

void
SocketListener::accept_socket_async(const SlotAsyncReady& slot)
{
  // Create a copy of the slot.
  // A pointer to it will be passed through the callback's data parameter
  // and deleted in the callback.
  auto slot_copy = new SlotAsyncReady(slot);

  g_socket_listener_accept_socket_async(gobj(), nullptr, &giomm_SignalProxy_async_callback, slot_copy);
}

Glib::RefPtr<Socket>
SocketListener::accept_socket_finish(
  const Glib::RefPtr<AsyncResult>& result, Glib::RefPtr<Glib::Object>& source_object)
{
  GError* gerror = nullptr;
  GObject* retobj = nullptr;
  auto retvalue =
    g_socket_listener_accept_socket_finish(gobj(), Glib::unwrap(result), &retobj, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);
  if (retobj)
    source_object = Glib::wrap(retobj);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<Socket>
SocketListener::accept_socket_finish(const Glib::RefPtr<AsyncResult>& result)
{
  GError* gerror = nullptr;
  auto retvalue =
    g_socket_listener_accept_socket_finish(gobj(), Glib::unwrap(result), nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<SocketConnection>
SocketListener::accept(
  Glib::RefPtr<Object>& source_object, const Glib::RefPtr<Cancellable>& cancellable)
{
  GError* gerror = nullptr;
  GObject* retobj = nullptr;
  auto retvalue = g_socket_listener_accept(gobj(), &retobj, Glib::unwrap(cancellable), &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  if (retobj)
    source_object = Glib::wrap(retobj);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<SocketConnection>
SocketListener::accept(Glib::RefPtr<Object>& source_object)
{
  GError* gerror = nullptr;
  GObject* retobj = nullptr;
  auto retvalue = g_socket_listener_accept(gobj(), &retobj, nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  if (retobj)
    source_object = Glib::wrap(retobj);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<SocketConnection>
SocketListener::accept(const Glib::RefPtr<Cancellable>& cancellable)
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_accept(gobj(), nullptr, Glib::unwrap(cancellable), &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<SocketConnection>
SocketListener::accept()
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_accept(gobj(), nullptr, nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return Glib::wrap(retvalue);
}

void
SocketListener::accept_async(const SlotAsyncReady& slot)
{
  // Create a copy of the slot.
  // A pointer to it will be passed through the callback's data parameter
  // and deleted in the callback.
  auto slot_copy = new SlotAsyncReady(slot);

  g_socket_listener_accept_async(gobj(), nullptr, &giomm_SignalProxy_async_callback, slot_copy);
}

void
SocketListener::accept_async(
  const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot)
{
  // Create a copy of the slot.
  // A pointer to it will be passed through the callback's data parameter
  // and deleted in the callback.
  auto slot_copy = new SlotAsyncReady(slot);

  g_socket_listener_accept_async(
    gobj(), Glib::unwrap(cancellable), &giomm_SignalProxy_async_callback, slot_copy);
}

Glib::RefPtr<SocketConnection>
SocketListener::accept_finish(
  const Glib::RefPtr<AsyncResult>& result, Glib::RefPtr<Glib::Object>& source_object)
{
  GError* gerror = nullptr;
  GObject* retobj = nullptr;
  auto retvalue = g_socket_listener_accept_finish(gobj(), Glib::unwrap(result), &retobj, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);
  if (retobj)
    source_object = Glib::wrap(retobj);

  return Glib::wrap(retvalue);
}

Glib::RefPtr<SocketConnection>
SocketListener::accept_finish(const Glib::RefPtr<AsyncResult>& result)
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_accept_finish(gobj(), Glib::unwrap(result), nullptr, &gerror);
  if (gerror)
    ::Glib::Error::throw_exception(gerror);

  return Glib::wrap(retvalue);
}

} // namespace Gio

namespace
{


extern "C" {
static void SocketListener_signal_event_connect_callback(GSocketListener* self, GSocketListenerEvent event,GSocket* socket,void* data)
{
  using namespace Gio;
  using SlotType = sigc::slot<void(Event, const Glib::RefPtr<Socket>&)>;

  auto obj = dynamic_cast<SocketListener*>(Glib::ObjectBase::_get_current_wrapper((GObject*) self));
  // Do not try to call a signal on a disassociated wrapper.
  if(obj)
  {
    try
    {
      if(const auto slot = Glib::SignalProxyNormal::data_to_slot(data))
        (*static_cast<SlotType*>(slot))(static_cast<Event>(event)
, Glib::wrap(socket, true)
);
    }
    catch(...)
    {
       Glib::exception_handlers_invoke();
    }
  }
}
} // extern "C"

static const Glib::SignalProxyInfo SocketListener_signal_event_info =
{
  "event",
  (GCallback) &SocketListener_signal_event_connect_callback,
  (GCallback) &SocketListener_signal_event_connect_callback
};


} // anonymous namespace

// static
GType Glib::Value<Gio::SocketListener::Event>::value_type()
{
  return g_socket_listener_event_get_type();
}


namespace Glib
{

Glib::RefPtr<Gio::SocketListener> wrap(GSocketListener* object, bool take_copy)
{
  return Glib::make_refptr_for_instance<Gio::SocketListener>( dynamic_cast<Gio::SocketListener*> (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& SocketListener_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_ = &SocketListener_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_socket_listener_get_type());

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

  }

  return *this;
}


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


}


Glib::ObjectBase* SocketListener_Class::wrap_new(GObject* object)
{
  return new SocketListener((GSocketListener*)object);
}


/* The implementation: */

GSocketListener* SocketListener::gobj_copy()
{
  reference();
  return gobj();
}

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

}

SocketListener::SocketListener(GSocketListener* castitem)
:
  Glib::Object((GObject*)(castitem))
{}


SocketListener::SocketListener(SocketListener&& src) noexcept
: Glib::Object(std::move(src))
{}

SocketListener& SocketListener::operator=(SocketListener&& src) noexcept
{
  Glib::Object::operator=(std::move(src));
  return *this;
}


SocketListener::~SocketListener() noexcept
{}


SocketListener::CppClassType SocketListener::socketlistener_class_; // initialize static member

GType SocketListener::get_type()
{
  return socketlistener_class_.init().get_type();
}


GType SocketListener::get_base_type()
{
  return g_socket_listener_get_type();
}


SocketListener::SocketListener()
:
  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(nullptr),
  Glib::Object(Glib::ConstructParams(socketlistener_class_.init()))
{
  

}

Glib::RefPtr<SocketListener> SocketListener::create()
{
  return Glib::make_refptr_for_instance<SocketListener>( new SocketListener() );
}

void SocketListener::set_backlog(int listen_backlog)
{
  g_socket_listener_set_backlog(gobj(), listen_backlog);
}

bool SocketListener::add_socket(const Glib::RefPtr<Socket>& socket, const Glib::RefPtr<Glib::Object>& source_object)
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_add_socket(gobj(), const_cast<GSocket*>(Glib::unwrap(socket)), Glib::unwrap(source_object), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
  return retvalue;
}

bool SocketListener::add_inet_port(guint16 port, const Glib::RefPtr<Glib::Object>& source_object)
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_add_inet_port(gobj(), port, Glib::unwrap(source_object), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
  return retvalue;
}

guint16 SocketListener::add_any_inet_port(const Glib::RefPtr<Glib::Object>& source_object)
{
  GError* gerror = nullptr;
  auto retvalue = g_socket_listener_add_any_inet_port(gobj(), Glib::unwrap(source_object), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
  return retvalue;
}

void SocketListener::close()
{
  g_socket_listener_close(gobj());
}


Glib::SignalProxy<void(Event, const Glib::RefPtr<Socket>&)> SocketListener::signal_event()
{
  return Glib::SignalProxy<void(Event, const Glib::RefPtr<Socket>&) >(this, &SocketListener_signal_event_info);
}


Glib::PropertyProxy< int > SocketListener::property_listen_backlog() 
{
  return Glib::PropertyProxy< int >(this, "listen-backlog");
}

Glib::PropertyProxy_ReadOnly< int > SocketListener::property_listen_backlog() const
{
  return Glib::PropertyProxy_ReadOnly< int >(this, "listen-backlog");
}


} // namespace Gio


