/*
 *  MICO --- a free CORBA implementation
 *  Copyright (C) 1997-98 Kay Roemer & Arno Puder
 *
 *  This file was automatically generated. DO NOT EDIT!
 */

#include "sequences.h"

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



// Stub interface Sequences
Sequences::~Sequences()
{
}

Sequences_ptr Sequences::_duplicate( Sequences_ptr _obj )
{
  if( !CORBA::is_nil( _obj ) )
    _obj->_ref();
  return _obj;
}

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

bool Sequences::_narrow_helper2( CORBA::Object_ptr _obj )
{
  if( strcmp( _obj->_repoid(), "IDL:Sequences:1.0" ) == 0) {
    return true;
  }
  for( vector<CORBA::Narrow_proto>::size_type _i = 0;
       _narrow_helpers && _i < _narrow_helpers->size(); _i++ ) {
    bool _res = (*(*_narrow_helpers)[ _i ])( _obj );
    if( _res )
      return true;
  }
  return false;
}

Sequences_ptr Sequences::_narrow( CORBA::Object_ptr _obj )
{
  Sequences_ptr _o;
  if( !CORBA::is_nil( _obj ) ) {
    void *_p;
    if( (_p = _obj->_narrow_helper( "IDL:Sequences:1.0" )))
      return _duplicate( (Sequences_ptr) _p );
    if( _narrow_helper2( _obj ) ) {
      _o = new Sequences_stub;
      _o->MICO_SCOPE(CORBA,Object::operator=)( *_obj );
      return _o;
    }
  }
  return _nil();
}

Sequences_ptr Sequences::_nil()
{
  return NULL;
}

Sequences_stub::~Sequences_stub()
{
}

Sequences::Longs* Sequences_stub::foo( const Sequences::Ten_shorts& x, Sequences::Ten_shorts*& y, Sequences::Longs& z )
{
  CORBA::StaticAny _x( _marshaller__seq_10b_short, &x );
  CORBA::StaticAny _y( _marshaller__seq_10b_short );
  CORBA::StaticAny _z( CORBA::_stcseq_long, &z );
  CORBA::StaticAny __res( CORBA::_stcseq_long );

  CORBA::StaticRequest __req( this, "foo" );
  __req.add_in_arg( &_x );
  __req.add_out_arg( &_y );
  __req.add_inout_arg( &_z );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  y = (Sequences::Ten_shorts*) _y._retn();
  return (Sequences::Longs*) __res._retn();
}


vector<CORBA::Narrow_proto> * Sequences::_narrow_helpers;

class _Marshaller_Sequences : public CORBA::StaticTypeInfo {
    typedef Sequences_ptr _T;
  public:
    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;
};


CORBA::StaticValueType _Marshaller_Sequences::create() const
{
  return (StaticValueType) new _T( 0 );
}

void _Marshaller_Sequences::assign( StaticValueType d, const StaticValueType s ) const
{
  *(_T*) d = ::Sequences::_duplicate( *(_T*) s );
}

void _Marshaller_Sequences::free( StaticValueType v ) const
{
  CORBA::release( *(_T *) v );
  delete (_T*) v;
}

CORBA::Boolean _Marshaller_Sequences::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
{
  CORBA::Object_ptr obj;
  if( !CORBA::_stc_Object->demarshal( dc, &obj ) )
    return FALSE;
  *(_T *) v = ::Sequences::_narrow( obj );
  CORBA::release( obj );
  return TRUE;
}

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

CORBA::StaticTypeInfo *_marshaller_Sequences;

class _Marshaller__seq_10b_short : public CORBA::StaticTypeInfo {
    typedef BoundedSequenceTmpl<CORBA::Short,MICO_TID_DEF,10> _T;
  public:
    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;
};


CORBA::StaticValueType _Marshaller__seq_10b_short::create() const
{
  return (StaticValueType) new _T;
}

