/*
 *  MICO --- an Open Source CORBA implementation
 *  Copyright (c) 1997-2003 by The Mico Team
 *
 *  This file was automatically generated. DO NOT EDIT!
 */

#include "DataBaseCorba.h"


using namespace std;

//--------------------------------------------------------
//  Implementation of stubs
//--------------------------------------------------------


/*
 * Base interface for class DataBaseCorba
 */

DataBaseCorba::~DataBaseCorba()
{
}

void *
DataBaseCorba::_narrow_helper( const char *_repoid )
{
  if( strcmp( _repoid, "IDL:DataBaseCorba:1.0" ) == 0 )
    return (void *)this;
  return NULL;
}

DataBaseCorba_ptr
DataBaseCorba::_narrow( CORBA::Object_ptr _obj )
{
  DataBaseCorba_ptr _o;
  if( !CORBA::is_nil( _obj ) ) {
    void *_p;
    if( (_p = _obj->_narrow_helper( "IDL:DataBaseCorba:1.0" )))
      return _duplicate( (DataBaseCorba_ptr) _p );
    if (!strcmp (_obj->_repoid(), "IDL:DataBaseCorba:1.0") || _obj->_is_a_remote ("IDL:DataBaseCorba:1.0")) {
      _o = new DataBaseCorba_stub;
      _o->CORBA::Object::operator=( *_obj );
      return _o;
    }
  }
  return _nil();
}

DataBaseCorba_ptr
DataBaseCorba::_narrow( CORBA::AbstractBase_ptr _obj )
{
  return _narrow (_obj->_to_object());
}

class _Marshaller_DataBaseCorba : public ::CORBA::StaticTypeInfo {
    typedef DataBaseCorba_ptr _MICO_T;
  public:
    ~_Marshaller_DataBaseCorba();
    StaticValueType create () const;
    void assign (StaticValueType dst, const StaticValueType src) const;
    void free (StaticValueType) const;
    void release (StaticValueType) const;
    ::CORBA::Boolean demarshal (::CORBA::DataDecoder&, StaticValueType) const;
    void marshal (::CORBA::DataEncoder &, StaticValueType) const;
};


_Marshaller_DataBaseCorba::~_Marshaller_DataBaseCorba()
{
}

::CORBA::StaticValueType _Marshaller_DataBaseCorba::create() const
{
  return (StaticValueType) new _MICO_T( 0 );
}

void _Marshaller_DataBaseCorba::assign( StaticValueType d, const StaticValueType s ) const
{
  *(_MICO_T*) d = ::DataBaseCorba::_duplicate( *(_MICO_T*) s );
}

void _Marshaller_DataBaseCorba::free( StaticValueType v ) const
{
  ::CORBA::release( *(_MICO_T *) v );
  delete (_MICO_T*) v;
}

void _Marshaller_DataBaseCorba::release( StaticValueType v ) const
{
  ::CORBA::release( *(_MICO_T *) v );
}

::CORBA::Boolean _Marshaller_DataBaseCorba::demarshal( ::CORBA::DataDecoder &dc, StaticValueType v ) const
{
  ::CORBA::Object_ptr obj;
  if (!::CORBA::_stc_Object->demarshal(dc, &obj))
    return FALSE;
  *(_MICO_T *) v = ::DataBaseCorba::_narrow( obj );
  ::CORBA::Boolean ret = ::CORBA::is_nil (obj) || !::CORBA::is_nil (*(_MICO_T *)v);
  ::CORBA::release (obj);
  return ret;
}

void _Marshaller_DataBaseCorba::marshal( ::CORBA::DataEncoder &ec, StaticValueType v ) const
{
  ::CORBA::Object_ptr obj = *(_MICO_T *) v;
  ::CORBA::_stc_Object->marshal( ec, &obj );
}

::CORBA::StaticTypeInfo *_marshaller_DataBaseCorba;


/*
 * Stub interface for class DataBaseCorba
 */

DataBaseCorba_stub::~DataBaseCorba_stub()
{
}

