// vi:set ft=cpp: -*- Mode: C++ -*-
/**
 * \file
 * \brief IPC helper
 */
/*
 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
 *               Alexander Warg <warg@os.inf.tu-dresden.de>
 *     economic rights: Technische Universität Dresden (Germany)
 *
 * License: see LICENSE.spdx (in this directory or the directories above)
 */
#pragma once

#include <l4/cxx/exceptions>
#include <l4/sys/utcb.h>

/**
 * \defgroup helper IPC Helpers
 */

namespace L4
{
#ifdef __EXCEPTIONS
  /**
   * \brief Throw an L4 IPC error as exception.
   *
   * \ingroup helper
   * \param o    The client side object, for which the IPC was invoked.
   * \param err  The IPC result code (error code).
   * \utcb{utcb}
   */
  inline void
  throw_ipc_exception([[maybe_unused]] L4::Cap<void> const &o,
                      l4_msgtag_t const &err, l4_utcb_t *utcb)
  {
    if (err.has_error())
      throw (L4::Com_error(l4_error_u(err, utcb)));
  }

  /**
   * \brief Throw an L4 IPC error as exception.
   *
   * \ingroup helper
   * \param o    The client side object, for which the IPC was invoked.
   * \param err  The IPC result code (error code).
   * \utcb{utcb}
   */
  inline void
  throw_ipc_exception(void const *o, l4_msgtag_t const &err,
                      l4_utcb_t *utcb)
  { throw_ipc_exception(L4::Cap<void>(o), err, utcb); }
#endif

}
