#include "TreeImproveC.h" #include "CipresHelper.h" #include "CipresFacilitator.h" #include "orbsvcs/CosNamingC.h" #include #include using namespace std; void usage(const char *cmd) { cerr << "Usage: " << cmd << " [-CipresIOR ]|[-CipresImpl ] [<-ORBxxx>]" << endl; cerr << "or " << cmd << " -ns [<-ORBxxx>]" << endl; cerr << "servicename must be 'TreeImprove'" << endl; } /* If first arg is "-ns" uses naming service. Next arg is the name of the object we want (eg. "TreeImprove") Subsequent args identify the Naming Service: eg. -ORBInitRef NameService=corbaloc:iiop:10.0.1.5:1050/NameService Otherwise first arg is an ior file name. */ int main(int argc, char *argv[]) { CipresFacilitator * facilitator = NULL; try { facilitator = CipresFacilitator::getSingletonPtr(); facilitator->initialize(argc, argv); CORBA::Object_var object; if (facilitator->lookupWithNameService() && facilitator->getImplName()) { CipresNameService &ns = facilitator->getCipresNameService(); object = ns.nsFind(facilitator->getImplName()); } else if (facilitator->getIORFile()) { object = facilitator->getObjectFromFile(facilitator->getIORFile()); } else { usage(argv[0]); throw 0; } if (CORBA::is_nil(object.in())) { cerr << "Nil object ref" << endl; throw 0; } CipresIDL_api1::TreeImprove_var ti_var = CipresIDL_api1::TreeImprove::_narrow(object.in()); if (CORBA::is_nil(ti_var.in())) { cerr << "Object ref is not of type TreeImprove" << endl; throw 0; } #ifdef NOTDEF CipresIDL_api1::TaxonSeq taxonSeq; taxonSeq.length(4); taxonSeq[0] = CORBA::string_dup("fish"); taxonSeq[1] = CORBA::string_dup("cat"); taxonSeq[2] = CORBA::string_dup("dog"); taxonSeq[3] = CORBA::string_dup("rabbit"); cout << "calling setTaxa: " << taxonSeq << endl; ti_var->setTaxa(taxonSeq); #endif CipresIDL_api1::DataMatrix chars; chars.m_symbols= "ACGT"; chars.m_numStates = 4; chars.m_stride = 1; chars.m_numCharacters = 4; chars.m_matrix.length(4); chars.m_matrix[0].length(3); chars.m_matrix[0][0] = 1; chars.m_matrix[0][1] = 2; chars.m_matrix[0][2] = 3; chars.m_matrix[1].length(3); chars.m_matrix[1][0] = 3; chars.m_matrix[1][1] = 2; chars.m_matrix[1][2] = 1; chars.m_matrix[2].length(3); chars.m_matrix[2][0] = 3; chars.m_matrix[2][1] = 3; chars.m_matrix[2][2] = 3; chars.m_matrix[3].length(3); chars.m_matrix[3][0] = 3; chars.m_matrix[3][1] = 3; chars.m_matrix[3][2] = 1; cout << "setting matrix:" << endl; cout << chars << endl; cout << "calling setMatrix" << endl; ti_var->setMatrix(chars); CipresIDL_api1::Tree tree; tree.m_score = 0; // paup requires a semicolon at the end of the newick string tree.m_newick = CORBA::string_dup("(((1,2),3),4);"); tree.m_leafSet.length(4); for (int i = 0; i < 4; i++) { tree.m_leafSet[i] = i + 1; } cout << "calling setTree: " << tree.m_newick << endl; ti_var->setTree(tree); cout << "calling improveTree" << endl; CipresIDL_api1::Tree_var resultTree = ti_var->improveTree(); cout << "got tree: " << resultTree->m_newick << endl; cout << "Calling remove() on the object ref. Paup should exit." << endl; ti_var->remove(); } catch(CORBA::Exception &ex) { cerr << "CORBA Exception raised: " << ex << endl; } catch (int) { } if (facilitator != NULL) facilitator->cleanup(); return 0; }