#ifndef MICO_CONF_NO_POA

void *
POA_DataBaseCorba::_narrow_helper (const char * repoid)
{
  if (strcmp (repoid, "IDL:DataBaseCorba:1.0") == 0) {
    return (void *) this;
  }
  return NULL;
}

POA_DataBaseCorba *
POA_DataBaseCorba::_narrow (PortableServer::Servant serv) 
{
  void * p;
  if ((p = serv->_narrow_helper ("IDL:DataBaseCorba:1.0")) != NULL) {
    serv->_add_ref ();
    return (POA_DataBaseCorba *) p;
  }
  return NULL;
}

DataBaseCorba_stub_clp::DataBaseCorba_stub_clp ()
{
}

DataBaseCorba_stub_clp::DataBaseCorba_stub_clp (PortableServer::POA_ptr poa, CORBA::Object_ptr obj)
  : CORBA::Object(*obj), PortableServer::StubBase(poa)
{
}

DataBaseCorba_stub_clp::~DataBaseCorba_stub_clp ()
{
}

#endif // MICO_CONF_NO_POA

void DataBaseCorba_stub::SetKey( const char* _par_sql )
{
  CORBA::StaticAny _sa_sql( CORBA::_stc_string, &_par_sql );
  CORBA::StaticRequest __req( this, "SetKey" );
  __req.add_in_arg( &_sa_sql );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
}


#ifndef MICO_CONF_NO_POA

void
DataBaseCorba_stub_clp::SetKey( const char* _par_sql )
{
  PortableServer::Servant _serv = _preinvoke ();
  if (_serv) {
    POA_DataBaseCorba * _myserv = POA_DataBaseCorba::_narrow (_serv);
    if (_myserv) {
      #ifdef HAVE_EXCEPTIONS
      try {
      #endif
        _myserv->SetKey(_par_sql);
      #ifdef HAVE_EXCEPTIONS
      }
      catch (...) {
        _myserv->_remove_ref();
        _postinvoke();
        throw;
      }
      #endif

      _myserv->_remove_ref();
      _postinvoke ();
      return;
    }
    _postinvoke ();
  }

  DataBaseCorba_stub::SetKey(_par_sql);
}

#endif // MICO_CONF_NO_POA

Result_slice* DataBaseCorba_stub::Display( CORBA::Long _par_i )
{
  CORBA::StaticAny _sa_i( CORBA::_stc_long, &_par_i );
  CORBA::StaticAny __res( _marshaller__a10__a100_string );

  CORBA::StaticRequest __req( this, "Display" );
  __req.add_in_arg( &_sa_i );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  return (Result_slice*) __res._retn();
}


#ifndef MICO_CONF_NO_POA

Result_slice*
DataBaseCorba_stub_clp::Display( CORBA::Long _par_i )
{
  PortableServer::Servant _serv = _preinvoke ();
  if (_serv) {
    POA_DataBaseCorba * _myserv = POA_DataBaseCorba::_narrow (_serv);
    if (_myserv) {
      Result_slice * __res;

      #ifdef HAVE_EXCEPTIONS
      try {
      #endif
        __res = _myserv->Display(_par_i);
      #ifdef HAVE_EXCEPTIONS
      }
      catch (...) {
        _myserv->_remove_ref();
        _postinvoke();
        throw;
      }
      #endif

      _myserv->_remove_ref();
      _postinvoke ();
      return __res;
    }
    _postinvoke ();
  }

  return DataBaseCorba_stub::Display(_par_i);
}

#endif // MICO_CONF_NO_POA

class _Marshaller__a10__a100_string : public ::CORBA::StaticTypeInfo {
    typedef CORBA::String_var _MICO_T[ 100 ];
  public:
    ~_Marshaller__a10__a100_string();
    StaticValueType create () const;
    void assign (StaticValueType dst, const StaticValueType src) const;
    void free (StaticValueType) const;
    ::CORBA::Boolean demarshal (::CORBA::DataDecoder&, StaticValueType) const;
    void marshal (::CORBA::DataEncoder &, StaticValueType) const;
};


