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

#include <glibmm/object.h>
#include <giomm/asyncresult.h>
#include <giomm/tlsconnection.h>

_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/object_p.h)
_PINCLUDE(gio/gio.h)

namespace Gio
{

_WRAP_ENUM(TlsInteractionResult, GTlsInteractionResult)
_WRAP_ENUM(TlsCertificateRequestFlags, GTlsCertificateRequestFlags)

class GIOMM_API Cancellable;
class GIOMM_API TlsPassword;

/** TlsInteraction - Interaction with the user during TLS operations.
 * TlsInteraction provides a mechanism for the TLS connection and database code
 * to interact with the user. It can be used to ask the user for passwords.
 *
 * To use a TlsInteraction with a TLS connection use
 * Gio::TlsConnection::set_interaction().
 *
 * Callers should instantiate a derived class that implements the various
 * interaction methods to show the required dialogs.
 *
 * Callers should use the 'invoke' functions like invoke_ask_password() to run
 * interaction methods. These functions make sure that the interaction is
 * invoked in the main loop and not in the current thread, if the current
 * thread is not running the main loop.
 *
 * Derived classes can choose to implement whichever interactions methods
 * they'd like to support by overriding those virtual methods. Any interactions
 * not implemented will return Gio::TLS_INTERACTION_UNHANDLED. If a derived
 * class implements an async method, it must also implement the corresponding
 * finish method.
 * @newin{2,36}
 */
class GIOMM_API TlsInteraction : public Glib::Object
{
  _CLASS_GOBJECT(TlsInteraction, GTlsInteraction, G_TLS_INTERACTION, Glib::Object, GObject, , , GIOMM_API)

protected:
  _CTOR_DEFAULT

public:
  _WRAP_METHOD(TlsInteractionResult ask_password(const Glib::RefPtr<TlsPassword>& password, const Glib::RefPtr<Cancellable>& cancellable{?}), g_tls_interaction_ask_password, errthrow)
  _WRAP_METHOD(void ask_password_async(const Glib::RefPtr<TlsPassword>& password, const SlotAsyncReady& slot{callback?}, const Glib::RefPtr<Cancellable>& cancellable{.?}), g_tls_interaction_ask_password_async, slot_name slot, slot_callback SignalProxy_async_callback)
  _WRAP_METHOD(TlsInteractionResult ask_password_finish(const Glib::RefPtr<AsyncResult>& result), g_tls_interaction_ask_password_finish, errthrow)
  _WRAP_METHOD(TlsInteractionResult invoke_ask_password(const Glib::RefPtr<TlsPassword>& password, const Glib::RefPtr<Cancellable>& cancellable{?}), g_tls_interaction_invoke_ask_password, errthrow)

  _WRAP_METHOD(TlsInteractionResult invoke_request_certificate(const Glib::RefPtr<TlsConnection>& connection, TlsCertificateRequestFlags flags, const Glib::RefPtr<Cancellable>& cancellable{?}), g_tls_interaction_invoke_request_certificate, errthrow)

  _WRAP_METHOD(TlsInteractionResult request_certificate(const Glib::RefPtr<TlsConnection>& connection, TlsCertificateRequestFlags flags, const Glib::RefPtr<Cancellable>& cancellable{?}), g_tls_interaction_request_certificate, errthrow)

  _WRAP_METHOD(void request_certificate_async(const Glib::RefPtr<TlsConnection>& connection, TlsCertificateRequestFlags flags, const SlotAsyncReady& slot{callback?}, const Glib::RefPtr<Cancellable>& cancellable{.?}), g_tls_interaction_request_certificate_async, slot_name slot, slot_callback SignalProxy_async_callback)

  _WRAP_METHOD(TlsInteractionResult request_certificate_finish(const Glib::RefPtr<AsyncResult>& result), g_tls_interaction_request_certificate_finish, errthrow)

protected:
#m4 _CONVERSION(`GTlsPassword*',`const Glib::RefPtr<TlsPassword>&',`Glib::wrap($3, true)')
  _WRAP_VFUNC(TlsInteractionResult ask_password(const Glib::RefPtr<TlsPassword>& password, const Glib::RefPtr<Cancellable>& cancellable), "ask_password", errthrow)
  _WRAP_VFUNC(void ask_password_async(const Glib::RefPtr<TlsPassword>& password, const SlotAsyncReady& slot{callback}, const Glib::RefPtr<Cancellable>& cancellable{.}), "ask_password_async", slot_name slot, slot_callback SignalProxy_async_callback)

#m4 _CONVERSION(`GAsyncResult*',`const Glib::RefPtr<AsyncResult>&',`Glib::wrap($3, true)')
  _WRAP_VFUNC(TlsInteractionResult ask_password_finish(const Glib::RefPtr<AsyncResult>& result), "ask_password_finish", errthrow)
};

} // namespace Gio
