/* gstreamermm - a C++ wrapper for gstreamer
 *
 * Copyright 2008 The gstreamermm 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 <gst/gst.h>
#include <gstreamermm/element.h>

namespace Gst
{

URIType URIHandler::get_type_vfunc()
{
  BaseClassType *const base = static_cast<BaseClassType*>(
    g_type_interface_peek_parent(
      g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type())
      )  );

  if(base && base->get_type)
  {
    return static_cast<URIType>((*base->get_type)(CppObjectType::get_type()));
  }

  return URIType();
}

GstURIType URIHandler_Class::get_type_vfunc_callback(GType type)
{
  gpointer self = g_object_new(type, nullptr);
  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  if(obj_base && obj_base->is_derived_())
  {
    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj)
    {
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      try
      {
      #endif //GLIBMM_EXCEPTIONS_ENABLED
        return static_cast<GstURIType>(obj->get_type_vfunc());
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
      #endif //GLIBMM_EXCEPTIONS_ENABLED
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
    g_type_interface_peek_parent(
      g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type())
      )  );

  if(base && base->get_type)
  {
    return (*base->get_type)(type);
  }

  return GstURIType();
}

const gchar * const * URIHandler::get_protocols_vfunc() const
{
  BaseClassType *const base = static_cast<BaseClassType*>(
    g_type_interface_peek_parent(
      g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type())
      )  );

  if(base && base->get_protocols)
  {
    return (*base->get_protocols)(CppObjectType::get_type());
  }
  static const gchar* protocols[] = {nullptr};
  return protocols;
}

const gchar * const * URIHandler_Class::get_protocols_vfunc_callback(GType type)
{
  gpointer self = g_object_new(type, nullptr);
  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  if(obj_base && obj_base->is_derived_())
  {
    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj)
    {
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      try
      {
      #endif //GLIBMM_EXCEPTIONS_ENABLED
        return obj->get_protocols_vfunc();
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
      #endif //GLIBMM_EXCEPTIONS_ENABLED
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
    g_type_interface_peek_parent(
      g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type())
      )  );

  if(base && base->get_protocols)
  {
    return (*base->get_protocols)(type);
  }
  static const gchar *protocols[] = { nullptr };
  return protocols;
}
}