_Marshaller__a10__a100_string::~_Marshaller__a10__a100_string()
{
}

::CORBA::StaticValueType _Marshaller__a10__a100_string::create() const
{
  return (StaticValueType) new _MICO_T[ 10 ];
}

void _Marshaller__a10__a100_string::assign( StaticValueType d, const StaticValueType s ) const
{
  for( int i = 0; i < 1000; i++ )
    ((CORBA::String_var *) d)[ i ] = ((CORBA::String_var *) s)[ i ];
}

void _Marshaller__a10__a100_string::free( StaticValueType v ) const
{
  delete[] (_MICO_T *) v;
}

::CORBA::Boolean _Marshaller__a10__a100_string::demarshal( ::CORBA::DataDecoder &dc, StaticValueType v ) const
{
  if( !dc.arr_begin() )
    return FALSE;
  for( ::CORBA::ULong i = 0; i < 10; i++ ) {
    if( !_marshaller__a100_string->demarshal( dc, &((_MICO_T*)v)[i] ) )
      return FALSE;
  }
  return dc.arr_end();
}

void _Marshaller__a10__a100_string::marshal( ::CORBA::DataEncoder &ec, StaticValueType v ) const
{
  ec.arr_begin();
  for( ::CORBA::ULong i = 0; i < 10; i++ )
    _marshaller__a100_string->marshal( ec, &((_MICO_T*)v)[i] );
  ec.arr_end();
}

::CORBA::StaticTypeInfo *_marshaller__a10__a100_string;

class _Marshaller__a100_string : public ::CORBA::StaticTypeInfo {
    typedef CORBA::String_var _MICO_T;
  public:
    ~_Marshaller__a100_string();
    StaticValueType create () const;
    void assign (StaticValueType dst, const StaticValueType src) const;
    void free (StaticValueType) const;
    ::CORBA::Boolean demarshal (::CORBA::DataDecoder&, StaticValueType) const;
    void marshal (::CORBA::DataEncoder &, StaticValueType) const;
};


_Marshaller__a100_string::~_Marshaller__a100_string()
{
}

::CORBA::StaticValueType _Marshaller__a100_string::create() const
{
  return (StaticValueType) new _MICO_T[ 100 ];
}

void _Marshaller__a100_string::assign( StaticValueType d, const StaticValueType s ) const
{
  for( int i = 0; i < 100; i++ )
    ((CORBA::String_var *) d)[ i ] = ((CORBA::String_var *) s)[ i ];
}

void _Marshaller__a100_string::free( StaticValueType v ) const
{
  delete[] (_MICO_T *) v;
}

::CORBA::Boolean _Marshaller__a100_string::demarshal( ::CORBA::DataDecoder &dc, StaticValueType v ) const
{
  if( !dc.arr_begin() )
    return FALSE;
  for( ::CORBA::ULong i = 0; i < 100; i++ ) {
    if( !CORBA::_stc_string->demarshal( dc, &((_MICO_T*)v)[i]._for_demarshal() ) )
      return FALSE;
  }
  return dc.arr_end();
}

void _Marshaller__a100_string::marshal( ::CORBA::DataEncoder &ec, StaticValueType v ) const
{
  ec.arr_begin();
  for( ::CORBA::ULong i = 0; i < 100; i++ )
    CORBA::_stc_string->marshal( ec, &((_MICO_T*)v)[i].inout() );
  ec.arr_end();
}

::CORBA::StaticTypeInfo *_marshaller__a100_string;

struct __tc_init_DATABASECORBA {
  __tc_init_DATABASECORBA()
  {
    _marshaller_DataBaseCorba = new _Marshaller_DataBaseCorba;
    _marshaller__a10__a100_string = new _Marshaller__a10__a100_string;
    _marshaller__a100_string = new _Marshaller__a100_string;
  }

