/* 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 <glibmm/object.h>
#include <giomm/socketconnection.h>

_DEFS(giomm,gio)
_PINCLUDE(giomm/private/socketconnection_p.h)

namespace Gio
{

/**
 * A Unix domain SocketConnection
 *
 * This is the subclass of SocketConnection that is created
 * for UNIX domain sockets.
 *
 * It contains functions to do some of the unix socket specific
 * functionallity like passing file descriptors.
 *
 * @newin{2,24}
 * @ingroup NetworkIO
 */
class GIOMM_API UnixConnection : public Gio::SocketConnection
{
    _CLASS_GOBJECT(UnixConnection, GUnixConnection, G_UNIX_CONNECTION, Gio::SocketConnection, GSocketConnection, , , GIOMM_API)
    _GTKMMPROC_WIN32_NO_WRAP

public:
    _WRAP_METHOD(bool send_fd(int fd, const Glib::RefPtr<Cancellable>& cancellable{?}), g_unix_connection_send_fd, errthrow)
    _WRAP_METHOD(int receive_fd(const Glib::RefPtr<Cancellable>& cancellable{?}), g_unix_connection_receive_fd, errthrow)

    _WRAP_METHOD(Glib::RefPtr<Credentials> receive_credentials(const Glib::RefPtr<Cancellable>& cancellable{?}), g_unix_connection_receive_credentials, errthrow)
    _WRAP_METHOD(Glib::RefPtr<const Credentials> receive_credentials(const Glib::RefPtr<Cancellable>& cancellable{?}) const, g_unix_connection_receive_credentials, errthrow, constversion)

  /**  Asynchronously receive credentials.
   * For more details, see receive_credentials() which is the synchronous
   * version of this call.
   *
   * When the operation is finished, @a slot will be called. You can then call
   * receive_credentials_finish() to get the result of the operation.
   *
   * @param slot A SlotAsyncReady to call when the request is satisfied.
   * @param cancellable A Cancellable object.
   * @newin{2,36}
   */
  void receive_credentials_async(const SlotAsyncReady& slot,
    const Glib::RefPtr<Cancellable>& cancellable);
  _IGNORE(g_unix_connection_receive_credentials_async)

  /// A non-cancellable version of receive_credentials_async().
  void receive_credentials_async(const SlotAsyncReady& slot);

  _WRAP_METHOD(Glib::RefPtr<Credentials> receive_credentials_finish(const Glib::RefPtr<AsyncResult>& result), g_unix_connection_receive_credentials_finish, errthrow)

    _WRAP_METHOD(bool send_credentials(const Glib::RefPtr<Cancellable>& cancellable{?}), g_unix_connection_send_credentials, errthrow)

  /**  Asynchronously send credentials.
   * For more details, see send_credentials() which is the synchronous version
   * of this call.
   *
   * When the operation is finished, @a slot will be called. You can then call
   * send_credentials_finish() to get the result of the operation.
   *
   * @param slot A SlotAsyncReady to call when the request is satisfied.
   * @param cancellable A Cancellable object.
   * @newin{2,36}
   */
  void send_credentials_async(const SlotAsyncReady& slot,
    const Glib::RefPtr<Cancellable>& cancellable);
  _IGNORE(g_unix_connection_send_credentials_async)

  /// A non-cancellable version of send_credentials_async().
  void send_credentials_async(const SlotAsyncReady& slot);

  _WRAP_METHOD(bool send_credentials_finish(const Glib::RefPtr<AsyncResult>& result), g_unix_connection_send_credentials_finish, errthrow)
};

} // namespace Gio
