diff options
author | Marc Laukien <marc@zeroc.com> | 2001-08-15 17:21:39 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-08-15 17:21:39 +0000 |
commit | 7aff96f568e834c4c13f26a46843d5ecbb1d325d (patch) | |
tree | e801f83704b85d59f80f1516576c3f91290f6d31 /cpp/src | |
parent | fix (diff) | |
download | ice-7aff96f568e834c4c13f26a46843d5ecbb1d325d.tar.bz2 ice-7aff96f568e834c4c13f26a46843d5ecbb1d325d.tar.xz ice-7aff96f568e834c4c13f26a46843d5ecbb1d325d.zip |
IcePack ; restructuring
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 26 | ||||
-rw-r--r-- | cpp/src/Ice/CommunicatorI.h | 9 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.cpp | 26 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.h | 8 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Ice/ThreadPool.cpp | 44 | ||||
-rw-r--r-- | cpp/src/Ice/TraceLevels.cpp | 8 | ||||
-rw-r--r-- | cpp/src/IcePack/.depend | 4 | ||||
-rw-r--r-- | cpp/src/IcePack/AdminI.cpp | 57 | ||||
-rw-r--r-- | cpp/src/IcePack/AdminI.h | 32 | ||||
-rw-r--r-- | cpp/src/IcePack/Client.cpp | 168 | ||||
-rw-r--r-- | cpp/src/IcePack/Forward.cpp | 40 | ||||
-rw-r--r-- | cpp/src/IcePack/Forward.h | 32 | ||||
-rw-r--r-- | cpp/src/IcePack/Makefile | 25 | ||||
-rw-r--r-- | cpp/src/IcePack/Server.cpp | 143 | ||||
-rw-r--r-- | cpp/src/slice2cpp/GenUtil.cpp | 6 |
16 files changed, 597 insertions, 37 deletions
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index b7a1a324960..02ff7d95913 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -80,7 +80,7 @@ Ice::CommunicatorI::createObjectAdapter(const string& name) { throw CommunicatorDestroyedException(__FILE__, __LINE__); } - string endpts = _instance->properties()->getProperty("ice.adapter." + name + ".endpoints"); + string endpts = _instance->properties()->getProperty("Ice.Adapter." + name + ".Endpoints"); return createObjectAdapterWithEndpoints(name, endpts); } @@ -173,13 +173,7 @@ Ice::initialize(int&, char*[], Int version) } #endif - PropertiesPtr properties; - const char* file = getenv("ICE_CONFIG"); - if (file && *file != '\0') - properties = new PropertiesI(file); - else - properties = new PropertiesI; - return new CommunicatorI(properties); + return new CommunicatorI(getDefaultProperties()); } CommunicatorPtr @@ -196,6 +190,22 @@ Ice::initializeWithProperties(int&, char*[], const PropertiesPtr& properties, In } PropertiesPtr +Ice::getDefaultProperties() +{ + PropertiesPtr properties; + const char* file = getenv("ICE_CONFIG"); + if (file && *file != '\0') + { + properties = new PropertiesI(file); + } + else + { + properties = new PropertiesI; + } + return properties; +} + +PropertiesPtr Ice::createProperties() { return new PropertiesI; diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h index bb75f1c6ba4..626c72e4e61 100644 --- a/cpp/src/Ice/CommunicatorI.h +++ b/cpp/src/Ice/CommunicatorI.h @@ -29,11 +29,9 @@ public: virtual ObjectPrx stringToProxy(const std::string&); virtual ObjectAdapterPtr createObjectAdapter(const std::string&); - virtual ObjectAdapterPtr createObjectAdapterWithEndpoints( - const std::string&, const std::string&); + virtual ObjectAdapterPtr createObjectAdapterWithEndpoints(const std::string&, const std::string&); - virtual void installValueFactory(const ValueFactoryPtr&, - const std::string&); + virtual void installValueFactory(const ValueFactoryPtr&, const std::string&); virtual PropertiesPtr getProperties(); @@ -48,8 +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(int&, char*[], const PropertiesPtr&, Int); ::IceInternal::InstancePtr _instance; }; diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index 58d4e2c123c..7da7efd958e 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -21,9 +21,13 @@ Ice::PropertiesI::getProperty(const string& key) { map<string, string>::const_iterator p = _properties.find(key); if (p != _properties.end()) + { return p->second; + } else + { return string(); + } } void @@ -32,6 +36,14 @@ Ice::PropertiesI::setProperty(const string& key, const string& value) _properties[key] = value; } +PropertiesPtr +Ice::PropertiesI::clone() +{ + PropertiesI* p = new PropertiesI; + p->_properties=_properties; + return p; +} + Ice::PropertiesI::PropertiesI() { } @@ -46,7 +58,9 @@ Ice::PropertiesI::load(const std::string& file) { ifstream in(file.c_str()); if (!in) + { throw SystemException(__FILE__, __LINE__); + } parse(in); } @@ -62,29 +76,41 @@ Ice::PropertiesI::parse(istream& in) 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(); diff --git a/cpp/src/Ice/PropertiesI.h b/cpp/src/Ice/PropertiesI.h index b1f51163121..eafeda007e1 100644 --- a/cpp/src/Ice/PropertiesI.h +++ b/cpp/src/Ice/PropertiesI.h @@ -12,7 +12,6 @@ #define ICE_PROPERTIES_I_H #include <Ice/Properties.h> -#include <Ice/CommunicatorF.h> #include <map> namespace Ice @@ -22,15 +21,16 @@ class ICE_API PropertiesI : public Properties { public: - std::string getProperty(const std::string&); - void setProperty(const std::string&, const std::string&); + virtual std::string getProperty(const std::string&); + virtual void setProperty(const std::string&, const std::string&); + virtual PropertiesPtr clone(); private: PropertiesI(); PropertiesI(const std::string&); - friend ICE_API CommunicatorPtr initialize(int&, char*[], Int); + friend ICE_API PropertiesPtr getDefaultProperties(); friend ICE_API PropertiesPtr createProperties(); friend ICE_API PropertiesPtr loadProperties(const std::string&); diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 9f368327613..e818d04df6a 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -145,6 +145,12 @@ IceProxy::Ice::Object::operator!=(const Object& r) const return _reference->identity != r._reference->identity; } +bool +IceProxy::Ice::Object::operator<(const Object& r) const +{ + return _reference->identity < r._reference->identity; +} + ObjectPrx IceProxy::Ice::Object::_twoway() const { diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index 014311c8c2f..4484d8ea99d 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -28,7 +28,9 @@ IceInternal::ThreadPool::_register(int fd, const EventHandlerPtr& handler) { JTCSyncT<JTCMonitorT<JTCMutex> > sync(*this); if (handler->server()) + { ++_servers; + } _adds.push_back(make_pair(fd, handler)); setInterrupt(); } @@ -58,7 +60,7 @@ IceInternal::ThreadPool::waitUntilServerFinished() { wait(); } - catch(const JTCInterruptedException&) + catch (const JTCInterruptedException&) { } } @@ -75,7 +77,7 @@ IceInternal::ThreadPool::waitUntilFinished() { wait(); } - catch(const JTCInterruptedException&) + catch (const JTCInterruptedException&) { } } @@ -114,12 +116,14 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance) : try { int threadNum = 10; - string value = _instance->properties()->getProperty("ice.thread_pool.size"); + string value = _instance->properties()->getProperty("Ice.ThreadPool.Size"); if (!value.empty()) { threadNum = atoi(value.c_str()); if (threadNum < 1) + { threadNum = 1; + } } for (int i = 0 ; i < threadNum ; ++i) @@ -129,7 +133,7 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance) : _threads.push_back(thread); } } - catch(const JTCException&) + catch (const JTCException&) { destroy(); throw; @@ -192,7 +196,9 @@ IceInternal::ThreadPool::run() if (::select(_maxFd + 1, &fdSet, 0, 0, 0) == SOCKET_ERROR) { if (interrupted()) + { goto repeatSelect; + } _threadMutex.unlock(); throw SocketException(__FILE__, __LINE__); @@ -259,20 +265,28 @@ IceInternal::ThreadPool::run() #endif q->second->finished(); if (q->second->server()) + { --_servers; + } _handlers.erase(q); } _removes.clear(); _maxFd = _fdIntrRead; if (!_handlers.empty()) + { _maxFd = max(_maxFd, (--_handlers.end())->first); + } again = true; if (_handlers.empty() || _servers == 0) + { notifyAll(); // For waitUntil...Finished() methods + } } if (again) + { goto repeatSelect; + } // // Round robin for the filedescriptors @@ -280,7 +294,9 @@ IceInternal::ThreadPool::run() do { if (++_lastFd > _maxFd) + { _lastFd = 0; + } } while (!FD_ISSET(_lastFd, &fdSet)); @@ -299,11 +315,11 @@ IceInternal::ThreadPool::run() { read(handler); } - catch(const TimeoutException&) // Expected + catch (const TimeoutException&) // Expected { goto repeatSelect; } - catch(const LocalException& ex) + catch (const LocalException& ex) { handler->exception(ex); goto repeatSelect; @@ -332,7 +348,9 @@ IceInternal::ThreadPool::read(const EventHandlerPtr& handler) handler->read(stream); if (stream.i != stream.b.end()) + { return; + } } if (stream.b.size() >= 8) // Interpret header? @@ -345,23 +363,31 @@ IceInternal::ThreadPool::read(const EventHandlerPtr& handler) Byte protVer; stream.read(protVer); if (protVer != 0) + { throw UnsupportedProtocolException(__FILE__, __LINE__); + } Byte encVer; stream.read(encVer); if (encVer != 0) + { throw UnsupportedEncodingException(__FILE__, __LINE__); + } Byte messageType; stream.read(messageType); Int size; stream.read(size); if (size > 1024 * 1024) // TODO: configurable + { throw ::Ice::MemoryLimitException(__FILE__, __LINE__); + } stream.b.resize(size); stream.i = stream.b.begin() + pos; } if (stream.b.size() > 8 && stream.i != stream.b.end()) + { handler->read(stream); + } } void @@ -371,15 +397,15 @@ IceInternal::ThreadPool::EventHandlerThread::run() { _pool->run(); } - catch(const LocalException& ex) + catch (const LocalException& ex) { cerr << ex << endl; } - catch(const JTCException& ex) + catch (const JTCException& ex) { cerr << ex << endl; } - catch(...) + catch (...) { cerr << "unknown exception" << endl; } diff --git a/cpp/src/Ice/TraceLevels.cpp b/cpp/src/Ice/TraceLevels.cpp index 7e454ff7dc5..e35c30c3a96 100644 --- a/cpp/src/Ice/TraceLevels.cpp +++ b/cpp/src/Ice/TraceLevels.cpp @@ -20,14 +20,14 @@ void IceInternal::decRef(TraceLevels* p) { p->__decRef(); } IceInternal::TraceLevels::TraceLevels(const PropertiesPtr& properties) : network(0), - networkCat("network"), + networkCat("Network"), protocol(0), - protocolCat("protocol"), + protocolCat("Protocol"), retry(0), - retryCat("retry") + retryCat("Retry") { string value; - const string keyBase = "ice.trace."; + const string keyBase = "Ice.Trace."; value = properties->getProperty(keyBase + networkCat); if (!value.empty()) diff --git a/cpp/src/IcePack/.depend b/cpp/src/IcePack/.depend index 6fe0e0596bc..be209f9bb99 100644 --- a/cpp/src/IcePack/.depend +++ b/cpp/src/IcePack/.depend @@ -1 +1,5 @@ Admin.o: Admin.cpp ../../include/IcePack/Admin.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Shared.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/LocalObject.h ../../include/Ice/LocalException.h +Client.o: Client.cpp ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/Shared.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ValueFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ValueFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h AdminI.h ../../include/IcePack/Admin.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h Forward.h +Server.o: Server.cpp ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/Shared.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ValueFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ValueFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h AdminI.h ../../include/IcePack/Admin.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h Forward.h +Forward.o: Forward.cpp ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/Shared.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ValueFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ValueFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h Forward.h ../../include/IcePack/Admin.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h +AdminI.o: AdminI.cpp ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/Shared.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ValueFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ValueFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h AdminI.h ../../include/IcePack/Admin.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h diff --git a/cpp/src/IcePack/AdminI.cpp b/cpp/src/IcePack/AdminI.cpp new file mode 100644 index 00000000000..663cccd106b --- /dev/null +++ b/cpp/src/IcePack/AdminI.cpp @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <AdminI.h> + +using namespace std; +using namespace Ice; +using namespace IcePack; + +AdminI::AdminI() +{ +} + +void +AdminI::add(const ServerDescriptionPtr& p) +{ + JTCSyncT<JTCMutex> sync(*this); + + if (p && p->object) + { + _map[p->object] = p; + } +} + +void +AdminI::remove(const ObjectPrx& p) +{ + JTCSyncT<JTCMutex> sync(*this); + + if (p) + { + _map.erase(p); + } +} + +ServerDescriptionPtr +AdminI::find(const ObjectPrx& p) +{ + JTCSyncT<JTCMutex> sync(*this); + + if (p) + { + return _map.find(p)->second; + } + else + { + return 0; + } +} diff --git a/cpp/src/IcePack/AdminI.h b/cpp/src/IcePack/AdminI.h new file mode 100644 index 00000000000..111f8efd118 --- /dev/null +++ b/cpp/src/IcePack/AdminI.h @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ADMIN_I_H +#define ADMIN_I_H + +#include <IcePack/Admin.h> +#include <map> + +class AdminI : public IcePack::Admin, public JTCMutex +{ +public: + + AdminI(); + + virtual void add(const IcePack::ServerDescriptionPtr&); + virtual void remove(const Ice::ObjectPrx&); + virtual IcePack::ServerDescriptionPtr find(const Ice::ObjectPrx&); + +private: + + std::map<Ice::ObjectPrx, IcePack::ServerDescriptionPtr> _map; +}; + +#endif diff --git a/cpp/src/IcePack/Client.cpp b/cpp/src/IcePack/Client.cpp new file mode 100644 index 00000000000..a2d94c3d1d5 --- /dev/null +++ b/cpp/src/IcePack/Client.cpp @@ -0,0 +1,168 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <AdminI.h> +#include <Forward.h> + +using namespace std; +using namespace Ice; +using namespace IcePack; + +void +usage(const char* n) +{ + cerr << "Usage: " << n << " [options] add|remove reference...\n"; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "--admin ENDPOINTS Use ENDPOINTS as administrative endpoints.\n" + ; +} + +int +run(int argc, char* argv[], CommunicatorPtr communicator) +{ + + PropertiesPtr properties = communicator->getProperties(); + + string adminEndpoints = properties->getProperty("Ice.Adapter.Admin.Endpoints"); + if(adminEndpoints.length() == 0) + { + cerr << argv[0] << ": `Ice.Adapter.Admin.Endpoints' property is not set" << endl; + return EXIT_FAILURE; + } + + if (argc < 2) + { + cerr << argv[0] << ": no command" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + + string cmd = argv[1]; + + if (argc < 3) + { + cerr << argv[0] << ": no reference" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + + Ice::ObjectPrx adminBase = communicator->stringToProxy("admin:" + adminEndpoints); + AdminPrx admin = AdminPrx::checkedCast(adminBase); + if (!admin) + { + cerr << argv[0] << ": `" << adminEndpoints << "' are no valid administrative endpoints" << endl; + return EXIT_FAILURE; + } + + if (cmd == "add") + { + for (int i = 2; i < argc; ++i) + { + ServerDescriptionPtr desc = new ServerDescription; + desc->object = communicator->stringToProxy(argv[i]); + admin->add(desc); + } + } + else if (cmd == "remove") + { + for (int i = 2; i < argc; ++i) + { + admin->remove(communicator->stringToProxy(argv[i])); + } + } + else + { + cerr << argv[0] << ": invalid command `" << cmd << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + PropertiesPtr properties = getDefaultProperties(); + + int idx = 1; + while (idx < argc) + { + if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) + { + usage(argv[0]); + return EXIT_SUCCESS; + } + else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) + { + 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; + usage(argv[0]); + return EXIT_FAILURE; + } + else + { + ++idx; + } + } + + int status; + CommunicatorPtr communicator; + + try + { + communicator = initializeWithProperties(argc, argv, properties); + status = run(argc, argv, communicator); + } + catch(const LocalException& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if (communicator) + { + try + { + communicator->destroy(); + } + catch(const LocalException& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/src/IcePack/Forward.cpp b/cpp/src/IcePack/Forward.cpp new file mode 100644 index 00000000000..ffce65f468f --- /dev/null +++ b/cpp/src/IcePack/Forward.cpp @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <Forward.h> + +using namespace std; +using namespace Ice; +using namespace IcePack; + +Forward::Forward(const AdminPtr& admin) : + _admin(admin) +{ +} + +ObjectPtr +Forward::locate(const ObjectAdapterPtr& adapter, const string& identity, ObjectPtr&) +{ + ObjectPrx proxy = adapter->identityToProxy(identity); + ServerDescriptionPtr desc = _admin->find(proxy); + if (desc) + { + assert(desc->object); + throw LocationForward(proxy); + } + return 0; +} + +void +Forward::finished(const ObjectAdapterPtr&, const string&, const ObjectPtr&, const ObjectPtr&) +{ + // Nothing to do +} diff --git a/cpp/src/IcePack/Forward.h b/cpp/src/IcePack/Forward.h new file mode 100644 index 00000000000..2a2cbdd44be --- /dev/null +++ b/cpp/src/IcePack/Forward.h @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef FORWARD_H +#define FORWARD_H + +#include <IcePack/Admin.h> +#include <map> + +class Forward : public Ice::ObjectLocator +{ +public: + + Forward(const IcePack::AdminPtr&); + + virtual Ice::ObjectPtr locate(const Ice::ObjectAdapterPtr&, const std::string&, Ice::ObjectPtr&); + virtual void finished(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&, + const Ice::ObjectPtr&); + +private: + + IcePack::AdminPtr _admin; +}; + +#endif diff --git a/cpp/src/IcePack/Makefile b/cpp/src/IcePack/Makefile index 109c105dc99..a6b07224c52 100644 --- a/cpp/src/IcePack/Makefile +++ b/cpp/src/IcePack/Makefile @@ -16,11 +16,22 @@ VERSIONED_BASE = $(BASE).$(VERSION) NAME = $(top_srcdir)/lib/$(BASE) VERSIONED_NAME = $(top_srcdir)/lib/$(VERSIONED_BASE) -TARGETS = $(NAME) $(VERSIONED_NAME) +CLIENT = $(top_srcdir)/bin/icepackadmin +SERVER = $(top_srcdir)/bin/icepack + +TARGETS = $(NAME) $(VERSIONED_NAME) $(CLIENT) $(SERVER) OBJS = Admin.o -SRCS = $(OBJS:.o=.cpp) +COBJS = Client.o + +SOBJS = Server.o \ + Forward.o \ + AdminI.o + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) HDIR = $(includedir)/IcePack IDIR = $(slicedir)/IcePack @@ -28,7 +39,7 @@ SLICECMD = $(SLICE) --include-dir IcePack --dll-export ICE_PACK_API -I$(slicedir include $(top_srcdir)/config/Make.rules -CPPFLAGS := -I.. $(CPPFLAGS) +CPPFLAGS := -I. -I.. $(CPPFLAGS) $(VERSIONED_NAME): $(OBJS) rm -f $@ @@ -38,6 +49,14 @@ $(NAME): $(VERSIONED_NAME) rm -f $@ ln -s $(VERSIONED_BASE) $@ +$(CLIENT): $(COBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(COBJS) -lIcePack $(LIBS) + +$(SERVER): $(SOBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(SOBJS) -lIcePack $(LIBS) + $(HDIR)/Admin.h Admin.cpp: $(IDIR)/Admin.ice $(SLICE) rm -f $(HDIR)/Admin.h Admin.cpp $(SLICECMD) $(IDIR)/Admin.ice diff --git a/cpp/src/IcePack/Server.cpp b/cpp/src/IcePack/Server.cpp new file mode 100644 index 00000000000..cfc5c19904c --- /dev/null +++ b/cpp/src/IcePack/Server.cpp @@ -0,0 +1,143 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <AdminI.h> +#include <Forward.h> + +using namespace std; +using namespace Ice; +using namespace IcePack; + +void +usage(const char* n) +{ + cerr << "Usage: " << n << " [options]\n"; + cerr << + "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" + ; +} + +int +run(int argc, char* argv[], CommunicatorPtr communicator) +{ + PropertiesPtr properties = communicator->getProperties(); + + string adminEndpoints = properties->getProperty("Ice.Adapter.Admin.Endpoints"); + if(adminEndpoints.length() != 0) + { + cerr << argv[0] << ": warning: administrative endpoints `Ice.Adapter.Admin.Endpoints' enabled" << endl; + } + + string forwardEndpoints = properties->getProperty("Ice.Adapter.Forward.Endpoints"); + if(forwardEndpoints.length() == 0) + { + cerr << argv[0] << ": `Ice.Adapter.Forward.Endpoints' property is not set" << endl; + return EXIT_FAILURE; + } + + AdminPtr admin = new AdminI; + ObjectLocatorPtr forward = new Forward(admin); + + if (adminEndpoints.length() != 0) + { + ObjectAdapterPtr adminAdapter = communicator->createObjectAdapter("Admin"); + adminAdapter->add(admin, "admin"); + adminAdapter->activate(); + } + + ObjectAdapterPtr forwardAdapter = communicator->createObjectAdapter("Forward"); + forwardAdapter->setObjectLocator(forward); + forwardAdapter->activate(); + + communicator->waitForShutdown(); + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + PropertiesPtr properties = getDefaultProperties(); + + for (int i = 1; i < argc; ++i) + { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) + { + usage(argv[0]); + return EXIT_SUCCESS; + } + else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + 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; + usage(argv[0]); + return EXIT_FAILURE; + } + } + + int status; + CommunicatorPtr communicator; + + try + { + communicator = initializeWithProperties(argc, argv, properties); + status = run(argc, argv, communicator); + } + catch(const LocalException& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if (communicator) + { + try + { + communicator->destroy(); + } + catch(const LocalException& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/src/slice2cpp/GenUtil.cpp b/cpp/src/slice2cpp/GenUtil.cpp index 8de9550af30..4249d7a7cda 100644 --- a/cpp/src/slice2cpp/GenUtil.cpp +++ b/cpp/src/slice2cpp/GenUtil.cpp @@ -142,9 +142,9 @@ Slice::outputTypeToString(const TypePtr& type) "::Ice::Double&", "::std::string&", "::std::wstring&", - "::Ice::ObjectPtr", - "::Ice::ObjectPrx", - "::Ice::LocalObjectPtr" + "::Ice::ObjectPtr&", + "::Ice::ObjectPrx&", + "::Ice::LocalObjectPtr&" }; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); |