#include "ORBTestICE.H"
class ORBTestClass :
public ORBObject<ORBTEST::ORBTestICE> {
public:
int method(int input, const Ice::Current& c=Ice::Current()){
cout<<"input was = "<<input<<endl;
input++;
cout<<"input now = "<<input<<endl;
return input;
}
};
template<> const string ORBTestClass::ORBObject<ORBTEST::ORBTestICE>::name("ORBTestClass");
Ice::ObjectPtr
create(
const std::string& type){
if(type == ORBTestClass::ice_staticId()) {
Ice::ObjectPtr objectPtr = new ORBTestClass;
return objectPtr;
}
cout<<"Can't find that class !"<<endl;
assert(false);
return 0;
}
public:
ORBTestReplicator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress) :
ORBReplicator(argc, argv, transportNameIn, ipAddress){
}
ORBTestReplicator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress, vector<pair<string,string> > extraProperties) :
ORBReplicator(argc, argv, transportNameIn, ipAddress, extraProperties){
}
};
cout<<"Usage : "<<str<<" -o "<<endl;
cout<<"Usage : "<<str<<" -r "<<endl;
cout<<"\t -o : run the originator\n\t -r : run the replicator"<<endl;
cout<<"Usage : "<<str<<" -host hostName "<<endl;
cout<<"Usage : "<<str<<" --host=hostName "<<endl;
cout<<"\t Where hostName is the ip address or host name to connect to : defaults to 127.0.0.1"<<endl;
}
int main(
int argc,
char *argv[]){
int i=0;
string dummy;
bool orig=(op.
getArg(
"o", argc, argv, dummy, i)!=i);
bool rep=(op.
getArg(
"r", argc, argv, dummy, i=0)!=i);
if (orig & rep){
return -1;
}
if (!orig & !rep){
return -1;
}
string hostName("127.0.0.1");
if (op.
getArg(
"host", argc, argv, hostName, i=0)==i)
cout<<"defaulting host to : "<<hostName<<endl;
vector<pair<string,string> > extraOptions;
extraOptions.push_back(pair<string,string>(string("Ice.Default.EncodingVersion"),string("1.0")));
if (orig){
ORBOriginator origin(argc, argv,
string(
"BasePipe"), extraOptions);
ORBTestClass *stc = new ORBTestClass;
stc->__setNoDelete(true);
stc->variable=1.23456;
stc->__setNoDelete(false);
}
if (rep){
ORBTestReplicator replicator(argc, argv, string("BasePipe"), hostName, extraOptions);
if (!replicator.connectedOK()){
cout<<"Couldn't connect to the origin on the host "<<hostName<<endl;
cout<<"exiting ..."<<endl;
return -1;
}
ORBTEST::ORBTestICEPrx oRBTestICEPrx = replicator.getObjectProxy<ORBTEST::ORBTestICEPrx>(ORBTestClass::name);
cout<<"input = "<<oRBTestICEPrx->method(1)<<endl;
ORBTestClass *stc = replicator.getObjectPointer<ORBTestClass>(ORBTestClass::name);
cout<<"variable = "<<stc->variable<<endl;
cout<<"\n\nNotice : if you call the method of the local Pointer (not the proxy) then it only executes locally, not on the originator"<<endl;
cout<<"input = "<<stc->method(4)<<endl;
stc->__setNoDelete(false);
replicator.shutdown();
}
return 0;
}