/* $Id: serveroperation.hg,v 1.2 2006/11/08 00:52:25 murrayc Exp $ */
// -*- C++ -*- //

/* serveroperation.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/value.h>
#include <glibmm/object.h>
#include <glibmm/error.h>
#include <libgda/gda-server-provider.h>

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

namespace Gnome
{

namespace Gda
{


class Connection;
class ServerProvider;

//_WRAP_ENUM(ClientSpecsType, GdaClientSpecsType)
_WRAP_ENUM(ServerOperationNodeType, GdaServerOperationNodeType)
_WRAP_ENUM(ServerOperationNodeStatus, GdaServerOperationNodeStatus)
_WRAP_ENUM(ServerOperationType, GdaServerOperationType)
typedef GdaServerOperationNode ServerOperationNode;

/** @defgroup DDL Data definition (DDL) queries
 */

/** Handles any DDL query in an abstract way.
 *
 * Basically this object is just a named data store: it can store named values, 
 * the values being organized hirarchically. A value can be read from its path
 * (similar to a Unix file path) using the get_value_at() method.
 * 
 * @ingroup DDL
 */
class ServerOperation : public Glib::Object
{
  _CLASS_GOBJECT(ServerOperation, GdaServerOperation, GDA_SERVER_OPERATION, Glib::Object, GObject)

public:
  // These are from gda-easy but they fit in here best
  static Glib::RefPtr<ServerOperation> prepare_create_database(const Glib::ustring& provider,
                                                               const Glib::ustring& db_name);
   
  static Glib::RefPtr<ServerOperation> prepare_drop_database(const Glib::ustring& provider,
                                                             const Glib::ustring& db_name);

  bool perform_drop_database(const Glib::ustring& provider);
  bool perform_create_database(const Glib::ustring& provider);

  // The C version of these take varargs for some reason.
  _WRAP_METHOD_DOCS_ONLY(gda_server_operation_get_value_at)
  Value get_value_at(const Glib::ustring& path_format) const;

  template <class ValueType>
  void set_value_at(const Glib::ustring& path_format, const ValueType& value);

  void set_value_at_as_value(const Glib::ustring& path_format, const Glib::ValueBase& value);

  //TODO: See http://bugzilla.gnome.org/show_bug.cgi?id=574742
  _WRAP_METHOD(ServerOperationNodeType get_node_type(const Glib::ustring& path, ServerOperationNodeStatus& status) const, gda_server_operation_get_node_type)
  _WRAP_METHOD(guint get_sequence_size(const Glib::ustring& path) const, gda_server_operation_get_sequence_size)
  _WRAP_METHOD(guint get_sequence_max_size(const Glib::ustring& path) const, gda_server_operation_get_sequence_max_size)
  _WRAP_METHOD(guint get_sequence_min_size(const Glib::ustring& path) const, gda_server_operation_get_sequence_min_size)

#m4 _CONVERSION(`gchar**',`std::vector<Glib::ustring>', `Glib::ArrayHandler<Glib::ustring>::array_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(std::vector<Glib::ustring> get_sequence_item_names(const Glib::ustring& path) const, gda_server_operation_get_sequence_item_names)

  _WRAP_METHOD(Glib::ustring get_sequence_name(const std::string& path) const, gda_server_operation_get_sequence_name)

  //TODO: Is this XML stuff really public API? murrayc.

  //TODO: get_node_info => varargs
  _WRAP_METHOD(bool is_valid(const std::string& xml_file) const, gda_server_operation_is_valid, errthrow)
  _WRAP_METHOD(bool load_data_from_xml(xmlNodePtr node), gda_server_operation_load_data_from_xml, errthrow)
  _WRAP_METHOD(xmlNodePtr save_data_to_xml(), gda_server_operation_save_data_to_xml, errthrow)  
  _WRAP_METHOD(Glib::ustring get_node_path_portion(const Glib::ustring& path) const, gda_server_operation_get_node_path_portion)
  _WRAP_METHOD(Glib::ustring get_node_parent(const Glib::ustring& path) const, gda_server_operation_get_node_parent)
  _WRAP_METHOD(ServerOperationType get_op_type() const, gda_server_operation_get_op_type)
  
  _WRAP_METHOD(bool del_item_from_sequence(const std::string& item_path), gda_server_operation_del_item_from_sequence)
  _WRAP_METHOD(guint add_item_to_sequence(const std::string& item_path), gda_server_operation_add_item_to_sequence)
  _WRAP_METHOD(std::vector<Glib::ustring> get_root_nodes() const, gda_server_operation_get_root_nodes)

  _WRAP_SIGNAL(void signal_sequence_item_added(Glib::ustring arg1, int arg2), "sequence-item-added", no_default_handler)
  _WRAP_SIGNAL(void signal_sequence_item_remove(Glib::ustring arg1, int arg2), "sequence-item-remove", no_default_handler)

  _WRAP_PROPERTY("connection", Glib::RefPtr<Connection>)
  _WRAP_PROPERTY("op-type", gint)

 //TODO: vfuncs.
};

#ifndef DOXYGEN_SHOULD_SKIP_THIS
template <class ValueType> inline
void ServerOperation::set_value_at(const Glib::ustring& path_format, const ValueType& value)
{
  Gnome::Gda::Value gdavalue(value);
  this->set_value_at_as_value(path_format.c_str(), gdavalue);
}
#endif //DOXYGEN_SHOULD_SKIP_THIS

} // namespace Gda
} // namespace Gnome

