//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / UNI
//
//File: unitransporter.cpp
//
//Version: $Revision: 1.12 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/11/20 10:04:07 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Jari Katajavuori
//
//Description:
//
//
//Copyright:
//
//
//Licence:
//
//
//History: 
//

#include "unitransporter.h"
#include "pf/debug.h"
#include "pf/mux.h"
#include "pf/factory.h"
#include "pf/protocol.h"
#include "pf/state.h"
#include "uniprotocol.h"

uniMuxCatcherTransporter uniMuxCatcherTransporter :: create(void)
{
    uniMuxCatcherTransporter newTransporter;
    return newTransporter;
}

//
// Method: constructors and destructor
//
// Description:
//

uniMuxCatcherTransporter :: uniMuxCatcherTransporter(void)
    : pfTransporter(),
      _mux(0)
{
    setAcceptMethodToSynchronous();
    return;
}

uniMuxCatcherTransporter ::
uniMuxCatcherTransporter(const uniMuxCatcherTransporter &other_)
    : pfTransporter(other_),
      _mux(other_._mux)
{
    return;
}

uniMuxCatcherTransporter :: ~uniMuxCatcherTransporter(void)
{
    return;
}

//
// Method: clone
//
// Description:
//

uniMuxCatcherTransporter *uniMuxCatcherTransporter :: clone(void)
{
    uniMuxCatcherTransporter *transporter =
        new uniMuxCatcherTransporter(*this);
    return transporter;
}

//
// Method: atMux
//
// Description:
//      Gets the pointer of the mux visited.
//

void uniMuxCatcherTransporter :: atMux(pfMux *const mux_)
{
    _mux = mux_;
    return;
}

//
// Method: catchedMux
//
// Description:
//      Returns the pointer catched.
//

pfMux *uniMuxCatcherTransporter :: catchedMux(void)
{
    return _mux;
}

//
// Class: uniCrossConnecter
//
// Method: constructor and destructor
//
// Description:
//

uniCrossConnecter :: uniCrossConnecter(void)
    : pfCrossConnecter(),
      _protocol(0)
{
    setAcceptMethodToSynchronous();
    return;
}

uniCrossConnecter :: ~uniCrossConnecter(void)
{
    return;
}

//
// Method: createUNICrossConnecter
//
// Description:
//

uniCrossConnecter uniCrossConnecter :: createUNICrossConnecter(void)
{
    uniCrossConnecter newCrossConnecter;
    return newCrossConnecter;
}

//
// Method: atFactory
//
// Description:
//

void uniCrossConnecter :: atFactory(pfFactory *const factory_)
{
    //factory_->receivingTrace(this);

    if (isFromA() == 0)
    {
        pfConduit firstConduit;
        pfConduit lastConduit;
        
        factory_->makeConduit(firstConduit, lastConduit);

        factory_->sendInstallerToA(firstConduit);

        // get pointer and call creating method
        firstConduit.accept(this);
        lastConduit = _protocol->createPointToPointConduits();

        setOtherSide(lastConduit);
    }
    else
    {
        // error
    }
}

//
// Method: atProtocol
//
// Description:
//

void uniCrossConnecter :: atProtocol(pfProtocol *const protocol_,
                                     pfState *)
{
    debugPfUlong("Protocol 1: ", (pfUlong)protocol_);
    _protocol = dynamic_cast<uniProtocol*>(protocol_);
    debugPfUlong("Protocol 2: ", (pfUlong)_protocol);
    return;
}

//
// Method: atMux
//
// Description:
//

void uniCrossConnecter :: atMux(pfMux *const mux_)
{
    mux_->toB(this);
    return;
}

