// Second_i.cpp,v 1.4 2003/08/18 16:16:30 ossama Exp

#include "Second_i.h"
#include "tao/ORB_Core.h"
#include "tao/debug.h"
#include "tao/Transport_Cache_Manager.h"
#include "tao/Thread_Lane_Resources.h"
#include "ace/Auto_Event.h"


ACE_RCSID (Two_Objects,
           Second_i,
           "Second_i.cpp,v 1.4 2003/08/18 16:16:30 ossama Exp")


Second_i::Second_i (CORBA::ORB_ptr orb,
                    CORBA::ULong len, ACE_Auto_Event &two_way_done)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    length_(len),
    two_way_done_(two_way_done)
{

}

Two_Objects_Test::Octet_Seq *
Second_i::twoway_method (ACE_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  Two_Objects_Test::Octet_Seq  *preply_mesg;

  ACE_NEW_THROW_EX (preply_mesg,
                    Two_Objects_Test::Octet_Seq (this->length_),
                    CORBA::NO_MEMORY ());

  Two_Objects_Test::Octet_Seq_var reply_var =
    preply_mesg;
  reply_var->length ( this->length_);

  ACE_DEBUG ((LM_DEBUG,
              "Twoway servant : (%P|%t) two way method called.\n"));

  // @@ This will not work with the latest copy of ACE+TAO :-). Irfan
  // has moved the cache somewhere else. You may want to check the
  // latest code in BiDir cals again ;)
  // @@ Try to use the current_size () instead of total_size ()
  ACE_ASSERT(this->orb_->orb_core ()->lane_resources().
               transport_cache ().current_size () == 1);

  ACE_DEBUG ((LM_DEBUG,
              "Twoway servant : (%P|%t) about to signal one way thread.\n"));

  two_way_done_.signal ();

  return reply_var._retn ();
}

void
Second_i::shutdown (ACE_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) about to shutdown the orb\n"));
  this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER);
}
