[omniORB] Callback loop stalling: sample code

Kevin Bailey noone@nowhere.com
Mon, 30 Oct 2000 08:49:14 -0800


--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Fri, Oct 27, 2000 at 03:45:23PM +0100, Duncan Grisby wrote:
> On Wednesday 25 October, Kevin Bailey wrote:
> 
> > I'm having trouble with a test of a callback client that I've
> > written. The client sits in a loop which makes two method calls
> > to a server. The server makes a call back to the client in the
> > second method call.
> 
> Can you post all of your code?  From what you've posted, it looks like
> it ought to work.

Attached is a sample program which is much simpler but displays
the same problem as mine. Again, this is omniORB 3.0.2 on
FreeBSD 4.1.

Thanks,
krb

--
Return address is bogus, please reply to list.

--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="test.idl"

interface Test
{
	void function1();
	void function2(in Test testref);
};

--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="test_impl.cc"

#include <iostream.h>
#include "test.hh"

class Test_i: public POA_Test
{
public:
  virtual void function1();
  virtual void function2(Test_ptr);
};

// This is the callback function. The server calls client->function1()
void Test_i::function1()
{
  cout << "function1" << endl;
}

// The client calls this (server->function2(client))
// with the client's object reference.
//
// As shown, it calls back function1 of the object reference passed it.
void Test_i::function2(Test_ptr testref)
{
  cout << "function2" << endl;
  
  testref->function1();
}

// A junk structure I use to pass 2 arguments to the thread.
struct TestrefPair
{
  Test_ptr our_testref, their_testref;
};

// The test loop
void run_test(TestrefPair *p_testref_pair)
{
  unsigned count = 0;
  
  while (1)
  {
    // Here, the client calls the server's function2
    // which will call back the client's function1.
    p_testref_pair->their_testref->function2(p_testref_pair->our_testref);
    
    // Progress indicator. Gets up to 939 or 940.
    cout << ++count;
  }
}

int main(int argc, char** argv)
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
    
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
    
    // Keep the next 3 outside the following block so
    // they don't disappear.
    Test_i our_test;
    Test_var our_testref = our_test._this();
    TestrefPair testref_pair;
    
    // The client will be passed an object reference on the command line.
    // If we're the client, convert reference to Test and spawn thread.
    if( argc == 2) {
      
      CORBA::Object_var obj = orb->string_to_object(argv[1]);
      Test_var their_testref = Test::_narrow(obj);
      if( CORBA::is_nil(their_testref) ) {
        cerr << "Can't narrow reference to type Echo (or it was nil)." << endl;
        return 1;
      }
      
      testref_pair.our_testref = Test::_duplicate(our_testref);
      testref_pair.their_testref = Test::_duplicate(their_testref);
      
      omni_thread* pot = new omni_thread((void(*)(void*))run_test,
                                         (void*)&testref_pair);
      pot->start();
    }
    
    CORBA::String_var sior(orb->object_to_string(our_testref));
    cerr << (char*)sior << endl;
    
    PortableServer::POAManager_var pman = poa->the_POAManager();
    pman->activate();

    orb->run();
    orb->destroy();
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
         << "object." << endl;
  }
  catch(CORBA::SystemException&) {
    cerr << "Caught a CORBA::SystemException." << endl;
  }
  catch(CORBA::Exception&) {
    cerr << "Caught CORBA::Exception." << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  catch(...) {
    cerr << "Caught unknown exception." << endl;
  }

  return 0;
}

--cWoXeonUoKmBZSoM--