/* $Id: serverprovider.hg,v 1.16 2006/11/30 06:58:55 murrayc Exp $ */
// -*- C++ -*- //

/* serverprovider.h
 *
 * Copyright 2001      Free Software Foundation
 *
 * 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 <libgdamm/statement.h>
//#include <libgdamm/connection.h>
#include <libgdamm/serveroperation.h>
#include <libgdamm/datahandler.h>

_DEFS(libgdamm,libgda)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gnome
{

namespace Gda
{

_WRAP_GERROR(ServerProviderError, GdaServerProviderError, GDA_SERVER_PROVIDER_ERROR)

_WRAP_ENUM(ConnectionFeature, GdaConnectionFeature)

class Connection;
class SqlParser;

/* TODO: Is this appropriate. Investigate how it is used. */
typedef GdaServerProviderInfo ServerProviderInfo;


/** Base class for all the DBMS providers.
  *
  * The ServerProvider class is an abstract class which all the DBMS providers
  * must inherit, and implement its virtual methods.
  *
  * @ingroup Connections
  */

class ServerProvider : public Glib::Object
{
  _CLASS_GOBJECT(ServerProvider, GdaServerProvider, GDA_SERVER_PROVIDER, Glib::Object, GObject)

public:
  _WRAP_METHOD(Glib::ustring get_version() const, gda_server_provider_get_version)

  _WRAP_METHOD(Glib::ustring get_server_version(const Glib::RefPtr<Connection>& cnc) const, gda_server_provider_get_server_version)

  //TODO: options may be NULL: Add a method overload.
  _WRAP_METHOD(bool supports_operation(const Glib::RefPtr<Connection>& cnc, ServerOperationType type, const Glib::RefPtr<Set>& options) const, gda_server_provider_supports_operation)

  _WRAP_METHOD(Glib::RefPtr<ServerOperation> create_operation(const Glib::RefPtr<Connection>& cnc, ServerOperationType type, const Glib::RefPtr<Set>& options), gda_server_provider_create_operation, errthrow)
  
  /** Creates a new Gda::ServerOperation object which can be modified in order to perform the @a type type of
   * action. The @a options can contain:
   * &lt;itemizedlist&gt;
   * &lt;listitem&gt;named values which ID is a path in the resulting GdaServerOperation object, to initialize some value&lt;/listitem&gt;
   * &lt;listitem&gt;named values which may change the contents of the GdaServerOperation, see this section for more information&lt;/listitem&gt;
   * &lt;/itemizedlist&gt;
   * @param cnc A Gda::Connection object which will be used to perform an action, or <tt>0</tt>.
   * @param type The type of operation requested.
   * @return A new Gda::ServerOperation object, or <tt>0</tt> in the provider does not support the @a type type
   * of operation or if an error occurred.
   */
  Glib::RefPtr<ServerOperation> create_operation(const Glib::RefPtr<Connection>& cnc, ServerOperationType type);


  _WRAP_METHOD(Glib::ustring render_operation(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<ServerOperation>& op), gda_server_provider_render_operation, errthrow)
  _WRAP_METHOD(bool perform_operation(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<ServerOperation>& op), gda_server_provider_perform_operation, errthrow)

  _WRAP_METHOD(bool supports_feature(const Glib::RefPtr<Connection>& cnc, ConnectionFeature feature) const, gda_server_provider_supports_feature)


  _WRAP_METHOD(Glib::ustring value_to_sql_string(const Glib::RefPtr<Connection>& cnc, const Value& from) const, gda_server_provider_value_to_sql_string)

  _WRAP_METHOD(Glib::ustring escape_string(const Glib::RefPtr<Connection>& cnc, const Glib::ustring& str) const, gda_server_provider_escape_string)
  _WRAP_METHOD(Glib::ustring unescape_string(const Glib::RefPtr<Connection>& cnc, const Glib::ustring& str) const, gda_server_provider_unescape_string)

  _WRAP_METHOD(Glib::RefPtr<DataHandler> get_data_handler_dbms(const Glib::RefPtr<Connection>& cnc,  const Glib::ustring& for_type), gda_server_provider_get_data_handler_dbms, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const DataHandler> get_data_handler_dbms(const Glib::RefPtr<Connection>& cnc,  const Glib::ustring& for_type) const, gda_server_provider_get_data_handler_dbms, constversion)

  _WRAP_METHOD(Glib::RefPtr<DataHandler> get_data_handler_g_type(const Glib::RefPtr<Connection>& cnc, GType for_type), gda_server_provider_get_data_handler_g_type, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const DataHandler> get_data_handler_g_type(const Glib::RefPtr<Connection>& cnc, GType for_type) const, gda_server_provider_get_data_handler_g_type, refreturn, constversion)

  _WRAP_METHOD(Glib::ustring get_default_dbms_type(const Glib::RefPtr<Connection>& cnc, GType type) const, gda_server_provider_get_default_dbms_type)

  _WRAP_METHOD(Glib::ustring get_name() const, gda_server_provider_get_name)
  _WRAP_METHOD(Glib::RefPtr<SqlParser> create_parser(const Glib::RefPtr<Connection>& cnc), gda_server_provider_create_parser)
  
  _WRAP_METHOD_DOCS_ONLY(gda_server_provider_string_to_value)

  //TODO: ValueBase can't be used as a return type.
  Value string_to_value(const Glib::RefPtr<Connection>& cnc, const Glib::ustring& string, GType prefered_type, Glib::ustring& dbms_type) const;

  _WRAP_METHOD(Glib::RefPtr<DataHandler> get_data_handler_default(const Glib::RefPtr<Connection>& cnc, GType type, const Glib::ustring& dbms_type), gda_server_provider_get_data_handler_default)

  //TODO: Should this be const?
  _WRAP_METHOD(std::string find_file(const std::string& inst_dir, const std::string& filename), gda_server_provider_find_file)

  _WRAP_METHOD(bool perform_operation_default(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<ServerOperation>& op), gda_server_provider_perform_operation_default, errthrow)
    
  // These are in a private header, so ignore them
  _IGNORE(gda_server_provider_handler_declare, gda_server_provider_handler_find, 
          gda_server_provider_internal_get_parser)

protected:
 //TODO: vfuncs.
};

} // namespace Gda
} // namespace Gnome

