//Editor-Info: -*- C++ -*-
//
//Subject: GSMP
//
//File: gsmpfactory.cpp
//
//Version: $Revision: 1.8 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/10 10:27:00 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//	Vesa-Matti Puro
//      Harri Sunila
//
//Description:
//      See corresponding header file
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//      
//Licence:
//
//History:
//

#include "gsmpfactory.h"
#include "gsmpeventmessages.h"
#include "pf/transp.h"
#include "pf/conduit.h"
#include "gsmpprotocol.h"

gsmpFactory *gsmpFactory::_only = 0;

//
// Function: instance
//
// Description:  
//

gsmpFactory *gsmpFactory :: instance(void)
{
    if (_only == 0)
    {
        _only = new gsmpFactory;
    }
    return _only;
}

//
// Function: init
//
// Description:
//     Initialize gsmpFactory to use the specific gsmpProtocol conduit.
//

void gsmpFactory :: init(const pfConduit &gsmp_)
{
    if (_only != 0)
    {
        _gsmp = gsmp_;
    }
    return;
}

//
// Function: gsmpFactory
//
// Description:  
//

gsmpFactory::gsmpFactory(void)
    : _gsmp()
{
    return;
}

//
// Function: ~gsmpFactory
//
// Description:  
//

gsmpFactory::~gsmpFactory(void)
{
    _only = 0;
    return;
}

//
// Function: createConnectionManagement
//
// Description:
//     Create a gsmpConnectionManagement object, which allows the user to
//     create, modify and delete virtual connections.
//

gsmpConnectionManagement *
gsmpFactory :: createConnectionManagement(swFabricCallback *callback_)
{
    gsmpConnectionManagement *management = 
        new gsmpConnectionManagement(callback_);
    management->connectToA(_gsmp);
    return management;
}

//
// Function: createConfigurationManagement
//
// Description:
//     Create a gsmpConfigurationManagement object, which allows user to get
//     configuration information from the switch.
//

gsmpConfigurationManagement *
gsmpFactory :: createConfigurationManagement(swConfigControl *configControl_)
{
    gsmpConfigurationManagement *management =
        new gsmpConfigurationManagement(configControl_);
    management->connectToA(_gsmp);
    return management;
}

//
// Function: createEventManagement
//
// Description:
//     Create a gsmpEventManagement object, which allows user to get event
//     information from the switch and GSMP protocol.
//

gsmpEventManagement *gsmpFactory :: createEventManagement(swEventIf *eventIf_)
{
    gsmpEventManagement *management = new gsmpEventManagement(eventIf_);
    management->connectToA(_gsmp);

    // Register the Event Management to gsmpProtocol
    gsmpListenEventsMessage *message = new gsmpListenEventsMessage();
    pfUlong transactionIdentifier;
    transactionIdentifier = gsmpProtocol::generateTransactionIdentifier();
    message->setTransactionIdentifier(transactionIdentifier);
    pfMsgTransporter *transporter = pfMsgTransporter::createMsgTransporter(
        message);
    pfConduit sender(management);
    transporter->setSender(sender);
    _gsmp.accept(transporter);
    return management;
}
