// **********************************************************************
//
// Generated by the ORBacus IDL-to-C++ Translator
//
// Copyright (c) 1998
// Object-Oriented Concepts, Inc.
// Billerica, MA, USA
//
// Copyright (c) 1998
// Object-Oriented Concepts GmbH
// Ettlingen, Germany
//
// All Rights Reserved
//
// **********************************************************************

// Version: 3.0.1
// License: non-commercial

#include <OB/CORBA.h>
#include <OB/TemplateI.h>
#include "aa_adapter.h"

//
// IDL:aaAdapter:1.0
//
#ifndef HAVE_NO_EXPLICIT_TEMPLATES
template class OBObjVar< aaAdapter >;
template class OBObjForSeq< aaAdapter >;
#else
#ifdef HAVE_PRAGMA_DEFINE
#pragma define(OBObjVar< aaAdapter >)
#pragma define(OBObjForSeq< aaAdapter >)
#endif
#endif

void
OBDuplicate(aaAdapter_ptr p)
{
    if(p)
        p -> _OB_incRef();
}

void
OBRelease(aaAdapter_ptr p)
{
    if(p)
        p -> _OB_decRef();
}

aaAdapter_ptr
aaAdapter::_narrow(CORBA_Object_ptr p)
{
    if(!CORBA_is_nil(p))
    {
        void* v = p -> _OB_narrowHelp("IDL:aaAdapter:1.0");

        if(v)
            return _duplicate((aaAdapter_ptr)v);

        if(p -> _OB_remoteIsA("IDL:aaAdapter:1.0"))
        {
            aaAdapter_ptr val = new aaAdapter;
            val -> _OB_copyFrom(p);
            return val;
        }
    }

    return _nil();
}

void*
aaAdapter::_OB_narrowHelp(const char* _ob_id) const
{
    if(strcmp("IDL:aaAdapter:1.0", _ob_id) == 0)
        return (void*)this;
    else
        return CORBA_Object::_OB_narrowHelp(_ob_id);
}

const char*
aaAdapter::_OB_typeId() const
{
    return "IDL:aaAdapter:1.0";
}

void
OBUnmarshal(aaAdapter_ptr& val, const CORBA_Octet*& coct, bool swap)
{
    aaAdapter_var old = val;
    CORBA_Object_var p;
    OBUnmarshal(p.inout(), coct, swap);

    if(!CORBA_is_nil(p))
    {
        void* v = p -> _OB_narrowHelp("IDL:aaAdapter:1.0");

        if(v)
            val = aaAdapter::_duplicate((aaAdapter_ptr)v);
        else
        {
            assert_nca(!(p -> _is_local() && p -> _is_dynamic()), OBNCADynamicAsStatic);
            assert(!p -> _is_local());
            val = new aaAdapter;
            val -> _OB_copyFrom(p);
        }
    }
    else
        val = aaAdapter::_nil();
}

OBTypeCodeConst _tc_aaAdapter(
"010000000e0000002a000000010000001200000049444c3a6161416461707465723a312e30000"
"0000a00000061614164617074657200"
);

void
operator<<=(CORBA_Any& any, aaAdapter_ptr val)
{
    OBObjAny* o = new OBObjAny;
    o -> b = CORBA_Object::_duplicate(val);
    o -> d = CORBA_Object::_duplicate(val);
    any.replace(_tc_aaAdapter, o, true);
}

void
operator<<=(CORBA_Any& any, aaAdapter_ptr* val)
{
    OBObjAny* o = new OBObjAny;
    o -> b = *val;
    o -> d = CORBA_Object::_duplicate(*val);
    any.replace(_tc_aaAdapter, o, true);
}

CORBA_Boolean
operator>>=(const CORBA_Any& any, aaAdapter_ptr& val)
{
    if(any.check_type(_tc_aaAdapter))
    {
        OBObjAny* o = (OBObjAny*)any.value();
        assert(o);

        if(!CORBA_is_nil(o -> d))
        {
            void* v = o -> d -> _OB_narrowHelp("IDL:aaAdapter:1.0");

            if(v)
                val = (aaAdapter_ptr)v;
            else
            {
                assert_nca(!(o -> d -> _is_local() && o -> d -> _is_dynamic()), OBNCADynamicAsStatic);
                assert(!o -> d -> _is_local());
                val = new aaAdapter;
                val -> _OB_copyFrom(o -> d);
                OBObjAny* no = new OBObjAny;
                no -> b = CORBA_Object::_duplicate(o -> b);
                no -> d = val;
                ((CORBA_Any&)any).replace(_tc_aaAdapter, no, true);
            }
        }
        else
            val = aaAdapter::_nil();

        return true;
    }
    else
        return false;
}

//
// IDL:aaAdapter/inject:1.0
//
void
aaAdapter::inject(CORBA_Long _ob_a0,
                  CORBA_Long _ob_a1)
{
    if(CORBA_is_nil(_ob_clt_))
        throw CORBA_NO_IMPLEMENT();

    CORBA_ULong _ob_off = _ob_clt_ -> offset(this, "inject");
    CORBA_ULong _ob_cnt = _ob_off;
    OBMarshalCount(_ob_a0, _ob_cnt);
    OBMarshalCount(_ob_a1, _ob_cnt);

    OBBuffer _ob_buf(_ob_cnt);
    CORBA_Octet* _ob_o = _ob_buf.data + _ob_off;
    OBMarshal(_ob_a0, _ob_o);
    OBMarshal(_ob_a1, _ob_o);

    bool _ob_sw, _ob_ex, _ob_fo;
    _ob_off = _ob_clt_ -> request(this, "inject", _ob_buf, _ob_sw, _ob_ex, _ob_fo, _ob_tout_);

    if(_ob_fo)
    {
        const CORBA_Octet* _ob_co = _ob_buf.data + _ob_off;
        _OB_forward(_ob_co, _ob_sw);
        inject(_ob_a0, _ob_a1);
        return;
    }

    if(_ob_ex)
        throw CORBA_UNKNOWN();
}
