// Generated by gtkmmproc -- DO NOT MODIFY!


#include <libgdamm/client.h>
#include <libgdamm/private/client_p.h>

/* $Id: client.ccg,v 1.2 2006/10/21 09:20:04 murrayc Exp $ */
// -*- C++ -*- //

/* client.cc
 * 
 * Copyright 2003 libgdamm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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/serveroperation.h>
#include <libgda/gda-client.h>
#include <libgda/gda-enum-types.h>

namespace Gnome
{


} /* namespace Gnome */


namespace
{


static void Client_signal_event_notification_callback(GdaClient* self, GdaConnection* p0,GdaClientEvent p1,GdaParameterList* p2,void* data)
{
  using namespace Gnome::Gda;
  typedef sigc::slot< void,const Glib::RefPtr<Connection>&,ClientEvent,const Glib::RefPtr<ParameterList>& > SlotType;

  // Do not try to call a signal on a disassociated wrapper.
  if(Glib::ObjectBase::_get_current_wrapper((GObject*) self))
  {
    #ifdef GLIBMM_EXCEPTIONS_ENABLED
    try
    {
    #endif //GLIBMM_EXCEPTIONS_ENABLED
      if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data))
        (*static_cast<SlotType*>(slot))(Glib::wrap(p0)
, ((ClientEvent)(p1))
, Glib::wrap(p2)
);
    #ifdef GLIBMM_EXCEPTIONS_ENABLED
    }
    catch(...)
    {
      Glib::exception_handlers_invoke();
    }
    #endif //GLIBMM_EXCEPTIONS_ENABLED
  }
}

static const Glib::SignalProxyInfo Client_signal_event_notification_info =
{
  "event_notification",
  (GCallback) &Client_signal_event_notification_callback,
  (GCallback) &Client_signal_event_notification_callback
};


} // anonymous namespace


Gnome::Gda::ClientError::ClientError(Gnome::Gda::ClientError::Code error_code, const Glib::ustring& error_message)
:
  Glib::Error (GDA_CLIENT_ERROR, error_code, error_message)
{}

Gnome::Gda::ClientError::ClientError(GError* gobject)
:
  Glib::Error (gobject)
{}

Gnome::Gda::ClientError::Code Gnome::Gda::ClientError::code() const
{
  return static_cast<Code>(Glib::Error::code());
}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
void Gnome::Gda::ClientError::throw_func(GError* gobject)
{
  throw Gnome::Gda::ClientError(gobject);
}
#else
//When not using exceptions, we just pass the Exception object around without throwing it:
std::auto_ptr<Glib::Error> Gnome::Gda::ClientError::throw_func(GError* gobject)
{
  return std::auto_ptr<Glib::Error>(new Gnome::Gda::ClientError(gobject));
}
#endif //GLIBMM_EXCEPTIONS_ENABLED

// static
GType Glib::Value<Gnome::Gda::ClientError::Code>::value_type()
{
  return gda_client_error_get_type();
}

// static
GType Glib::Value<Gnome::Gda::ClientEvent>::value_type()
{
  return gda_client_event_get_type();
}


namespace Glib
{

Glib::RefPtr<Gnome::Gda::Client> wrap(GdaClient* object, bool take_copy)
{
  return Glib::RefPtr<Gnome::Gda::Client>( dynamic_cast<Gnome::Gda::Client*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
  //We use dynamic_cast<> in case of multiple inheritance.
}

} /* namespace Glib */


namespace Gnome
{

namespace Gda
{


/* The *_Class implementation: */

const Glib::Class& Client_Class::init()
{
  if(!gtype_) // create the GType if necessary
  {
    // Glib::Class has to know the class init function to clone custom types.
    class_init_func_ = &Client_Class::class_init_function;

    // This is actually just optimized away, apparently with no harm.
    // Make sure that the parent type has been created.
    //CppClassParent::CppObjectType::get_type();

    // Create the wrapper type, with the same class/instance size as the base type.
    register_derived_type(gda_client_get_type());

    // Add derived versions of interfaces, if the C type implements any interfaces:

  }

  return *this;
}

void Client_Class::class_init_function(void* g_class, void* class_data)
{
  BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
  CppClassParent::class_init_function(klass, class_data);

#ifdef GLIBMM_VFUNCS_ENABLED
#endif //GLIBMM_VFUNCS_ENABLED

#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
  klass->event_notification = &event_notification_callback;
#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
}

#ifdef GLIBMM_VFUNCS_ENABLED
#endif //GLIBMM_VFUNCS_ENABLED

#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
void Client_Class::event_notification_callback(GdaClient* self, GdaConnection* p0, GdaClientEvent p1, GdaParameterList* p2)
{
  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
      #endif //GLIBMM_EXCEPTIONS_ENABLED
        // Call the virtual member method, which derived classes might override.
        obj->on_event_notification(Glib::wrap(p0)
, ((ClientEvent)(p1))
, Glib::wrap(p2)
);
        return;
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
      #endif //GLIBMM_EXCEPTIONS_ENABLED
    }
  }
  
