#include "ls_i.h" #include "CipresRegistry.h" #include #include using namespace std; /* If first arg is "-ns" uses naming service. Next arg is the name of the object we want (eg. "LargeSeq") 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[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "orb1"); if (argc < 2) { cerr << "usage: " << argv[0] << " iorFileName" << endl; return 1; } CORBA::Object_var object; if (strcmp(argv[1], "-ns") == 0) { // todo: check for right number of arguments before accessing argv CipresRegistry registry(orb.in()); object = registry.nsFind(argv[2]); } else { fstream f(argv[1], ios::in); CORBA::String_var iorstring; f >> iorstring; cout << "ior is: " << iorstring << endl; object = orb->string_to_object(iorstring); } if (CORBA::is_nil(object.in())) { cerr << "Nil object ref" << endl; throw 0; } ls_var ls = ls::_narrow(object.in()); if (CORBA::is_nil(ls.in())) { cerr << "Object ref is not of type ls" << endl; throw 0; } long size; cout << "Enter size of sequence to send" << endl; cin >> size; cout << "Creating sequence of " << size << " bytes" << endl; ByteSeq_var dataseq = new ByteSeq(size); dataseq->length(size); for (long i = 0; i < size; ++i) { dataseq[i] = (unsigned char)(i % 10); } cout << "Sending sequence" << endl; // Sequence_var has a conversion to Sequence & ls->sendData((ByteSeq &)dataseq); cout << "Getting sequence of size " << size << endl; dataseq = ls->getData(size); cout << "The last element of the returned sequence is " << (int) dataseq[size - 1] << endl; } catch (CORBA::Exception &ex) { cerr << "caught exception: " << ex << endl; } return 0; }