void _Marshaller__seq_10b_short::assign( StaticValueType d, const StaticValueType s ) const
{
  *(_T*) d = *(_T*) s;
}

void _Marshaller__seq_10b_short::free( StaticValueType v ) const
{
  delete (_T*) v;
}

CORBA::Boolean _Marshaller__seq_10b_short::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
{
  CORBA::ULong len;
  if( !dc.seq_begin( len ) )
    return FALSE;
  ((_T *) v)->length( len );
  for( CORBA::ULong i = 0; i < len; i++ ) {
    if( !CORBA::_stc_short->demarshal( dc, &(*(_T*)v)[i] ) )
      return FALSE;
  }
  return dc.seq_end();
}

void _Marshaller__seq_10b_short::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
{
  CORBA::ULong len = ((_T *) v)->length();
  ec.seq_begin( len );
  for( CORBA::ULong i = 0; i < len; i++ )
    CORBA::_stc_short->marshal( ec, &(*(_T*)v)[i] );
  ec.seq_end();
}

CORBA::StaticTypeInfo *_marshaller__seq_10b_short;

struct __tc_init_SEQUENCES {
  __tc_init_SEQUENCES()
  {
    _marshaller_Sequences = new _Marshaller_Sequences;

    _marshaller__seq_10b_short = new _Marshaller__seq_10b_short;

  }
};

static __tc_init_SEQUENCES __init_SEQUENCES;

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

Sequences_skel::Sequences_skel( const CORBA::BOA::ReferenceData &_id )
{
  CORBA::ImplementationDef_var _impl =
    _find_impl( "IDL:Sequences:1.0", "Sequences" );
  assert( !CORBA::is_nil( _impl ) );
  _create_ref( _id,
    CORBA::InterfaceDef::_nil(),
    _impl,
    "IDL:Sequences:1.0" );
  register_dispatcher( new StaticInterfaceDispatcherWrapper<Sequences_skel>( this ) );
}

Sequences_skel::Sequences_skel( CORBA::Object_ptr _obj )
{
  CORBA::ImplementationDef_var _impl =
    _find_impl( "IDL:Sequences:1.0", "Sequences" );
  assert( !CORBA::is_nil( _impl ) );
  _restore_ref( _obj,
    CORBA::BOA::ReferenceData(),
    CORBA::InterfaceDef::_nil(),
    _impl );
  register_dispatcher( new StaticInterfaceDispatcherWrapper<Sequences_skel>( this ) );
}

Sequences_skel::~Sequences_skel()
{
}

bool Sequences_skel::dispatch( CORBA::StaticServerRequest_ptr _req, CORBA::Environment & /*_env*/ )
{
  #ifdef HAVE_EXCEPTIONS
  try {
  #endif
    if( strcmp( _req->op_name(), "foo" ) == 0 ) {
      Ten_shorts x;
      CORBA::StaticAny _x( _marshaller__seq_10b_short, &x );
      Ten_shorts* y;
      CORBA::StaticAny _y( _marshaller__seq_10b_short );
      Longs z;
      CORBA::StaticAny _z( CORBA::_stcseq_long, &z );

      Longs* _res;
      CORBA::StaticAny __res( CORBA::_stcseq_long );
      _req->add_in_arg( &_x );
      _req->add_out_arg( &_y );
      _req->add_inout_arg( &_z );
      _req->set_result( &__res );

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

      _res = foo( x, y, z );
      _y.value( _marshaller__seq_10b_short, y );
      __res.value( CORBA::_stcseq_long, _res );
      _req->write_results();
      delete y;
      delete _res;
      return true;
    }
  #ifdef HAVE_EXCEPTIONS
  } catch( CORBA::SystemException_var &_ex ) {
    _req->set_exception( _ex->_clone() );
    _req->write_results();
    return true;
  } catch( ... ) {
    assert( 0 );
    return true;
  }
  #endif
  return false;
}

Sequences_ptr Sequences_skel::_this()
{
  return Sequences::_duplicate( this );
}

