Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Examples

TestClient2_MPI.cc

#include "mpi.h"

#include <unistd.h>
#include <iostream>
#include <sstream>
#include <cassert>
#include "ColCOWS.hh"
 
#include <math.h>
#include "echo.hh"
#ifdef ORBACUS_ORB
#include "echo_skel.hh" 
#endif

using namespace std;

class Echo_impl : public POA_Echo,
                public PortableServer::RefCountServantBase
{
public:
  inline Echo_impl(int num_proc) {_counter = 0; _num_proc = num_proc;}
  virtual ~Echo_impl() {}
  virtual char* echoString(const char* mesg) throw (CORBA::SystemException);

  long int _counter; 
  long int _num_proc; 
};


char* Echo_impl::echoString(const char* mesg) throw (CORBA::SystemException)
{
  _counter++;

  stringstream ss(stringstream::in|stringstream::out);

  ss << "(" << _num_proc << ":" << _counter << ") " << mesg ;
  cout << "Upcall : " << ss.str() << endl;

  return CORBA::string_dup(ss.str().c_str());
}

//===========================================================================//

int main(int argc, char** argv) {
  int base;
  char c;
  int psize, prank;

  // initialisation
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&psize);
  MPI_Comm_rank(MPI_COMM_WORLD,&prank);

  // initialisation
  if (argc == 1) { // default
    base   = 2;
  }  
  else if(argc == 2) {
    base = atoi(argv[1]);
  }
  else {
    cerr << "usage: [b] [ORB options]" << endl;
    return 0;
  }


  //! Pointer on the ORB
  CORBA::ORB_ptr _orbp;
  PortableServer::POA_var _poa;
  PortableServer::POAManager_var  _poa_man;

  // start corba server
  _orbp = CORBA::ORB_init(argc, argv);
    
  // Obtain a reference of the root POA
  CORBA::Object_var objref = _orbp->resolve_initial_references("RootPOA");
  _poa = PortableServer::POA::_narrow(objref);

  // Get and  Activate the POA Manager
  _poa_man = _poa->the_POAManager( );
  _poa_man->activate( );

  
  cout << endl << "**************** CREATE LOCAL NODES ****************" << endl;
  // create local nodes
  ColCOWS::Node * localNode;

    cout << "Test calcul father and max descendant :"
         << "psize = " << psize << ", "
         << "prank = " << prank << ", "
         << "base = " << base << endl;

    localNode = ColCOWS::Node::NewHierachical("B",
                                              "TestClient2",
                                              prank,
                                              psize,
                                              base,
                                              _orbp);

  cout << endl << "**************** ADD REFERENCES ****************" << endl;

  // add ref on local nodes
  Echo_impl * echo = new Echo_impl(prank);
  localNode->addReference("echo", "echo-echo", echo->_this());

  cout << endl << "**************** ACTIVATION ****************" << endl;

  // activation
  localNode->activate();

  localNode->waitActivation();

  if (prank == 0) {
    cout << endl << "**************** CONNECTION ****************" << endl;
    unsigned long num_connection = localNode->connect("A", "TestServer");

    if ( num_connection != ColCOWS::NOT_CONNECTED ) {

      cout << endl << "**************** GET_SIZE ****************" << endl;

      cout << " getRemoteNbNodes( num_connection ) = " << localNode->getRemoteNbNodes( num_connection )  << endl;
    
    }
    else {
      cout << "Connection failed !!!" << endl;
    }

    cout << endl << "To exit press any key > " << flush; cin >> c;

    cout << endl << "**************** DISCONNECTION ****************" << endl;

    localNode->disconnectAll();

    cout << endl << "**************** DEACTIVATION ****************" << endl;

    localNode->deactivate();

  }

  MPI_Barrier(MPI_COMM_WORLD);

  localNode->waitDeactivation();


  // deactivate POA
  _poa_man->deactivate(true,true);

  // shutdown ORB
  if(!CORBA::is_nil(_orbp))
    _orbp->shutdown(1); // do not wait for completion


  // goodbye !  
  cerr << "return OK" << endl;
  return 0;
}

// EOF


Generated on Tue Jun 21 12:55:55 2005 for ColCOWS by  doxygen 1.4.1