diff options
author | Marc Laukien <marc@zeroc.com> | 2001-08-19 16:12:56 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-08-19 16:12:56 +0000 |
commit | 05dd3feba5b858949d0d078effb406c85dda1d90 (patch) | |
tree | 1edaee86dfd436e488dbdcbaaee2a41facc1e35f /cpp | |
parent | removed file (diff) | |
download | ice-05dd3feba5b858949d0d078effb406c85dda1d90.tar.bz2 ice-05dd3feba5b858949d0d078effb406c85dda1d90.tar.xz ice-05dd3feba5b858949d0d078effb406c85dda1d90.zip |
--Ice...
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/Ice/hello/Client.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Ice/hello/Server.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Ice/latency/Client.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Ice/latency/Server.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Ice/value/Client.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Ice/value/Server.cpp | 4 | ||||
-rw-r--r-- | cpp/include/Ice/Initialize.h | 8 | ||||
-rw-r--r-- | cpp/include/Ice/Outgoing.h | 1 | ||||
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 46 | ||||
-rw-r--r-- | cpp/src/Ice/CommunicatorI.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Outgoing.cpp | 3 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.cpp | 142 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.h | 12 | ||||
-rw-r--r-- | cpp/src/Ice/ThreadPool.cpp | 13 | ||||
-rw-r--r-- | cpp/src/IcePack/Client.cpp | 21 | ||||
-rw-r--r-- | cpp/src/IcePack/Server.cpp | 28 | ||||
-rwxr-xr-x | cpp/test/IcePack/simple/run.py | 12 |
17 files changed, 165 insertions, 147 deletions
diff --git a/cpp/demo/Ice/hello/Client.cpp b/cpp/demo/Ice/hello/Client.cpp index 5575853015a..e4f1e8e7b05 100644 --- a/cpp/demo/Ice/hello/Client.cpp +++ b/cpp/demo/Ice/hello/Client.cpp @@ -83,8 +83,8 @@ main(int argc, char* argv[]) try { - Ice::PropertiesPtr properties = Ice::loadProperties("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); + Ice::PropertiesPtr properties = Ice::loadProperties(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const Ice::LocalException& ex) diff --git a/cpp/demo/Ice/hello/Server.cpp b/cpp/demo/Ice/hello/Server.cpp index 5a93ea767e8..2102b3c59b0 100644 --- a/cpp/demo/Ice/hello/Server.cpp +++ b/cpp/demo/Ice/hello/Server.cpp @@ -32,8 +32,8 @@ main(int argc, char* argv[]) try { - Ice::PropertiesPtr properties = Ice::loadProperties("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); + Ice::PropertiesPtr properties = Ice::loadProperties(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const Ice::LocalException& ex) diff --git a/cpp/demo/Ice/latency/Client.cpp b/cpp/demo/Ice/latency/Client.cpp index 9445e11f48a..56e6cfb4697 100644 --- a/cpp/demo/Ice/latency/Client.cpp +++ b/cpp/demo/Ice/latency/Client.cpp @@ -88,8 +88,8 @@ main(int argc, char* argv[]) try { - Ice::PropertiesPtr properties = Ice::loadProperties("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); + Ice::PropertiesPtr properties = Ice::loadProperties(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const Ice::LocalException& ex) diff --git a/cpp/demo/Ice/latency/Server.cpp b/cpp/demo/Ice/latency/Server.cpp index 5ec63450707..25eaacb4ca7 100644 --- a/cpp/demo/Ice/latency/Server.cpp +++ b/cpp/demo/Ice/latency/Server.cpp @@ -32,8 +32,8 @@ main(int argc, char* argv[]) try { - Ice::PropertiesPtr properties = Ice::loadProperties("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); + Ice::PropertiesPtr properties = Ice::loadProperties(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const Ice::LocalException& ex) diff --git a/cpp/demo/Ice/value/Client.cpp b/cpp/demo/Ice/value/Client.cpp index c687dd4342b..6a915e4eedc 100644 --- a/cpp/demo/Ice/value/Client.cpp +++ b/cpp/demo/Ice/value/Client.cpp @@ -167,8 +167,8 @@ main(int argc, char* argv[]) try { - Ice::PropertiesPtr properties = Ice::loadProperties("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); + Ice::PropertiesPtr properties = Ice::loadProperties(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const Ice::LocalException& ex) diff --git a/cpp/demo/Ice/value/Server.cpp b/cpp/demo/Ice/value/Server.cpp index 62a21ce9186..21101d22ae5 100644 --- a/cpp/demo/Ice/value/Server.cpp +++ b/cpp/demo/Ice/value/Server.cpp @@ -32,8 +32,8 @@ main(int argc, char* argv[]) try { - Ice::PropertiesPtr properties = Ice::loadProperties("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); + Ice::PropertiesPtr properties = Ice::loadProperties(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const Ice::LocalException& ex) diff --git a/cpp/include/Ice/Initialize.h b/cpp/include/Ice/Initialize.h index 9f5a0bcaa74..9518cee392d 100644 --- a/cpp/include/Ice/Initialize.h +++ b/cpp/include/Ice/Initialize.h @@ -15,11 +15,11 @@ namespace Ice { ICE_API CommunicatorPtr initialize(int&, char*[], Int = ICE_INT_VERSION); -ICE_API CommunicatorPtr initializeWithProperties(int&, char*[], const PropertiesPtr&, Int = ICE_INT_VERSION); +ICE_API CommunicatorPtr initializeWithProperties(const PropertiesPtr&, Int = ICE_INT_VERSION); -ICE_API PropertiesPtr getDefaultProperties(); -ICE_API PropertiesPtr createProperties(); -ICE_API PropertiesPtr loadProperties(const std::string&); +ICE_API PropertiesPtr getDefaultProperties(int&, char*[]); +ICE_API PropertiesPtr createProperties(int&, char*[]); +ICE_API PropertiesPtr loadProperties(int&, char*[], const std::string&); } diff --git a/cpp/include/Ice/Outgoing.h b/cpp/include/Ice/Outgoing.h index e1dbc330428..302162f7180 100644 --- a/cpp/include/Ice/Outgoing.h +++ b/cpp/include/Ice/Outgoing.h @@ -68,7 +68,6 @@ private: enum { - StateUnsent, StateInProgress, StateOK, StateException, diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 02ff7d95913..4d0f63979a1 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -164,7 +164,7 @@ Ice::CommunicatorI::~CommunicatorI() } CommunicatorPtr -Ice::initialize(int&, char*[], Int version) +Ice::initialize(int& argc, char* argv[], Int version) { #ifndef ICE_IGNORE_VERSION if (version != ICE_INT_VERSION) @@ -173,11 +173,11 @@ Ice::initialize(int&, char*[], Int version) } #endif - return new CommunicatorI(getDefaultProperties()); + return new CommunicatorI(getDefaultProperties(argc, argv)); } CommunicatorPtr -Ice::initializeWithProperties(int&, char*[], const PropertiesPtr& properties, Int version) +Ice::initializeWithProperties(const PropertiesPtr& properties, Int version) { #ifndef ICE_IGNORE_VERSION if (version != ICE_INT_VERSION) @@ -189,30 +189,44 @@ Ice::initializeWithProperties(int&, char*[], const PropertiesPtr& properties, In return new CommunicatorI(properties); } -PropertiesPtr -Ice::getDefaultProperties() +static PropertiesPtr defaultProperties; +class DefaultPropertiesDestroyer { - PropertiesPtr properties; - const char* file = getenv("ICE_CONFIG"); - if (file && *file != '\0') +public: + + ~DefaultPropertiesDestroyer() { - properties = new PropertiesI(file); + defaultProperties = 0; } - else +}; +static DefaultPropertiesDestroyer defaultPropertiesDestroyer; + +PropertiesPtr +Ice::getDefaultProperties(int& argc, char* argv[]) +{ + if (!defaultProperties) { - properties = new PropertiesI; + const char* file = getenv("ICE_CONFIG"); + if (file && *file != '\0') + { + defaultProperties = new PropertiesI(argc, argv, file); + } + else + { + defaultProperties = new PropertiesI(argc, argv); + } } - return properties; + return defaultProperties; } PropertiesPtr -Ice::createProperties() +Ice::createProperties(int& argc, char* argv[]) { - return new PropertiesI; + return new PropertiesI(argc, argv); } PropertiesPtr -Ice::loadProperties(const std::string& file) +Ice::loadProperties(int& argc, char* argv[], const std::string& file) { - return new PropertiesI(file); + return new PropertiesI(argc, argv, file); } diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h index 626c72e4e61..044b6a7af86 100644 --- a/cpp/src/Ice/CommunicatorI.h +++ b/cpp/src/Ice/CommunicatorI.h @@ -46,7 +46,7 @@ private: virtual ~CommunicatorI(); friend ICE_API CommunicatorPtr initialize(int&, char*[], Int); - friend ICE_API CommunicatorPtr initializeWithProperties(int&, char*[], const PropertiesPtr&, Int); + friend ICE_API CommunicatorPtr initializeWithProperties(const PropertiesPtr&, Int); ::IceInternal::InstancePtr _instance; }; diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp index 50c02c12ca5..4e99b11507e 100644 --- a/cpp/src/Ice/Outgoing.cpp +++ b/cpp/src/Ice/Outgoing.cpp @@ -45,7 +45,7 @@ IceInternal::NonRepeatable::get() const IceInternal::Outgoing::Outgoing(const EmitterPtr& emitter, const ReferencePtr& reference) : _emitter(emitter), _reference(reference), - _state(StateUnsent), + _state(StateInProgress), _is(reference->instance), _os(reference->instance) { @@ -70,7 +70,6 @@ IceInternal::Outgoing::invoke() JTCSyncT<JTCMonitorT<JTCMutex> > sync(*this); _emitter->sendRequest(this, false); - _state = StateInProgress; Int timeout = _emitter->timeout(); while (_state == StateInProgress) diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index 7da7efd958e..da529c0f115 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -39,18 +39,55 @@ Ice::PropertiesI::setProperty(const string& key, const string& value) PropertiesPtr Ice::PropertiesI::clone() { - PropertiesI* p = new PropertiesI; - p->_properties=_properties; + int dummy = 0; + PropertiesI* p = new PropertiesI(dummy, 0); + p->_properties = _properties; return p; } -Ice::PropertiesI::PropertiesI() +Ice::PropertiesI::PropertiesI(int& argc, char* argv[]) { + parseArgs(argc, argv); } -Ice::PropertiesI::PropertiesI(const string& file) +Ice::PropertiesI::PropertiesI(int& argc, char* argv[], const string& file) { load(file); + parseArgs(argc, argv); +} + +void +Ice::PropertiesI::parseArgs(int& argc, char* argv[]) +{ + if (!argv) + { + return; + } + + int idx = 1; + while (idx < argc) + { + if (strncmp(argv[idx], "--Ice.", 6) == 0) + { + string line = argv[idx]; + for (int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + + if (line.find('=') == string::npos) + { + line += "=1"; + } + + parseLine(line.c_str() + 2); + } + else + { + ++idx; + } + } } void @@ -67,55 +104,60 @@ Ice::PropertiesI::load(const std::string& file) void Ice::PropertiesI::parse(istream& in) { - const string delim = " \t"; - char line[1024]; while (in.getline(line, 1024)) { - string s = line; - - string::size_type idx = s.find('#'); - if (idx != string::npos) - { - s.erase(idx); - } - - idx = s.find_last_not_of(delim); - if (idx != string::npos && idx + 1 < s.length()) - { - s.erase(idx + 1); - } - - string::size_type beg = s.find_first_not_of(delim); - if (beg == string::npos) - { - continue; - } - - string::size_type end = s.find_first_of(delim + "=", beg); - if (end == string::npos) - { - continue; - } - - string key = s.substr(beg, end - beg); - - end = s.find('=', end); - if (end == string::npos) - { - continue; - } - - beg = s.find_first_not_of(delim + "=", end); - if (beg == string::npos) - { - continue; - } - - end = s.length(); + parseLine(line); + } +} - string value = s.substr(beg, end - beg); - - setProperty(key, value); +void +Ice::PropertiesI::parseLine(const char* line) +{ + const string delim = " \t"; + string s = line; + + string::size_type idx = s.find('#'); + if (idx != string::npos) + { + s.erase(idx); + } + + idx = s.find_last_not_of(delim); + if (idx != string::npos && idx + 1 < s.length()) + { + s.erase(idx + 1); + } + + string::size_type beg = s.find_first_not_of(delim); + if (beg == string::npos) + { + return; + } + + string::size_type end = s.find_first_of(delim + "=", beg); + if (end == string::npos) + { + return; + } + + string key = s.substr(beg, end - beg); + + end = s.find('=', end); + if (end == string::npos) + { + return; + } + + beg = s.find_first_not_of(delim + "=", end); + if (beg == string::npos) + { + return; } + + end = s.length(); + + string value = s.substr(beg, end - beg); + + setProperty(key, value); } diff --git a/cpp/src/Ice/PropertiesI.h b/cpp/src/Ice/PropertiesI.h index eafeda007e1..a30fa1e1f57 100644 --- a/cpp/src/Ice/PropertiesI.h +++ b/cpp/src/Ice/PropertiesI.h @@ -27,15 +27,17 @@ public: private: - PropertiesI(); - PropertiesI(const std::string&); + PropertiesI(int&, char*[]); + PropertiesI(int&, char*[], const std::string&); - friend ICE_API PropertiesPtr getDefaultProperties(); - friend ICE_API PropertiesPtr createProperties(); - friend ICE_API PropertiesPtr loadProperties(const std::string&); + friend ICE_API PropertiesPtr getDefaultProperties(int&, char*[]); + friend ICE_API PropertiesPtr createProperties(int&, char*[]); + friend ICE_API PropertiesPtr loadProperties(int&, char*[], const std::string&); + void parseArgs(int&, char*[]); void load(const std::string&); void parse(std::istream&); + void parseLine(const char*); std::map<std::string, std::string> _properties; }; diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index 4484d8ea99d..2f34c72b5d9 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -236,8 +236,7 @@ IceInternal::ThreadPool::run() // // New handlers have been added // - vector<pair<int, EventHandlerPtr> >::iterator p; - for (p = _adds.begin(); p != _adds.end(); ++p) + for (vector<pair<int, EventHandlerPtr> >::iterator p = _adds.begin(); p != _adds.end(); ++p) { _handlers.insert(*p); FD_SET(p->first, &_fdSet); @@ -252,16 +251,14 @@ IceInternal::ThreadPool::run() // // Handlers are permanently removed // - vector<int>::iterator p; - for (p = _removes.begin(); p != _removes.end(); ++p) + for (vector<int>::iterator p = _removes.begin(); p != _removes.end(); ++p) { - std::map<int, EventHandlerPtr>::iterator q = - _handlers.find(*p); + std::map<int, EventHandlerPtr>::iterator q = _handlers.find(*p); assert(q != _handlers.end()); #ifdef WIN32 - FD_CLR(static_cast<u_int>(*p), &_fdSet); + FD_CLR(static_cast<u_int>(*p), &_fdSet); #else - FD_CLR(*p, &_fdSet); + FD_CLR(*p, &_fdSet); #endif q->second->finished(); if (q->second->server()) diff --git a/cpp/src/IcePack/Client.cpp b/cpp/src/IcePack/Client.cpp index 85462a61fdf..3f9ae3b08d4 100644 --- a/cpp/src/IcePack/Client.cpp +++ b/cpp/src/IcePack/Client.cpp @@ -24,7 +24,6 @@ usage(const char* n) "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" - "--admin ENDPOINTS Use ENDPOINTS as administrative endpoints.\n" ; } @@ -111,7 +110,7 @@ run(int argc, char* argv[], CommunicatorPtr communicator) int main(int argc, char* argv[]) { - PropertiesPtr properties = getDefaultProperties(); + PropertiesPtr properties = getDefaultProperties(argc, argv); int idx = 1; while (idx < argc) @@ -126,22 +125,6 @@ main(int argc, char* argv[]) cout << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } - else if (strcmp(argv[idx], "--admin") == 0) - { - if (idx + 1 >= argc) - { - cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - properties->setProperty("Ice.Adapter.Admin.Endpoints", argv[idx + 1]); - for (int i = idx ; i + 2 < argc ; ++i) - { - argv[i] = argv[i + 2]; - } - argc -= 2; - } else if (argv[idx][0] == '-') { cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; @@ -159,7 +142,7 @@ main(int argc, char* argv[]) try { - communicator = initializeWithProperties(argc, argv, properties); + communicator = initializeWithProperties(properties); status = run(argc, argv, communicator); } catch(const LocalException& ex) diff --git a/cpp/src/IcePack/Server.cpp b/cpp/src/IcePack/Server.cpp index ea0b0a4e967..115e1628b1f 100644 --- a/cpp/src/IcePack/Server.cpp +++ b/cpp/src/IcePack/Server.cpp @@ -24,8 +24,6 @@ usage(const char* n) "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" - "--forward ENDPOINTS Use ENDPOINTS as endpoints for the forwarder.\n" - "--admin ENDPOINTS Enable administrative endpoints and set them to ENDPOINTS.\n" "--nowarn Don't print any security warnings.\n" "--pid Print the process id on standard output upon startup.\n" ; @@ -75,7 +73,7 @@ run(int argc, char* argv[], CommunicatorPtr communicator, bool pid, bool nowarn) int main(int argc, char* argv[]) { - PropertiesPtr properties = getDefaultProperties(); + PropertiesPtr properties = getDefaultProperties(argc, argv); bool nowarn = false; bool pid = false; @@ -99,28 +97,6 @@ main(int argc, char* argv[]) { pid = true; } - else if (strcmp(argv[i], "--forward") == 0) - { - if (i + 1 >= argc) - { - cerr << argv[0] << ": argument expected for`" << argv[i] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - properties->setProperty("Ice.Adapter.Forward.Endpoints", argv[++i]); - } - else if (strcmp(argv[i], "--admin") == 0) - { - if (i + 1 >= argc) - { - cerr << argv[0] << ": argument expected for`" << argv[i] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - properties->setProperty("Ice.Adapter.Admin.Endpoints", argv[++i]); - } else { cerr << argv[0] << ": unknown option `" << argv[i] << "'" << endl; @@ -134,7 +110,7 @@ main(int argc, char* argv[]) try { - communicator = initializeWithProperties(argc, argv, properties); + communicator = initializeWithProperties(properties); status = run(argc, argv, communicator, pid, nowarn); } catch(const LocalException& ex) diff --git a/cpp/test/IcePack/simple/run.py b/cpp/test/IcePack/simple/run.py index b56cac18f2a..f4276492f29 100755 --- a/cpp/test/IcePack/simple/run.py +++ b/cpp/test/IcePack/simple/run.py @@ -24,7 +24,9 @@ icePack = os.path.join(toplevel, "bin", "icepack") icePackAdmin = os.path.join(toplevel, "bin", "icepackadmin") print "starting icepack...", -icePackPipe = os.popen(icePack + ' --nowarn --pid --forward "tcp -p 12346 -t 2000" --admin "tcp -p 12347 -t 2000"') +icePackPipe = os.popen(icePack + ' --nowarn --pid' + \ + ' "--Ice.Adapter.Forward.Endpoints=tcp -p 12346 -t 2000"' + \ + ' "--Ice.Adapter.Admin.Endpoints=tcp -p 12347 -t 2000"') output = icePackPipe.readline().strip() if not output: print "failed!" @@ -33,7 +35,9 @@ TestUtil.serverPids.append(int(output)) print "ok" print "registering server with icepack...", -icePackAdminPipe = os.popen(icePackAdmin + ' --admin "tcp -p 12347 -t 2000" add "test:tcp -p 12345 -t 2000"') +icePackAdminPipe = os.popen(icePackAdmin + \ + ' "--Ice.Adapter.Admin.Endpoints=tcp -p 12347 -t 2000"' + \ + ' add "test:tcp -p 12345 -t 2000"') icePackAdminPipe.close() print "ok" @@ -42,7 +46,9 @@ TestUtil.clientServerTest(toplevel, name) TestUtil.collocatedTest(toplevel, name) print "shutting down icepack...", -icePackAdminPipe = os.popen(icePackAdmin + ' --admin "tcp -p 12347 -t 2000" shutdown') +icePackAdminPipe = os.popen(icePackAdmin + \ + ' "--Ice.Adapter.Admin.Endpoints=tcp -p 12347 -t 2000"' + \ + ' shutdown') icePackAdminPipe.close() print "ok" |