  BaseClassType *const base = static_cast<BaseClassType*>(
        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
    );

  // Call the original underlying C function:
  if(base && base->event_notification)
    (*base->event_notification)(self, p0, p1, p2);
}
#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED


Glib::ObjectBase* Client_Class::wrap_new(GObject* object)
{
  return new Client((GdaClient*)object);
}


/* The implementation: */

GdaClient* Client::gobj_copy()
{
  reference();
  return gobj();
}

Client::Client(const Glib::ConstructParams& construct_params)
:
  Glib::Object(construct_params)
{

}

Client::Client(GdaClient* castitem)
:
  Glib::Object((GObject*)(castitem))
{}

Client::~Client()
{}


Client::CppClassType Client::client_class_; // initialize static member

GType Client::get_type()
{
  return client_class_.init().get_type();
}

GType Client::get_base_type()
{
  return gda_client_get_type();
}


Client::Client()
:
  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Glib::Object(Glib::ConstructParams(client_class_.init()))
{
  

}

Glib::RefPtr<Client> Client::create()
{
  return Glib::RefPtr<Client>( new Client() );
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<Connection> Client::open_connection(const Glib::ustring& dsn, const Glib::ustring& username, const Glib::ustring& password, ConnectionOptions options)
#else
Glib::RefPtr<Connection> Client::open_connection(const Glib::ustring& dsn, const Glib::ustring& username, const Glib::ustring& password, ConnectionOptions options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  Glib::RefPtr<Connection> retvalue = Glib::wrap(gda_client_open_connection(gobj(), dsn.c_str(), username.c_str(), password.c_str(), ((GdaConnectionOptions)(options)), &(gerror)));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<Connection> Client::open_connection_from_string(const Glib::ustring& provider_id, const Glib::ustring& cnc_string, const Glib::ustring& username, const Glib::ustring& password, ConnectionOptions options)
#else
Glib::RefPtr<Connection> Client::open_connection_from_string(const Glib::ustring& provider_id, const Glib::ustring& cnc_string, const Glib::ustring& username, const Glib::ustring& password, ConnectionOptions options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  Glib::RefPtr<Connection> retvalue = Glib::wrap(gda_client_open_connection_from_string(gobj(), provider_id.c_str(), cnc_string.c_str(), username.c_str(), password.c_str(), ((GdaConnectionOptions)(options)), &(gerror)));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}

void Client::declare_connection(const Glib::RefPtr<Connection>& cnc)
{
gda_client_declare_connection(gobj(), Glib::unwrap(cnc)); 
}

Glib::ListHandle< Glib::RefPtr<Connection> > Client::get_connections()
{
  return Glib::ListHandle< Glib::RefPtr<Connection> >((GList*)gda_client_get_connections(gobj()), Glib::OWNERSHIP_NONE);
}

Glib::ListHandle< Glib::RefPtr<const Connection> > Client::get_connections() const
{
  return Glib::ListHandle< Glib::RefPtr<const Connection> >((GList*)gda_client_get_connections(const_cast<GdaClient*>(gobj())), Glib::OWNERSHIP_NONE);
}

Glib::RefPtr<Connection> Client::find_connection(const Glib::ustring& dsn, const Glib::ustring& username, const Glib::ustring& password)
{

  Glib::RefPtr<Connection> retvalue = Glib::wrap(gda_client_find_connection(gobj(), dsn.c_str(), username.c_str(), password.c_str()));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;

}

void Client::close_all_connections()
{
gda_client_close_all_connections(gobj()); 
}

void Client::notify_event(const Glib::RefPtr<Connection>& cnc, ClientEvent event, const Glib::RefPtr<ParameterList>& params)
{
gda_client_notify_event(gobj(), Glib::unwrap(cnc), ((GdaClientEvent)(event)), Glib::unwrap(params)); 
}

void Client::notify_error_event(const Glib::RefPtr<Connection>& cnc, GdaConnectionEvent * error)
{
gda_client_notify_error_event(gobj(), Glib::unwrap(cnc), error); 
}

void Client::notify_connection_opened_event(const Glib::RefPtr<Connection>& cnc)
{
gda_client_notify_connection_opened_event(gobj(), Glib::unwrap(cnc)); 
}

void Client::notify_connection_closed_event(const Glib::RefPtr<Connection>& cnc)
{
gda_client_notify_connection_closed_event(gobj(), Glib::unwrap(cnc)); 
}

Glib::ustring Client::get_dsn_specs(const Glib::ustring& provider) const
{
  return Glib::convert_return_gchar_ptr_to_ustring(gda_client_get_dsn_specs(const_cast<GdaClient*>(gobj()), provider.c_str()));
}

Glib::RefPtr<ServerOperation> Client::prepare_create_database(const Glib::ustring& db_name, const Glib::ustring& provider)
{
  return Glib::wrap(gda_client_prepare_create_database(gobj(), db_name.c_str(), provider.c_str()));
}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Client::perform_create_database(const Glib::RefPtr<ServerOperation>& op)
#else
bool Client::perform_create_database(const Glib::RefPtr<ServerOperation>& op, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  bool retvalue = gda_client_perform_create_database(gobj(), Glib::unwrap(op), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}

Glib::RefPtr<ServerOperation> Client::prepare_drop_database(const Glib::ustring& db_name, const Glib::ustring& provider)
{
  return Glib::wrap(gda_client_prepare_drop_database(gobj(), db_name.c_str(), provider.c_str()));
}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Client::perform_drop_database(const Glib::RefPtr<ServerOperation>& op)
#else
bool Client::perform_drop_database(const Glib::RefPtr<ServerOperation>& op, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  bool retvalue = gda_client_perform_drop_database(gobj(), Glib::unwrap(op), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Client::begin_transaction(const Glib::ustring& name, TransactionIsolation level)
#else
bool Client::begin_transaction(const Glib::ustring& name, TransactionIsolation level, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  bool retvalue = gda_client_begin_transaction(gobj(), name.c_str(), ((GdaTransactionIsolation)(level)), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Client::commit_transaction(const Glib::ustring& name)
#else
bool Client::commit_transaction(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  bool retvalue = gda_client_commit_transaction(gobj(), name.c_str(), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}

#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Client::rollback_transaction(const Glib::ustring& name)
#else
bool Client::rollback_transaction(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
  GError* gerror = 0;
  bool retvalue = gda_client_rollback_transaction(gobj(), name.c_str(), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
#else
  if(gerror)
    error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED

  return retvalue;

}


Glib::SignalProxy3< void,const Glib::RefPtr<Connection>&,ClientEvent,const Glib::RefPtr<ParameterList>& > Client::signal_event_notification()
{
  return Glib::SignalProxy3< void,const Glib::RefPtr<Connection>&,ClientEvent,const Glib::RefPtr<ParameterList>& >(this, &Client_signal_event_notification_info);
}


#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
void Gnome::Gda::Client::on_event_notification(const Glib::RefPtr<Connection>& cnc, ClientEvent event, const Glib::RefPtr<ParameterList>& params)
{
  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
  );

  if(base && base->event_notification)
    (*base->event_notification)(gobj(),Glib::unwrap(cnc),((GdaClientEvent)(event)),Glib::unwrap(params));
}
#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED

#ifdef GLIBMM_VFUNCS_ENABLED
#endif //GLIBMM_VFUNCS_ENABLED


} // namespace Gda

} // namespace Gnome


