// src/backend/sgpemv2/module.hh - Copyright 2005, 2006, University
//               of Padova, dept. of Pure and Applied
//               Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// SGPEMv2 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.


#ifndef MODULE_HH
#define MODULE_HH 1

#include <sgpemv2/sgpemv2-visibility.hh>

#include <sgpemv2/invalid_plugin_exception.hh>

#include <glibmm/module.h>
#include <glibmm/ustring.h>

namespace sgpem
{

  /// \brief A link to a loaded DSO object
  ///
  /// When a plugin is found, PluginManager::rescan_dirs() tries to load it by
  /// creating an object of this class.
  /// The constructor should throw InvalidPluginException if the plugin isn't 
  /// a valid SGPEMv2 one. This should be handled directly into
  /// PluginManager::rescan_dirs().
  class Module;

  class SG_DLLEXPORT Module : public Glib::Module
  {
  public:

    /// \brief Constructor taking an identifier.
    /// 
    /// Constructor taking an identifier.
    /// \throw InvalidPluginException If the DSO you're trying to load
    ///  doesn't export a valid SGPEMv2 backend::Plugin interface.
    /// \param identifier A string with the DSO name without any file-extension 
    /// suffix. This is retrieved by PluginManager::rescan_dirs().
    Module(const Glib::ustring& identifier);

    /// \brief Enables or disables a plugin
    ///
    /// Enables/disables a plugin, calling its on_init()/on_exit() exported 
    /// functions where appropriate.
    /// \param enabled whether to enable or disable the module.
    void set_enabled(bool enabled = true);

    /// \brief Returns the name of the module.
    ///
    /// Calls Plugin::get_name()
    /// \return the name of the module.
    Glib::ustring get_name() const;

    /// \brief Returns the author of the module.
    ///
    /// Calls Plugin::get_author()
    /// \return the author of the module.
    Glib::ustring get_author() const;

    /// \brief Returns a description of the module.
    ///
    /// Calls Plugin::describe()
    /// \return a description of the module.
    Glib::ustring describe() const;

    /// \brief Returns the version of the module.
    ///
    /// Calls Plugin::get_version()
    /// \return the version of the module.
    float get_version() const;

    /// \brief Returns whether the module is enabled or disabled.
    ///
    /// Enables/disables a plugin, calling its on_init()/on_exit() exported 
    /// functions where appropriate.
    /// \param enabled whether to enable or disable the module.
    bool get_enabled() const;

  private:
    typedef void (*f_void)(void);
    typedef const char* (*f_ustring)(void);
    typedef float (*f_float)(void);

    /// True if the plugin is enabled, false otherwise
    ///
    bool _enabled;

    /// A string containing the DSO name, stripped of any file-extension suffix
    ///
    Glib::ustring _id;

    f_void    on_init_ptr;
    f_void    on_exit_ptr;
    f_ustring describe_ptr;
    f_ustring get_name_ptr;
    f_ustring get_author_ptr;
    f_float   get_version_ptr;

  }
  ; //~ class Module

} //~ namespace sgpem

#endif

