diff options
Diffstat (limited to 'cpp/src')
45 files changed, 2207 insertions, 1109 deletions
diff --git a/cpp/src/Freeze/BackgroundSaveEvictorI.cpp b/cpp/src/Freeze/BackgroundSaveEvictorI.cpp index 1d8fa7acce4..7b2215f7341 100644 --- a/cpp/src/Freeze/BackgroundSaveEvictorI.cpp +++ b/cpp/src/Freeze/BackgroundSaveEvictorI.cpp @@ -301,10 +301,12 @@ Freeze::BackgroundSaveEvictorI::addFacet(const ObjectPtr& servant, const Identit ObjectRecord& rec = element->rec; rec.servant = servant; - rec.stats.creationTime = IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds(); - rec.stats.lastSaveTime = 0; - rec.stats.avgSaveTime = 0; - + if(store->keepStats()) + { + rec.stats.creationTime = IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds(); + rec.stats.lastSaveTime = 0; + rec.stats.avgSaveTime = 0; + } addToModifiedQueue(element); break; } @@ -1115,6 +1117,7 @@ Freeze::BackgroundSaveEvictorI::run() } Long saveStart = IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds(); + try { DbTxn* tx = 0; @@ -1393,14 +1396,18 @@ Freeze::BackgroundSaveEvictorI::stream(const BackgroundSaveEvictorElementPtr& el obj.status = element->status; obj.store = &element->store; - + const Identity& ident = element->cachePosition->first; ObjectStoreBase::marshal(ident, obj.key, _communicator, _encoding); if(element->status != destroyed) { - EvictorIBase::updateStats(element->rec.stats, streamStart); - ObjectStoreBase::marshal(element->rec, obj.value, _communicator, _encoding); + bool keepStats = obj.store->keepStats(); + if(keepStats) + { + EvictorIBase::updateStats(element->rec.stats, streamStart); + } + ObjectStoreBase::marshal(element->rec, obj.value, _communicator, _encoding, keepStats); } } @@ -1422,6 +1429,8 @@ Freeze::BackgroundSaveEvictorElement::BackgroundSaveEvictorElement(ObjectStore<B stale(true), status(clean) { + const Statistics cleanStats = { 0 }; + rec.stats = cleanStats; } Freeze::BackgroundSaveEvictorElement::~BackgroundSaveEvictorElement() diff --git a/cpp/src/Freeze/IndexI.cpp b/cpp/src/Freeze/IndexI.cpp index f0910bb2452..11a9bfc4be4 100644 --- a/cpp/src/Freeze/IndexI.cpp +++ b/cpp/src/Freeze/IndexI.cpp @@ -405,7 +405,7 @@ Freeze::IndexI::secondaryKeyCreate(Db* secondary, const Dbt* dbKey, ObjectRecord rec; Byte* first = static_cast<Byte*>(dbValue->get_data()); Value value(first, first + dbValue->get_size()); - ObjectStoreBase::unmarshal(rec, value, communicator, encoding); + ObjectStoreBase::unmarshal(rec, value, communicator, encoding, _store->keepStats()); Key bytes; if(_index.marshalKey(rec.servant, bytes)) diff --git a/cpp/src/Freeze/ObjectStore.cpp b/cpp/src/Freeze/ObjectStore.cpp index 744381ed984..4015ab63eb5 100644 --- a/cpp/src/Freeze/ObjectStore.cpp +++ b/cpp/src/Freeze/ObjectStore.cpp @@ -29,7 +29,8 @@ Freeze::ObjectStoreBase::ObjectStoreBase(const string& facet, const string& face _evictor(evictor), _indices(indices), _communicator(evictor->communicator()), - _encoding(evictor->encoding()) + _encoding(evictor->encoding()), + _keepStats(false) { if(facet == "") { @@ -60,10 +61,17 @@ Freeze::ObjectStoreBase::ObjectStoreBase(const string& facet, const string& face Catalog::iterator p = catalog.find(evictor->filename()); if(p != catalog.end()) { - if(p->second.evictor == false) + if(p->second.evictor) + { + // + // empty means the value is ::Freeze::ObjectRecord + // + _keepStats = p->second.value.empty(); + } + else { DatabaseException ex(__FILE__, __LINE__); - ex.message = evictor->filename() + " is an evictor database"; + ex.message = evictor->filename() + " is not an evictor database"; throw ex; } } @@ -141,6 +149,8 @@ Freeze::ObjectStoreBase::ObjectStoreBase(const string& facet, const string& face { CatalogData catalogData; catalogData.evictor = true; + catalogData.key = "Ice::Identity"; + catalogData.value = "Object"; catalog.put(Catalog::value_type(evictor->filename(), catalogData)); } @@ -348,12 +358,21 @@ void Freeze::ObjectStoreBase::marshal(const ObjectRecord& v, Value& bytes, const CommunicatorPtr& communicator, - const EncodingVersion& encoding) + const EncodingVersion& encoding, + bool keepStats) { IceInternal::InstancePtr instance = IceInternal::getInstance(communicator); IceInternal::BasicStream stream(instance.get(), encoding, true); stream.startWriteEncaps(); - v.__write(&stream); + if(keepStats) + { + v.__write(&stream); + } + else + { + stream.write(v.servant); + } + stream.writePendingObjects(); stream.endWriteEncaps(); vector<Byte>(stream.b.begin(), stream.b.end()).swap(bytes); @@ -363,7 +382,8 @@ void Freeze::ObjectStoreBase::unmarshal(ObjectRecord& v, const Value& bytes, const CommunicatorPtr& communicator, - const EncodingVersion& encoding) + const EncodingVersion& encoding, + bool keepStats) { IceInternal::InstancePtr instance = IceInternal::getInstance(communicator); IceInternal::BasicStream stream(instance.get(), encoding, true); @@ -372,7 +392,16 @@ Freeze::ObjectStoreBase::unmarshal(ObjectRecord& v, memcpy(&stream.b[0], &bytes[0], bytes.size()); stream.i = stream.b.begin(); stream.startReadEncaps(); - v.__read(&stream); + + if(keepStats) + { + v.__read(&stream); + } + else + { + stream.read(v.servant); + } + stream.readPendingObjects(); stream.endReadEncaps(); } @@ -436,7 +465,7 @@ Freeze::ObjectStoreBase::load(const Identity& ident, const TransactionIPtr& tran } } - unmarshal(rec, value, _communicator, _encoding); + unmarshal(rec, value, _communicator, _encoding, _keepStats); _evictor->initialize(ident, _facet, rec.servant); return true; } @@ -460,7 +489,7 @@ Freeze::ObjectStoreBase::update(const Identity& ident, const ObjectRecord& rec, marshal(ident, key, _communicator, _encoding); Value value; - marshal(rec, value, _communicator, _encoding); + marshal(rec, value, _communicator, _encoding, _keepStats); Dbt dbKey; Dbt dbValue; @@ -505,7 +534,7 @@ Freeze::ObjectStoreBase::insert(const Identity& ident, const ObjectRecord& rec, marshal(ident, key, _communicator, _encoding); Value value; - marshal(rec, value, _communicator, _encoding); + marshal(rec, value, _communicator, _encoding, _keepStats); Dbt dbKey; Dbt dbValue; @@ -653,7 +682,7 @@ Freeze::ObjectStoreBase::loadImpl(const Identity& ident, ObjectRecord& rec) } } - unmarshal(rec, value, _communicator, _encoding); + unmarshal(rec, value, _communicator, _encoding, _keepStats); _evictor->initialize(ident, _facet, rec.servant); return true; } diff --git a/cpp/src/Freeze/ObjectStore.h b/cpp/src/Freeze/ObjectStore.h index a78c3e197d9..ff2574fa931 100644 --- a/cpp/src/Freeze/ObjectStore.h +++ b/cpp/src/Freeze/ObjectStore.h @@ -44,8 +44,8 @@ public: static void marshal(const Ice::Identity&, Key&, const Ice::CommunicatorPtr&, const Ice::EncodingVersion&); static void unmarshal(Ice::Identity&, const Key&, const Ice::CommunicatorPtr&, const Ice::EncodingVersion&); - static void marshal(const ObjectRecord&, Value&, const Ice::CommunicatorPtr&, const Ice::EncodingVersion&); - static void unmarshal(ObjectRecord&, const Value&, const Ice::CommunicatorPtr&, const Ice::EncodingVersion&); + static void marshal(const ObjectRecord&, Value&, const Ice::CommunicatorPtr&, const Ice::EncodingVersion&, bool); + static void unmarshal(ObjectRecord&, const Value&, const Ice::CommunicatorPtr&, const Ice::EncodingVersion&, bool); bool load(const Ice::Identity&, const TransactionIPtr&, ObjectRecord&); void update(const Ice::Identity&, const ObjectRecord&, const TransactionIPtr&); @@ -64,7 +64,8 @@ public: const Ice::CommunicatorPtr& communicator() const; const Ice::EncodingVersion& encoding() const; const std::string& facet() const; - + bool keepStats() const; + protected: bool loadImpl(const Ice::Identity&, ObjectRecord&); @@ -79,6 +80,7 @@ private: Ice::CommunicatorPtr _communicator; Ice::EncodingVersion _encoding; Ice::ObjectPtr _sampleServant; + bool _keepStats; }; @@ -156,6 +158,12 @@ ObjectStoreBase::facet() const return _facet; } +inline bool +ObjectStoreBase::keepStats() const +{ + return _keepStats; +} + inline const Ice::ObjectPtr& ObjectStoreBase::sampleServant() const { diff --git a/cpp/src/Freeze/TransactionalEvictorContext.cpp b/cpp/src/Freeze/TransactionalEvictorContext.cpp index b0dacafe261..298019aed26 100644 --- a/cpp/src/Freeze/TransactionalEvictorContext.cpp +++ b/cpp/src/Freeze/TransactionalEvictorContext.cpp @@ -275,8 +275,11 @@ Freeze::TransactionalEvictorContext::ServantHolder::~ServantHolder() { if(!_body.readOnly && !_body.removed) { - EvictorIBase::updateStats(_body.rec.stats, - IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds()); + if(_body.store->keepStats()) + { + EvictorIBase::updateStats(_body.rec.stats, + IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds()); + } _body.store->update(_body.current->id, _body.rec, ctx->_tx); } diff --git a/cpp/src/Freeze/TransactionalEvictorI.cpp b/cpp/src/Freeze/TransactionalEvictorI.cpp index 5d984a5cf4f..dfca69dee6a 100644 --- a/cpp/src/Freeze/TransactionalEvictorI.cpp +++ b/cpp/src/Freeze/TransactionalEvictorI.cpp @@ -139,24 +139,29 @@ Freeze::TransactionalEvictorI::addFacet(const ObjectPtr& servant, const Identity checkIdentity(ident); DeactivateController::Guard deactivateGuard(_deactivateController); - Ice::Long currentTime = IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds(); - - Statistics stats = { currentTime }; - ObjectRecord rec; - rec.servant = servant; - rec.stats = stats; - ObjectStore<TransactionalEvictorElement>* store = findStore(facet, _createDb); - if(store == 0) { throw NotFoundException(__FILE__, __LINE__, "addFacet: could not open database for facet '" + facet + "'"); } + Ice::Long currentTime = 0; + + if(store->keepStats()) + { + currentTime = IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds(); + } + + Statistics stats = { currentTime }; + ObjectRecord rec = { servant, stats }; + TransactionIPtr tx = beforeQuery(); - updateStats(rec.stats, currentTime); + if(store->keepStats()) + { + updateStats(rec.stats, currentTime); + } if(!store->insert(ident, rec, tx)) { diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp index 5472b1d50a8..b2da041ec3d 100755 --- a/cpp/src/FreezeScript/DumpDB.cpp +++ b/cpp/src/FreezeScript/DumpDB.cpp @@ -314,7 +314,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator { selectExpr = opts.optArg("select"); } - + if(outputFile.empty() && args.size() != 2) { usage(appName); @@ -357,15 +357,16 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator if(inputFile.empty()) { const string evictorKeyTypeName = "::Ice::Identity"; - const string evictorValueTypeName = "::Freeze::ObjectRecord"; + const string oldEvictorValueTypeName = "::Freeze::ObjectRecord"; + const string newEvictorValueTypeName = "Object"; - if((!keyTypeName.empty() && valueTypeName.empty()) || (keyTypeName.empty() && !valueTypeName.empty())) + if((!keyTypeName.empty() && valueTypeName.empty()) || (keyTypeName.empty() && !valueTypeName.empty() && !evictor)) { cerr << appName << ": a key type and a value type must be specified" << endl; usage(appName); return EXIT_FAILURE; } - else if(!evictor && keyTypeName.empty() && valueTypeName.empty()) + else if(valueTypeName.empty()) { try { @@ -387,24 +388,32 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator { evictor = true; } - else - { - keyTypeName = p->second.key; - valueTypeName = p->second.value; - } + keyTypeName = p->second.key; + valueTypeName = p->second.value; + + if(evictor && valueTypeName.empty()) + { + valueTypeName = oldEvictorValueTypeName; + } } } catch(const FreezeScript::FailureException& ex) { - cerr << appName << ": " << ex.reason() << endl; - return EXIT_FAILURE; + cerr << appName << ": " << ex.reason() << endl; + return EXIT_FAILURE; } } if(evictor) { - keyTypeName = evictorKeyTypeName; - valueTypeName = evictorValueTypeName; + if(keyTypeName.empty()) + { + keyTypeName = evictorKeyTypeName; + } + if(valueTypeName.empty()) + { + valueTypeName = newEvictorValueTypeName; + } } Slice::TypePtr keyType, valueType; @@ -536,7 +545,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); Dbc* dbc = 0; - db.cursor(0, &dbc, 0); + db.cursor(txn, &dbc, 0); while(dbc->get(&dbKey, &dbValue, DB_NEXT) == 0) { diff --git a/cpp/src/FreezeScript/Exception.cpp b/cpp/src/FreezeScript/Exception.cpp index ba2f0a353d4..602624ff835 100644 --- a/cpp/src/FreezeScript/Exception.cpp +++ b/cpp/src/FreezeScript/Exception.cpp @@ -42,7 +42,7 @@ FreezeScript::FailureException::ice_print(ostream& out) const } } -IceUtil::Exception* +FreezeScript::FailureException* FreezeScript::FailureException::ice_clone() const { return new FailureException(ice_file(), ice_line(), _reason); diff --git a/cpp/src/FreezeScript/Exception.h b/cpp/src/FreezeScript/Exception.h index 3d19ec8e2dc..b5f5e8c8c2c 100644 --- a/cpp/src/FreezeScript/Exception.h +++ b/cpp/src/FreezeScript/Exception.h @@ -22,7 +22,7 @@ public: virtual ~FailureException() throw(); virtual std::string ice_name() const; virtual void ice_print(std::ostream&) const; - virtual IceUtil::Exception* ice_clone() const; + virtual FailureException* ice_clone() const; virtual void ice_throw() const; std::string reason() const; diff --git a/cpp/src/FreezeScript/Parser.cpp b/cpp/src/FreezeScript/Parser.cpp index 7bc5e70a5d9..0fcf26f067a 100644 --- a/cpp/src/FreezeScript/Parser.cpp +++ b/cpp/src/FreezeScript/Parser.cpp @@ -174,7 +174,7 @@ FreezeScript::EvaluateException::ice_print(ostream& out) const } } -IceUtil::Exception* +FreezeScript::EvaluateException* FreezeScript::EvaluateException::ice_clone() const { return new EvaluateException(ice_file(), ice_line(), _reason); diff --git a/cpp/src/FreezeScript/Parser.h b/cpp/src/FreezeScript/Parser.h index 397de172fac..e5c79800fb8 100644 --- a/cpp/src/FreezeScript/Parser.h +++ b/cpp/src/FreezeScript/Parser.h @@ -41,7 +41,7 @@ public: virtual ~EvaluateException() throw(); virtual std::string ice_name() const; virtual void ice_print(std::ostream&) const; - virtual IceUtil::Exception* ice_clone() const; + virtual EvaluateException* ice_clone() const; virtual void ice_throw() const; std::string reason() const; diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp index 6a6bd5fe7f5..f4583394b5c 100755 --- a/cpp/src/FreezeScript/transformdb.cpp +++ b/cpp/src/FreezeScript/transformdb.cpp @@ -184,8 +184,7 @@ transformDb(bool evictor, const Ice::CommunicatorPtr& communicator, } Freeze::Catalog catalogNew(connectionNew, Freeze::catalogName()); - Freeze::CatalogData catalogData; - catalogData.evictor = true; + Freeze::CatalogData catalogData = { true, "::Ice::Identity", "Object" }; catalogNew.put(Freeze::Catalog::value_type(dbName, catalogData)); } else @@ -308,6 +307,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator purgeObjects = opts.isSet("p"); catastrophicRecover = opts.isSet("c"); suppress = opts.isSet("w"); + if(opts.isSet("f")) { inputFile = opts.optArg("f"); @@ -490,7 +490,8 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator FreezeScript::TransformAnalyzer analyzer(oldUnit, newUnit, ignoreTypeChanges, out, missingTypes, analyzeErrors); const string evictorKeyName = "::Ice::Identity"; - const string evictorValueName = "::Freeze::ObjectRecord"; + const string oldEvictorValueName = "::Freeze::ObjectRecord"; + const string newEvictorValueName = "Object"; if(allDb) { @@ -503,8 +504,17 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator if(p->second.evictor) { - keyName = evictorKeyName; - valueName = evictorValueName; + keyName = p->second.key; + valueName = p->second.value; + + if(keyName.empty()) + { + keyName = evictorKeyName; + } + if(valueName.empty()) + { + valueName = oldEvictorValueName; + } } else { @@ -533,7 +543,20 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator cerr << appName << ": type `" << valueName << "' from database `" << p->first << "' not found in old Slice definitions" << endl; } - Slice::TypePtr newValueType = findType(newUnit, valueName); + + Slice::TypePtr newValueType; + if(p->second.evictor) + { + // + // The new evictor does not keep stats + // + newValueType = findType(newUnit, newEvictorValueName); + } + else + { + newValueType = findType(newUnit, valueName); + } + if(!newValueType) { cerr << appName << ": type `" << valueName << "' from database `" << p->first @@ -553,46 +576,44 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator { return EXIT_FAILURE; } - + analyzer.addDatabase(p->first, oldKeyType, newKeyType, oldValueType, newValueType); } } else { string oldKeyName, newKeyName, oldValueName, newValueName; - - if(evictor) - { - oldKeyName = newKeyName = evictorKeyName; - oldValueName = newValueName = evictorValueName; - } - else - { - string::size_type pos; - - if(keyTypeNames.empty() || valueTypeNames.empty()) - { - usage(appName); - return EXIT_FAILURE; - } - - pos = keyTypeNames.find(','); - if(pos == 0 || pos == keyTypeNames.size()) - { - usage(appName); - return EXIT_FAILURE; - } - if(pos == string::npos) - { - oldKeyName = keyTypeNames; - newKeyName = keyTypeNames; - } + + string::size_type pos; + + if(!evictor && (keyTypeNames.empty() || valueTypeNames.empty())) + { + usage(appName); + return EXIT_FAILURE; + } + + if(!keyTypeNames.empty()) + { + pos = keyTypeNames.find(','); + if(pos == 0 || pos == keyTypeNames.size()) + { + usage(appName); + return EXIT_FAILURE; + } + if(pos == string::npos) + { + oldKeyName = keyTypeNames; + newKeyName = keyTypeNames; + } else { oldKeyName = keyTypeNames.substr(0, pos); newKeyName = keyTypeNames.substr(pos + 1); } + } + if(!valueTypeNames.empty()) + { pos = valueTypeNames.find(','); if(pos == 0 || pos == valueTypeNames.size()) { @@ -610,6 +631,26 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator newValueName = valueTypeNames.substr(pos + 1); } } + + if(evictor) + { + if(oldKeyName.empty()) + { + oldKeyName = evictorKeyName; + } + if(newKeyName.empty()) + { + newKeyName = evictorKeyName; + } + if(oldValueName.empty()) + { + oldValueName = newEvictorValueName; + } + if(newValueName.empty()) + { + newValueName = newEvictorValueName; + } + } // // Look up the key and value types in the old and new Slice definitions. diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp index 3bc2e23100c..31c68a5d4f5 100644 --- a/cpp/src/Ice/Incoming.cpp +++ b/cpp/src/Ice/Incoming.cpp @@ -363,12 +363,10 @@ IceInternal::IncomingBase::__handleException(const std::exception& exc) _os.write(replyUnknownLocalException); ostringstream str; str << *le; -#ifdef __GNUC__ if(IceUtilInternal::printStackTraces) { str << '\n' << ex->ice_stackTrace(); } -#endif _os.write(str.str(), false); } else if(const UserException* ue = dynamic_cast<const UserException*>(&exc)) @@ -376,12 +374,10 @@ IceInternal::IncomingBase::__handleException(const std::exception& exc) _os.write(replyUnknownUserException); ostringstream str; str << *ue; -#ifdef __GNUC__ if(IceUtilInternal::printStackTraces) { str << '\n' << ex->ice_stackTrace(); } -#endif _os.write(str.str(), false); } else diff --git a/cpp/src/Ice/LoggerUtil.cpp b/cpp/src/Ice/LoggerUtil.cpp index 3673f5ff650..ebf9ea5de11 100644 --- a/cpp/src/Ice/LoggerUtil.cpp +++ b/cpp/src/Ice/LoggerUtil.cpp @@ -39,7 +39,6 @@ Ice::operator<<(Ice::LoggerOutputBase& out, ios_base& (*val)(ios_base&)) Ice::LoggerOutputBase& Ice::operator<<(Ice::LoggerOutputBase& out, const std::exception& ex) { -#ifdef __GNUC__ if(IceUtilInternal::printStackTraces) { const ::IceUtil::Exception* exception = dynamic_cast<const ::IceUtil::Exception*>(&ex); @@ -49,7 +48,6 @@ Ice::operator<<(Ice::LoggerOutputBase& out, const std::exception& ex) return out; } } -#endif out.__str() << ex.what(); return out; } diff --git a/cpp/src/IceDB/FreezeTypes.cpp b/cpp/src/IceDB/FreezeTypes.cpp index 319dd30dc11..15b8ba61b97 100644 --- a/cpp/src/IceDB/FreezeTypes.cpp +++ b/cpp/src/IceDB/FreezeTypes.cpp @@ -29,7 +29,7 @@ DatabaseException::ice_print(ostream& out) const out << ":\n" << message; } -::IceUtil::Exception* +DatabaseException* DatabaseException::ice_clone() const { return new DatabaseException(*this); @@ -58,7 +58,7 @@ DeadlockException::ice_print(ostream& out) const out << ":\n" << message; } -::IceUtil::Exception* +DeadlockException* DeadlockException::ice_clone() const { return new DeadlockException(*this); @@ -79,7 +79,7 @@ NotFoundException::~NotFoundException() throw() { } -::IceUtil::Exception* +NotFoundException* NotFoundException::ice_clone() const { return new NotFoundException(*this); @@ -139,7 +139,7 @@ DatabaseConnection::rollbackTransaction() _connection->currentTransaction()->rollback(); } -DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator, const string& envName) : +ConnectionPool::ConnectionPool(const Ice::CommunicatorPtr& communicator, const string& envName) : _communicator(communicator), _envName(envName), _connection(newConnection()) @@ -147,13 +147,13 @@ DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator, const str } IceDB::DatabaseConnectionPtr -DatabaseCache::getConnection() +ConnectionPool::getConnection() { return _connection; } IceDB::DatabaseConnectionPtr -DatabaseCache::newConnection() +ConnectionPool::newConnection() { return new DatabaseConnection(Freeze::createConnection(_communicator, _envName)); } diff --git a/cpp/src/IceDB/FreezeTypes.h b/cpp/src/IceDB/FreezeTypes.h index ec351dc48c8..d10645b7197 100644 --- a/cpp/src/IceDB/FreezeTypes.h +++ b/cpp/src/IceDB/FreezeTypes.h @@ -23,9 +23,10 @@ public: virtual ~DatabaseException() throw(); virtual void ice_print(::std::ostream&) const; - virtual ::IceUtil::Exception* ice_clone() const; + virtual DatabaseException* ice_clone() const; virtual void ice_throw() const; +private: std::string message; }; @@ -37,9 +38,10 @@ public: virtual ~DeadlockException() throw(); virtual void ice_print(::std::ostream&) const; - virtual ::IceUtil::Exception* ice_clone() const; + virtual DeadlockException* ice_clone() const; virtual void ice_throw() const; +private: std::string message; }; @@ -50,13 +52,13 @@ public: NotFoundException(const char*, int); virtual ~NotFoundException() throw(); - virtual ::IceUtil::Exception* ice_clone() const; + virtual NotFoundException* ice_clone() const; virtual void ice_throw() const; }; void throwDatabaseException(const char*, int, const Freeze::DatabaseException&); -class DatabaseConnection : public IceDB::DatabaseConnection +class DatabaseConnection : public virtual IceDB::DatabaseConnection { public: @@ -68,8 +70,7 @@ public: virtual void commitTransaction(); virtual void rollbackTransaction(); - Freeze::ConnectionPtr - freezeConnection() + Freeze::ConnectionPtr freezeConnection() const { return _connection; } @@ -79,11 +80,11 @@ private: Freeze::ConnectionPtr _connection; }; -class DatabaseCache : virtual public IceDB::DatabaseCache +class ConnectionPool : public virtual IceDB::ConnectionPool { public: - DatabaseCache(const Ice::CommunicatorPtr&, const std::string&); + ConnectionPool(const Ice::CommunicatorPtr&, const std::string&); virtual IceDB::DatabaseConnectionPtr getConnection(); virtual IceDB::DatabaseConnectionPtr newConnection(); @@ -99,7 +100,8 @@ template<class Dict, class Key, class Value> class Wrapper : public virtual IceD { public: - Wrapper(const Freeze::ConnectionPtr& connection, const std::string& dbName) : _dict(connection, dbName) + Wrapper(const Freeze::ConnectionPtr& connection, const std::string& dbName) : + _dict(connection, dbName) { } diff --git a/cpp/src/IceDB/IceDB.cpp b/cpp/src/IceDB/IceDB.cpp index 015699cacf6..ff012579483 100644 --- a/cpp/src/IceDB/IceDB.cpp +++ b/cpp/src/IceDB/IceDB.cpp @@ -16,18 +16,34 @@ using namespace IceDB; using namespace std; + +IceDB::DatabaseException::DatabaseException(const char* file, int line) : + IceUtil::Exception(file, line) +{ +} + string DatabaseException::ice_name() const { return "IceDB::DatabaseException"; } +DeadlockException::DeadlockException(const char* file, int line) : + DatabaseException(file, line) +{ +} + string DeadlockException::ice_name() const { return "IceDB::DeadlockException"; } +NotFoundException::NotFoundException(const char* file, int line) : +DatabaseException(file, line) +{ +} + string NotFoundException::ice_name() const { diff --git a/cpp/src/IceDB/IceDB.h b/cpp/src/IceDB/IceDB.h index ea7ea21c073..53053b326de 100644 --- a/cpp/src/IceDB/IceDB.h +++ b/cpp/src/IceDB/IceDB.h @@ -32,9 +32,7 @@ class ICE_DB_API DatabaseException : public IceUtil::Exception { protected: - DatabaseException(const char* file, int line) : IceUtil::Exception(file, line) - { - } + DatabaseException(const char*, int); virtual std::string ice_name() const; }; @@ -43,9 +41,7 @@ class ICE_DB_API DeadlockException : public DatabaseException { protected: - DeadlockException(const char* file, int line) : DatabaseException(file, line) - { - } + DeadlockException(const char*, int); virtual std::string ice_name() const; }; @@ -54,14 +50,12 @@ class ICE_DB_API NotFoundException : public DatabaseException { protected: - NotFoundException(const char* file, int line) : DatabaseException(file, line) - { - } + NotFoundException(const char*, int); virtual std::string ice_name() const; }; -class ICE_DB_API DatabaseConnection : virtual public IceUtil::Shared +class ICE_DB_API DatabaseConnection : public IceUtil::Shared { public: @@ -89,23 +83,21 @@ private: // Not implemented // TransactionHolder(const TransactionHolder&); - - TransactionHolder& - operator=(const TransactionHolder&); + TransactionHolder& operator=(const TransactionHolder&); DatabaseConnectionPtr _connection; }; -class ICE_DB_API DatabaseCache : public IceUtil::Shared +class ICE_DB_API ConnectionPool : public IceUtil::Shared { public: virtual DatabaseConnectionPtr getConnection() = 0; virtual DatabaseConnectionPtr newConnection() = 0; }; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; -template<class Key, class Value> class Wrapper : virtual public IceUtil::Shared +template<class Key, class Value> class Wrapper : public IceUtil::Shared { public: @@ -116,4 +108,4 @@ public: virtual void clear() = 0; }; -}; +} diff --git a/cpp/src/IceDB/SqlTypes.cpp b/cpp/src/IceDB/SqlTypes.cpp index b4d4e340069..293957363a2 100644 --- a/cpp/src/IceDB/SqlTypes.cpp +++ b/cpp/src/IceDB/SqlTypes.cpp @@ -36,7 +36,7 @@ DatabaseException::ice_print(ostream& out) const out << "\n driver error: " << error.driverText().toUtf8().data(); } -::IceUtil::Exception* +DatabaseException* DatabaseException::ice_clone() const { return new DatabaseException(*this); @@ -66,7 +66,7 @@ DeadlockException::ice_print(ostream& out) const out << "\n driver error: " << error.driverText().toUtf8().data(); } -::IceUtil::Exception* +DeadlockException* DeadlockException::ice_clone() const { return new DeadlockException(*this); @@ -87,7 +87,7 @@ NotFoundException::~NotFoundException() throw() { } -::IceUtil::Exception* +NotFoundException* NotFoundException::ice_clone() const { return new NotFoundException(*this); @@ -167,7 +167,7 @@ DatabaseConnection::rollbackTransaction() } } -DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator, +ConnectionPool::ConnectionPool(const Ice::CommunicatorPtr& communicator, const string& type, const string& name, const string& host, @@ -211,7 +211,7 @@ DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator, } } -DatabaseCache::~DatabaseCache() +ConnectionPool::~ConnectionPool() { // // QSqlDatabase references must be removed before calling removeDatabase. @@ -230,9 +230,9 @@ DatabaseCache::~DatabaseCache() } IceDB::DatabaseConnectionPtr -DatabaseCache::getConnection() +ConnectionPool::getConnection() { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); ThreadDatabaseMap::iterator p = _cache.find(IceUtil::ThreadControl().id()); if(p != _cache.end()) @@ -323,15 +323,15 @@ DatabaseCache::getConnection() } IceDB::DatabaseConnectionPtr -DatabaseCache::newConnection() +ConnectionPool::newConnection() { return getConnection(); } void -DatabaseCache::threadStopped() +ConnectionPool::threadStopped() { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); ThreadDatabaseMap::iterator p = _cache.find(IceUtil::ThreadControl().id()); if(p != _cache.end()) @@ -350,9 +350,9 @@ ThreadHook::ThreadHook() } void -ThreadHook::setDatabaseCache(const DatabaseCachePtr& cache) +ThreadHook::setConnectionPool(const ConnectionPoolPtr& cache) { - IceUtil::Mutex::Lock sync(*this); + IceUtil::Mutex::Lock sync(_mutex); _cache = cache; } @@ -364,7 +364,7 @@ ThreadHook::start() void ThreadHook::stop() { - IceUtil::Mutex::Lock sync(*this); + IceUtil::Mutex::Lock sync(_mutex); if(_cache) { _cache->threadStopped(); diff --git a/cpp/src/IceDB/SqlTypes.h b/cpp/src/IceDB/SqlTypes.h index 764556699ff..ad310c755f9 100644 --- a/cpp/src/IceDB/SqlTypes.h +++ b/cpp/src/IceDB/SqlTypes.h @@ -35,9 +35,10 @@ public: virtual ~DatabaseException() throw(); virtual void ice_print(::std::ostream&) const; - virtual ::IceUtil::Exception* ice_clone() const; + virtual DatabaseException* ice_clone() const; virtual void ice_throw() const; +private: QSqlError error; }; @@ -49,9 +50,10 @@ public: virtual ~DeadlockException() throw(); virtual void ice_print(::std::ostream&) const; - virtual ::IceUtil::Exception* ice_clone() const; + virtual DeadlockException* ice_clone() const; virtual void ice_throw() const; +private: QSqlError error; }; @@ -62,7 +64,7 @@ public: NotFoundException(const char*, int); virtual ~NotFoundException() throw(); - virtual ::IceUtil::Exception* ice_clone() const; + virtual NotFoundException* ice_clone() const; virtual void ice_throw() const; }; @@ -71,7 +73,7 @@ void throwDatabaseException(const char*, int, const QSqlError&); // // Database connection // -class DatabaseConnection : public IceDB::DatabaseConnection +class DatabaseConnection : public virtual IceDB::DatabaseConnection { public: @@ -83,12 +85,12 @@ public: virtual void commitTransaction(); virtual void rollbackTransaction(); - QSqlDatabase sqlConnection() + QSqlDatabase sqlConnection() const { return _connection; } - QString sqlConnectionName() + QString sqlConnectionName() const { return _connectionName; } @@ -103,10 +105,10 @@ typedef IceUtil::Handle<DatabaseConnection> DatabaseConnectionPtr; // -// Cache per thread of database information +// Connection pool // -class DatabaseCache : public IceUtil::Mutex, virtual public IceDB::DatabaseCache +class ConnectionPool : public virtual IceDB::ConnectionPool { public: @@ -117,9 +119,9 @@ public: protected: - DatabaseCache(const Ice::CommunicatorPtr&, const std::string&, const std::string&, const std::string&, int, + ConnectionPool(const Ice::CommunicatorPtr&, const std::string&, const std::string&, const std::string&, int, const std::string&, const std::string&, bool, const Ice::EncodingVersion&); - virtual ~DatabaseCache(); + virtual ~ConnectionPool(); typedef std::map<IceUtil::ThreadControl::ID, DatabaseConnectionPtr> ThreadDatabaseMap; @@ -130,28 +132,30 @@ private: IceUtilInternal::FileLockPtr _fileLock; const Ice::EncodingVersion _encoding; + IceUtil::Mutex _mutex; }; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; -class ThreadHook : public Ice::ThreadNotification, public IceUtil::Mutex +class ThreadHook : public Ice::ThreadNotification { public: ThreadHook(); - void setDatabaseCache(const DatabaseCachePtr&); + void setConnectionPool(const ConnectionPoolPtr&); virtual void start(); virtual void stop(); private: - DatabaseCachePtr _cache; + ConnectionPoolPtr _cache; + IceUtil::Mutex _mutex; }; typedef IceUtil::Handle<ThreadHook> ThreadHookPtr; -template<class Table, class Key, class Value> class Wrapper : virtual public IceDB::Wrapper<Key, Value> +template<class Table, class Key, class Value> class Wrapper : public virtual IceDB::Wrapper<Key, Value> { typedef IceUtil::Handle<Table> TablePtr; diff --git a/cpp/src/IceGrid/DB.h b/cpp/src/IceGrid/DB.h index eb9607b33f4..2fa0daf11b6 100644 --- a/cpp/src/IceGrid/DB.h +++ b/cpp/src/IceGrid/DB.h @@ -37,7 +37,7 @@ public: }; typedef IceUtil::Handle<ObjectsWrapper> ObjectsWrapperPtr; -class DatabaseCache : virtual public IceDB::DatabaseCache +class ConnectionPool : public virtual IceDB::ConnectionPool { public: @@ -46,13 +46,13 @@ public: virtual ObjectsWrapperPtr getObjects(const IceDB::DatabaseConnectionPtr&) = 0; virtual ObjectsWrapperPtr getInternalObjects(const IceDB::DatabaseConnectionPtr&) = 0; }; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; class DatabasePlugin : virtual public Ice::Plugin { public: - virtual DatabaseCachePtr getDatabaseCache() = 0; + virtual ConnectionPoolPtr getConnectionPool() = 0; }; typedef IceUtil::Handle<DatabasePlugin> DatabasePluginPtr; diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index 0d8fb7888dd..7604f5cd353 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -76,15 +76,15 @@ Database::Database(const Ice::ObjectAdapterPtr& registryAdapter, _objectCache(_communicator), _allocatableObjectCache(_communicator), _serverCache(_communicator, _instanceName, _nodeCache, _adapterCache, _objectCache, _allocatableObjectCache), - _databaseCache(plugin->getDatabaseCache()), + _connectionPool(plugin->getConnectionPool()), _databasePlugin(plugin), _lock(0), _applicationSerial(0) { ServerEntrySeq entries; - DatabaseConnectionPtr connection = _databaseCache->getConnection(); - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); map<string, ApplicationInfo> applications = applicationsWrapper->getMap(); for(map<string, ApplicationInfo>::iterator p = applications.begin(); p != applications.end(); ++p) { @@ -110,10 +110,10 @@ Database::Database(const Ice::ObjectAdapterPtr& registryAdapter, _registryObserverTopic = new RegistryObserverTopic(_topicManager); _applicationObserverTopic = new ApplicationObserverTopic(_topicManager, applications); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); _adapterObserverTopic = new AdapterObserverTopic(_topicManager, adaptersWrapper->getMap()); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); _objectObserverTopic = new ObjectObserverTopic(_topicManager, objectsWrapper->getMap()); _registryObserverTopic->registryUp(info); @@ -125,7 +125,7 @@ Database::~Database() // Release first the cache and then the plugin. This must be done in this order // to make sure the plugin is destroyed after the database cache. // - _databaseCache = 0; + _connectionPool = 0; _databasePlugin = 0; } @@ -215,11 +215,11 @@ Database::syncApplications(const ApplicationInfoSeq& newApplications) map<string, ApplicationInfo> oldApplications; for(;;) { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); try { TransactionHolder txHolder(connection); - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); oldApplications = applicationsWrapper->getMap(); applicationsWrapper->clear(); for(ApplicationInfoSeq::const_iterator p = newApplications.begin(); p != newApplications.end(); ++p) @@ -288,11 +288,11 @@ Database::syncAdapters(const AdapterInfoSeq& adapters) Lock sync(*this); for(;;) { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); try { TransactionHolder txHolder(connection); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); adaptersWrapper->clear(); for(AdapterInfoSeq::const_iterator r = adapters.begin(); r != adapters.end(); ++r) { @@ -323,11 +323,11 @@ Database::syncObjects(const ObjectInfoSeq& objects) Lock sync(*this); for(;;) { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); try { TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); objectsWrapper->clear(); for(ObjectInfoSeq::const_iterator q = objects.begin(); q != objects.end(); ++q) { @@ -361,10 +361,10 @@ Database::addApplication(const ApplicationInfo& info, AdminSessionI* session) waitForUpdate(info.descriptor.name); - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); try { - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); applicationsWrapper->find(info.descriptor.name); throw DeploymentException("application `" + info.descriptor.name + "' already exists"); } @@ -407,7 +407,7 @@ Database::addApplication(const ApplicationInfo& info, AdminSessionI* session) Lock sync(*this); entries.clear(); unload(ApplicationHelper(_communicator, info.descriptor), entries); - removeApplication(info.descriptor.name, _databaseCache->getConnection()); + removeApplication(info.descriptor.name, _connectionPool->getConnection()); } catch(const DeploymentException& ex) { @@ -455,8 +455,8 @@ Database::updateApplication(const ApplicationUpdateInfo& updt, bool noRestart, A waitForUpdate(update.descriptor.name); - DatabaseConnectionPtr connection = _databaseCache->getConnection(); - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); try { oldApp = applicationsWrapper->find(update.descriptor.name); @@ -498,8 +498,8 @@ Database::syncApplicationDescriptor(const ApplicationDescriptor& newDesc, bool n waitForUpdate(newDesc.name); - DatabaseConnectionPtr connection = _databaseCache->getConnection(); - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); try { oldApp = applicationsWrapper->find(newDesc.name); @@ -545,8 +545,8 @@ Database::instantiateServer(const string& application, waitForUpdate(application); - DatabaseConnectionPtr connection = _databaseCache->getConnection(); - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); try { oldApp = applicationsWrapper->find(application); @@ -587,11 +587,11 @@ Database::removeApplication(const string& name, AdminSessionI* session) waitForUpdate(name); - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); ApplicationInfo appInfo; try { - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); appInfo = applicationsWrapper->find(name); } catch(const NotFoundException&) @@ -656,10 +656,10 @@ Database::removeApplication(const string& name, AdminSessionI* session) ApplicationInfo Database::getApplicationInfo(const std::string& name) { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); try { - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); return applicationsWrapper->find(name); } catch(const NotFoundException&) @@ -671,8 +671,8 @@ Database::getApplicationInfo(const std::string& name) Ice::StringSeq Database::getAllApplications(const string& expression) { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); return getMatchingKeys<map<string, ApplicationInfo> >(applicationsWrapper->getMap(), expression); } @@ -763,9 +763,9 @@ Database::setAdapterDirectProxy(const string& adapterId, const string& replicaGr { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); try { adaptersWrapper->find(adapterId); @@ -828,8 +828,8 @@ Database::setAdapterDirectProxy(const string& adapterId, const string& replicaGr Ice::ObjectPrx Database::getAdapterDirectProxy(const string& id) { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); try { return adaptersWrapper->find(id).proxy; @@ -873,9 +873,9 @@ Database::removeAdapter(const string& adapterId) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); try { adaptersWrapper->find(adapterId); @@ -976,8 +976,8 @@ Database::getAdapterInfo(const string& id) // Otherwise, we check the adapter endpoint table -- if there's an // entry the adapter is managed by the registry itself. // - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); AdapterInfoSeq infos; try { @@ -1007,8 +1007,8 @@ Database::getAllAdapters(const string& expression) result.swap(ids); set<string> groups; - DatabaseConnectionPtr connection = _databaseCache->getConnection(); - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); map<string, AdapterInfo> adapters = adaptersWrapper->getMap(); for(map<string, AdapterInfo>::const_iterator p = adapters.begin(); p != adapters.end(); ++p) { @@ -1050,9 +1050,9 @@ Database::addObject(const ObjectInfo& info) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); try { objectsWrapper->find(id); @@ -1104,9 +1104,9 @@ Database::addOrUpdateObject(const ObjectInfo& info) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); try { objectsWrapper->find(id); @@ -1167,9 +1167,9 @@ Database::removeObject(const Ice::Identity& id) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); try { objectsWrapper->find(id); @@ -1229,9 +1229,9 @@ Database::updateObject(const Ice::ObjectPrx& proxy) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); try { info = objectsWrapper->find(id); @@ -1278,9 +1278,9 @@ Database::addOrUpdateObjectsInDatabase(const ObjectInfoSeq& objects) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { objectsWrapper->put(p->proxy->ice_getIdentity(), *p); @@ -1310,9 +1310,9 @@ Database::removeObjectsInDatabase(const ObjectInfoSeq& objects) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { objectsWrapper->erase(p->proxy->ice_getIdentity()); @@ -1346,10 +1346,10 @@ Database::getObjectProxy(const Ice::Identity& id) { } - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); try { - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); return objectsWrapper->find(id).proxy; } catch(const NotFoundException&) @@ -1408,8 +1408,8 @@ Database::getObjectsByType(const string& type) { Ice::ObjectProxySeq proxies = _objectCache.getObjectsByType(type); - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); vector<ObjectInfo> infos = objectsWrapper->findByType(type); for(unsigned int i = 0; i < infos.size(); ++i) { @@ -1430,8 +1430,8 @@ Database::getObjectInfo(const Ice::Identity& id) { } - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); try { return objectsWrapper->find(id); @@ -1447,8 +1447,8 @@ Database::getAllObjectInfos(const string& expression) { ObjectInfoSeq infos = _objectCache.getAll(expression); - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); map<Ice::Identity, ObjectInfo> objects = objectsWrapper->getMap(); for(map<Ice::Identity, ObjectInfo>::const_iterator p = objects.begin(); p != objects.end(); ++p) { @@ -1465,8 +1465,8 @@ Database::getObjectInfosByType(const string& type) { ObjectInfoSeq infos = _objectCache.getAllByType(type); - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); ObjectInfoSeq dbInfos = objectsWrapper->findByType(type); for(unsigned int i = 0; i < dbInfos.size(); ++i) { @@ -1485,9 +1485,9 @@ Database::addInternalObject(const ObjectInfo& info, bool replace) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr internalObjectsWrapper = _databaseCache->getInternalObjects(connection); + ObjectsWrapperPtr internalObjectsWrapper = _connectionPool->getInternalObjects(connection); if(!replace) { try @@ -1523,9 +1523,9 @@ Database::removeInternalObject(const Ice::Identity& id) { try { - DatabaseConnectionPtr connection = _databaseCache->getConnection(); + DatabaseConnectionPtr connection = _connectionPool->getConnection(); TransactionHolder txHolder(connection); - ObjectsWrapperPtr internalObjectsWrapper = _databaseCache->getInternalObjects(connection); + ObjectsWrapperPtr internalObjectsWrapper = _connectionPool->getInternalObjects(connection); try { internalObjectsWrapper->find(id); @@ -1556,8 +1556,8 @@ Database::getInternalObjectsByType(const string& type) { Ice::ObjectProxySeq proxies; - DatabaseConnectionPtr connection = _databaseCache->newConnection(); - ObjectsWrapperPtr internalObjectsWrapper = _databaseCache->getInternalObjects(connection); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); + ObjectsWrapperPtr internalObjectsWrapper = _connectionPool->getInternalObjects(connection); vector<ObjectInfo> infos = internalObjectsWrapper->findByType(type); for(unsigned int i = 0; i < infos.size(); ++i) { @@ -1578,7 +1578,7 @@ Database::checkForAddition(const ApplicationHelper& app, const DatabaseConnectio for_each(serverIds.begin(), serverIds.end(), objFunc(*this, &Database::checkServerForAddition)); if(!adapterIds.empty()) { - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); for(set<string>::const_iterator p = adapterIds.begin(); p != adapterIds.end(); ++p) { checkAdapterForAddition(*p, adaptersWrapper); @@ -1586,7 +1586,7 @@ Database::checkForAddition(const ApplicationHelper& app, const DatabaseConnectio } if(!objectIds.empty()) { - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); for(set<Ice::Identity>::const_iterator p = objectIds.begin(); p != objectIds.end(); ++p) { checkObjectForAddition(*p, objectsWrapper); @@ -1619,7 +1619,7 @@ Database::checkForUpdate(const ApplicationHelper& origApp, set_difference(newAdpts.begin(), newAdpts.end(), oldAdpts.begin(), oldAdpts.end(), back_inserter(addedAdpts)); if(!addedAdpts.empty()) { - AdaptersWrapperPtr adaptersWrapper = _databaseCache->getAdapters(connection); + AdaptersWrapperPtr adaptersWrapper = _connectionPool->getAdapters(connection); for(Ice::StringSeq::const_iterator p = addedAdpts.begin(); p != addedAdpts.end(); ++p) { checkAdapterForAddition(*p, adaptersWrapper); @@ -1630,7 +1630,7 @@ Database::checkForUpdate(const ApplicationHelper& origApp, set_difference(newObjs.begin(), newObjs.end(), oldObjs.begin(), oldObjs.end(), back_inserter(addedObjs)); if(!addedObjs.empty()) { - ObjectsWrapperPtr objectsWrapper = _databaseCache->getObjects(connection); + ObjectsWrapperPtr objectsWrapper = _connectionPool->getObjects(connection); for(vector<Ice::Identity>::const_iterator p = addedObjs.begin(); p != addedObjs.end(); ++p) { checkObjectForAddition(*p, objectsWrapper); @@ -1982,7 +1982,7 @@ Database::saveApplication(const ApplicationInfo& info, const DatabaseConnectionP { try { - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); TransactionHolder txHolder(connection); applicationsWrapper->put(info.descriptor.name, info); txHolder.commit(); @@ -2006,7 +2006,7 @@ Database::removeApplication(const string& name, const DatabaseConnectionPtr& con { try { - ApplicationsWrapperPtr applicationsWrapper = _databaseCache->getApplications(connection); + ApplicationsWrapperPtr applicationsWrapper = _connectionPool->getApplications(connection); TransactionHolder txHolder(connection); applicationsWrapper->erase(name); txHolder.commit(); diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h index e3bae73ab67..a3a8acd5656 100644 --- a/cpp/src/IceGrid/Database.h +++ b/cpp/src/IceGrid/Database.h @@ -185,7 +185,7 @@ private: AdapterObserverTopicPtr _adapterObserverTopic; ObjectObserverTopicPtr _objectObserverTopic; - DatabaseCachePtr _databaseCache; + ConnectionPoolPtr _connectionPool; DatabasePluginPtr _databasePlugin; AdminSessionI* _lock; diff --git a/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp b/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp index 9b19db4927e..72f3f3560fe 100644 --- a/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp +++ b/cpp/src/IceGrid/FreezeDB/FreezeDB.cpp @@ -93,13 +93,13 @@ public: } -FreezeDatabaseCache::FreezeDatabaseCache(const Ice::CommunicatorPtr& communicator) : - FreezeDB::DatabaseCache(communicator, "Registry") +FreezeConnectionPool::FreezeConnectionPool(const Ice::CommunicatorPtr& communicator) : + FreezeDB::ConnectionPool(communicator, "Registry") { } ApplicationsWrapperPtr -FreezeDatabaseCache::getApplications(const IceDB::DatabaseConnectionPtr& connection) +FreezeConnectionPool::getApplications(const IceDB::DatabaseConnectionPtr& connection) { FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); // COMPILERFIX: GCC 4.4 w/ -O2 emits strict aliasing warnings @@ -109,21 +109,21 @@ FreezeDatabaseCache::getApplications(const IceDB::DatabaseConnectionPtr& connect } AdaptersWrapperPtr -FreezeDatabaseCache::getAdapters(const IceDB::DatabaseConnectionPtr& connection) +FreezeConnectionPool::getAdapters(const IceDB::DatabaseConnectionPtr& connection) { FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); return new FreezeAdaptersWrapper(c->freezeConnection(), "adapters"); } ObjectsWrapperPtr -FreezeDatabaseCache::getObjects(const IceDB::DatabaseConnectionPtr& connection) +FreezeConnectionPool::getObjects(const IceDB::DatabaseConnectionPtr& connection) { FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); return new FreezeObjectsWrapper(c->freezeConnection(), "objects"); } ObjectsWrapperPtr -FreezeDatabaseCache::getInternalObjects(const IceDB::DatabaseConnectionPtr& connection) +FreezeConnectionPool::getInternalObjects(const IceDB::DatabaseConnectionPtr& connection) { FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); return new FreezeObjectsWrapper(c->freezeConnection(), "internal-objects"); @@ -154,17 +154,17 @@ FreezeDBPlugin::FreezeDBPlugin(const Ice::CommunicatorPtr& communicator) : _comm void FreezeDBPlugin::initialize() { - _databaseCache = new FreezeDatabaseCache(_communicator); + _connectionPool = new FreezeConnectionPool(_communicator); } void FreezeDBPlugin::destroy() { - _databaseCache = 0; + _connectionPool = 0; } -DatabaseCachePtr -FreezeDBPlugin::getDatabaseCache() +ConnectionPoolPtr +FreezeDBPlugin::getConnectionPool() { - return _databaseCache; + return _connectionPool; } diff --git a/cpp/src/IceGrid/FreezeDB/FreezeDB.h b/cpp/src/IceGrid/FreezeDB/FreezeDB.h index 47bcbb9fc22..6604c5ece55 100644 --- a/cpp/src/IceGrid/FreezeDB/FreezeDB.h +++ b/cpp/src/IceGrid/FreezeDB/FreezeDB.h @@ -16,18 +16,18 @@ namespace IceGrid { -class FreezeDatabaseCache : public FreezeDB::DatabaseCache, public DatabaseCache +class FreezeConnectionPool : public FreezeDB::ConnectionPool, public ConnectionPool { public: - FreezeDatabaseCache(const Ice::CommunicatorPtr&); + FreezeConnectionPool(const Ice::CommunicatorPtr&); virtual ApplicationsWrapperPtr getApplications(const IceDB::DatabaseConnectionPtr&); virtual AdaptersWrapperPtr getAdapters(const IceDB::DatabaseConnectionPtr&); virtual ObjectsWrapperPtr getObjects(const IceDB::DatabaseConnectionPtr&); virtual ObjectsWrapperPtr getInternalObjects(const IceDB::DatabaseConnectionPtr&); }; -typedef IceUtil::Handle<FreezeDatabaseCache> FreezeDatabaseCachePtr; +typedef IceUtil::Handle<FreezeConnectionPool> FreezeConnectionPoolPtr; class FreezeDBPlugin : public DatabasePlugin { @@ -38,12 +38,12 @@ public: void initialize(); void destroy(); - DatabaseCachePtr getDatabaseCache(); + ConnectionPoolPtr getConnectionPool(); private: const Ice::CommunicatorPtr _communicator; - FreezeDatabaseCachePtr _databaseCache; + FreezeConnectionPoolPtr _connectionPool; }; } diff --git a/cpp/src/IceGrid/SqlDB/SqlDB.cpp b/cpp/src/IceGrid/SqlDB/SqlDB.cpp index ac84041e365..06c2ea9a258 100644 --- a/cpp/src/IceGrid/SqlDB/SqlDB.cpp +++ b/cpp/src/IceGrid/SqlDB/SqlDB.cpp @@ -87,17 +87,17 @@ public: } -SqlDatabaseCache::SqlDatabaseCache(const Ice::CommunicatorPtr& communicator, - const string& databaseType, - const string& databaseName, - const string& hostname, - int port, - const string& username, - const string& password, - const string& tablePrefix, - const string& encoding) : - SqlDB::DatabaseCache(communicator, databaseType, databaseName, hostname, port, username, password, true, - Ice::stringToEncodingVersion(encoding)) +SqlConnectionPool::SqlConnectionPool(const Ice::CommunicatorPtr& communicator, + const string& databaseType, + const string& databaseName, + const string& hostname, + int port, + const string& username, + const string& password, + const string& tablePrefix, + const string& encoding) : + SqlDB::ConnectionPool(communicator, databaseType, databaseName, hostname, port, username, password, true, + Ice::stringToEncodingVersion(encoding)) { IceDB::DatabaseConnectionPtr connection = getConnection(); IceDB::TransactionHolder txn(connection); @@ -116,30 +116,30 @@ SqlDatabaseCache::SqlDatabaseCache(const Ice::CommunicatorPtr& communicator, txn.commit(); } -SqlDatabaseCache::~SqlDatabaseCache() +SqlConnectionPool::~SqlConnectionPool() { } ApplicationsWrapperPtr -SqlDatabaseCache::getApplications(const IceDB::DatabaseConnectionPtr& connection) +SqlConnectionPool::getApplications(const IceDB::DatabaseConnectionPtr& connection) { return new SqlApplicationsWrapper(SqlDB::DatabaseConnectionPtr::dynamicCast(connection.get()), _applications); } AdaptersWrapperPtr -SqlDatabaseCache::getAdapters(const IceDB::DatabaseConnectionPtr& connection) +SqlConnectionPool::getAdapters(const IceDB::DatabaseConnectionPtr& connection) { return new SqlAdaptersWrapper(SqlDB::DatabaseConnectionPtr::dynamicCast(connection.get()), _adapters); } ObjectsWrapperPtr -SqlDatabaseCache::getObjects(const IceDB::DatabaseConnectionPtr& connection) +SqlConnectionPool::getObjects(const IceDB::DatabaseConnectionPtr& connection) { return new SqlObjectsWrapper(SqlDB::DatabaseConnectionPtr::dynamicCast(connection.get()), _objects); } ObjectsWrapperPtr -SqlDatabaseCache::getInternalObjects(const IceDB::DatabaseConnectionPtr& connection) +SqlConnectionPool::getInternalObjects(const IceDB::DatabaseConnectionPtr& connection) { return new SqlObjectsWrapper(SqlDB::DatabaseConnectionPtr::dynamicCast(connection.get()), _internalObjects); } @@ -214,20 +214,25 @@ SqlDBPlugin::initialize() replace(tablePrefix.begin(), tablePrefix.end(), ';', '_'); } - _databaseCache = new SqlDatabaseCache(_communicator, - properties->getProperty("IceGrid.SQL.DatabaseType"), - databaseName, - properties->getProperty("IceGrid.SQL.HostName"), - properties->getPropertyAsInt("IceGrid.SQL.Port"), - properties->getProperty("IceGrid.SQL.UserName"), - properties->getProperty("IceGrid.SQL.Password"), - tablePrefix, - properties->getProperty("IceGrid.SQL.EncodingVersion")); + string encodingVersionString = + properties->getPropertyWithDefault("IceGrid.SQL.EncodingVersion", + encodingVersionToString(Ice::currentEncoding)); + + + _connectionPool = new SqlConnectionPool(_communicator, + properties->getProperty("IceGrid.SQL.DatabaseType"), + databaseName, + properties->getProperty("IceGrid.SQL.HostName"), + properties->getPropertyAsInt("IceGrid.SQL.Port"), + properties->getProperty("IceGrid.SQL.UserName"), + properties->getProperty("IceGrid.SQL.Password"), + tablePrefix, + encodingVersionString); SqlDB::ThreadHookPtr threadHook = SqlDB::ThreadHookPtr::dynamicCast(IceInternal::getInstance(_communicator)->initializationData().threadHook); assert(threadHook); - threadHook->setDatabaseCache(_databaseCache); + threadHook->setConnectionPool(_connectionPool); } void @@ -240,13 +245,13 @@ SqlDBPlugin::destroy() SqlDB::ThreadHookPtr threadHook = SqlDB::ThreadHookPtr::dynamicCast(IceInternal::getInstance(_communicator)->initializationData().threadHook); assert(threadHook); - threadHook->setDatabaseCache(0); + threadHook->setConnectionPool(0); - _databaseCache = 0; + _connectionPool = 0; } -DatabaseCachePtr -SqlDBPlugin::getDatabaseCache() +ConnectionPoolPtr +SqlDBPlugin::getConnectionPool() { - return _databaseCache; + return _connectionPool; } diff --git a/cpp/src/IceGrid/SqlDB/SqlDB.h b/cpp/src/IceGrid/SqlDB/SqlDB.h index ff3b5ba5110..9f3f3d11767 100644 --- a/cpp/src/IceGrid/SqlDB/SqlDB.h +++ b/cpp/src/IceGrid/SqlDB/SqlDB.h @@ -20,14 +20,14 @@ namespace IceGrid { -class SqlDatabaseCache : public SqlDB::DatabaseCache, public DatabaseCache +class SqlConnectionPool : public SqlDB::ConnectionPool, public ConnectionPool { public: - SqlDatabaseCache(const Ice::CommunicatorPtr&, const std::string&, const std::string&, - const std::string&, int, const std::string&, const std::string&, const std::string&, - const std::string&); - virtual ~SqlDatabaseCache(); + SqlConnectionPool(const Ice::CommunicatorPtr&, const std::string&, const std::string&, + const std::string&, int, const std::string&, const std::string&, const std::string&, + const std::string&); + virtual ~SqlConnectionPool(); virtual ApplicationsWrapperPtr getApplications(const IceDB::DatabaseConnectionPtr&); virtual AdaptersWrapperPtr getAdapters(const IceDB::DatabaseConnectionPtr&); @@ -41,7 +41,7 @@ private: const SqlIdentityObjectInfoDictPtr _objects; const SqlIdentityObjectInfoDictPtr _internalObjects; }; -typedef IceUtil::Handle<SqlDatabaseCache> SqlDatabaseCachePtr; +typedef IceUtil::Handle<SqlConnectionPool> SqlConnectionPoolPtr; class SqlDBPlugin : public DatabasePlugin { @@ -53,12 +53,12 @@ public: virtual void initialize(); virtual void destroy(); - DatabaseCachePtr getDatabaseCache(); + ConnectionPoolPtr getConnectionPool(); private: const Ice::CommunicatorPtr _communicator; - SqlDatabaseCachePtr _databaseCache; + SqlConnectionPoolPtr _connectionPool; QCoreApplication* _qtApp; }; diff --git a/cpp/src/IceStorm/DB.h b/cpp/src/IceStorm/DB.h index 78b5b605280..87501b61f0d 100644 --- a/cpp/src/IceStorm/DB.h +++ b/cpp/src/IceStorm/DB.h @@ -21,7 +21,7 @@ namespace IceStorm class Instance; typedef IceUtil::Handle<Instance> InstancePtr; -class LLUWrapper : public virtual IceUtil::Shared +class LLUWrapper : public IceUtil::Shared { public: @@ -38,20 +38,20 @@ public: }; typedef IceUtil::Handle<SubscribersWrapper> SubscribersWrapperPtr; -class DatabaseCache : virtual public IceDB::DatabaseCache +class ConnectionPool : public virtual IceDB::ConnectionPool { public: virtual LLUWrapperPtr getLLU(const IceDB::DatabaseConnectionPtr&) = 0; virtual SubscribersWrapperPtr getSubscribers(const IceDB::DatabaseConnectionPtr&) = 0; }; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; -class DatabasePlugin : virtual public Ice::Plugin +class DatabasePlugin : public Ice::Plugin { public: - virtual DatabaseCachePtr getDatabaseCache(const std::string&) = 0; + virtual ConnectionPoolPtr getConnectionPool(const std::string&) = 0; }; typedef IceUtil::Handle<DatabasePlugin> DatabasePluginPtr; diff --git a/cpp/src/IceStorm/FreezeDB/FreezeDB.cpp b/cpp/src/IceStorm/FreezeDB/FreezeDB.cpp index 6c3555de427..e132a078f2a 100644 --- a/cpp/src/IceStorm/FreezeDB/FreezeDB.cpp +++ b/cpp/src/IceStorm/FreezeDB/FreezeDB.cpp @@ -119,20 +119,20 @@ public: } -FreezeDatabaseCache::FreezeDatabaseCache(const Ice::CommunicatorPtr& communicator, const string& envName) : - FreezeDB::DatabaseCache(communicator, envName) +FreezeConnectionPool::FreezeConnectionPool(const Ice::CommunicatorPtr& communicator, const string& envName) : + FreezeDB::ConnectionPool(communicator, envName) { } LLUWrapperPtr -FreezeDatabaseCache::getLLU(const IceDB::DatabaseConnectionPtr& connection) +FreezeConnectionPool::getLLU(const IceDB::DatabaseConnectionPtr& connection) { FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); return new FreezeLLUWrapper(c->freezeConnection(), "llu"); } SubscribersWrapperPtr -FreezeDatabaseCache::getSubscribers(const IceDB::DatabaseConnectionPtr& connection) +FreezeConnectionPool::getSubscribers(const IceDB::DatabaseConnectionPtr& connection) { FreezeDB::DatabaseConnection* c = dynamic_cast<FreezeDB::DatabaseConnection*>(connection.get()); // COMPILERFIX: GCC 4.4 w/ -O2 emits strict aliasing warnings @@ -155,8 +155,8 @@ FreezeDBPlugin::destroy() { } -DatabaseCachePtr -FreezeDBPlugin::getDatabaseCache(const string& name) +ConnectionPoolPtr +FreezeDBPlugin::getConnectionPool(const string& name) { - return new FreezeDatabaseCache(_communicator, name); + return new FreezeConnectionPool(_communicator, name); } diff --git a/cpp/src/IceStorm/FreezeDB/FreezeDB.h b/cpp/src/IceStorm/FreezeDB/FreezeDB.h index 17744ec5e1b..d52d5e7f8c8 100644 --- a/cpp/src/IceStorm/FreezeDB/FreezeDB.h +++ b/cpp/src/IceStorm/FreezeDB/FreezeDB.h @@ -16,16 +16,16 @@ namespace IceStorm { -class FreezeDatabaseCache : public FreezeDB::DatabaseCache, public DatabaseCache +class FreezeConnectionPool : public FreezeDB::ConnectionPool, public ConnectionPool { public: - FreezeDatabaseCache(const Ice::CommunicatorPtr&, const std::string&); + FreezeConnectionPool(const Ice::CommunicatorPtr&, const std::string&); virtual LLUWrapperPtr getLLU(const IceDB::DatabaseConnectionPtr&); virtual SubscribersWrapperPtr getSubscribers(const IceDB::DatabaseConnectionPtr&); }; -typedef IceUtil::Handle<FreezeDatabaseCache> FreezeDatabaseCachePtr; +typedef IceUtil::Handle<FreezeConnectionPool> FreezeConnectionPoolPtr; class FreezeDBPlugin : public DatabasePlugin { @@ -36,7 +36,7 @@ public: void initialize(); void destroy(); - DatabaseCachePtr getDatabaseCache(const std::string&); + ConnectionPoolPtr getConnectionPool(const std::string&); private: diff --git a/cpp/src/IceStorm/Instance.cpp b/cpp/src/IceStorm/Instance.cpp index add665c71f2..db9446b93cc 100644 --- a/cpp/src/IceStorm/Instance.cpp +++ b/cpp/src/IceStorm/Instance.cpp @@ -25,7 +25,7 @@ Instance::Instance( const string& instanceName, const string& name, const Ice::CommunicatorPtr& communicator, - const DatabaseCachePtr& databaseCache, + const ConnectionPoolPtr& connectionPool, const Ice::ObjectAdapterPtr& publishAdapter, const Ice::ObjectAdapterPtr& topicAdapter, const Ice::ObjectAdapterPtr& nodeAdapter, @@ -44,7 +44,7 @@ Instance::Instance( name + ".Flush.Timeout", 1000))), // default one second. // default one minute. _sendTimeout(communicator->getProperties()->getPropertyAsIntWithDefault(name + ".Send.Timeout", 60 * 1000)), - _databaseCache(databaseCache) + _connectionPool(connectionPool) { try { @@ -180,10 +180,10 @@ Instance::publisherReplicaProxy() const return _publisherReplicaProxy; } -DatabaseCachePtr -Instance::databaseCache() const +ConnectionPoolPtr +Instance::connectionPool() const { - return _databaseCache; + return _connectionPool; } IceUtil::Time diff --git a/cpp/src/IceStorm/Instance.h b/cpp/src/IceStorm/Instance.h index 0f6b0540258..71f9aa333eb 100644 --- a/cpp/src/IceStorm/Instance.h +++ b/cpp/src/IceStorm/Instance.h @@ -40,14 +40,14 @@ namespace IceStorm class TraceLevels; typedef IceUtil::Handle<TraceLevels> TraceLevelsPtr; -class DatabaseCache; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +class ConnectionPool; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; class Instance : public IceUtil::Shared { public: - Instance(const std::string&, const std::string&, const Ice::CommunicatorPtr&, const DatabaseCachePtr&, + Instance(const std::string&, const std::string&, const Ice::CommunicatorPtr&, const ConnectionPoolPtr&, const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr& = 0, const IceStormElection::NodePrx& = 0); ~Instance(); @@ -69,7 +69,7 @@ public: IceUtil::TimerPtr timer() const; Ice::ObjectPrx topicReplicaProxy() const; Ice::ObjectPrx publisherReplicaProxy() const; - DatabaseCachePtr databaseCache() const; + ConnectionPoolPtr connectionPool() const; IceUtil::Time discardInterval() const; IceUtil::Time flushInterval() const; @@ -93,7 +93,7 @@ private: const int _sendTimeout; const Ice::ObjectPrx _topicReplicaProxy; const Ice::ObjectPrx _publisherReplicaProxy; - const DatabaseCachePtr _databaseCache; + const ConnectionPoolPtr _connectionPool; IceStormElection::NodeIPtr _node; IceStormElection::ObserversPtr _observers; IceUtil::TimerPtr _batchFlusher; diff --git a/cpp/src/IceStorm/Service.cpp b/cpp/src/IceStorm/Service.cpp index 9bb02dc0b83..fa94c80619a 100644 --- a/cpp/src/IceStorm/Service.cpp +++ b/cpp/src/IceStorm/Service.cpp @@ -200,11 +200,11 @@ ServiceI::start( e.reason = s.str(); throw e; } - DatabaseCachePtr databaseCache = plugin->getDatabaseCache(name); + ConnectionPoolPtr connectionPool = plugin->getConnectionPool(name); if(id == -1) // No replication. { - _instance = new Instance(instanceName, name, communicator, databaseCache, publishAdapter, topicAdapter); + _instance = new Instance(instanceName, name, communicator, connectionPool, publishAdapter, topicAdapter); try { @@ -352,7 +352,7 @@ ServiceI::start( } Ice::ObjectAdapterPtr nodeAdapter = communicator->createObjectAdapter(name + ".Node"); - _instance = new Instance(instanceName, name, communicator, databaseCache, publishAdapter, topicAdapter, + _instance = new Instance(instanceName, name, communicator, connectionPool, publishAdapter, topicAdapter, nodeAdapter, nodes[id]); _instance->observers()->setMajority(static_cast<unsigned int>(nodes.size())/2); diff --git a/cpp/src/IceStorm/SqlDB/SqlDB.cpp b/cpp/src/IceStorm/SqlDB/SqlDB.cpp index 5b0486d61e4..9ed4bec7dbc 100644 --- a/cpp/src/IceStorm/SqlDB/SqlDB.cpp +++ b/cpp/src/IceStorm/SqlDB/SqlDB.cpp @@ -85,17 +85,17 @@ public: } -SqlDatabaseCache::SqlDatabaseCache(const Ice::CommunicatorPtr& communicator, - const string& databaseType, - const string& databaseName, - const string& hostname, - int port, - const string& username, - const string& password, - const string& tablePrefix, - const string& encoding) : - SqlDB::DatabaseCache(communicator, databaseType, databaseName, hostname, port, username, password, false, - Ice::stringToEncodingVersion(encoding)) +SqlConnectionPool::SqlConnectionPool(const Ice::CommunicatorPtr& communicator, + const string& databaseType, + const string& databaseName, + const string& hostname, + int port, + const string& username, + const string& password, + const string& tablePrefix, + const string& encoding) : + SqlDB::ConnectionPool(communicator, databaseType, databaseName, hostname, port, username, password, false, + Ice::stringToEncodingVersion(encoding)) { IceDB::DatabaseConnectionPtr connection = getConnection(); IceDB::TransactionHolder txn(connection); @@ -108,18 +108,18 @@ SqlDatabaseCache::SqlDatabaseCache(const Ice::CommunicatorPtr& communicator, txn.commit(); } -SqlDatabaseCache::~SqlDatabaseCache() +SqlConnectionPool::~SqlConnectionPool() { } LLUWrapperPtr -SqlDatabaseCache::getLLU(const IceDB::DatabaseConnectionPtr& connection) +SqlConnectionPool::getLLU(const IceDB::DatabaseConnectionPtr& connection) { return new SqlLLUWrapper(SqlDB::DatabaseConnectionPtr::dynamicCast(connection.get()), _llu); } SubscribersWrapperPtr -SqlDatabaseCache::getSubscribers(const IceDB::DatabaseConnectionPtr& connection) +SqlConnectionPool::getSubscribers(const IceDB::DatabaseConnectionPtr& connection) { return new SqlSubscribersWrapper(SqlDB::DatabaseConnectionPtr::dynamicCast(connection.get()), _subscribers); } @@ -161,12 +161,12 @@ SqlDBPlugin::destroy() SqlDB::ThreadHookPtr::dynamicCast(IceInternal::getInstance(_communicator)->initializationData().threadHook); if(threadHook) { - threadHook->setDatabaseCache(0); + threadHook->setConnectionPool(0); } } -DatabaseCachePtr -SqlDBPlugin::getDatabaseCache(const string& name) +ConnectionPoolPtr +SqlDBPlugin::getConnectionPool(const string& name) { Ice::PropertiesPtr properties = _communicator->getProperties(); @@ -184,19 +184,25 @@ SqlDBPlugin::getDatabaseCache(const string& name) } tablePrefix += "_"; - SqlDatabaseCachePtr databaseCache = new SqlDatabaseCache(_communicator, - properties->getProperty(name + ".SQL.DatabaseType"), - properties->getProperty(name + ".SQL.DatabaseName"), - properties->getProperty(name + ".SQL.HostName"), - properties->getPropertyAsInt(name + ".SQL.Port"), - properties->getProperty(name + ".SQL.UserName"), - properties->getProperty(name + ".SQL.Password"), - tablePrefix, - properties->getProperty(name + ".SQL.EncodingVersion")); + + string encodingVersionString = + properties->getPropertyWithDefault(name + ".SQL.EncodingVersion", + encodingVersionToString(Ice::currentEncoding)); + + + SqlConnectionPoolPtr connectionPool = new SqlConnectionPool(_communicator, + properties->getProperty(name + ".SQL.DatabaseType"), + properties->getProperty(name + ".SQL.DatabaseName"), + properties->getProperty(name + ".SQL.HostName"), + properties->getPropertyAsInt(name + ".SQL.Port"), + properties->getProperty(name + ".SQL.UserName"), + properties->getProperty(name + ".SQL.Password"), + tablePrefix, + encodingVersionString); SqlDB::ThreadHookPtr threadHook = SqlDB::ThreadHookPtr::dynamicCast(IceInternal::getInstance(_communicator)->initializationData().threadHook); assert(threadHook); - threadHook->setDatabaseCache(databaseCache); - return databaseCache; + threadHook->setConnectionPool(connectionPool); + return connectionPool; } diff --git a/cpp/src/IceStorm/SqlDB/SqlDB.h b/cpp/src/IceStorm/SqlDB/SqlDB.h index 0ea16233ec0..cf8cf750a84 100644 --- a/cpp/src/IceStorm/SqlDB/SqlDB.h +++ b/cpp/src/IceStorm/SqlDB/SqlDB.h @@ -19,14 +19,14 @@ namespace IceStorm { -class SqlDatabaseCache : public SqlDB::DatabaseCache, public DatabaseCache +class SqlConnectionPool : public SqlDB::ConnectionPool, public ConnectionPool { public: - SqlDatabaseCache(const Ice::CommunicatorPtr&, const std::string&, const std::string&, + SqlConnectionPool(const Ice::CommunicatorPtr&, const std::string&, const std::string&, const std::string&, int, const std::string&, const std::string&, const std::string&, const std::string&); - virtual ~SqlDatabaseCache(); + virtual ~SqlConnectionPool(); virtual LLUWrapperPtr getLLU(const IceDB::DatabaseConnectionPtr&); virtual SubscribersWrapperPtr getSubscribers(const IceDB::DatabaseConnectionPtr&); @@ -36,7 +36,7 @@ private: const SqlLLUPtr _llu; const SqlSubscriberMapPtr _subscribers; }; -typedef IceUtil::Handle<SqlDatabaseCache> SqlDatabaseCachePtr; +typedef IceUtil::Handle<SqlConnectionPool> SqlConnectionPoolPtr; class SqlDBPlugin : public DatabasePlugin { @@ -48,7 +48,7 @@ public: virtual void initialize(); virtual void destroy(); - DatabaseCachePtr getDatabaseCache(const std::string&); + ConnectionPoolPtr getConnectionPool(const std::string&); private: diff --git a/cpp/src/IceStorm/TopicI.cpp b/cpp/src/IceStorm/TopicI.cpp index a19ac8b7289..3c354627413 100644 --- a/cpp/src/IceStorm/TopicI.cpp +++ b/cpp/src/IceStorm/TopicI.cpp @@ -400,7 +400,7 @@ TopicImpl::TopicImpl( _instance(instance), _name(name), _id(id), - _databaseCache(instance->databaseCache()), + _connectionPool(instance->connectionPool()), _destroyed(false) { try @@ -640,17 +640,17 @@ TopicImpl::subscribe(const QoS& origQoS, const Ice::ObjectPrx& obj) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; key.topic = _id; key.id = record.id; - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->erase(key); - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); @@ -677,18 +677,18 @@ TopicImpl::subscribe(const QoS& origQoS, const Ice::ObjectPrx& obj) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; key.topic = _id; key.id = subscriber->id(); - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->put(key, record); // Update the LLU. - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); @@ -762,17 +762,17 @@ TopicImpl::subscribeAndGetPublisher(const QoS& qos, const Ice::ObjectPrx& obj) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; key.topic = _id; key.id = subscriber->id(); - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->put(key, record); - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); @@ -886,17 +886,17 @@ TopicImpl::link(const TopicPrx& topic, Ice::Int cost) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; key.topic = _id; key.id = id; - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->put(key, record); - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); @@ -1282,18 +1282,18 @@ TopicImpl::observerAddSubscriber(const LogUpdate& llu, const SubscriberRecord& r { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; key.topic = _id; key.id = subscriber->id(); - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->put(key, record); // Update the LLU. - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); lluWrapper->put(llu); txn.commit(); @@ -1351,7 +1351,7 @@ TopicImpl::observerRemoveSubscriber(const LogUpdate& llu, const Ice::IdentitySeq { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); for(Ice::IdentitySeq::const_iterator id = ids.begin(); id != ids.end(); ++id) @@ -1360,11 +1360,11 @@ TopicImpl::observerRemoveSubscriber(const LogUpdate& llu, const Ice::IdentitySeq key.topic = _id; key.id = *id; - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->erase(key); } - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); lluWrapper->put(llu); txn.commit(); @@ -1427,15 +1427,15 @@ TopicImpl::destroyInternal(const LogUpdate& origLLU, bool master) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); // Erase all subscriber records and the topic record. - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->eraseTopic(_id); // Update the LLU. - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); if(master) { llu = lluWrapper->get(); @@ -1502,7 +1502,7 @@ TopicImpl::removeSubscribers(const Ice::IdentitySeq& ids) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); for(Ice::IdentitySeq::const_iterator id = ids.begin(); id != ids.end(); ++id) @@ -1511,11 +1511,11 @@ TopicImpl::removeSubscribers(const Ice::IdentitySeq& ids) key.topic = _id; key.id = *id; - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->erase(key); } - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); diff --git a/cpp/src/IceStorm/TopicI.h b/cpp/src/IceStorm/TopicI.h index 11c4d4c6e2f..023665ffbae 100644 --- a/cpp/src/IceStorm/TopicI.h +++ b/cpp/src/IceStorm/TopicI.h @@ -23,8 +23,8 @@ typedef IceUtil::Handle<Instance> InstancePtr; class Subscriber; typedef IceUtil::Handle<Subscriber> SubscriberPtr; -class DatabaseCache; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +class ConnectionPool; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; class TopicImpl : public IceUtil::Shared { @@ -77,7 +77,7 @@ private: const std::string _name; // The topic name const Ice::Identity _id; // The topic identity const std::string _envName; - const DatabaseCachePtr _databaseCache; // The database cache. + const ConnectionPoolPtr _connectionPool; // The connection pool /*const*/ Ice::ObjectPrx _publisherPrx; // The actual publisher proxy. diff --git a/cpp/src/IceStorm/TopicManagerI.cpp b/cpp/src/IceStorm/TopicManagerI.cpp index 11d00224ff1..a1756deed63 100644 --- a/cpp/src/IceStorm/TopicManagerI.cpp +++ b/cpp/src/IceStorm/TopicManagerI.cpp @@ -290,7 +290,7 @@ nameToIdentity(const InstancePtr& instance, const string& name) TopicManagerImpl::TopicManagerImpl(const InstancePtr& instance) : _instance(instance), - _databaseCache(instance->databaseCache()) + _connectionPool(instance->connectionPool()) { try { @@ -312,15 +312,15 @@ TopicManagerImpl::TopicManagerImpl(const InstancePtr& instance) : _sync = _instance->nodeAdapter()->addWithUUID(_syncImpl); } - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); // Ensure that the llu counter is present in the log. - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); LogUpdate empty = {0, 0}; lluWrapper->put(empty); // Recreate each of the topics. - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); map<SubscriberRecordKey, SubscriberRecord> subscriberMap = subscribersWrapper->getMap(); map<SubscriberRecordKey, SubscriberRecord>::const_iterator p = subscriberMap.begin(); @@ -381,7 +381,7 @@ TopicManagerImpl::create(const string& name) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; @@ -390,10 +390,10 @@ TopicManagerImpl::create(const string& name) rec.link = false; rec.cost = 0; - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->put(key, rec); - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); @@ -486,13 +486,13 @@ TopicManagerImpl::observerInit(const LogUpdate& llu, const TopicContentSeq& cont { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); lluWrapper->put(llu); - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->clear(); for(TopicContentSeq::const_iterator p = content.begin(); p != content.end(); ++p) @@ -590,7 +590,7 @@ TopicManagerImpl::observerCreateTopic(const LogUpdate& llu, const string& name) { try { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; @@ -599,7 +599,7 @@ TopicManagerImpl::observerCreateTopic(const LogUpdate& llu, const string& name) rec.link = false; rec.cost = 0; - SubscribersWrapperPtr subscribersWrapper = _databaseCache->getSubscribers(connection); + SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); try { subscribersWrapper->find(key); @@ -610,7 +610,7 @@ TopicManagerImpl::observerCreateTopic(const LogUpdate& llu, const string& name) } subscribersWrapper->put(key, rec); - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); lluWrapper->put(llu); txn.commit(); @@ -687,7 +687,7 @@ TopicManagerImpl::getContent(LogUpdate& llu, TopicContentSeq& content) reap(); } - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); for(;;) { @@ -700,7 +700,7 @@ TopicManagerImpl::getContent(LogUpdate& llu, TopicContentSeq& content) content.push_back(rec); } - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); break; } @@ -718,13 +718,13 @@ TopicManagerImpl::getContent(LogUpdate& llu, TopicContentSeq& content) LogUpdate TopicManagerImpl::getLastLogUpdate() const { - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); for(;;) { try { - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); return lluWrapper->get(); } catch(const DeadlockException&) @@ -776,7 +776,7 @@ TopicManagerImpl::initMaster(const set<GroupNodeInfo>& slaves, const LogUpdate& { content.clear(); - DatabaseConnectionPtr connection = _databaseCache->newConnection(); + DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); for(map<string, TopicImplPtr>::const_iterator p = _topics.begin(); p != _topics.end(); ++p) @@ -785,7 +785,7 @@ TopicManagerImpl::initMaster(const set<GroupNodeInfo>& slaves, const LogUpdate& content.push_back(rec); } - LLUWrapperPtr lluWrapper = _databaseCache->getLLU(connection); + LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); lluWrapper->put(llu); txn.commit(); diff --git a/cpp/src/IceStorm/TopicManagerI.h b/cpp/src/IceStorm/TopicManagerI.h index 6c560fd3d0a..bb04b96a73f 100644 --- a/cpp/src/IceStorm/TopicManagerI.h +++ b/cpp/src/IceStorm/TopicManagerI.h @@ -25,8 +25,8 @@ namespace IceStorm class Instance; typedef IceUtil::Handle<Instance> InstancePtr; -class DatabaseCache; -typedef IceUtil::Handle<DatabaseCache> DatabaseCachePtr; +class ConnectionPool; +typedef IceUtil::Handle<ConnectionPool> ConnectionPoolPtr; class TopicImpl; typedef IceUtil::Handle<TopicImpl> TopicImplPtr; @@ -76,7 +76,7 @@ private: const IceStorm::SubscriberRecordSeq& = IceStorm::SubscriberRecordSeq()); const InstancePtr _instance; - const DatabaseCachePtr _databaseCache; + const ConnectionPoolPtr _connectionPool; std::map<std::string, TopicImplPtr> _topics; diff --git a/cpp/src/IceUtil/Exception.cpp b/cpp/src/IceUtil/Exception.cpp index 3d4a40a91fc..6b932274198 100644 --- a/cpp/src/IceUtil/Exception.cpp +++ b/cpp/src/IceUtil/Exception.cpp @@ -12,8 +12,10 @@ #include <IceUtil/Mutex.h> #include <IceUtil/StringUtil.h> #include <ostream> +#include <iomanip> #include <cstdlib> + #if defined(__GNUC__) && !defined(__sun) && !defined(__FreeBSD__) && !defined(__MINGW32__) # include <execinfo.h> # include <cxxabi.h> @@ -25,7 +27,6 @@ # include <IceUtil/Unicode.h> # define DBGHELP_TRANSLATE_TCHAR # include <DbgHelp.h> -# include <iomanip> # define ICE_STACK_TRACES # define ICE_WIN32_STACK_TRACES #endif @@ -64,11 +65,11 @@ public: delete globalMutex; globalMutex = 0; #ifdef ICE_WIN32_STACK_TRACES - if(process != 0) - { - SymCleanup(process); - process = 0; - } + if(process != 0) + { + SymCleanup(process); + process = 0; + } #endif } }; @@ -93,14 +94,14 @@ getStackTrace() IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(globalMutex); if(process == 0) { - process = GetCurrentProcess(); - SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME); - BOOL ok = SymInitialize(process, 0, TRUE); - if(!ok) - { - process = 0; - return "No stack trace: SymInitialize failed with " + IceUtilInternal::errorToString(GetLastError()); - } + process = GetCurrentProcess(); + SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME); + BOOL ok = SymInitialize(process, 0, TRUE); + if(!ok) + { + process = 0; + return "No stack trace: SymInitialize failed with " + IceUtilInternal::errorToString(GetLastError()); + } } lock.release(); @@ -115,46 +116,46 @@ getStackTrace() if(frames > 0) { - char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; - SYMBOL_INFO* symbol = reinterpret_cast<SYMBOL_INFO*>(buffer); - symbol->SizeOfStruct = sizeof(SYMBOL_INFO); - symbol->MaxNameLen = MAX_SYM_NAME; - - IMAGEHLP_LINE64 line = {}; - line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - DWORD displacement = 0; - - lock.acquire(); - for(int i = 0; i < frames; i++) - { - if(!stackTrace.empty()) - { - stackTrace += "\n"; - } - - stringstream s; - s << setw(3) << i << " "; - - DWORD64 address = reinterpret_cast<DWORD64>(stack[i]); - - BOOL ok = SymFromAddr(process, address, 0, symbol); - if(ok) - { - s << IceUtil::wstringToString(symbol->Name); - - ok = SymGetLineFromAddr64(process, address, &displacement, &line); - if(ok) - { - s << " at line " << line.LineNumber << " in " << IceUtil::wstringToString(line.FileName); - } - } - else - { - s << hex << "0x" << address; - } - stackTrace += s.str(); - } - lock.release(); + char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; + SYMBOL_INFO* symbol = reinterpret_cast<SYMBOL_INFO*>(buffer); + symbol->SizeOfStruct = sizeof(SYMBOL_INFO); + symbol->MaxNameLen = MAX_SYM_NAME; + + IMAGEHLP_LINE64 line = {}; + line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); + DWORD displacement = 0; + + lock.acquire(); + for(int i = 0; i < frames; i++) + { + if(!stackTrace.empty()) + { + stackTrace += "\n"; + } + + stringstream s; + s << setw(3) << i << " "; + + DWORD64 address = reinterpret_cast<DWORD64>(stack[i]); + + BOOL ok = SymFromAddr(process, address, 0, symbol); + if(ok) + { + s << IceUtil::wstringToString(symbol->Name); + + ok = SymGetLineFromAddr64(process, address, &displacement, &line); + if(ok) + { + s << " at line " << line.LineNumber << " in " << IceUtil::wstringToString(line.FileName); + } + } + else + { + s << hex << "0x" << address; + } + stackTrace += s.str(); + } + lock.release(); } # elif defined(ICE_GCC_STACK_TRACES) @@ -165,37 +166,27 @@ getStackTrace() size_t stackDepth = backtrace(stackAddrs, maxDepth); char **stackStrings = backtrace_symbols(stackAddrs, stackDepth); - bool checkException = true; + // + // Start at 1 to skip the top frame (== call to this function) + // for (size_t i = 1; i < stackDepth; i++) { string line(stackStrings[i]); - // - // Don't add the traces for the Exception constructors. - // - if(checkException) - { - if(line.find("ExceptionC") != string::npos) - { - continue; - } - else - { - checkException = false; - } - } - else + if(i > 1) { stackTrace += "\n"; } - stackTrace += " "; + stringstream s; + s << setw(3) << i - 1 << " "; // // For each line attempt to parse the mangled function name as well // as the source library/executable. // string mangled; + string source; string::size_type openParen = line.find_first_of('('); if(openParen != string::npos) { @@ -211,7 +202,7 @@ getStackTrace() { mangled = tmp.substr(0 , plus); - stackTrace += line.substr(0, openParen); + source = line.substr(0, openParen); } } } @@ -221,9 +212,9 @@ getStackTrace() // Format: "1 libIce.3.3.1.dylib 0x000933a1 _ZN7IceUtil9ExceptionC2EPKci + 71" // string::size_type plus = line.find_last_of('+'); - if(plus != string::npos) - { - string tmp = line.substr(0, plus - 1); + if(plus != string::npos) + { + string tmp = line.substr(0, plus - 1); string::size_type space = tmp.find_last_of(" \t"); if(space != string::npos) { @@ -237,16 +228,14 @@ getStackTrace() { mangled = tmp; - stackTrace += line.substr(start, finish - start); + source = line.substr(start, finish - start); } } } - } + } } if(mangled.size() != 0) { - stackTrace += ": "; - // // Unmangle the function name // @@ -254,19 +243,26 @@ getStackTrace() char* unmangled = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status); if(unmangled) { - stackTrace += unmangled; + s << unmangled; free(unmangled); } else { - stackTrace += mangled; - stackTrace += "()"; + s << mangled << "()"; + } + + if(!source.empty()) + { + s << " in " << source; } } else { - stackTrace += line; + s << line; } + + stackTrace += s.str(); + } free(stackStrings); diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index a4ae0905b3f..c14476148c2 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -48,7 +48,7 @@ sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typ string seqType = findMetaData(metaData, typeCtx); if(!seqType.empty()) { - if(seqType == "array" || seqType == "range:array") + if(seqType == "%array" || seqType == "%range:array") { BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); if(typeCtx & TypeContextAMIPrivateEnd) @@ -77,12 +77,12 @@ sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typ string s = typeToString(seq->type(), seq->typeMetaData(), inWstringModule(seq) ? TypeContextUseWstring : 0); return "::std::pair<const " + s + "*, const " + s + "*>"; } - else if(seqType.find("range") == 0) + else if(seqType.find("%range") == 0) { string s; - if(seqType.find("range:") == 0) + if(seqType.find("%range:") == 0) { - s = seqType.substr(strlen("range:")); + s = seqType.substr(strlen("%range:")); } else { @@ -151,16 +151,16 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st } string s; - if(seqType == "array" || seqType == "range:array") + if(seqType == "%array" || seqType == "%range:array") { s = typeToString(seq, metaData, TypeContextAMIPrivateEnd); } - else if(seqType.find("range") == 0) + else if(seqType.find("%range") == 0) { StringList md; - if(seqType.find("range:") == 0) + if(seqType.find("%range:") == 0) { - md.push_back("cpp:type:" + seqType.substr(strlen("range:"))); + md.push_back("cpp:type:" + seqType.substr(strlen("%range:"))); } s = typeToString(seq, md); } @@ -190,7 +190,7 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& } if(!protobuf) { - if(seqType == "array" || seqType == "range:array") + if(seqType == "%array" || seqType == "%range:array") { BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); if(builtin && @@ -234,7 +234,7 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& } } } - else if(seqType.find("range") == 0) + else if(seqType.find("%range") == 0) { if(optional) { @@ -449,7 +449,7 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx StructPtr st = StructPtr::dynamicCast(type); if(st) { - if(findMetaData(st->getMetaData()) == "class") + if(findMetaData(st->getMetaData()) == "%class") { return fixKwd(st->scoped() + "Ptr"); } @@ -567,7 +567,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m StructPtr st = StructPtr::dynamicCast(type); if(st) { - if(findMetaData(st->getMetaData()) == "class") + if(findMetaData(st->getMetaData()) == "%class") { return "const " + fixKwd(st->scoped() + "Ptr&"); } @@ -654,7 +654,7 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& StructPtr st = StructPtr::dynamicCast(type); if(st) { - if(findMetaData(st->getMetaData()) == "class") + if(findMetaData(st->getMetaData()) == "%class") { return fixKwd(st->scoped() + "Ptr&"); } @@ -867,7 +867,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional if(seq && !(typeCtx & TypeContextAMIPrivateEnd)) { string seqType = findMetaData(metaData, typeCtx); - if(seqType == "array" || seqType == "range:array") + if(seqType == "%array" || seqType == "%range:array") { BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); if(builtin && builtin->kind() == Builtin::KindByte) @@ -880,7 +880,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional writeParamEndCode(out, seq, optional, param, metaData); return; } - else if(seqType.find("range") == 0) + else if(seqType.find("%range") == 0) { out << nl << func << "___" << param << ");"; writeParamEndCode(out, seq, optional, param, metaData); @@ -932,7 +932,7 @@ Slice::getEndArg(const TypePtr& type, const StringList& metaData, const string& } if(!protobuf) { - if(seqType == "array" || seqType == "range:array") + if(seqType == "%array" || seqType == "%range:array") { BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); if(builtin && @@ -948,12 +948,12 @@ Slice::getEndArg(const TypePtr& type, const StringList& metaData, const string& endArg = "___" + endArg; } } - else if(seqType.find("range") == 0) + else if(seqType.find("%range") == 0) { StringList md; - if(seqType.find("range:") == 0) + if(seqType.find("%range:") == 0) { - md.push_back("cpp:type:" + seqType.substr(strlen("range:"))); + md.push_back("cpp:type:" + seqType.substr(strlen("%range:"))); } endArg = "___" + endArg; } @@ -1002,8 +1002,9 @@ Slice::findMetaData(const SequencePtr& seq, const StringList& metaData, bool& is // // If the form is cpp:type:<...> the data after cpp:type: - // is returned. If the form is cpp:range:<...> (and this - // is an inParam) the data after cpp: is returned. + // is returned. + // If the form is cpp:range[:<...>], cpp:array or cpp:class, + // the return value is % followed by the string after cpp:. // if(ss.find("protobuf") == 0 || pos != string::npos) { @@ -1028,11 +1029,11 @@ Slice::findMetaData(const SequencePtr& seq, const StringList& metaData, bool& is else if((typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd)) && !(typeCtx & TypeContextAMIEnd) && ss.find("range:") == 0) { - return str.substr(prefix.size()); + return string("%") + str.substr(prefix.size()); } else if((typeCtx & TypeContextAMIPrivateEnd) && ss == "range:array") { - return str.substr(prefix.size()); + return "%range:array"; } } // @@ -1043,11 +1044,11 @@ Slice::findMetaData(const SequencePtr& seq, const StringList& metaData, bool& is { if(ss == "array") { - return ss; + return "%array"; } else if((typeCtx & TypeContextInParam) && ss == "range") { - return ss; + return "%range"; } } // @@ -1057,7 +1058,7 @@ Slice::findMetaData(const SequencePtr& seq, const StringList& metaData, bool& is { if(ss == "class") { - return ss; + return "%class"; } } } @@ -1077,11 +1078,13 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) if(str.find(prefix) == 0) { string::size_type pos = str.find(':', prefix.size()); - // + + // // If the form is cpp:type:<...> the data after cpp:type: - // is returned. If the form is cpp:range:<...> the data - // after cpp: is returned. - // + // is returned. + // If the form is cpp:range[:<...>], cpp:array or cpp:class, + // the return value is % followed by the string after cpp:. + // if(pos != string::npos) { string ss = str.substr(prefix.size()); @@ -1092,11 +1095,11 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) else if((typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd)) && !(typeCtx & TypeContextAMIEnd) && ss.find("range:") == 0) { - return str.substr(prefix.size()); + return string("%") + str.substr(prefix.size()); } else if((typeCtx & TypeContextAMIPrivateEnd) && ss == "range:array") { - return str.substr(prefix.size()); + return "%range:array"; } } else if(typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd) && !(typeCtx & TypeContextAMIEnd)) @@ -1104,11 +1107,11 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) string ss = str.substr(prefix.size()); if(ss == "array") { - return ss; + return "%array"; } else if((typeCtx & TypeContextInParam) && ss == "range") { - return ss; + return "%range"; } } // @@ -1119,7 +1122,7 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) string ss = str.substr(prefix.size()); if(ss == "class") { - return ss; + return "%class"; } } } diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 482ee8a11b1..2de30fd49c1 100644 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -138,7 +138,7 @@ Slice::CsGenerator::fixId(const ContainedPtr& cont, int baseTypes, bool mangleCa ContainedPtr contained = ContainedPtr::dynamicCast(container); if(contained && contained->hasMetaData("clr:property")) { - return cont->name() + "_prop"; + return cont->name() + "__prop"; } else { @@ -147,13 +147,123 @@ Slice::CsGenerator::fixId(const ContainedPtr& cont, int baseTypes, bool mangleCa } string -Slice::CsGenerator::typeToString(const TypePtr& type) +Slice::CsGenerator::getOptionalType(const TypePtr& type) +{ + BuiltinPtr bp = BuiltinPtr::dynamicCast(type); + if(bp) + { + switch(bp->kind()) + { + case Builtin::KindByte: + case Builtin::KindBool: + { + return "Ice.OptionalType.F1"; + } + case Builtin::KindShort: + { + return "Ice.OptionalType.F2"; + } + case Builtin::KindInt: + case Builtin::KindFloat: + { + return "Ice.OptionalType.F4"; + } + case Builtin::KindLong: + case Builtin::KindDouble: + { + return "Ice.OptionalType.F8"; + } + case Builtin::KindString: + { + return "Ice.OptionalType.VSize"; + } + case Builtin::KindObject: + { + return "Ice.OptionalType.Size"; + } + case Builtin::KindObjectProxy: + { + return "Ice.OptionalType.FSize"; + } + case Builtin::KindLocalObject: + { + assert(false); + break; + } + } + } + + if(EnumPtr::dynamicCast(type)) + { + return "Ice.OptionalType.Size"; + } + + SequencePtr seq = SequencePtr::dynamicCast(type); + if(seq) + { + return seq->type()->isVariableLength() ? "Ice.OptionalType.FSize" : "Ice.OptionalType.VSize"; + } + + DictionaryPtr d = DictionaryPtr::dynamicCast(type); + if(d) + { + return (d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) ? + "Ice.OptionalType.FSize" : "Ice.OptionalType.VSize"; + } + + StructPtr st = StructPtr::dynamicCast(type); + if(st) + { + return st->isVariableLength() ? "Ice.OptionalType.FSize" : "Ice.OptionalType.VSize"; + } + + if(ProxyPtr::dynamicCast(type)) + { + return "Ice.OptionalType.FSize"; + } + + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); + assert(cl); + return "Ice.OptionalType.Size"; +} + +string +Slice::CsGenerator::getStaticId(const TypePtr& type) +{ + BuiltinPtr b = BuiltinPtr::dynamicCast(type); + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); + + assert((b && b->kind() == Builtin::KindObject) || cl); + + if(b) + { + return "Ice.ObjectImpl.ice_staticId()"; + } + else if(cl->isInterface()) + { + ContainedPtr cont = ContainedPtr::dynamicCast(cl->container()); + assert(cont); + return fixId(cont->scoped(), DotNet::ICloneable) + "." + cl->name() + "Disp_.ice_staticId()"; + } + else + { + return fixId(cl->scoped(), DotNet::ICloneable) + ".ice_staticId()"; + } +} + +string +Slice::CsGenerator::typeToString(const TypePtr& type, bool optional) { if(!type) { return "void"; } + if(optional) + { + return "Ice.Optional<" + typeToString(type, false) + ">"; + } + static const char* builtinTable[] = { "byte", @@ -298,10 +408,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, bool marshal, - bool streamingAPI, - bool isOutParam, - const string& patchParams, - bool newAMI) + bool streamingAPI) { string stream; @@ -423,26 +530,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - if(isOutParam) - { - out << nl << "IceInternal.ParamPatcher<Ice.Object> " << param - << "_PP = new IceInternal.ParamPatcher<Ice.Object>(\"::Ice::Object\");"; - out << nl << stream << ".readObject("; - if(streamingAPI) - { - out << "(Ice.ReadObjectCallback)"; - } - out << param << "_PP);"; - } - else - { - out << nl << stream << ".readObject("; - if(streamingAPI) - { - out << "(Ice.ReadObjectCallback)"; - } - out << "new Patcher__(\"::Ice::Object\", " << patchParams << "));"; - } + out << nl << stream << ".readObject(" << param << ");"; } break; } @@ -502,27 +590,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - if(isOutParam) - { - out << nl << "IceInternal.ParamPatcher<" << typeToString(type) << ">" << param - << "_PP = new IceInternal.ParamPatcher<" << typeToString(type) << ">(\"" - << cl->scoped() << "\");"; - out << nl << stream << ".readObject("; - if(streamingAPI) - { - out << "(Ice.ReadObjectCallback)"; - } - out << param << "_PP);"; - } - else - { - out << nl << stream << ".readObject("; - if(streamingAPI) - { - out << "(Ice.ReadObjectCallback)"; - } - out << "new Patcher__(\"" << cl->scoped() << "\", " << patchParams << "));"; - } + out << nl << stream << ".readObject(" << param << ");"; } return; } @@ -537,7 +605,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, out << nl << "if(" << param << " == null)"; out << sb; string typeS = typeToString(st); - out << nl << typeS << " " << "tmp__ = new " << typeS << "();"; + out << nl << typeS << " tmp__ = new " << typeS << "();"; out << nl << "tmp__."; out << (streamingAPI ? "ice_write" : "write__") << "(" << stream << ");"; out << eb; @@ -611,7 +679,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { - writeSequenceMarshalUnmarshalCode(out, seq, param, marshal, streamingAPI); + writeSequenceMarshalUnmarshalCode(out, seq, param, marshal, streamingAPI, true); return; } @@ -637,11 +705,356 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } void +Slice::CsGenerator::writeOptionalMarshalUnmarshalCode(Output &out, + const TypePtr& type, + const string& param, + int tag, + bool marshal, + bool streamingAPI) +{ + string stream; + + if(marshal) + { + stream = streamingAPI ? "outS__" : "os__"; + } + else + { + stream = streamingAPI ? "inS__" : "is__"; + } + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) + { + switch(builtin->kind()) + { + case Builtin::KindByte: + { + if(marshal) + { + out << nl << stream << ".writeByte(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readByte(" << tag << ");"; + } + break; + } + case Builtin::KindBool: + { + if(marshal) + { + out << nl << stream << ".writeBool(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readBool(" << tag << ");"; + } + break; + } + case Builtin::KindShort: + { + if(marshal) + { + out << nl << stream << ".writeShort(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readShort(" << tag << ");"; + } + break; + } + case Builtin::KindInt: + { + if(marshal) + { + out << nl << stream << ".writeInt(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readInt(" << tag << ");"; + } + break; + } + case Builtin::KindLong: + { + if(marshal) + { + out << nl << stream << ".writeLong(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readLong(" << tag << ");"; + } + break; + } + case Builtin::KindFloat: + { + if(marshal) + { + out << nl << stream << ".writeFloat(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readFloat(" << tag << ");"; + } + break; + } + case Builtin::KindDouble: + { + if(marshal) + { + out << nl << stream << ".writeDouble(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readDouble(" << tag << ");"; + } + break; + } + case Builtin::KindString: + { + if(marshal) + { + out << nl << stream << ".writeString(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readString(" << tag << ");"; + } + break; + } + case Builtin::KindObject: + { + if(marshal) + { + out << nl << stream << ".writeObject(" << tag << ", " << param << ");"; + } + else + { + out << nl << stream << ".readObject(" << tag << ", " << param << ");"; + } + break; + } + case Builtin::KindObjectProxy: + { + string typeS = typeToString(type); + if(marshal) + { + out << nl << stream << ".writeProxy(" << tag << ", " << param << ");"; + } + else + { + out << nl << param << " = new Ice.Optional<Ice.ObjectPrx>(" << stream << ".readProxy(" << tag + << "));"; + } + break; + } + case Builtin::KindLocalObject: + { + assert(false); + break; + } + } + return; + } + + ProxyPtr prx = ProxyPtr::dynamicCast(type); + if(prx) + { + if(marshal) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag + << ", Ice.OptionalType.FSize))"; + out << sb; + out << nl << stream << ".startSize();"; + writeMarshalUnmarshalCode(out, type, param + ".Value", marshal, streamingAPI); + out << nl << stream << ".endSize();"; + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", Ice.OptionalType.FSize))"; + out << sb; + out << nl << stream << ".skip(4);"; + string tmp = "tmpVal__"; + string typeS = typeToString(type); + out << nl << typeS << ' ' << tmp << ';'; + writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); + out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << typeS << ">();"; + out << eb; + } + return; + } + + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); + if(cl) + { + if(marshal) + { + out << nl << stream << ".writeObject(" << tag << ", " << param << ");"; + } + else + { + out << nl << stream << ".readObject(" << tag << ", " << param << ");"; + } + return; + } + + StructPtr st = StructPtr::dynamicCast(type); + if(st) + { + if(marshal) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " + << getOptionalType(st) << "))"; + out << sb; + if(st->isVariableLength()) + { + out << nl << stream << ".startSize();"; + } + else + { + out << nl << stream << ".writeSize(" << st->minWireSize() << ");"; + } + writeMarshalUnmarshalCode(out, type, param + ".Value", marshal, streamingAPI); + if(st->isVariableLength()) + { + out << nl << stream << ".endSize();"; + } + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(st) << "))"; + out << sb; + if(st->isVariableLength()) + { + out << nl << stream << ".skip(4);"; + } + else + { + out << nl << stream << ".skipSize();"; + } + string typeS = typeToString(type); + string tmp = "tmpVal__"; + if(isValueType(st)) + { + out << nl << typeS << ' ' << tmp << " = new " << typeS << "();"; + } + else + { + out << nl << typeS << ' ' << tmp << " = null;"; + } + writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); + out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << typeS << ">();"; + out << eb; + } + return; + } + + EnumPtr en = EnumPtr::dynamicCast(type); + if(en) + { + size_t sz = en->getEnumerators().size(); + if(marshal) + { + out << nl << "if(" << param << ".HasValue)"; + out << sb; + out << nl << stream << ".writeEnum(" << tag << ", (int)" << param << ".Value, " << sz << ");"; + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", Ice.OptionalType.Size))"; + out << sb; + string typeS = typeToString(type); + string tmp = "tmpVal__"; + out << nl << typeS << ' ' << tmp << ';'; + writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); + out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << typeS << ">();"; + out << eb; + } + return; + } + + SequencePtr seq = SequencePtr::dynamicCast(type); + if(seq) + { + writeOptionalSequenceMarshalUnmarshalCode(out, seq, param, tag, marshal, streamingAPI); + return; + } + + DictionaryPtr d = DictionaryPtr::dynamicCast(type); + assert(d); + TypePtr keyType = d->keyType(); + TypePtr valueType = d->valueType(); + if(marshal) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " + << getOptionalType(d) << "))"; + out << sb; + if(keyType->isVariableLength() || valueType->isVariableLength()) + { + out << nl << stream << ".startSize();"; + } + else + { + out << nl << stream << ".writeSize(" << param << ".Value == null ? 1 : " << param << ".Value.Count * " + << (keyType->minWireSize() + valueType->minWireSize()) << " + (" << param + << ".Value.Count > 254 ? 5 : 1));"; + } + writeMarshalUnmarshalCode(out, type, param + ".Value", marshal, streamingAPI); + if(keyType->isVariableLength() || valueType->isVariableLength()) + { + out << nl << stream << ".endSize();"; + } + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(d) << "))"; + out << sb; + if(keyType->isVariableLength() || valueType->isVariableLength()) + { + out << nl << stream << ".skip(4);"; + } + else + { + out << nl << stream << ".skipSize();"; + } + string typeS = typeToString(type); + string tmp = "tmpVal__"; + out << nl << typeS << ' ' << tmp << " = new " << typeS << "();"; + writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); + out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << typeS << ">();"; + out << eb; + } +} + +void Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, const SequencePtr& seq, const string& param, bool marshal, - bool streamingAPI) + bool streamingAPI, + bool useHelper) { string stream; if(marshal) @@ -653,13 +1066,29 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, stream = streamingAPI ? "inS__" : "is__"; } + if(useHelper) + { + ContainedPtr cont = ContainedPtr::dynamicCast(seq->container()); + assert(cont); + string helperName = fixId(cont->scoped(), DotNet::ICloneable) + "." + seq->name() + "Helper"; + if(marshal) + { + out << nl << helperName << ".write(" << stream << ", " << param << ");"; + } + else + { + out << nl << param << " = " << helperName << ".read(" << stream << ");"; + } + return; + } + TypePtr type = seq->type(); string typeS = typeToString(type); - string genericPrefix = "clr:generic:"; + const string genericPrefix = "clr:generic:"; string genericType; string addMethod = "Add"; - bool isGeneric = seq->findMetaData(genericPrefix, genericType); + const bool isGeneric = seq->findMetaData(genericPrefix, genericType); bool isStack = false; bool isList = false; bool isLinkedList = false; @@ -690,9 +1119,9 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, isCustom = true; } } - bool isCollection = seq->hasMetaData("clr:collection"); - bool isArray = !isGeneric && !isCollection; - string limitID = isArray ? "Length" : "Count"; + const bool isCollection = seq->hasMetaData("clr:collection"); + const bool isArray = !isGeneric && !isCollection; + const string limitID = isArray ? "Length" : "Count"; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) @@ -1404,6 +1833,215 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, return; } +void +Slice::CsGenerator::writeOptionalSequenceMarshalUnmarshalCode(Output& out, + const SequencePtr& seq, + const string& param, + int tag, + bool marshal, + bool streamingAPI) +{ + string stream; + if(marshal) + { + stream = streamingAPI ? "outS__" : "os__"; + } + else + { + stream = streamingAPI ? "inS__" : "is__"; + } + + const TypePtr type = seq->type(); + const string typeS = typeToString(type); + const string seqS = typeToString(seq); + + string meta; + const bool isArray = !seq->findMetaData("clr:generic:", meta) && !seq->hasMetaData("clr:collection"); + const string length = isArray ? param + ".Value.Length" : param + ".Value.Count"; + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) + { + switch(builtin->kind()) + { + case Builtin::KindByte: + case Builtin::KindBool: + case Builtin::KindShort: + case Builtin::KindInt: + case Builtin::KindFloat: + case Builtin::KindLong: + case Builtin::KindDouble: + case Builtin::KindString: + { + string func = typeS; + func[0] = toupper(static_cast<unsigned char>(typeS[0])); + const bool isSerializable = seq->findMetaData("clr:serializable:", meta); + + if(marshal) + { + if(isSerializable) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag + << ", Ice.OptionalType.VSize))"; + out << sb; + out << nl << stream << ".writeSerializable(" << param << ".Value);"; + out << eb; + } + else if(isArray) + { + out << nl << stream << ".write" << func << "Seq(" << tag << ", " << param << ");"; + } + else + { + out << nl << "if(" << param << ".HasValue)"; + out << sb; + out << nl << stream << ".write" << func << "Seq(" << tag << ", " << param + << ".Value == null ? 0 : " << param << ".Value.Count, " << param << ".Value);"; + out << eb; + } + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(seq) << "))"; + out << sb; + if(builtin->isVariableLength()) + { + out << nl << stream << ".skip(4);"; + } + else if(builtin->kind() != Builtin::KindByte && builtin->kind() != Builtin::KindBool) + { + out << nl << stream << ".skipSize();"; + } + string tmp = "tmpVal__"; + out << nl << seqS << ' ' << tmp << ';'; + writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); + out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << seqS << ">();"; + out << eb; + } + break; + } + + case Builtin::KindObject: + case Builtin::KindObjectProxy: + { + if(marshal) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " + << getOptionalType(seq) << "))"; + out << sb; + out << nl << stream << ".startSize();"; + writeSequenceMarshalUnmarshalCode(out, seq, param + ".Value", marshal, streamingAPI, true); + out << nl << stream << ".endSize();"; + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(seq) << "))"; + out << sb; + out << nl << stream << ".skip(4);"; + string tmp = "tmpVal__"; + out << nl << seqS << ' ' << tmp << ';'; + writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); + out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << seqS << ">();"; + out << eb; + } + break; + } + + case Builtin::KindLocalObject: + assert(false); + } + + return; + } + + StructPtr st = StructPtr::dynamicCast(type); + if(st) + { + if(marshal) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " + << getOptionalType(seq) << "))"; + out << sb; + if(st->isVariableLength()) + { + out << nl << stream << ".startSize();"; + } + else + { + out << nl << stream << ".writeSize(" << param << ".Value == null ? 1 : " << length << " * " + << st->minWireSize() << " + (" << length << " > 254 ? 5 : 1));"; + } + writeSequenceMarshalUnmarshalCode(out, seq, param + ".Value", marshal, streamingAPI, true); + if(st->isVariableLength()) + { + out << nl << stream << ".endSize();"; + } + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(seq) << "))"; + out << sb; + if(st->isVariableLength()) + { + out << nl << stream << ".skip(4);"; + } + else + { + out << nl << stream << ".skipSize();"; + } + string tmp = "tmpVal__"; + out << nl << seqS << ' ' << tmp << ';'; + writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); + out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << seqS << ">();"; + out << eb; + } + return; + } + + // + // At this point, all remaining element types have variable size. + // + if(marshal) + { + out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " + << getOptionalType(seq) << "))"; + out << sb; + out << nl << stream << ".startSize();"; + writeSequenceMarshalUnmarshalCode(out, seq, param + ".Value", marshal, streamingAPI, true); + out << nl << stream << ".endSize();"; + out << eb; + } + else + { + out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(seq) << "))"; + out << sb; + out << nl << stream << ".skip(4);"; + string tmp = "tmpVal__"; + out << nl << seqS << ' ' << tmp << ';'; + writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); + out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << " = new Ice.Optional<" << seqS << ">();"; + out << eb; + } +} + string Slice::CsGenerator::toArrayAlloc(const string& decl, const string& sz) { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index f6cb56d797b..53ef4dea799 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1076,7 +1076,7 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) string name = fixKwd(p->name()); - bool classMetaData = findMetaData(p->getMetaData()) == "class"; + bool classMetaData = findMetaData(p->getMetaData()) == "%class"; if(classMetaData) { H << sp << nl << "class " << _dllExport << name << " : public IceUtil::Shared"; @@ -1119,7 +1119,7 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) // Generate a one-shot constructor if the struct uses the class mapping, or if at least // one of its members has a default value. // - if(!dataMembers.empty() && (findMetaData(p->getMetaData()) == "class" || p->hasDefaultValues())) + if(!dataMembers.empty() && (findMetaData(p->getMetaData()) == "%class" || p->hasDefaultValues())) { DataMemberList::const_iterator q; vector<string> paramDecls; @@ -1183,7 +1183,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } string dllExport; - if(findMetaData(p->getMetaData()) != "class") + if(findMetaData(p->getMetaData()) != "%class") { dllExport = _dllExport; } @@ -1292,7 +1292,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) H << eb << ';'; - if(findMetaData(p->getMetaData()) == "class") + if(findMetaData(p->getMetaData()) == "%class") { H << sp << nl << "typedef ::IceUtil::Handle< " << scoped << "> " << p->name() + "Ptr;"; } @@ -3393,11 +3393,18 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) H << nl << "public:" << sp; H.inc(); - if(!p->isLocal()) + // + // In C++, a nested type cannot have the same name as the enclosing type + // + if(!p->isLocal() && p->name() != "ProxyType") { H << nl << "typedef " << p->name() << "Prx ProxyType;"; } - H << nl << "typedef " << p->name() << "Ptr PointerType;"; + + if(p->name() != "PointerType") + { + H << nl << "typedef " << p->name() << "Ptr PointerType;"; + } vector<string> params; vector<string> allTypes; @@ -6094,7 +6101,7 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p) { if(!p->isLocal()) { - bool classMetaData = findMetaData(p->getMetaData(), false) == "class"; + bool classMetaData = findMetaData(p->getMetaData(), false) == "%class"; string scoped = p->scoped(); H << nl << "template<>"; if(classMetaData) diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index a79ea86851e..c0a19a334ce 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -79,6 +79,13 @@ opFormatTypeToString(const OperationPtr& op) return "???"; } +static bool +isClassType(const TypePtr type) +{ + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + return (builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type); +} + static string getDeprecateReason(const ContainedPtr& p1, const ContainedPtr& p2, const string& type) { @@ -115,130 +122,475 @@ Slice::CsVisitor::~CsVisitor() } void -Slice::CsVisitor::writeMarshalDataMember(const DataMemberPtr& member, const string& name) +Slice::CsVisitor::writeMarshalUnmarshalParams(const ParamDeclList& params, const OperationPtr& op, bool marshal) { - writeMarshalUnmarshalCode(_out, member->type(), name, true, false, false); + ParamDeclList optionals; + ParamDeclList::const_iterator pli; -#if 0 - if(!member->optional()) + for(pli = params.begin(); pli != params.end(); ++pli) + { + string param = fixId((*pli)->name()); + TypePtr type = (*pli)->type(); + if(!marshal && isClassType(type)) + { + param = (*pli)->name() + "__PP"; + string typeS = typeToString(type); + if((*pli)->optional()) + { + _out << nl << "Ice.OptionalPatcher<" << typeS << "> " << param + << " = new Ice.OptionalPatcher<" << typeS << ">(" << getStaticId(type) << ");"; + } + else + { + _out << nl << "IceInternal.ParamPatcher<" << typeS << "> " << param + << " = new IceInternal.ParamPatcher<" << typeS << ">(" << getStaticId(type) << ");"; + } + } + + if((*pli)->optional()) + { + optionals.push_back(*pli); + } + else + { + writeMarshalUnmarshalCode(_out, type, param, marshal, false); + } + } + + TypePtr ret; + + if(op && op->returnType()) { - writeMarshalUnmarshalCode(out, package, member->type(), OptionalNone, false, 0, fixKwd(member->name()), - true, iter, false, member->getMetaData()); + ret = op->returnType(); + + string param = "ret__"; + if(!marshal && isClassType(ret)) + { + param += "PP"; + string typeS = typeToString(ret); + if(op->returnIsOptional()) + { + _out << nl << "Ice.OptionalPatcher<" << typeS << "> " << param + << " = new Ice.OptionalPatcher<" << typeS << ">(" << getStaticId(ret) << ");"; + } + else + { + _out << nl << "IceInternal.ParamPatcher<" << typeS << "> " << param + << " = new IceInternal.ParamPatcher<" << typeS << ">(" << getStaticId(ret) << ");"; + } + } + + if(!op->returnIsOptional()) + { + writeMarshalUnmarshalCode(_out, ret, param, marshal, false); + } + } + + // + // Sort optional parameters by tag. + // + class SortFn + { + public: + static bool compare(const ParamDeclPtr& lhs, const ParamDeclPtr& rhs) + { + return lhs->tag() < rhs->tag(); + } + }; + optionals.sort(SortFn::compare); + + // + // Handle optional parameters. + // + bool checkReturnType = op && op->returnIsOptional(); + + for(pli = optionals.begin(); pli != optionals.end(); ++pli) + { + if(checkReturnType && op->returnTag() < (*pli)->tag()) + { + const string param = !marshal && isClassType(ret) ? "ret__PP" : "ret__"; + writeOptionalMarshalUnmarshalCode(_out, ret, param, op->returnTag(), marshal, false); + checkReturnType = false; + } + + string param = fixId((*pli)->name()); + TypePtr type = (*pli)->type(); + + if(!marshal && isClassType(type)) + { + param = (*pli)->name() + "__PP"; + } + + writeOptionalMarshalUnmarshalCode(_out, type, param, (*pli)->tag(), marshal, false); + } + + if(checkReturnType) + { + const string param = !marshal && isClassType(ret) ? "ret__PP" : "ret__"; + writeOptionalMarshalUnmarshalCode(_out, ret, param, op->returnTag(), marshal, false); + } +} + +void +Slice::CsVisitor::writePostUnmarshalParams(const ParamDeclList& params, const OperationPtr& op) +{ + for(ParamDeclList::const_iterator pli = params.begin(); pli != params.end(); ++pli) + { + if(isClassType((*pli)->type())) + { + const string tmp = (*pli)->name() + "__PP"; + _out << nl << fixId((*pli)->name()) << " = " << tmp << ".value;"; + } + } + + if(op && op->returnType() && isClassType(op->returnType())) + { + _out << nl << "ret__ = ret__PP.value;"; + } +} + +void +Slice::CsVisitor::writeMarshalDataMember(const DataMemberPtr& member, const string& name) +{ + if(member->optional()) + { + writeOptionalMarshalUnmarshalCode(_out, member->type(), name, member->tag(), true, false); } else { - out << nl << "if(__has_" << member->name() << " && __os.writeOpt(" << member->tag() << ", " - << getOptionalType(member->type()) << "))"; - out << sb; - writeMarshalUnmarshalCode(out, package, member->type(), OptionalMember, false, 0, fixKwd(member->name()), true, - iter, false, member->getMetaData()); - out << eb; + writeMarshalUnmarshalCode(_out, member->type(), name, true, false); } -#endif } void Slice::CsVisitor::writeUnmarshalDataMember(const DataMemberPtr& member, const string& name, bool needPatcher, int& patchIter) { - string patchParams = "this"; - if(needPatcher) + const bool classType = isClassType(member->type()); + + string patcher; + if(classType) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(member->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(member->type())) + patcher = "new Patcher__(" + getStaticId(member->type()) + ", this"; + if(needPatcher) { ostringstream ostr; ostr << ", " << patchIter++; - patchParams += ostr.str(); + patcher += ostr.str(); } + patcher += ")"; } - writeMarshalUnmarshalCode(_out, member->type(), name, false, false, false, patchParams); -#if 0 - if(!member->optional()) + if(member->optional()) { - writeMarshalUnmarshalCode(out, package, member->type(), OptionalNone, false, 0, fixKwd(member->name()), false, - iter, false, member->getMetaData(), patchParams); + writeOptionalMarshalUnmarshalCode(_out, member->type(), classType ? patcher : name, member->tag(), false, + false); } else { - out << nl << "if(__has_" << member->name() << " = __is.readOpt(" << member->tag() << ", " - << getOptionalType(member->type()) << "))"; - out << sb; - writeMarshalUnmarshalCode(out, package, member->type(), OptionalMember, false, 0, fixKwd(member->name()), false, - iter, false, member->getMetaData(), patchParams); - out << eb; + writeMarshalUnmarshalCode(_out, member->type(), classType ? patcher : name, false, false); } -#endif } void Slice::CsVisitor::writeStreamMarshalDataMember(const DataMemberPtr& member, const string& name) { - writeMarshalUnmarshalCode(_out, member->type(), name, true, true, false); -#if 0 if(!member->optional()) { - writeStreamMarshalUnmarshalCode(out, package, member->type(), false, 0, fixKwd(member->name()), true, - iter, false, member->getMetaData()); + writeMarshalUnmarshalCode(_out, member->type(), name, true, true); + return; } - else + + const string flag = name + ".HasValue"; + const string value = name + ".Value"; + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(member->type()); + if(builtin) { - out << nl << "if(__has_" << member->name() << " && __outS.writeOptional(" << member->tag() << ", " - << getOptionalType(member->type()) << "))"; - out << sb; - writeStreamMarshalUnmarshalCode(out, package, member->type(), true, member->tag(), fixKwd(member->name()), - true, iter, false, member->getMetaData()); - out << eb; + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + if(builtin->kind() == Builtin::KindObjectProxy) + { + _out << nl << "outS__.startSize();"; + } + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + if(builtin->kind() == Builtin::KindObjectProxy) + { + _out << nl << "outS__.endSize();"; + } + _out << eb; + return; } -#endif + + SequencePtr seq = SequencePtr::dynamicCast(member->type()); + if(seq) + { + string meta; + const bool serializable = seq->findMetaData("clr:serializable:", meta); + const bool isArray = !seq->findMetaData("clr:generic:", meta) && !seq->hasMetaData("clr:collection"); + const string length = isArray ? value + ".Length" : value + ".Count"; + + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + + BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); + + if(serializable) + { + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + } + else if(b) + { + switch(b->kind()) + { + case Builtin::KindByte: + case Builtin::KindBool: + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + break; + case Builtin::KindShort: + case Builtin::KindInt: + case Builtin::KindFloat: + case Builtin::KindLong: + case Builtin::KindDouble: + _out << nl << "outS__.writeSize(" << value << " == null ? 1 : " << length << " * " << b->minWireSize() + << " + (" << length << " > 254 ? 5 : 1));"; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + break; + case Builtin::KindString: + case Builtin::KindObject: + case Builtin::KindObjectProxy: + { + _out << nl << "outS__.startSize();"; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + _out << nl << "outS__.endSize();"; + break; + } + case Builtin::KindLocalObject: + { + assert(false); + break; + } + } + } + else + { + StructPtr st = StructPtr::dynamicCast(seq->type()); + if(st && !st->isVariableLength()) + { + _out << nl << "outS__.writeSize(" << value << " == null ? 1 : " << length << " * " << st->minWireSize() + << " + (" << length << " > 254 ? 5 : 1));"; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + } + else + { + _out << nl << "outS__.startSize();"; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + _out << nl << "outS__.endSize();"; + } + } + + _out << eb; + return; + } + + DictionaryPtr d = DictionaryPtr::dynamicCast(member->type()); + if(d) + { + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + + if(d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) + { + _out << nl << "outS__.startSize();"; + } + else + { + _out << nl << "outS__.writeSize(" << value << " == null ? 1 : " << value << ".Count * " + << (d->keyType()->minWireSize() + d->valueType()->minWireSize()) << " + (" << value + << ".Count > 254 ? 5 : 1));"; + } + + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + if(d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) + { + _out << nl << "outS__.endSize();"; + } + _out << eb; + return; + } + + StructPtr st = StructPtr::dynamicCast(member->type()); + if(st) + { + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + + if(st->isVariableLength()) + { + _out << nl << "outS__.startSize();"; + } + else + { + _out << nl << "outS__.writeSize(" << st->minWireSize() << ");"; + } + + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + if(st->isVariableLength()) + { + _out << nl << "outS__.endSize();"; + } + _out << eb; + return; + } + + EnumPtr en = EnumPtr::dynamicCast(member->type()); + if(en) + { + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + _out << eb; + return; + } + + ProxyPtr pr = ProxyPtr::dynamicCast(member->type()); + if(pr) + { + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + _out << nl << "outS__.startSize();"; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + _out << nl << "outS__.endSize();"; + _out << eb; + return; + } + + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(member->type()); + assert(cl); + _out << nl << "if(" << flag << " && outS__.writeOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + writeMarshalUnmarshalCode(_out, member->type(), value, true, true); + _out << eb; } void Slice::CsVisitor::writeStreamUnmarshalDataMember(const DataMemberPtr& member, const string& name, bool needPatcher, int& patchIter) { - string patchParams = "this"; - if(needPatcher) + const bool classType = isClassType(member->type()); + + string patcher; + if(classType) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(member->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(member->type())) + patcher = "new Patcher__(" + getStaticId(member->type()) + ", this"; + if(needPatcher) { ostringstream ostr; ostr << ", " << patchIter++; - patchParams += ostr.str(); + patcher += ostr.str(); + } + patcher += ")"; + } + + if(!member->optional()) + { + writeMarshalUnmarshalCode(_out, member->type(), classType ? patcher : name, false, true); + return; + } + + _out << nl << "if(inS__.readOptional(" << member->tag() << ", " + << getOptionalType(member->type()) << "))"; + _out << sb; + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(member->type()); + if(builtin && builtin->kind() == Builtin::KindObjectProxy) + { + _out << nl << "inS__.skip(4);"; + } + + SequencePtr seq = SequencePtr::dynamicCast(member->type()); + if(seq) + { + BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); + if(!b || (b->kind() != Builtin::KindByte && b->kind() != Builtin::KindBool)) + { + if(seq->type()->isVariableLength()) + { + _out << nl << "inS__.skip(4);"; + } + else + { + _out << nl << "inS__.skipSize();"; + } } } - writeMarshalUnmarshalCode(_out, member->type(), name, false, true, false, patchParams); -#if 0 - string patchParams; - if(needPatcher) + DictionaryPtr d = DictionaryPtr::dynamicCast(member->type()); + if(d) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(member->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(member->type())) + if(d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) { - ostringstream ostr; - ostr << "new Patcher(" << patchIter++ << ')'; - patchParams = ostr.str(); + _out << nl << "inS__.skip(4);"; + } + else + { + _out << nl << "inS__.skipSize();"; } } - if(!member->optional()) + StructPtr st = StructPtr::dynamicCast(member->type()); + if(st) { - writeStreamMarshalUnmarshalCode(out, package, member->type(), false, 0, fixKwd(member->name()), false, - iter, false, member->getMetaData(), patchParams); + if(st->isVariableLength()) + { + _out << nl << "inS__.skip(4);"; + } + else + { + _out << nl << "inS__.skipSize();"; + } } - else + + ProxyPtr pr = ProxyPtr::dynamicCast(member->type()); + if(pr) { - out << nl << "if(__has_" << member->name() << " = __inS.readOptional(" << member->tag() << ", " - << getOptionalType(member->type()) << "))"; - out << sb; - writeStreamMarshalUnmarshalCode(out, package, member->type(), true, member->tag(), fixKwd(member->name()), - false, iter, false, member->getMetaData(), patchParams); - out << eb; + _out << nl << "inS__.skip(4);"; } -#endif + + const string typeS = typeToString(member->type()); + const string tmp = "tmpValue__"; + + if(st) + { + if(isValueType(st)) + { + _out << nl << typeS << ' ' << tmp << " = new " << typeS << "();"; + } + else + { + _out << nl << typeS << ' ' << tmp << " = null;"; + } + } + else if(!classType) + { + _out << nl << typeS << ' ' << tmp << ';'; + } + + writeMarshalUnmarshalCode(_out, member->type(), classType ? patcher : tmp, false, true); + + if(!classType) + { + _out << nl << name << " = new " << typeToString(member->type(), true) << '(' << tmp << ");"; + } + + _out << eb; } void @@ -459,26 +811,73 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) << " obj__, IceInternal.Incoming inS__, Ice.Current current__)"; _out << sb; - bool amd = p->hasMetaData("amd") || op->hasMetaData("amd"); - if(!amd) + TypePtr ret = op->returnType(); + + ParamDeclList paramList = op->parameters(); + ParamDeclList::const_iterator pli; + ParamDeclList inParams; + ParamDeclList outParams; + + for(pli = paramList.begin(); pli != paramList.end(); ++pli) { - TypePtr ret = op->returnType(); + if((*pli)->isOutParam()) + { + outParams.push_back(*pli); + } + else + { + inParams.push_back(*pli); + } + } - TypeStringList inParams; - TypeStringList outParams; - ParamDeclList paramList = op->parameters(); - for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + _out << nl << "checkMode__(" << sliceModeToIceMode(op->mode()) << ", current__.mode);"; + if(!inParams.empty()) + { + // + // Unmarshal 'in' parameters. + // + _out << nl << "IceInternal.BasicStream is__ = inS__.startReadParams();"; + for(pli = inParams.begin(); pli != inParams.end(); ++pli) { - if((*pli)->isOutParam()) + string param = fixId((*pli)->name()); + string typeS = typeToString((*pli)->type(), (*pli)->optional()); + const bool isClass = isClassType((*pli)->type()); + + if((*pli)->optional()) { - outParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + if(!isClass) + { + _out << nl << typeS << ' ' << param << ';'; + } } - else + else if(!isClass) { - inParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + _out << nl << typeS << ' ' << param << ';'; + StructPtr st = StructPtr::dynamicCast((*pli)->type()); + if(st) + { + if(isValueType((*pli)->type())) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } + } } } + writeMarshalUnmarshalParams(inParams, 0, false); + _out << nl << "inS__.endReadParams();"; + } + else + { + _out << nl << "inS__.readEmptyParams();"; + } + const bool amd = p->hasMetaData("amd") || op->hasMetaData("amd"); + if(!amd) + { ExceptionList throws = op->throws(); throws.sort(); throws.unique(); @@ -495,55 +894,10 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) throws.sort(Slice::DerivedToBaseCompare()); #endif - TypeStringList::const_iterator q; - - _out << nl << "checkMode__(" << sliceModeToIceMode(op->mode()) << ", current__.mode);"; - if(!inParams.empty()) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - // - // Unmarshal 'in' parameters. - // - _out << nl << "IceInternal.BasicStream is__ = inS__.startReadParams();"; - for(q = inParams.begin(); q != inParams.end(); ++q) - { - string param = fixId(q->second); - string typeS = typeToString(q->first); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - bool isClass = (builtin && builtin->kind() == Builtin::KindObject) - || ClassDeclPtr::dynamicCast(q->first); - if(!isClass) - { - _out << nl << typeS << ' ' << param << ';'; - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) - { - if(isValueType(q->first)) - { - _out << nl << param << " = new " << typeS << "();"; - } - else - { - _out << nl << param << " = null;"; - } - } - } - writeMarshalUnmarshalCode(_out, q->first, param, false, false, true); - } - if(op->sendsClasses()) - { - _out << nl << "is__.readPendingObjects();"; - } - _out << nl << "inS__.endReadParams();"; - } - else - { - _out << nl << "inS__.readEmptyParams();"; - } - - for(q = outParams.begin(); q != outParams.end(); ++q) - { - string typeS = typeToString(q->first); - _out << nl << typeS << ' ' << fixId(q->second) << ";"; + string typeS = typeToString((*pli)->type(), (*pli)->optional()); + _out << nl << typeS << ' ' << fixId((*pli)->name()) << ";"; } // @@ -557,31 +911,22 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << nl; if(ret) { - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); _out << retS << " ret__ = "; } _out << "obj__." << fixId(opName, DotNet::ICloneable, true) << spar; - for(q = inParams.begin(); q != inParams.end(); ++q) + for(pli = inParams.begin(); pli != inParams.end(); ++pli) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - bool isClass = (builtin && builtin->kind() == Builtin::KindObject) - || ClassDeclPtr::dynamicCast(q->first); - - string arg; - if(isClass) - { - arg += "(" + typeToString(q->first) + ")"; - } - arg += fixId(q->second); - if(isClass) + string arg = fixId((*pli)->name()); + if(isClassType((*pli)->type())) { - arg += "_PP.value"; + arg = (*pli)->name() + "__PP.value"; } _out << arg; } - for(q = outParams.begin(); q != outParams.end(); ++q) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - _out << "out " + fixId(q->second); + _out << "out " + fixId((*pli)->name()); } _out << "current__" << epar << ';'; @@ -592,18 +937,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) { _out << nl << "IceInternal.BasicStream os__ = inS__.startWriteParams__(" << opFormatTypeToString(op) << ");"; - for(q = outParams.begin(); q != outParams.end(); ++q) - { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false, true, ""); - } - if(ret) - { - writeMarshalUnmarshalCode(_out, ret, "ret__", true, false, true, ""); - } - if(op->returnsClasses()) - { - _out << nl << "os__.writePendingObjects();"; - } + writeMarshalUnmarshalParams(outParams, op, true); _out << nl << "inS__.endWriteParams__(true);"; } else @@ -634,61 +968,6 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) } else { - TypeStringList inParams; - ParamDeclList paramList = op->parameters(); - for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) - { - if(!(*pli)->isOutParam()) - { - inParams.push_back(make_pair((*pli)->type(), (*pli)->name())); - } - } - - TypeStringList::const_iterator q; - _out << nl << "checkMode__(" << sliceModeToIceMode(op->mode()) << ", current__.mode);"; - - if(!inParams.empty()) - { - // - // Unmarshal 'in' parameters. - // - _out << nl << "IceInternal.BasicStream is__ = inS__.startReadParams();"; - for(q = inParams.begin(); q != inParams.end(); ++q) - { - string param = fixId(q->second); - string typeS = typeToString(q->first); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - bool isClass = (builtin && builtin->kind() == Builtin::KindObject) - || ClassDeclPtr::dynamicCast(q->first); - if(!isClass) - { - _out << nl << typeS << ' ' << param << ';'; - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) - { - if(isValueType(q->first)) - { - _out << nl << param << " = new " << typeS << "();"; - } - else - { - _out << nl << param << " = null;"; - } - } - } - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); - } - if(op->sendsClasses()) - { - _out << nl << "is__.readPendingObjects();"; - } - _out << nl << "inS__.endReadParams();"; - } - else - { - _out << nl << "inS__.readEmptyParams();"; - } - // // Call on the servant. // @@ -711,20 +990,12 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) { _out << "cb__"; } - for(q = inParams.begin(); q != inParams.end(); ++q) + for(pli = inParams.begin(); pli != inParams.end(); ++pli) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - bool isClass = (builtin && builtin->kind() == Builtin::KindObject) - || ClassDeclPtr::dynamicCast(q->first); - string arg; - if(isClass) - { - arg += "(" + typeToString(q->first) + ")"; - } - arg += fixId(q->second); - if(isClass) + string arg = fixId((*pli)->name()); + if(isClassType((*pli)->type())) { - arg += "_PP.value"; + arg = (*pli)->name() + "__PP.value"; } _out << arg; } @@ -860,6 +1131,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) DataMemberList allClassMembers = p->allClassDataMembers(); DataMemberList::const_iterator d; DataMemberList members = p->dataMembers(); + DataMemberList optionalMembers = p->orderedOptionalDataMembers(); DataMemberList classMembers = p->classDataMembers(); const bool basePreserved = p->inheritsMetaData("preserve-slice"); const bool preserved = basePreserved || p->hasMetaData("preserve-slice"); @@ -902,6 +1174,13 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << nl << "os__.startWriteSlice(ice_staticId(), " << (!base ? "true" : "false") << ");"; for(d = members.begin(); d != members.end(); ++d) { + if(!(*d)->optional()) + { + writeMarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true)); + } + } + for(d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + { writeMarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true)); } _out << nl << "os__.endWriteSlice();"; @@ -923,7 +1202,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) { _out << "new "; } - _out << "class Patcher__ : IceInternal.Patcher<" << name << ">"; + _out << "class Patcher__ : IceInternal.Patcher"; _out << sb; _out << sp << nl << "internal Patcher__(string type, Ice.ObjectImpl instance"; if(allClassMembers.size() > 1) @@ -958,11 +1237,30 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out.inc(); } string memberName = fixId((*d)->name(), DotNet::ICloneable, true); - string memberType = typeToString((*d)->type()); - _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; - ContainedPtr contained = ContainedPtr::dynamicCast((*d)->type()); - string sliceId = contained ? contained->scoped() : string("::Ice::Object"); - _out << nl << "_typeId = \"" << sliceId << "\";"; + string memberType = typeToString((*d)->type(), (*d)->optional()); + if((*d)->optional()) + { + if(ClassDeclPtr::dynamicCast((*d)->type())) + { + _out << nl << "_instance." << memberName << " = new " << memberType << "((" + << typeToString((*d)->type()) << ")v);"; + } + else + { + _out << nl << "_instance." << memberName << " = new " << memberType << "(v);"; + } + } + else + { + if(ClassDeclPtr::dynamicCast((*d)->type())) + { + _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; + } + else + { + _out << nl << "_instance." << memberName << " = v;"; + } + } if(allClassMembers.size() > 1) { _out << nl << "break;"; @@ -976,7 +1274,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << eb; _out << nl << "catch(_System.InvalidCastException)"; _out << sb; - _out << nl << "IceInternal.Ex.throwUOE(_typeId, v.ice_id());"; + _out << nl << "IceInternal.Ex.throwUOE(type(), v.ice_id());"; _out << eb; _out << eb; @@ -985,7 +1283,6 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) { _out << nl << "private int _member;"; } - _out << nl << "private string _typeId;"; _out << eb; } @@ -1020,6 +1317,13 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) const bool needCustomPatcher = classMembers.size() > 1 || allClassMembers.size() > 1; for(d = members.begin(); d != members.end(); ++d) { + if(!(*d)->optional()) + { + writeUnmarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true), needCustomPatcher, classMemberCount); + } + } + for(d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + { writeUnmarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true), needCustomPatcher, classMemberCount); } _out << nl << "is__.endReadSlice();"; @@ -1063,6 +1367,13 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << nl << "outS__.startSlice(ice_staticId(), " << (!base ? "true" : "false") << ");"; for(d = members.begin(); d != members.end(); ++d) { + if(!(*d)->optional()) + { + writeStreamMarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true)); + } + } + for(d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + { writeStreamMarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true)); } _out << nl << "outS__.endSlice();"; @@ -1102,6 +1413,14 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) classMemberCount = static_cast<int>(allClassMembers.size() - classMembers.size()); for(d = members.begin(); d != members.end(); ++d) { + if(!(*d)->optional()) + { + writeStreamUnmarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true), needCustomPatcher, + classMemberCount); + } + } + for(d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + { writeStreamUnmarshalDataMember(*d, fixId(*d, DotNet::ICloneable, true), needCustomPatcher, classMemberCount); } @@ -1180,7 +1499,7 @@ Slice::CsVisitor::getParams(const OperationPtr& op) { param += "out "; } - param += typeToString((*q)->type()) + " " + fixId((*q)->name()); + param += typeToString((*q)->type(), (*q)->optional()) + " " + fixId((*q)->name()); params.push_back(param); } return params; @@ -1205,7 +1524,8 @@ Slice::CsVisitor::getParamsAsync(const OperationPtr& op, bool amd, bool newAMI) { if(!(*q)->isOutParam()) { - params.push_back(getParamAttributes(*q) + typeToString((*q)->type()) + " " + fixId((*q)->name())); + params.push_back(getParamAttributes(*q) + typeToString((*q)->type(), (*q)->optional()) + " " + + fixId((*q)->name())); } } return params; @@ -1221,7 +1541,7 @@ Slice::CsVisitor::getParamsAsyncCB(const OperationPtr& op, bool newAMI, bool out TypePtr ret = op->returnType(); if(ret) { - params.push_back(typeToString(ret) + " ret__"); + params.push_back(typeToString(ret, op->returnIsOptional()) + " ret__"); } } @@ -1232,7 +1552,8 @@ Slice::CsVisitor::getParamsAsyncCB(const OperationPtr& op, bool newAMI, bool out { if(!newAMI) { - params.push_back(getParamAttributes(*q) + typeToString((*q)->type()) + ' ' + fixId((*q)->name())); + params.push_back(getParamAttributes(*q) + typeToString((*q)->type(), (*q)->optional()) + ' ' + + fixId((*q)->name())); } else { @@ -1241,7 +1562,7 @@ Slice::CsVisitor::getParamsAsyncCB(const OperationPtr& op, bool newAMI, bool out { s += "out "; } - s += typeToString((*q)->type()) + ' ' + fixId((*q)->name()); + s += typeToString((*q)->type(), (*q)->optional()) + ' ' + fixId((*q)->name()); params.push_back(s); } } @@ -1515,16 +1836,24 @@ Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& members, int { if((*p)->defaultValueType()) { - string memberName = fixId((*p)->name(), baseTypes); - _out << nl << "this." << memberName; + _out << nl << "this."; if(propertyMapping) { - _out << "_prop"; + _out << (*p)->name() << "__prop"; + } + else + { + _out << fixId((*p)->name(), baseTypes); } _out << " = "; writeConstantValue((*p)->type(), (*p)->defaultValueType(), (*p)->defaultValue()); _out << ';'; } + else if((*p)->optional()) + { + _out << nl << "this." << fixId((*p)->name(), baseTypes) << " = new " << typeToString((*p)->type(), true) + << "();"; + } } } @@ -2565,7 +2894,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) if(!allDataMembers.empty()) { - bool propertyMapping = p->hasMetaData("clr:property"); + const bool propertyMapping = p->hasMetaData("clr:property"); _out << sp << nl << "#region Constructors"; _out << sp; @@ -2602,19 +2931,26 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) _out << baseParamNames << epar; } _out << sb; - vector<string> paramNames; for(d = dataMembers.begin(); d != dataMembers.end(); ++d) { - paramNames.push_back(fixId((*d)->name())); - } - for(vector<string>::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) - { - _out << nl << "this." << *i; + _out << nl << "this."; + const string paramName = fixId((*d)->name()); if(propertyMapping) { - _out << "_prop"; + _out << (*d)->name() << "__prop"; + } + else + { + _out << paramName; + } + if((*d)->optional()) + { + _out << " = new " << typeToString((*d)->type(), true) << '(' << paramName << ");"; + } + else + { + _out << " = " << paramName << ';'; } - _out << " = " << *i << ';'; } _out << eb; @@ -2668,7 +3004,7 @@ Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p) params = getParams(p); args = getArgs(p); name = fixId(name, DotNet::ICloneable, true); - retS = typeToString(p->returnType()); + retS = typeToString(p->returnType(), p->returnIsOptional()); } else { @@ -2759,8 +3095,8 @@ Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p) { _out << "public abstract "; } - _out << typeToString(p->returnType()) << " end_" << name << spar << getParamsAsyncCB(p, true) - << "Ice.AsyncResult r__" << epar << ';'; + _out << typeToString(p->returnType(), p->returnIsOptional()) << " end_" << name << spar + << getParamsAsyncCB(p, true) << "Ice.AsyncResult r__" << epar << ';'; } } @@ -2994,7 +3330,15 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { string name = fixId((*q)->name(), DotNet::Exception, false); - _out << nl << "this." << name << " = " << fixId((*q)->name()) << ';'; + if((*q)->optional()) + { + _out << nl << "this." << name << " = new " << typeToString((*q)->type(), true) << '(' << + fixId((*q)->name()) << ");"; + } + else + { + _out << nl << "this." << name << " = " << fixId((*q)->name()) << ';'; + } } _out << eb; } @@ -3161,7 +3505,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) { _out << "new "; } - _out << "class Patcher__ : IceInternal.Patcher<" << name << ">"; + _out << "class Patcher__ : IceInternal.Patcher"; _out << sb; _out << sp << nl << "internal Patcher__(string type, Ice.Exception instance"; if(allClassMembers.size() > 1) @@ -3196,11 +3540,30 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out.inc(); } string memberName = fixId((*q)->name(), DotNet::Exception); - string memberType = typeToString((*q)->type()); - _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; - ContainedPtr contained = ContainedPtr::dynamicCast((*q)->type()); - string sliceId = contained ? contained->scoped() : string("::Ice::Object"); - _out << nl << "_typeId = \"" << sliceId << "\";"; + string memberType = typeToString((*q)->type(), (*q)->optional()); + if((*q)->optional()) + { + if(ClassDeclPtr::dynamicCast((*q)->type())) + { + _out << nl << "_instance." << memberName << " = new " << memberType << "((" + << typeToString((*q)->type()) << ")v);"; + } + else + { + _out << nl << "_instance." << memberName << " = new " << memberType << "(v);"; + } + } + else + { + if(ClassDeclPtr::dynamicCast((*q)->type())) + { + _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; + } + else + { + _out << nl << "_instance." << memberName << " = v;"; + } + } if(allClassMembers.size() > 1) { _out << nl << "break;"; @@ -3214,7 +3577,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << eb; _out << nl << "catch(_System.InvalidCastException)"; _out << sb; - _out << nl << "IceInternal.Ex.throwUOE(_typeId, v.ice_id());"; + _out << nl << "IceInternal.Ex.throwUOE(type(), v.ice_id());"; _out << eb; _out << eb; @@ -3223,7 +3586,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) { _out << nl << "private int _member;"; } - _out << nl << "private string _typeId;"; _out << eb; } @@ -3422,11 +3784,11 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) DataMemberList dataMembers = p->dataMembers(); DataMemberList::const_iterator q; - bool propertyMapping = p->hasMetaData("clr:property"); + const bool propertyMapping = p->hasMetaData("clr:property"); _out << sp << nl << "#endregion"; // Slice data members - bool isClass = !isValueType(p) || p->hasDefaultValues(); + const bool isClass = !isValueType(p) || p->hasDefaultValues(); _out << sp << nl << "#region Constructor"; if(isClass) @@ -3450,24 +3812,27 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) emitGeneratedCodeAttribute(); _out << nl << "public " << name << spar; vector<string> paramDecl; - vector<string> paramNames; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { string memberName = fixId((*q)->name(), isClass ? DotNet::ICloneable : 0); string memberType = typeToString((*q)->type()); paramDecl.push_back(memberType + " " + memberName); - paramNames.push_back(memberName); } _out << paramDecl << epar; _out << sb; - for(vector<string>::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) + for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - _out << nl << "this." << *i; + string paramName = fixId((*q)->name(), isClass ? DotNet::ICloneable : 0); + _out << nl << "this."; if(propertyMapping) { - _out << "_prop"; + _out << (*q)->name() << "__prop"; } - _out << " = " << *i << ';'; + else + { + _out << paramName; + } + _out << " = " << paramName << ';'; } _out << eb; @@ -3563,17 +3928,15 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0), - true, false, false); + writeMarshalDataMember(*q, fixId(*q, isClass ? DotNet::ICloneable : 0)); } _out << eb; - if(isClass && classMembers.size() != 0) { _out << sp; emitGeneratedCodeAttribute(); - _out << nl << "public sealed class Patcher__ : IceInternal.Patcher<" << name << ">"; + _out << nl << "public sealed class Patcher__ : IceInternal.Patcher"; _out << sb; _out << sp << nl << "internal Patcher__(string type, " << name << " instance"; if(classMembers.size() > 1) @@ -3609,10 +3972,14 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } string memberType = typeToString((*q)->type()); string memberName = fixId((*q)->name(), isClass ? DotNet::ICloneable : 0); - _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; - ContainedPtr contained = ContainedPtr::dynamicCast((*q)->type()); - string sliceId = contained ? contained->scoped() : string("::Ice::Object"); - _out << nl << "_typeId = \"" << sliceId << "\";"; + if(ClassDeclPtr::dynamicCast((*q)->type())) + { + _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; + } + else + { + _out << nl << "_instance." << memberName << " = v;"; + } if(classMembers.size() > 1) { _out << nl << "break;"; @@ -3626,7 +3993,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << eb; _out << nl << "catch(_System.InvalidCastException)"; _out << sb; - _out << nl << "IceInternal.Ex.throwUOE(_typeId, v.ice_id());"; + _out << nl << "IceInternal.Ex.throwUOE(type(), v.ice_id());"; _out << eb; _out << eb; @@ -3636,7 +4003,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) { _out << nl << "private int _member;"; } - _out << nl << "private string _typeId;"; _out << eb; } @@ -3645,20 +4011,11 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << nl << "public void read__(IceInternal.BasicStream is__)"; _out << sb; int classMemberCount = 0; + const bool needCustomPatcher = classMembers.size() > 1; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - ostringstream patchParams; - patchParams << "this"; - BuiltinPtr builtin = BuiltinPtr::dynamicCast((*q)->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast((*q)->type())) - { - if(classMembers.size() > 1) - { - patchParams << ", " << classMemberCount++; - } - } - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0 ), - false, false, false, patchParams.str()); + writeUnmarshalDataMember(*q, fixId(*q, isClass ? DotNet::ICloneable : 0), needCustomPatcher, + classMemberCount); } _out << eb; @@ -3670,8 +4027,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0), - true, true, false); + writeStreamMarshalDataMember(*q, fixId(*q, isClass ? DotNet::ICloneable : 0)); } _out << eb; @@ -3682,18 +4038,8 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) classMemberCount = 0; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - ostringstream patchParams; - patchParams << "this"; - BuiltinPtr builtin = BuiltinPtr::dynamicCast((*q)->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast((*q)->type())) - { - if(classMembers.size() > 1) - { - patchParams << ", " << classMemberCount++; - } - } - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0 ), - false, true, false, patchParams.str()); + writeStreamUnmarshalDataMember(*q, fixId(*q, isClass ? DotNet::ICloneable : 0), needCustomPatcher, + classMemberCount); } _out << eb; } @@ -3794,13 +4140,13 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) _out << sp << nl << "public static void write(Ice.OutputStream outS__, " << scoped << " v__)"; _out << sb; - writeMarshalUnmarshalCode(_out, p, "v__", true, true, false); + writeMarshalUnmarshalCode(_out, p, "v__", true, true); _out << eb; _out << sp << nl << "public static " << scoped << " read(Ice.InputStream inS__)"; _out << sb; _out << nl << scoped << " v__;"; - writeMarshalUnmarshalCode(_out, p, "v__", false, true, false); + writeMarshalUnmarshalCode(_out, p, "v__", false, true); _out << nl << "return v__;"; _out << eb; @@ -3828,9 +4174,10 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) { int baseTypes = 0; bool isClass = false; - bool propertyMapping = false; + bool isProperty = false; bool isValue = false; bool isProtected = false; + const bool isOptional = p->optional(); ContainedPtr cont = ContainedPtr::dynamicCast(p->container()); assert(cont); if(StructPtr::dynamicCast(cont)) @@ -3842,7 +4189,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) } if(cont->hasMetaData("clr:property")) { - propertyMapping = true; + isProperty = true; } } else if(ExceptionPtr::dynamicCast(cont)) @@ -3855,7 +4202,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) isClass = true; if(cont->hasMetaData("clr:property")) { - propertyMapping = true; + isProperty = true; } isProtected = cont->hasMetaData("protected") || p->hasMetaData("protected"); } @@ -3864,15 +4211,19 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) emitDeprecate(p, cont, _out, "member"); - string type = typeToString(p->type()); + string type = typeToString(p->type(), isOptional); string propertyName = fixId(p->name(), baseTypes, isClass); - string dataMemberName = propertyName; - if(propertyMapping) + string dataMemberName; + if(isProperty) { - dataMemberName += "_prop"; + dataMemberName = p->name() + "__prop"; + } + else + { + dataMemberName = propertyName; } - if(propertyMapping) + if(isProperty) { _out << nl << "private"; } @@ -3888,31 +4239,37 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) emitGeneratedCodeAttribute(); _out << nl << "public"; } - _out << ' ' << type << ' ' << dataMemberName << ';'; - if(!propertyMapping) + if(isOptional && isValue) { - return; + _out << ' ' << type << ' ' << dataMemberName << " = new " << type << "();"; + } + else + { + _out << ' ' << type << ' ' << dataMemberName << ';'; } - emitAttributes(p); - emitGeneratedCodeAttribute(); - _out << nl << (isProtected ? "protected" : "public"); - if(!isValue) + if(isProperty) { - _out << " virtual"; + emitAttributes(p); + emitGeneratedCodeAttribute(); + _out << nl << (isProtected ? "protected" : "public"); + if(!isValue) + { + _out << " virtual"; + } + _out << ' ' << type << ' ' << propertyName; + _out << sb; + _out << nl << "get"; + _out << sb; + _out << nl << "return " << dataMemberName << ';'; + _out << eb; + _out << nl << "set"; + _out << sb; + _out << nl << dataMemberName << " = value;"; + _out << eb; + _out << eb; } - _out << ' ' << type << ' ' << propertyName; - _out << sb; - _out << nl << "get"; - _out << sb; - _out << nl << "return " << dataMemberName << ';'; - _out << eb; - _out << nl << "set"; - _out << sb; - _out << nl << dataMemberName << " = value;"; - _out << eb; - _out << eb; } void @@ -3920,7 +4277,12 @@ Slice::Gen::TypesVisitor::writeMemberHashCode(const DataMemberList& dataMembers, { for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) { - _out << nl << "IceInternal.HashUtil.hashAdd(ref h__, " << fixId((*q)->name(), baseTypes) << ");"; + _out << nl << "IceInternal.HashUtil.hashAdd(ref h__, " << fixId((*q)->name(), baseTypes); + if((*q)->optional()) + { + _out << ".Value"; + } + _out << ");"; } } @@ -3931,7 +4293,7 @@ Slice::Gen::TypesVisitor::writeMemberEquals(const DataMemberList& dataMembers, i { string memberName = fixId((*q)->name(), baseTypes); TypePtr memberType = (*q)->type(); - if(!isValueType(memberType)) + if(!(*q)->optional() && !isValueType(memberType)) { _out << nl << "if(" << memberName << " == null)"; _out << sb; @@ -4086,7 +4448,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) string name = fixId(p->name(), DotNet::ICloneable, true); vector<string> params = getParams(p); ParamDeclList paramList = p->parameters(); - + string retS = typeToString(p->returnType(), p->returnIsOptional()); _out << sp; @@ -4110,14 +4472,14 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) { _out << nl << "[_System.Obsolete(\"" << deprecateReason << "\")]"; } - _out << nl << typeToString(p->returnType()) << " " << name << spar << params << epar << ';'; + _out << nl << retS << " " << name << spar << params << epar << ';'; if(!deprecateReason.empty()) { _out << nl << "[_System.Obsolete(\"" << deprecateReason << "\")]"; } - _out << nl << typeToString(p->returnType()) << " " << name - << spar << params << "_System.Collections.Generic.Dictionary<string, string> context__" << epar << ';'; + _out << nl << retS << " " << name << spar << params + << "_System.Collections.Generic.Dictionary<string, string> context__" << epar << ';'; // // Write the operations for the new async mapping. @@ -4163,8 +4525,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) // end_ method. // _out << sp; - _out << nl << typeToString(p->returnType()) << " end_" << p->name() << spar - << getParamsAsyncCB(p, true) << "Ice.AsyncResult r__" << epar << ';'; + _out << nl << retS << " end_" << p->name() << spar << getParamsAsyncCB(p, true) << "Ice.AsyncResult r__" << epar + << ';'; if(cl->hasMetaData("ami") || p->hasMetaData("ami")) { @@ -4233,7 +4595,7 @@ Slice::Gen::AsyncDelegateVisitor::visitOperation(const OperationPtr& p) } vector<string> paramDeclAMI = getParamsAsyncCB(p, true, false); - string retS = typeToString(p->returnType()); + string retS = typeToString(p->returnType(), p->returnIsOptional()); string delName = "Callback_" + cl->name() + "_" + p->name(); _out << sp; @@ -4382,7 +4744,7 @@ Slice::Gen::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurrent) emitDeprecate(op, p, _out, "operation"); emitAttributes(op); - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); _out << nl << retS << ' ' << opname << spar << params; if(!noCurrent && !p->isLocal()) { @@ -4449,7 +4811,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) OperationPtr op = *r; string opName = fixId(op->name(), DotNet::ICloneable, true); TypePtr ret = op->returnType(); - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); vector<string> params = getParams(op); vector<string> args = getArgs(op); @@ -4553,20 +4915,20 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) string opName = op->name(); - TypeStringList inParams; - TypeStringList outParams; - TypeStringList::const_iterator q; - ParamDeclList paramList = op->parameters(); - for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + ParamDeclList::const_iterator pli; + ParamDeclList inParams; + ParamDeclList outParams; + + for(pli = paramList.begin(); pli != paramList.end(); ++pli) { if((*pli)->isOutParam()) { - outParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + outParams.push_back(*pli); } else { - inParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + inParams.push_back(*pli); } } @@ -4619,7 +4981,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sp << nl << "private const string " << flatName << " = \"" << op->name() << "\";"; TypePtr ret = op->returnType(); - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); _out << sp << nl << "public " << retS << " end_" << opName << spar << getParamsAsyncCB(op, true) << "Ice.AsyncResult r__" << epar; _out << sb; @@ -4662,6 +5024,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl << "throw new Ice.UnknownUserException(ex__.ice_name(), ex__);"; _out << eb; _out << eb; + if(ret || !outParams.empty()) { if(ret) @@ -4669,63 +5032,52 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl << retS << " ret__;"; } _out << nl << "IceInternal.BasicStream is__ = outAsync__.startReadParams__();"; - for(q = outParams.begin(); q != outParams.end(); ++q) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - string param = fixId(q->second); - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) + string param = fixId((*pli)->name()); + string typeS = typeToString((*pli)->type(), (*pli)->optional()); + const bool isClass = isClassType((*pli)->type()); + + if(!(*pli)->optional() && !isClass) { - if(isValueType(st)) - { - _out << nl << param << " = new " << typeToString(q->first) << "();"; - } - else + StructPtr st = StructPtr::dynamicCast((*pli)->type()); + if(st) { - _out << nl << param << " = null;"; + if(isValueType((*pli)->type())) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } } } - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); } if(ret) { - StructPtr st = StructPtr::dynamicCast(ret); - if(st) + string typeS = typeToString(ret, op->returnIsOptional()); + const bool isClass = isClassType(ret); + + if(!op->returnIsOptional() && !isClass) { - if(isValueType(ret)) - { - _out << nl << "ret__ = new " << retS << "();"; - } - else + StructPtr st = StructPtr::dynamicCast(ret); + if(st) { - _out << nl << "ret__ = null;"; + if(isValueType(ret)) + { + _out << nl << "ret__ = new " << typeS << "();"; + } + else + { + _out << nl << "ret__ = null;"; + } } } - writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true); - } - if(op->returnsClasses()) - { - _out << nl << "is__.readPendingObjects();"; } + writeMarshalUnmarshalParams(outParams, op, false); _out << nl << "outAsync__.endReadParams__();"; - for(q = outParams.begin(); q != outParams.end(); ++q) - { - string param = fixId(q->second); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) - { - string type = typeToString(q->first); - _out << nl << param << " = (" << type << ")" << param << "_PP.value;"; - } - } - if(ret) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) - { - string type = typeToString(ret); - _out << nl << "ret__ = (" << retS << ")ret___PP.value;"; - } - } + writePostUnmarshalParams(outParams, op); if(ret) { _out << nl << "return ret__;"; @@ -4776,15 +5128,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << nl << "IceInternal.BasicStream os__ = result__.startWriteParams__(" << opFormatTypeToString(op) << ");"; - for(q = inParams.begin(); q != inParams.end(); ++q) - { - string typeS = typeToString(q->first); - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false, false, "", true); - } - if(op->sendsClasses()) - { - _out << nl << "os__.writePendingObjects();"; - } + writeMarshalUnmarshalParams(inParams, 0, true); _out << nl << "result__.endWriteParams__();"; } else @@ -4808,10 +5152,9 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sp << nl << "private void " << op->name() << "_completed__(Ice.AsyncResult r__, " << delType << " cb__, Ice.ExceptionCallback excb__)"; _out << sb; - TypeStringList::const_iterator tsli; - for(tsli = outParams.begin(); tsli != outParams.end(); ++tsli) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - _out << nl << typeToString(tsli->first) << ' ' << fixId(tsli->second) << ';'; + _out << nl << typeToString((*pli)->type(), (*pli)->optional()) << ' ' << fixId((*pli)->name()) << ';'; } if(ret) { @@ -4825,9 +5168,9 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) _out << "ret__ = "; } _out << "end_" << op->name() << spar; - for(tsli = outParams.begin(); tsli != outParams.end(); ++tsli) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - _out << "out " + fixId(tsli->second); + _out << "out " + fixId((*pli)->name()); } _out << "r__" << epar << ';'; _out << eb; @@ -4846,9 +5189,9 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << "ret__"; } - for(tsli = outParams.begin(); tsli != outParams.end(); ++tsli) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - _out << fixId(tsli->second); + _out << fixId((*pli)->name()); } _out << epar << ';'; _out << eb; @@ -5188,13 +5531,13 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) _out << sp << nl << "public static void write(IceInternal.BasicStream os__, " << typeS << " v__)"; _out << sb; - writeSequenceMarshalUnmarshalCode(_out, p, "v__", true, false); + writeSequenceMarshalUnmarshalCode(_out, p, "v__", true, false, false); _out << eb; _out << sp << nl << "public static " << typeS << " read(IceInternal.BasicStream is__)"; _out << sb; _out << nl << typeS << " v__;"; - writeSequenceMarshalUnmarshalCode(_out, p, "v__", false, false); + writeSequenceMarshalUnmarshalCode(_out, p, "v__", false, false, false); _out << nl << "return v__;"; _out << eb; @@ -5202,13 +5545,13 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) { _out << sp << nl << "public static void write(Ice.OutputStream outS__, " << typeS << " v__)"; _out << sb; - writeSequenceMarshalUnmarshalCode(_out, p, "v__", true, true); + writeSequenceMarshalUnmarshalCode(_out, p, "v__", true, true, false); _out << eb; _out << sp << nl << "public static " << typeS << " read(Ice.InputStream inS__)"; _out << sb; _out << nl << typeS << " v__;"; - writeSequenceMarshalUnmarshalCode(_out, p, "v__", false, true); + writeSequenceMarshalUnmarshalCode(_out, p, "v__", false, true, false); _out << nl << "return v__;"; _out << eb; } @@ -5315,18 +5658,18 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << " e__ in v__)"; _out << sb; string keyArg = isNewMapping ? string("e__.Key") : "((" + keyS + ")e__.Key)"; - writeMarshalUnmarshalCode(_out, key, keyArg, true, false, false); + writeMarshalUnmarshalCode(_out, key, keyArg, true, false); string valueArg = isNewMapping ? string("e__.Value") : "((" + valueS + ")e__.Value)"; - writeMarshalUnmarshalCode(_out, value, valueArg, true, false, false); + writeMarshalUnmarshalCode(_out, value, valueArg, true, false); _out << eb; _out << eb; _out << eb; - BuiltinPtr builtin = BuiltinPtr::dynamicCast(value); - bool hasClassValue = (builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(value); + const bool hasClassValue = isClassType(value); + if(hasClassValue) { - _out << sp << nl << "public sealed class Patcher__ : IceInternal.Patcher<" << valueS << ">"; + _out << sp << nl << "public sealed class Patcher__ : IceInternal.Patcher"; _out << sb; _out << sp << nl << "internal Patcher__(string type, " << name << " m, " << keyS << " key) : base(type)"; _out << sb; @@ -5334,16 +5677,23 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "_key = key;"; _out << eb; - _out << sp << nl << "public override void" << nl << "patch(Ice.Object v)"; - _out << sb; - _out << nl << "try"; - _out << sb; - _out << nl << "_m[_key] = (" << valueS << ")v;"; - _out << eb; - _out << nl << "catch(_System.InvalidCastException)"; + _out << sp << nl << "public override void patch(Ice.Object v)"; _out << sb; - _out << nl << "IceInternal.Ex.throwUOE(type(), v.ice_id());"; - _out << eb; + if(ClassDeclPtr::dynamicCast(value)) + { + _out << nl << "try"; + _out << sb; + _out << nl << "_m[_key] = (" << valueS << ")v;"; + _out << eb; + _out << nl << "catch(_System.InvalidCastException)"; + _out << sb; + _out << nl << "IceInternal.Ex.throwUOE(type(), v.ice_id());"; + _out << eb; + } + else + { + _out << nl << "_m[_key] = v;"; + } _out << eb; _out << sp << nl << "private " << name << " _m;"; @@ -5370,8 +5720,14 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "k__ = null;"; } } - writeMarshalUnmarshalCode(_out, key, "k__", false, false, false); - if(!hasClassValue) + writeMarshalUnmarshalCode(_out, key, "k__", false, false); + + string patcher; + if(hasClassValue) + { + patcher = "new Patcher__(" + getStaticId(value) + ", r__, k__)"; + } + else { _out << nl << valueS << " v__;"; @@ -5388,7 +5744,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) } } } - writeMarshalUnmarshalCode(_out, value, "v__", false, false, false, "r__, k__"); + writeMarshalUnmarshalCode(_out, value, hasClassValue ? patcher : "v__", false, false); if(!hasClassValue) { _out << nl << "r__[k__] = v__;"; @@ -5419,8 +5775,8 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) } _out << " e__ in v__)"; _out << sb; - writeMarshalUnmarshalCode(_out, key, keyArg, true, true, false); - writeMarshalUnmarshalCode(_out, value, valueArg, true, true, false); + writeMarshalUnmarshalCode(_out, key, keyArg, true, true); + writeMarshalUnmarshalCode(_out, value, valueArg, true, true); _out << eb; _out << eb; _out << eb; @@ -5444,7 +5800,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "k__ = null;"; } } - writeMarshalUnmarshalCode(_out, key, "k__", false, true, false); + writeMarshalUnmarshalCode(_out, key, "k__", false, true); if(!hasClassValue) { _out << nl << valueS << " v__;"; @@ -5461,7 +5817,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) } } } - writeMarshalUnmarshalCode(_out, value, "v__", false, true, false, "r__, k__"); + writeMarshalUnmarshalCode(_out, value, hasClassValue ? patcher : "v__", false, true); if(!hasClassValue) { _out << nl << "r__[k__] = v__;"; @@ -5541,7 +5897,7 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) OperationPtr op = *r; string opName = fixId(op->name(), DotNet::ICloneable, true); TypePtr ret = op->returnType(); - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); vector<string> params = getParams(op); _out << sp << nl << retS << ' ' << opName << spar << params @@ -5606,25 +5962,25 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) OperationPtr op = *r; string opName = fixId(op->name(), DotNet::ICloneable, true); TypePtr ret = op->returnType(); - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); - TypeStringList inParams; - TypeStringList outParams; ParamDeclList paramList = op->parameters(); - for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + ParamDeclList::const_iterator pli; + ParamDeclList inParams; + ParamDeclList outParams; + + for(pli = paramList.begin(); pli != paramList.end(); ++pli) { if((*pli)->isOutParam()) { - outParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + outParams.push_back(*pli); } else { - inParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + inParams.push_back(*pli); } } - TypeStringList::const_iterator q; - ExceptionList throws = op->throws(); throws.sort(); throws.unique(); @@ -5656,14 +6012,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl << "try"; _out << sb; _out << nl << "IceInternal.BasicStream os__ = og__.startWriteParams(" << opFormatTypeToString(op) << ");"; - for(q = inParams.begin(); q != inParams.end(); ++q) - { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false, false); - } - if(op->sendsClasses()) - { - _out << nl << "os__.writePendingObjects();"; - } + writeMarshalUnmarshalParams(inParams, 0, true); _out << nl << "og__.endWriteParams();"; _out << eb; _out << nl << "catch(Ice.LocalException ex__)"; @@ -5708,77 +6057,62 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) if(ret || !outParams.empty()) { _out << nl << "IceInternal.BasicStream is__ = og__.startReadParams();"; - for(q = outParams.begin(); q != outParams.end(); ++q) + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - string param = fixId(q->second); - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) + const bool isClass = isClassType((*pli)->type()); + + if(!(*pli)->optional() && !isClass) { - if(isValueType(q->first)) - { - _out << nl << param << " = new " << typeToString(q->first) << "();"; - } - else + StructPtr st = StructPtr::dynamicCast((*pli)->type()); + if(st) { - _out << nl << param << " = null;"; + string param = fixId((*pli)->name()); + string typeS = typeToString(st, (*pli)->optional()); + if(isValueType(st)) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } } } - writeMarshalUnmarshalCode(_out, q->first, param, false, false, true, ""); } if(ret) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) + string typeS = typeToString(ret, op->returnIsOptional()); + const bool isClass = isClassType(ret); + + _out << nl << typeS << " ret__;"; + + if(op->returnIsOptional()) { - _out << nl << retS << " ret__;"; - ContainedPtr contained = ContainedPtr::dynamicCast(ret); - string sliceId = contained ? contained->scoped() : string("::Ice::Object"); - _out << nl << "IceInternal.ParamPatcher<" << retS << "> ret___PP = new IceInternal.ParamPatcher<" - << retS << ">(\"" << sliceId << "\");"; - _out << nl << "is__.readObject(ret___PP);"; + BuiltinPtr b = BuiltinPtr::dynamicCast(ret); + if(!b || isClass) + { + _out << nl << "ret__ = new " << typeS << "();"; + } } - else + else if(!isClass) { - _out << nl << retS << " ret__;"; StructPtr st = StructPtr::dynamicCast(ret); if(st) { - if(isValueType(st)) + if(isValueType(ret)) { - _out << nl << "ret__ = new " << retS << "();"; + _out << nl << "ret__ = new " << typeS << "();"; } else { _out << nl << "ret__ = null;"; } } - writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true, ""); - } - } - if(op->returnsClasses()) - { - _out << nl << "is__.readPendingObjects();"; - for(q = outParams.begin(); q != outParams.end(); ++q) - { - string param = fixId(q->second); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) - { - string type = typeToString(q->first); - _out << nl << "try"; - _out << sb; - _out << nl << param << " = (" << type << ")" << param << "_PP.value;"; - _out << eb; - _out << nl << "catch(_System.InvalidCastException)"; - _out << sb; - _out << nl << param << " = null;"; - _out << nl << "IceInternal.Ex.throwUOE(" << param << "_PP.type(), " - << param << "_PP.value.ice_id());"; - _out << eb; - } } } + writeMarshalUnmarshalParams(outParams, op, false); _out << nl << "og__.endReadParams();"; + writePostUnmarshalParams(outParams, op); } else { @@ -5787,19 +6121,6 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) if(ret) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) - { - _out << nl << "try"; - _out << sb; - _out << nl << "ret__ = (" << retS << ")ret___PP.value;"; - _out << eb; - _out << nl << "catch(_System.InvalidCastException)"; - _out << sb; - _out << nl << "ret__ = null;"; - _out << nl << "IceInternal.Ex.throwUOE(ret___PP.type(), ret___PP.value.ice_id());"; - _out << eb; - } _out << nl << "return ret__;"; } _out << eb; @@ -5877,7 +6198,7 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) OperationPtr op = *r; string opName = fixId(op->name(), DotNet::ICloneable, true); TypePtr ret = op->returnType(); - string retS = typeToString(ret); + string retS = typeToString(ret, op->returnIsOptional()); ClassDefPtr containingClass = ClassDefPtr::dynamicCast(op->container()); ExceptionList throws = op->throws(); @@ -5914,7 +6235,6 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) << sliceModeToIceMode(op->sendMode()) << ", context__);"; - // // Create out holders and delArgs // @@ -5927,7 +6247,17 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) string arg = fixId((*q)->name()); if((*q)->isOutParam()) { - _out << nl << typeToString((*q)->type()) << " " << arg << "Holder__ = " << writeValue((*q)->type()) << ";"; + string typeS = typeToString((*q)->type(), (*q)->optional()); + _out << nl << typeS << " " << arg << "Holder__ = "; + if((*q)->optional()) + { + _out << "new " << typeS << "()"; + } + else + { + _out << writeValue((*q)->type()); + } + _out << ';'; outHolders.push_back(arg); arg = "out " + arg + "Holder__"; } @@ -5936,7 +6266,16 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) if(ret) { - _out << nl << retS << " result__ = " << writeValue(ret) << ";"; + _out << nl << retS << " result__ = "; + if(op->returnIsOptional()) + { + _out << "new " << retS << "()"; + } + else + { + _out << writeValue(ret); + } + _out << ';'; } if(!throws.empty()) @@ -5953,7 +6292,8 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) _out << eb; _out << nl << "catch(_System.InvalidCastException)"; _out << sb; - _out << nl << "throw new Ice.OperationNotExistException(current__.id, current__.facet, current__.operation);"; + _out << nl + << "throw new Ice.OperationNotExistException(current__.id, current__.facet, current__.operation);"; _out << eb; if(!throws.empty()) @@ -6119,7 +6459,8 @@ Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p) args = getArgs(*op); } - _out << sp << nl << "public " << typeToString(ret) << " " << opname << spar << params << epar; + string retS = typeToString(ret, (*op)->returnIsOptional()); + _out << sp << nl << "public " << retS << " " << opname << spar << params << epar; _out << sb << nl; if(ret) { @@ -6128,7 +6469,7 @@ Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p) _out << opname << spar << args << "Ice.ObjectImpl.defaultCurrent" << epar << ';'; _out << eb; - _out << sp << nl << "public abstract " << typeToString(ret) << " " << opname << spar << params; + _out << sp << nl << "public abstract " << retS << " " << opname << spar << params; if(!p->isLocal()) { _out << "Ice.Current current__"; @@ -6242,13 +6583,15 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) TypePtr ret = p->returnType(); - TypeStringList outParams; ParamDeclList paramList = p->parameters(); - for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + ParamDeclList::const_iterator pli; + ParamDeclList outParams; + + for(pli = paramList.begin(); pli != paramList.end(); ++pli) { if((*pli)->isOutParam()) { - outParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + outParams.push_back(*pli); } } @@ -6268,7 +6611,6 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) throws.sort(Slice::DerivedToBaseCompare()); #endif - TypeStringList::const_iterator q; _out << sp; emitGeneratedCodeAttribute(); _out << nl << "class " << classNameAMDI << '_' << name @@ -6288,20 +6630,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << nl << "try"; _out << sb; _out << nl << "IceInternal.BasicStream os__ = startWriteParams__(" << opFormatTypeToString(p) << ");"; - for(q = outParams.begin(); q != outParams.end(); ++q) - { - string typeS = typeToString(q->first); - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false, false); - } - if(ret) - { - string retS = typeToString(ret); - writeMarshalUnmarshalCode(_out, ret, "ret__", true, false, false); - } - if(p->returnsClasses()) - { - _out << nl << "os__.writePendingObjects();"; - } + writeMarshalUnmarshalParams(outParams, p, true); _out << nl << "endWriteParams__(true);"; _out << eb; _out << nl << "catch(Ice.LocalException ex__)"; diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h index 2c171a71e25..597bf5a11d4 100644 --- a/cpp/src/slice2cs/Gen.h +++ b/cpp/src/slice2cs/Gen.h @@ -24,6 +24,8 @@ public: protected: + void writeMarshalUnmarshalParams(const ParamDeclList&, const OperationPtr&, bool); + void writePostUnmarshalParams(const ParamDeclList&, const OperationPtr&); void writeMarshalDataMember(const DataMemberPtr&, const std::string&); void writeUnmarshalDataMember(const DataMemberPtr&, const std::string&, bool, int&); void writeStreamMarshalDataMember(const DataMemberPtr&, const std::string&); |