#include "mpi.h"
#include <unistd.h>
#include <iostream>
#include <cassert>
#include "ColCOWS.hh"
#include "echo.hh"
#ifdef ORBACUS_ORB
#include "echo_skel.hh"
#endif
using namespace std;
int main(int argc, char** argv) {
char c;
int psize, prank;
string local_ws_id = "B";
string local_ws_kind = "TestServer";
string node_kind = "regular_node";
if(argc == 1) {
}
else if(argc >= 3) {
local_ws_id = argv[1];
local_ws_kind = argv[2];
}
else {
cerr << "usage: [local_ws_id] [local_ws_kind] [ORB options]" << endl;
return 0;
}
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&psize);
MPI_Comm_rank(MPI_COMM_WORLD,&prank);
CORBA::ORB_ptr _orbp;
PortableServer::POA_var _poa;
PortableServer::POAManager_var _poa_man;
_orbp = CORBA::ORB_init(argc, argv);
CORBA::Object_var objref = _orbp->resolve_initial_references("RootPOA");
_poa = PortableServer::POA::_narrow(objref);
_poa_man = _poa->the_POAManager( );
_poa_man->activate( );
cout << endl << "**************** CREATE NODES ****************" << endl;
ColCOWS::Node * collectiveNode = NULL;
ColCOWS::Node * localNode;
localNode = ColCOWS::Node::NewNode( local_ws_id,
local_ws_kind,
node_kind,
prank,
psize,
_orbp );
cout << endl << "**************** ACTIVATION ****************" << endl;
localNode->activate();
localNode->waitActivation();
if (prank == 0) {
cout << endl << "To call 'echo' press any key (x - exit) > " << flush; cin >> c;
while (c != 'x') {
if (c == 't') {
}
else {
cout << endl << endl << "**************** EXPERIMENT 2 ****************" << endl << endl;
ColCOWS::RemoteWorkspaceManager * ws_manager = localNode->getRemoteWorkspaceManager();
cout << "Got " << ws_manager->size() << " num connection ..." << endl;
ColCOWS::RemoteWorkspaceManager::iterator wsm_it, wsm_it_begin, wsm_it_end;
wsm_it_begin = ws_manager->begin();
wsm_it_end = ws_manager->end();
for (wsm_it = wsm_it_begin; wsm_it != wsm_it_end; wsm_it++ )
{
cout << "for connection " << wsm_it->first << endl;
ColCOWS::WorkspaceDesc * ws_desc = wsm_it->second;
vector< ColCOWS::ExtObjectDesc > ref_vec;
vector< ColCOWS::ExtObjectDesc >::iterator ref_it;
ws_desc->getObjectDescVec(ref_vec, "" , "echo", "echo-echo");
cout << "Got " << ref_vec.size() << " references ..." << endl;
for (ref_it = ref_vec.begin(); ref_it != ref_vec.end(); ++ref_it ){
if (! CORBA::is_nil(ref_it->obj_ref)) {
Echo_var echo = Echo::_narrow(ref_it->obj_ref);
cout << "( " << ref_it->num_node << " " << ref_it->obj_id << ":" << ref_it->obj_kind
<< " ) -> echo() = " << echo->echoString("new coucou !!") << endl;
}
}
}
}
cout << endl << "(x - exit) > " << flush; cin >> c;
}
cout << endl << "**************** DISCONNECT ALL ****************" << endl;
localNode->disconnectAll();
cout << endl << "**************** DEACTIVATION ****************" << endl;
localNode->deactivate();
}
MPI_Barrier(MPI_COMM_WORLD);
localNode->waitDeactivation();
_poa_man->deactivate(true,true);
if(!CORBA::is_nil(_orbp))
_orbp->shutdown(1);
MPI_Finalize();
cerr << "return OK" << endl;
return 0;
}