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

#include "arrays.h"

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



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

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

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

bool arrays::_narrow_helper2( CORBA::Object_ptr _obj )
{
  if( strcmp( _obj->_repoid(), "IDL:arrays: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;
}

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

arrays_ptr arrays::_nil()
{
  return NULL;
}

arrays_stub::~arrays_stub()
{
}

arrays::Row_slice* arrays_stub::Move_row( const arrays::Matrix A, arrays::Matrix B, CORBA::Long row_index )
{
  CORBA::StaticAny _A( _marshaller__a100__a20_float, A );
  CORBA::StaticAny _B( _marshaller__a100__a20_float, B );
  CORBA::StaticAny _row_index( CORBA::_stc_long, &row_index );
  CORBA::StaticAny __res( _marshaller__a20_float );

  CORBA::StaticRequest __req( this, "Move_row" );
  __req.add_in_arg( &_A );
  __req.add_out_arg( &_B );
  __req.add_in_arg( &_row_index );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  return (arrays::Row_slice*) __res._retn();
}


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

class _Marshaller_arrays : public CORBA::StaticTypeInfo {
    typedef arrays_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_arrays::create() const
{
  return (StaticValueType) new _T( 0 );
}

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

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

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

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

CORBA::StaticTypeInfo *_marshaller_arrays;

class _Marshaller__a20_float : public CORBA::StaticTypeInfo {
    typedef CORBA::Float _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__a20_float::create() const
{
  return (StaticValueType) new _T[ 20 ];
}

void _Marshaller__a20_float::assign( StaticValueType d, const StaticValueType s ) const
{
  for( int i = 0; i < 20; i++ )
    ((_T *) d)[ i ] = ((_T *) s)[ i ];
}

void _Marshaller__a20_float::free( StaticValueType v ) const
{
  delete[] (_T *) v;
}

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

void _Marshaller__a20_float::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
{
  ec.arr_begin();
  for( CORBA::ULong i = 0; i < 20; i++ )
    CORBA::_stc_float->marshal( ec, &((_T*)v)[i] );
  ec.arr_end();
}

CORBA::StaticTypeInfo *_marshaller__a20_float;

class _Marshaller__a100__a20_float : public CORBA::StaticTypeInfo {
    typedef CORBA::Float _T[ 20 ];
  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__a100__a20_float::create() const
{
  return (StaticValueType) new _T[ 100 ];
}

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

void _Marshaller__a100__a20_float::free( StaticValueType v ) const
{
  delete[] (_T *) v;
}

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

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

CORBA::StaticTypeInfo *_marshaller__a100__a20_float;

struct __tc_init_ARRAYS {
  __tc_init_ARRAYS()
  {
    _marshaller_arrays = new _Marshaller_arrays;

    _marshaller__a20_float = new _Marshaller__a20_float;

    _marshaller__a100__a20_float = new _Marshaller__a100__a20_float;

  }
};

static __tc_init_ARRAYS __init_ARRAYS;

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

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

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

arrays_skel::~arrays_skel()
{
}

bool arrays_skel::dispatch( CORBA::StaticServerRequest_ptr _req, CORBA::Environment & /*_env*/ )
{
  #ifdef HAVE_EXCEPTIONS
  try {
  #endif
    if( strcmp( _req->op_name(), "Move_row" ) == 0 ) {
      Matrix A;
      CORBA::StaticAny _A( _marshaller__a100__a20_float, &A );
      Matrix B;
      CORBA::StaticAny _B( _marshaller__a100__a20_float, &B );
      CORBA::Long row_index;
      CORBA::StaticAny _row_index( CORBA::_stc_long, &row_index );

      Row_slice* _res;
      CORBA::StaticAny __res( _marshaller__a20_float );
      _req->add_in_arg( &_A );
      _req->add_out_arg( &_B );
      _req->add_in_arg( &_row_index );
      _req->set_result( &__res );

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

      _res = Move_row( A, B, row_index );
      __res.value( _marshaller__a20_float, _res );
      _req->write_results();
      Row_free( _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;
}

arrays_ptr arrays_skel::_this()
{
  return arrays::_duplicate( this );
}

