/* -*- mode: c++; c-basic-offset: 4; -*-
 *
 * MICO --- a CORBA implementation
 * Copyright (C) 1997-98 Kay Roemer & Arno Puder
 * 
 * multi-thread dispatcher
 * Copyright (C) 1999 Andreas Schultz                                 
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Send comments and/or bug reports to:
 *                mico@informatik.uni-frankfurt.de
 *
 * $Id: mt_dispatcher.cc,v 1.12 1999/12/28 22:05:42 aschultz Exp $
 *
 */

#define MICO_DEBUG_MODULE MICODebug::Thread

#define MICO_CONF_IMR
#include <CORBA-SMALL.h>
#ifndef _WINDOWS
#include <string.h>
#endif
#include <iostream.h>
#include <mico/impl.h>
#include <mico/template_impl.h>
#include <mico/util.h>

MICO::MTDispatcher::MTDispatcher() {

    __MTOUT( MT_TRACE ( MICODebug::instance()->printer() << "MICO::InputHandler::InputHandler()" << endl ));
    Info().set_OP_id( MICO::Operation::ORB );
}


MICO::MTDispatcher::MTDispatcher( const MICO::MTDispatcher &op ): passiveOperation( op ) {

    Info().set_OP_id( MICO::Operation::ORB );
}

MICO::Operation *
MICO::MTDispatcher::copy() const {

    return new MICO::MTDispatcher( *this );
}

void
MICO::MTDispatcher::process( MICO::msg_type * msg ) {

    MICO::ORBMsg *_msg = (MICO::ORBMsg *)msg->data();

    __MTOUT( MT_TRACE ( MICODebug::instance()->printer() << "MTDispatcher::process" << endl ));
    switch (_msg->ev) {

    case MICO::ORBMsg::KillConn:
	__MTOUT( MT_TRACE ( MICODebug::instance()->printer() << "  ORBMsg::KillConn" << endl ));
	assert( _msg->conn->State() == MICOMT::StateRefCnt::Terminated );
	delete _msg->conn;
	break;
    case MICO::ORBMsg::CloseConn:
	__MTOUT( MT_TRACE ( MICODebug::instance()->printer() << "  ORBMsg::CloseConn" << endl ));
	_msg->cb->callback (_msg->conn, GIOPConnCallback::Closed);
	break;
    default: 
	__MTOUT( MT_TRACE ( MICODebug::instance()->printer() << _msg->ev << endl ));
    }

    delete _msg;
    delete msg;
}

