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

#include "interface1.h"

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

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

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

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

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

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

T_ptr T::_nil()
{
  return NULL;
}

T_stub::~T_stub()
{
}

CORBA::Long T_stub::x()
{
  CORBA::Long _res;
  CORBA::StaticAny __res( CORBA::_stc_long, &_res );

  CORBA::StaticRequest __req( this, "_get_x" );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  return _res;
}


void T_stub::x( CORBA::Long _value )
{
  CORBA::StaticAny __value( CORBA::_stc_long, &_value );
  CORBA::StaticRequest __req( this, "_set_x" );
  __req.add_in_arg( &__value );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
}


CORBA::Char T_stub::c()
{
  CORBA::Char _res;
  CORBA::StaticAny __res( CORBA::_stc_char, &_res );

  CORBA::StaticRequest __req( this, "_get_c" );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  return _res;
}


void T_stub::op1()
{
  CORBA::StaticRequest __req( this, "op1" );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
}


void T_stub::op2( CORBA::Float y )
{
  CORBA::StaticAny _y( CORBA::_stc_float, &y );
  CORBA::StaticRequest __req( this, "op2" );
  __req.add_in_arg( &_y );

  __req.oneway();

  mico_sii_throw( &__req, 
    0);
}


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

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

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

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

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

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

CORBA::StaticTypeInfo *_marshaller_T;

struct __tc_init_INTERFACE1 {
  __tc_init_INTERFACE1()
  {
    _marshaller_T = new _Marshaller_T;

  }
};

static __tc_init_INTERFACE1 __init_INTERFACE1;

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

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

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

T_skel::~T_skel()
{
}

bool T_skel::dispatch( CORBA::StaticServerRequest_ptr _req, CORBA::Environment & /*_env*/ )
{
  #ifdef HAVE_EXCEPTIONS
  try {
  #endif
    if( strcmp( _req->op_name(), "_get_x" ) == 0 ) {
      CORBA::Long _res;
      CORBA::StaticAny __res( CORBA::_stc_long, &_res );
      _req->set_result( &__res );

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

      _res = x();
      _req->write_results();
      return true;
    }
    if( strcmp( _req->op_name(), "_set_x" ) == 0 ) {
      CORBA::Long _value;
      CORBA::StaticAny __value( CORBA::_stc_long, &_value );

      _req->add_in_arg( &__value );

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

      x( _value );
      _req->write_results();
      return true;
    }
    if( strcmp( _req->op_name(), "_get_c" ) == 0 ) {
      CORBA::Char _res;
      CORBA::StaticAny __res( CORBA::_stc_char, &_res );
      _req->set_result( &__res );

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

      _res = c();
      _req->write_results();
      return true;
    }
    if( strcmp( _req->op_name(), "op1" ) == 0 ) {

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

      op1();
      _req->write_results();
      return true;
    }
    if( strcmp( _req->op_name(), "op2" ) == 0 ) {
      CORBA::Float y;
      CORBA::StaticAny _y( CORBA::_stc_float, &y );

      _req->add_in_arg( &_y );

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

      op2( y );
      _req->write_results();
      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;
}

T_ptr T_skel::_this()
{
  return T::_duplicate( this );
}