  ~__tc_init_DATABASECORBA()
  {
    delete static_cast<_Marshaller_DataBaseCorba*>(_marshaller_DataBaseCorba);
    delete static_cast<_Marshaller__a10__a100_string*>(_marshaller__a10__a100_string);
    delete static_cast<_Marshaller__a100_string*>(_marshaller__a100_string);
  }
};

static __tc_init_DATABASECORBA __init_DATABASECORBA;

//--------------------------------------------------------
//  Implementation of skeletons
//--------------------------------------------------------

// PortableServer Skeleton Class for interface DataBaseCorba
POA_DataBaseCorba::~POA_DataBaseCorba()
{
}

::DataBaseCorba_ptr
POA_DataBaseCorba::_this ()
{
  CORBA::Object_var obj = PortableServer::ServantBase::_this();
  return ::DataBaseCorba::_narrow (obj);
}

CORBA::Boolean
POA_DataBaseCorba::_is_a (const char * repoid)
{
  if (strcmp (repoid, "IDL:DataBaseCorba:1.0") == 0) {
    return TRUE;
  }
  return FALSE;
}

CORBA::InterfaceDef_ptr
POA_DataBaseCorba::_get_interface ()
{
  CORBA::InterfaceDef_ptr ifd = PortableServer::ServantBase::_get_interface ("IDL:DataBaseCorba:1.0");

  if (CORBA::is_nil (ifd)) {
    mico_throw (CORBA::OBJ_ADAPTER (0, CORBA::COMPLETED_NO));
  }

  return ifd;
}

CORBA::RepositoryId
POA_DataBaseCorba::_primary_interface (const PortableServer::ObjectId &, PortableServer::POA_ptr)
{
  return CORBA::string_dup ("IDL:DataBaseCorba:1.0");
}

CORBA::Object_ptr
POA_DataBaseCorba::_make_stub (PortableServer::POA_ptr poa, CORBA::Object_ptr obj)
{
  return new ::DataBaseCorba_stub_clp (poa, obj);
}

bool
POA_DataBaseCorba::dispatch (CORBA::StaticServerRequest_ptr __req)
{
  #ifdef HAVE_EXCEPTIONS
  try {
  #endif
    if( strcmp( __req->op_name(), "SetKey" ) == 0 ) {
      CORBA::String_var _par_sql;
      CORBA::StaticAny _sa_sql( CORBA::_stc_string, &_par_sql._for_demarshal() );

      __req->add_in_arg( &_sa_sql );

      if( !__req->read_args() )
        return true;

      SetKey( _par_sql.inout() );
      __req->write_results();
      return true;
    }
    if( strcmp( __req->op_name(), "Display" ) == 0 ) {
      CORBA::Long _par_i;
      CORBA::StaticAny _sa_i( CORBA::_stc_long, &_par_i );

      ::Result_slice* _res;
      CORBA::StaticAny __res( _marshaller__a10__a100_string );
      __req->add_in_arg( &_sa_i );
      __req->set_result( &__res );

      if( !__req->read_args() )
        return true;

      _res = Display( _par_i );
      __res.value( _marshaller__a10__a100_string, _res );
      __req->write_results();
      ::Result_free( _res );
      return true;
    }
  #ifdef HAVE_EXCEPTIONS
  } catch( CORBA::SystemException_catch &_ex ) {
    __req->set_exception( _ex->_clone() );
    __req->write_results();
    return true;
  } catch( ... ) {
    CORBA::UNKNOWN _ex (CORBA::OMGVMCID | 1, CORBA::COMPLETED_MAYBE);
    __req->set_exception (_ex->_clone());
    __req->write_results ();
    return true;
  }
  #endif

  return false;
}

void
POA_DataBaseCorba::invoke (CORBA::StaticServerRequest_ptr __req)
{
  if (dispatch (__req)) {
      return;
  }

  CORBA::Exception * ex = 
    new CORBA::BAD_OPERATION (0, CORBA::COMPLETED_NO);
  __req->set_exception (ex);
  __req->write_results();
}

