24 #ifndef ZEROC_ICE_EMBEDDED 26 #include <IceUtil/Mutex.h> 28 #include <IceE/IceE.h> 29 #include <IceE/Mutex.h> 53 #define ORB_DEFAULT_BASEPORT 10000 88 template <
class ZEROCICETYPE>
108 void init(
int basePortDifferent) {
109 basePort=basePortDifferent;
117 init(basePortDifferent);
126 if (offsetList.size()>0) {
129 std::list<int>::iterator offset=offsetList.begin();
130 while (*(offset++)==++i) ;
133 offsetList.push_back(i);
144 offsetList.remove(whichOffset);
153 return basePort+2*portOffset;
162 return getTCPUDPPort(portOffset)+1;
179 string generateEndPoint(
const string& transportName, std::string& ipAddress,
int& portOffset) {
180 string tn=transportName, ia=ipAddress;
182 return generateEndPoint(tn, ia, po);
192 stringstream endPoint;
193 if (ipAddress.size()>0) {
194 ipAddress=string(
" -h ")+ipAddress+
' ';
195 endPoint<<transportName<<
":";
197 endPoint<<
"tcp " <<ipAddress<<
"-p "<<getTCPUDPPort(portOffset);
198 #ifndef ZEROC_ICE_EMBEDDED 199 endPoint<<
" : udp "<<ipAddress<<
"-p "<<getTCPUDPPort(portOffset);
201 cout<<
"endpoint :"<<endl;
202 cout<<endPoint.str()<<endl;
205 return endPoint.str();
237 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress) {
238 initialise(argc, argv, transportNameIn, ipAddress, vector<pair<string,string> >());
248 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
const vector<pair<string,string> > extraProperties) {
249 initialise(argc, argv, transportNameIn, ipAddress, extraProperties);
259 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
int basePortDifferent):
ORBBase(basePortDifferent) {
260 initialise(argc, argv, transportNameIn, ipAddress, vector<pair<string,string> >());
271 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
const vector<pair<string,string> > extraProperties,
int basePortDifferent):
ORBBase(basePortDifferent) {
272 initialise(argc, argv, transportNameIn, ipAddress, extraProperties);
284 void initialise(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
const vector<pair<string,string> > extraProperties) {
286 hostAddress=ipAddress;
287 portOffset=getPortOffset();
288 transportName=transportNameIn;
289 Ice::InitializationData initData;
290 initData.properties = Ice::createProperties();
291 initData.properties->setProperty(
"Ice.Warn.Connections",
"2");
292 initData.properties->setProperty(
"Ice.Warn.UnusedProperties",
"1");
294 for (vector<pair<string,string> >::const_iterator pss=extraProperties.begin(); pss!=extraProperties.end(); ++pss)
295 initData.properties->setProperty(pss->first, pss->second);
297 communicator = Ice::initialize(argc, argv, initData);
304 adapterPtr=communicator->createObjectAdapterWithEndpoints(transportName+
".Control",generateEndPoint(transportName, hostAddress, portOffset).c_str());
305 adapterPtr->add((
ORB::ORBICE*)
this, communicator->stringToIdentity(transportName));
306 adapterPtr->activate();
312 void getObjectPointer(
const string &name, Ice::ObjectPtr &objectPointer,
const Ice::Current& cur) {
313 Ice::Identity identity;
315 objectPointer=adapterPtr->find(identity);
328 initialise(argc, argv, transportNameIn,
string(), vector<pair<string,string> >());
340 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
int basePortDifferent):
ORBBase(basePortDifferent) {
341 initialise(argc, argv, transportNameIn,
string(), vector<pair<string,string> >());
353 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
const vector<pair<string,string> > extraProperties) {
354 initialise(argc, argv, transportNameIn,
string(), extraProperties);
367 ORBOriginator(
int argc,
char *argv[],
string transportNameIn,
const vector<pair<string,string> > extraProperties,
int basePortDifferent):
ORBBase(basePortDifferent) {
368 initialise(argc, argv, transportNameIn,
string(), extraProperties);
374 removePortOffset(portOffset);
376 communicator->shutdown();
383 cur.adapter->getCommunicator()->shutdown();
391 return communicator->isShutdown();
399 void addClass(Ice::ObjectPtr objectToORB,
const string &name) {
400 Ice::Identity identity;
402 if (adapterPtr->find(identity))
403 cerr<<
"ORBOriginator::addClass : WARNING : that class is already serlialised on the adapter"<<endl;
404 adapterPtr->add(objectToORB, identity);
410 communicator->waitForShutdown();
444 oRBOriginatorPrx = ORB::ORBICEPrx::checkedCast(communicator->stringToProxy(generateEndPoint(transportName, hostAddress, portOffset).c_str())->ice_twoway()->ice_timeout(-1)->ice_secure(
false));
445 }
catch (
const Ice::Exception& e) {
447 }
catch (...) { cout <<
"unknown exception"; }
448 if (!oRBOriginatorPrx) {
449 cerr<<
"ORBReplicator::initialise : couldn't get the ORBOriginator proxy, can't continue \n\n\tPlease check that the intended application on the other side of the netowrk is up and running!"<<endl;
476 ORBReplicator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
int basePortDifferent) :
ORBOriginator(argc, argv, transportNameIn, ipAddress, basePortDifferent) {
489 ORBReplicator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
const vector<pair<string,string> > extraProperties) :
ORBOriginator(argc, argv, transportNameIn, ipAddress, extraProperties) {
503 ORBReplicator(
int argc,
char *argv[],
string transportNameIn,
string ipAddress,
const vector<pair<string,string> > extraProperties,
int basePortDifferent) :
ORBOriginator(argc, argv, transportNameIn, ipAddress, extraProperties, basePortDifferent) {
510 virtual Ice::ObjectPtr
create(
const std::string&)=0;
526 void addClass(Ice::ObjectPtr objectToORB,
const string &name) {
527 cerr<<
"ORBReplicator::addClass : Only ORBOriginators can add classes to the ORB application layer\n\t You need an originator on this side to add your classes to the ORB application layer"<<endl;
533 oRBOriginatorPrx->shutdown();
542 template<
typename PRXTYPE>
544 return PRXTYPE::checkedCast(communicator->stringToProxy(generateEndPoint(nameIn, hostAddress, portOffset).c_str()));
557 template<
typename CLASSTYPE>
559 if (!communicator->findObjectFactory(CLASSTYPE::ice_staticId()))
560 communicator->addObjectFactory(static_cast<Ice::ObjectFactory*>(
this), CLASSTYPE::ice_staticId());
563 Ice::ObjectPtr objectPtr;
564 oRBOriginatorPrx->getObjectPointer(nameIn, objectPtr);
565 objectPtr->__setNoDelete(
true);
567 return dynamic_cast<CLASSTYPE *
>(objectPtr.get());
574 return (
bool)oRBOriginatorPrx!=NULL;
ORBReplicator(int argc, char *argv[], string transportNameIn, string ipAddress)
void shutdown(const Ice::Current &cur)
Ice::CommunicatorPtr communicator
Resident communicator.
ORBReplicator(int argc, char *argv[], string transportNameIn, string ipAddress, const vector< pair< string, string > > extraProperties, int basePortDifferent)
ORBOriginator(int argc, char *argv[], string transportNameIn, int basePortDifferent)
#define ORB_DEFAULT_BASEPORT
The default base port for networking.
int basePort
The starting network port.
int getSSLPort(int portOffset)
ORBOriginator(int argc, char *argv[], string transportNameIn, string ipAddress, const vector< pair< string, string > > extraProperties, int basePortDifferent)
string hostAddress
The hostname or IP address of the node to connect to, empty for the originator and set for the replic...
void addClass(Ice::ObjectPtr objectToORB, const string &name)
ORBBase(int basePortDifferent)
ORBOriginator(int argc, char *argv[], string transportNameIn, const vector< pair< string, string > > extraProperties, int basePortDifferent)
void initialiseAdapter(void)
void removePortOffset(int whichOffset)
void waitForShutdown(void)
ORBOriginator(int argc, char *argv[], string transportNameIn, string ipAddress)
ORBOriginator(int argc, char *argv[], string transportNameIn, string ipAddress, const vector< pair< string, string > > extraProperties)
ORBReplicator(int argc, char *argv[], string transportNameIn, string ipAddress, int basePortDifferent)
string generateEndPoint(const string &transportName, std::string &ipAddress, int &portOffset)
int getTCPUDPPort(int portOffset)
static const string name
The name of this class - once set, it can't be changed.
ORBOriginator(int argc, char *argv[], string transportNameIn)
void getObjectPointer(const string &name, Ice::ObjectPtr &objectPointer, const Ice::Current &cur)
void initialise(int argc, char *argv[], string transportNameIn, string ipAddress, const vector< pair< string, string > > extraProperties)
virtual ~ORBOriginator(void)
Destructor.
ORB::ORBICEPrx oRBOriginatorPrx
The proxy of the ORBOriginator on the other side of the network.
ORBReplicator(int argc, char *argv[], string transportNameIn, string ipAddress, const vector< pair< string, string > > extraProperties)
Ice::ObjectAdapterPtr adapterPtr
Resident adapter.
ORBOriginator(int argc, char *argv[], string transportNameIn, const vector< pair< string, string > > extraProperties)
string transportName
Zeroc ICE application layer name.
int portOffset
The port offset of this application layer.
void addClass(Ice::ObjectPtr objectToORB, const string &name)
list< int > offsetList
The list of port offsets used.
string generateEndPoint(string &transportName, string ipAddress, int portOffset)
PRXTYPE getObjectProxy(const string &nameIn)
ORBOriginator(int argc, char *argv[], string transportNameIn, string ipAddress, int basePortDifferent)
CLASSTYPE * getObjectPointer(const string &nameIn)
ORBBase(void)
Constructor using ORB_DEFAULT_BASEPORT as the starting base network port.
void init(int basePortDifferent)
IceUtil::Mutex countMutex
Mutex semaphore to enable the manipulation of the offsetList.