[hydra-commits] beagles: branch ice/preserve-graphs r633 - in /ice/branches/preserve-graphs: ...

SVN commits to the Hydra project hydra-commits at lists.digium.com
Mon May 24 11:06:52 CDT 2010


Author: beagles
Date: Mon May 24 11:06:51 2010
New Revision: 633

URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=633
Log:
fixed backwards test in object patcher generation and updated the C# translator

Added:
    ice/branches/preserve-graphs/cs/src/Ice/ObjectPatcher.cs   (with props)
    ice/branches/preserve-graphs/cs/src/Ice/SkippedSlice.cs   (with props)
Modified:
    ice/branches/preserve-graphs/cpp/include/Slice/CsUtil.h
    ice/branches/preserve-graphs/cpp/include/Slice/JavaUtil.h
    ice/branches/preserve-graphs/cpp/src/Slice/CsUtil.cpp
    ice/branches/preserve-graphs/cpp/src/Slice/JavaUtil.cpp
    ice/branches/preserve-graphs/cpp/src/slice2cs/Gen.cpp
    ice/branches/preserve-graphs/cpp/src/slice2java/Gen.cpp
    ice/branches/preserve-graphs/cs/src/Ice/.depend
    ice/branches/preserve-graphs/cs/src/Ice/.depend.mak
    ice/branches/preserve-graphs/cs/src/Ice/BasicStream.cs
    ice/branches/preserve-graphs/cs/src/Ice/Makefile
    ice/branches/preserve-graphs/cs/src/Ice/Makefile.mak
    ice/branches/preserve-graphs/cs/test/Ice/slicing/objects/AllTests.cs
    ice/branches/preserve-graphs/cs/test/Ice/slicing/objects/ClientPrivate.ice
    ice/branches/preserve-graphs/cs/test/Ice/slicing/objects/Server.cs
    ice/branches/preserve-graphs/cs/test/Ice/slicing/objects/ServerPrivate.ice
    ice/branches/preserve-graphs/cs/test/Ice/slicing/objects/Test.ice
    ice/branches/preserve-graphs/slice/Ice/Preserve.ice

Modified: ice/branches/preserve-graphs/cpp/include/Slice/CsUtil.h
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cpp/include/Slice/CsUtil.h?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cpp/include/Slice/CsUtil.h (original)
+++ ice/branches/preserve-graphs/cpp/include/Slice/CsUtil.h Mon May 24 11:06:51 2010
@@ -42,7 +42,7 @@
     // Generate code to marshal or unmarshal a type
     //
     void writeMarshalUnmarshalCode(::IceUtilInternal::Output&, const TypePtr&, const std::string&, bool, bool,
-                                   bool, const std::string& = "", bool = false);
+                                   bool, const std::string& = "", bool = false, bool = false);
     void writeSequenceMarshalUnmarshalCode(::IceUtilInternal::Output&, const SequencePtr&, const std::string&,
                                            bool, bool);
 

Modified: ice/branches/preserve-graphs/cpp/include/Slice/JavaUtil.h
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cpp/include/Slice/JavaUtil.h?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cpp/include/Slice/JavaUtil.h (original)
+++ ice/branches/preserve-graphs/cpp/include/Slice/JavaUtil.h Mon May 24 11:06:51 2010
@@ -127,7 +127,7 @@
     //
     void writeMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const TypePtr&, const std::string&,
                                    bool, int&, bool = false, const StringList& = StringList(),
-                                   const std::string& patchParams = "");
+                                   const std::string& patchParams = "", bool = false);
 
     //
     // Generate code to marshal or unmarshal a dictionary type.

Modified: ice/branches/preserve-graphs/cpp/src/Slice/CsUtil.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cpp/src/Slice/CsUtil.cpp?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cpp/src/Slice/CsUtil.cpp (original)
+++ ice/branches/preserve-graphs/cpp/src/Slice/CsUtil.cpp Mon May 24 11:06:51 2010
@@ -301,7 +301,8 @@
                                               bool streamingAPI,
                                               bool isOutParam,
                                               const string& patchParams,
-					      bool newAMI)
+					      bool newAMI,
+					      bool preserving)
 {
     string stream;
 
@@ -498,7 +499,21 @@
     {
         if(marshal)
         {
-            out << nl << stream << ".writeObject(" << param << ");";
+	    if(preserving)
+	    {
+		out << nl << "offset = new Ice.ObjectIdOffset();";
+		out << nl << "offset.offset = " << stream << ".getWriteSliceOffset();";
+		out << nl << "offset.id = ";
+	    }
+	    else
+	    {
+		out << nl;
+	    }
+            out << stream << ".writeObject(" << param << ");";
+	    if(preserving)
+	    {
+		out << nl << "offsetSeq.Add(offset);";
+	    }
         }
         else
         {

Modified: ice/branches/preserve-graphs/cpp/src/Slice/JavaUtil.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cpp/src/Slice/JavaUtil.cpp?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cpp/src/Slice/JavaUtil.cpp (original)
+++ ice/branches/preserve-graphs/cpp/src/Slice/JavaUtil.cpp Mon May 24 11:06:51 2010
@@ -654,7 +654,8 @@
                                                 int& iter,
                                                 bool holder,
                                                 const StringList& metaData,
-                                                const string& patchParams)
+                                                const string& patchParams,
+						bool preserving)
 {
     string stream = marshal ? "__os" : "__is";
     string v;
@@ -835,7 +836,21 @@
     {
         if(marshal)
         {
-            out << nl << stream << ".writeObject(" << v << ");";
+	    if(preserving)
+	    {
+		out << nl << "offset = new Ice.ObjectIdOffset();";
+		out << nl << "offset.offset = " << stream << ".getWriteSliceOffset();";
+		out << nl << "offset.id = ";
+	    }
+	    else
+	    {
+		out << nl;
+	    }
+            out << stream << ".writeObject(" << v << ");";
+	    if(preserving)
+	    {
+		out << nl << "offsetSeq.Add(offset);";
+	    }
         }
         else
         {

Modified: ice/branches/preserve-graphs/cpp/src/slice2cs/Gen.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cpp/src/slice2cs/Gen.cpp?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cpp/src/slice2cs/Gen.cpp (original)
+++ ice/branches/preserve-graphs/cpp/src/slice2cs/Gen.cpp Mon May 24 11:06:51 2010
@@ -693,40 +693,93 @@
 
     if(switchWrites)
     {
-	_out << sp << nl << "protected byte[] preserved__ = null;";
+	_out << sp << nl << "protected _System.Collections.Generic.List<Ice.SkippedSlice> preserved__ = null;";
+	_out << sp << nl << "protected _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> > objectIdMap__ = new _System.Collections.Generic.Dictionary<string, _System.Collections.Generic.List<Ice.ObjectIdOffset> >();";
+	_out << sp << nl << "protected _System.Collections.Generic.Dictionary<int, Ice.ObjectPatcher>  objectMap__ = new _System.Collections.Generic.Dictionary<int, Ice.ObjectPatcher>();";
     }
 
     _out << sp << nl << "public override void write__(IceInternal.BasicStream os__)";
     _out << sb;
     if(preserving)
     {
+	_out << nl << "_System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> > idMap = new _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> >();";
 	_out << nl << "if(preserved__ != null)";
 	_out << sb;
-	_out << nl << "os__.writeBlob(preserved__);";
+	_out << nl << "foreach(Ice.SkippedSlice i in preserved__)";
+	_out << sb;
+	_out << nl << "os__.writeTypeId(i.typeId);";
+	_out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> offsets;";
+	_out << nl << "if(objectIdMap__.TryGetValue(i.typeId, out offsets))";
+	_out << sb;
+	_out << nl << "byte[] blob = new byte[i.slice.Length];";
+	_out << nl << "i.slice.CopyTo(blob, 0);";
+	_out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> offsetSeq = new _System.Collections.Generic.List<Ice.ObjectIdOffset>();";
+	_out << nl << "foreach(Ice.ObjectIdOffset offs in offsets)";
+	_out << sb;
+	_out << nl << "Ice.ObjectPatcher preservedObject = objectMap__[offs.id];";
+	_out << nl << "if(preservedObject != null)";
+	_out << sb;
+	_out << nl << "Ice.ObjectIdOffset newId = new Ice.ObjectIdOffset();";
+	_out << nl << "newId.id = os__.addPendingObject(preservedObject.obj);";
+	_out << nl << "newId.offset = offs.offset;";
+	_out << nl << "offsetSeq.Add(newId);";
+	_out << nl << "Ice.SkippedSlice.updateObjectId(blob, newId.offset, -newId.id);"; 
 	_out << eb;
-	_out << nl << "writeImpl__(os__);";
+	_out << nl << "else";
+	_out << sb;
+	_out << nl << "throw new Ice.MarshalException(\"unable to locate preserved object\");";
+	_out << eb;
+	_out << eb;
+	_out << nl << "idMap.Add(i.typeId, offsetSeq);";
+	_out << nl << "os__.writeBlob(blob);"; 
+	_out << eb;
+	_out << nl << "else";
+	_out << sb;
+	_out << nl << "os__.writeBlob(i.slice);";
+	_out << eb;
+	_out << eb;
+	_out << eb;
+	_out << nl << "writeImpl__(os__, idMap);";
 	_out << eb;
 	if(switchWrites)
 	{
-	    _out << sp << nl << "public virtual void writeImpl__(IceInternal.BasicStream os__)";
+	    _out << sp << nl << "public virtual void writeImpl__(IceInternal.BasicStream os__, _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> >  idMap)";
 	}
 	else
 	{
-	    _out << sp << nl << "public override void writeImpl__(IceInternal.BasicStream os__)";
+	    _out << sp << nl << "public override void writeImpl__(IceInternal.BasicStream os__, _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> >  idMap)";
 	}
 	_out << sb;
     }
     _out << nl << "os__.writeTypeId(ice_staticId());";
     _out << nl << "os__.startWriteSlice();";
+    bool genOffsets = preserving && !members.empty();
+    if(genOffsets)
+    {
+	_out << nl << "Ice.ObjectIdOffset offset;";
+	_out << nl << "offset.id = 0;";
+	_out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> offsetSeq = new _System.Collections.Generic.List<Ice.ObjectIdOffset>();";
+    }
     for(d = members.begin(); d != members.end(); ++d)
     {
         writeMarshalUnmarshalCode(_out, (*d)->type(), fixId(*d, DotNet::ICloneable, true),
                                   true, false, false);
     }
+    if(genOffsets)
+    {
+	_out << nl << "if(offsetSeq.Count > 0)";
+	_out << sb;
+	_out << nl << "idMap.Add(ice_staticId(), offsetSeq);";
+	_out << eb;
+    }
+    if(switchWrites)
+    {
+	_out << nl << "Ice.ObjectIdMapHelper.write(os__, idMap);";
+    }
     _out << nl << "os__.endWriteSlice();";
     if(preserving && !switchWrites)
     {
-	_out << nl << "base.writeImpl__(os__);";
+	_out << nl << "base.writeImpl__(os__, idMap);";
     }
     else
     {
@@ -837,7 +890,31 @@
         writeMarshalUnmarshalCode(_out, (*d)->type(), fixId(*d, DotNet::ICloneable, true),
                                   false, false, false, patchParams.str());
     }
+    if(switchWrites)
+    {
+	_out << nl << "objectIdMap__ = Ice.ObjectIdMapHelper.read(is__);";
+    }
     _out << nl << "is__.endReadSlice();";
+    if(switchWrites)
+    {
+	_out << nl << "foreach(Ice.SkippedSlice i in preserved__)";
+	_out << sb;
+	_out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> objs;"; 
+	_out << nl << "if(objectIdMap__.TryGetValue(i.typeId, out objs))";
+	_out << sb;
+	_out << nl << "foreach(Ice.ObjectIdOffset offset in objs)";
+	_out << sb;
+	_out << nl << "Ice.ObjectPatcher mappedObj;";
+	_out << nl << "if(!objectMap__.TryGetValue(offset.id, out mappedObj))";
+	_out << sb;
+	_out << nl << "Ice.ObjectPatcher patcher = new Ice.ObjectPatcher();";
+	_out << nl << "objectMap__.Add(offset.id, patcher);";
+	_out << nl << "is__.addPreservedPatcher(patcher, offset.id);";
+	_out << eb;
+	_out << eb;
+	_out << eb;
+	_out << eb;
+    }
     _out << nl << "base.read__(is__, true);";
     _out << eb;
 
@@ -2762,7 +2839,9 @@
 
 	if(switchWrites)
 	{
-	    _out << sp << nl << "protected byte[] preserved__ = null;";
+	    _out << sp << nl << "protected _System.Collections.Generic.List<Ice.SkippedSlice> preserved__ = null;";
+	    _out << sp << nl << "protected _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> > objectIdMap__ = new _System.Collections.Generic.Dictionary<string, _System.Collections.Generic.List<Ice.ObjectIdOffset> >();";
+	    _out << sp << nl << "protected _System.Collections.Generic.Dictionary<int, Ice.ObjectPatcher>  objectMap__ = new _System.Collections.Generic.Dictionary<int, Ice.ObjectPatcher>();";
 	}
 
         string scoped = p->scoped();
@@ -2772,35 +2851,86 @@
         _out << sb;
 	if(preserving)
 	{
+	    _out << nl << "_System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> > idMap = new _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> >(); ";
 	    _out << nl << "if(preserved__ != null)";
 	    _out << sb;
-	    _out << nl << "os__.writeBlob(preserved__);";
+	    _out << nl << "foreach(Ice.SkippedSlice i in preserved__)";
+	    _out << sb;
+	    _out << nl << "os__.writeTypeId(i.typeId);";
+	    _out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> offsets;";
+	    _out << nl << "if(objectIdMap__.TryGetValue(i.typeId, out offsets))";
+	    _out << sb;
+	    _out << nl << "byte[] blob = new byte[i.slice.Length];";
+	    _out << nl << "i.slice.CopyTo(blob, 0);";
+	    _out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> offsetSeq = new _System.Collections.Generic.List<Ice.ObjectIdOffset>();";
+	    _out << nl << "foreach(Ice.ObjectIdOffset offs in offsets)";
+	    _out << sb;
+	    _out << nl << "Ice.ObjectPatcher preservedObject = objectMap__[offs.id];";
+	    _out << nl << "if(preservedObject != null)";
+	    _out << sb;
+	    _out << nl << "Ice.ObjectIdOffset newId = new Ice.ObjectIdOffset();";
+	    _out << nl << "newId.id = os__.addPendingObject(preservedObject.obj);";
+	    _out << nl << "newId.offset = offs.offset;";
+	    _out << nl << "offsetSeq.Add(newId);";
+	    _out << nl << "Ice.SkippedSlice.updateObjectId(blob, newId.offset, -newId.id);"; 
 	    _out << eb;
-	    _out << nl << "writeImpl__(os__);";
+	    _out << nl << "else";
+	    _out << sb;
+	    _out << nl << "throw new Ice.MarshalException(\"unable to locate preserved object\");";
+	    _out << eb;
+	    _out << eb;
+	    _out << nl << "idMap.put(i.typeId, offsetSeq);";
+	    _out << nl << "os__.writeBlob(blob);"; 
+	    _out << eb;
+	    _out << nl << "else";
+	    _out << sb;
+	    _out << nl << "os__.writeBlob(i.slice);";
+	    _out << eb;
+	    _out << eb;
+	    _out << eb;
+	    _out << nl << "writeImpl__(os__, idMap);";
 	    _out << eb;
 	    if(switchWrites)
 	    {
-		_out << sp << nl << "public virtual void writeImpl__(IceInternal.BasicStream os__)";
+		_out << sp << nl << "public virtual void writeImpl__(IceInternal.BasicStream os__, _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> >  idMap)";
 	    }
 	    else
 	    {
-		_out << sp << nl << "public override void writeImpl__(IceInternal.BasicStream os__)";
+		_out << sp << nl << "public override void writeImpl__(IceInternal.BasicStream os__, _System.Collections.Generic.Dictionary<string,  _System.Collections.Generic.List<Ice.ObjectIdOffset> > idMap)";
 	    }
 	    _out << sb;
 	}
         _out << nl << "os__.writeString(\"" << scoped << "\");";
         _out << nl << "os__.startWriteSlice();";
+	bool genOffsets = preserving && !dataMembers.empty();
+	if(genOffsets)
+	{
+	    _out << nl << "Ice.ObjectIdOffset offset;";
+	    _out << nl << "offset.id = 0;";
+	    _out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> offsetSeq = _System.Collections.Generic.new List<Ice.ObjectIdOffset>();";
+	}
         for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
         {
             writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, DotNet::Exception),
                                       true, false, false);
         }
+	if(genOffsets)
+	{
+	    _out << nl << "if(offsetSeq.Count > 0)";
+	    _out << sb;
+	    _out << nl << "idMap.put(ice_staticId(), offsetSeq);";
+	    _out << eb;
+	}
+	if(switchWrites)
+	{
+	    _out << nl << "Ice.ObjectIdMapHelper.write(os__, idMap);";
+	}
         _out << nl << "os__.endWriteSlice();";
         if(base)
         {
 	    if(preserving && !switchWrites)
 	    {
-		_out << nl << "base.writeImpl__(os__);";
+		_out << nl << "base.writeImpl__(os__, idMap);";
 	    }
 	    else
 	    {
@@ -2915,7 +3045,31 @@
             writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name(), DotNet::Exception),
                                       false, false, false, patchParams.str());
         }
+	if(switchWrites)
+	{
+	    _out << nl << "objectIdMap__ = Ice.ObjectIdMap.read(is__);";
+	}
         _out << nl << "is__.endReadSlice();";
+	if(switchWrites)
+	{
+	    _out << nl << "foreach(Ice.SkippedSlice i in preserved__)";
+	    _out << sb;
+	    _out << nl << "_System.Collections.Generic.List<Ice.ObjectIdOffset> objs;"; 
+	    _out << nl << "if(objectIdMap__.TryGetValue(i.typeId, out objs))";
+	    _out << sb;
+	    _out << nl << "foreach(Ice.ObjectIdOffset offset in objs)";
+	    _out << sb;
+	    _out << nl << "Ice.ObjectPatcher mappedObj;";
+	    _out << nl << "if(!objectMap.TryGetValue(offset.id, out mappedObj)))";
+	    _out << sb;
+	    _out << nl << "Ice.ObjectPatcher patcher = new Ice.ObjectPatcher();";
+	    _out << nl << "objectMap__.Add(offset.id, patcher);";
+	    _out << nl << "is__.addPreservedPatcher(patcher, offset.id);";
+	    _out << eb;
+	    _out << eb;
+	    _out << eb;
+	    _out << eb;
+	}
         if(base)
         {
             _out << nl << "base.read__(is__, true);";

Modified: ice/branches/preserve-graphs/cpp/src/slice2java/Gen.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cpp/src/slice2java/Gen.cpp?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cpp/src/slice2java/Gen.cpp (original)
+++ ice/branches/preserve-graphs/cpp/src/slice2java/Gen.cpp Mon May 24 11:06:51 2010
@@ -1048,34 +1048,86 @@
     }
     if(switchWrites)
     {
-	out << sp << nl << "protected byte[] __preserved = null;";
+	out << sp << nl << "protected java.util.List<Ice.SkippedSlice>  __preserved = null;";
+	out << sp << nl << "protected java.util.Map<String, java.util.List<Ice.ObjectIdOffset> > __objectIdMap = new java.util.HashMap<String, java.util.List<Ice.ObjectIdOffset>>();";
+	out << sp << nl << "protected java.util.Map<Integer, Ice.ObjectPatcher> __objectMap = new java.util.HashMap<Integer, Ice.ObjectPatcher>();";
     }
 
     out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)";
     out << sb;
     if(preserving)
     {
+	out << nl << "java.util.Map<String, java.util.List<Ice.ObjectIdOffset>> idMap = new java.util.HashMap<String, java.util.List<Ice.ObjectIdOffset>>();";
 	out << nl << "if(__preserved != null)";
 	out << sb;
-	out << nl << "__os.writeBlob(__preserved);";
+	out << nl << "for(Ice.SkippedSlice i : __preserved)";
+	out << sb;
+	out << nl << "__os.writeTypeId(i.typeId);";
+	out << nl << "java.util.List<Ice.ObjectIdOffset> offsets = __objectIdMap.get(i.typeId);";
+	out << nl << "if(offsets != null)";
+	out << sb;
+	out << nl << "byte[] blob = new byte[i.slice.length];";
+	out << nl << "java.lang.System.arraycopy(i.slice, 0, blob, 0, i.slice.length);";
+	out << nl << "java.util.List<Ice.ObjectIdOffset> offsetSeq = new java.util.ArrayList<Ice.ObjectIdOffset>();";
+	out << nl << "for(Ice.ObjectIdOffset offs : offsets)";
+	out << sb;
+	out << nl << "Ice.ObjectPatcher preservedObject = __objectMap.get(offs.id);";
+	out << nl << "if(preservedObject != null)";
+	out << sb;
+	out << nl << "Ice.ObjectIdOffset newId = new Ice.ObjectIdOffset();";
+	out << nl << "newId.id = __os.addPendingObject(preservedObject.obj);";
+	out << nl << "newId.offset = offs.offset;";
+	out << nl << "offsetSeq.add(newId);";
+	out << nl << "Ice.SkippedSlice.updateObjectId(blob, newId.offset, -newId.id);";
 	out << eb;
-	out << nl << "__writeImpl(__os);";
+	out << nl << "else";
+	out << sb;
+	out << nl << "throw new Ice.MarshalException(\"unable to locate preserved object\");";
 	out << eb;
-	out << sp << nl << "public void" << nl << "__writeImpl(IceInternal.BasicStream __os)";
+	out << eb;
+	out << nl << "idMap.put(i.typeId, offsetSeq);";
+	out << nl << "__os.writeBlob(blob);";
+	out << eb;
+	out << nl << "else";
+	out << sb;
+	out << nl << "__os.writeBlob(i.slice);";
+	out << eb;
+	out << eb;
+	out << eb;
+	out << nl << "__writeImpl(__os, idMap);";
+	out << eb;
+	out << sp << nl << "public void" << nl << "__writeImpl(IceInternal.BasicStream __os, java.util.Map<String, java.util.List<Ice.ObjectIdOffset>> idMap)";
 	out << sb;
     }
     out << nl << "__os.writeTypeId(ice_staticId());";
     out << nl << "__os.startWriteSlice();";
+    bool genOffsets = preserving && !members.empty();
+    if(genOffsets)
+    {
+	out << nl << "Ice.ObjectIdOffset offset = null;";
+	out << nl << "java.util.List<Ice.ObjectIdOffset> offsetSeq = new java.util.ArrayList<Ice.ObjectIdOffset>();";
+    }
     iter = 0;
     for(d = members.begin(); d != members.end(); ++d)
     {
         StringList metaData = (*d)->getMetaData();
         writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), true, iter, false, metaData);
     }
+    if(genOffsets)
+    {
+	out << nl << "if(offsetSeq.size() > 0)";
+	out << sb;
+	out << nl << "idMap.put(ice_staticId(), offsetSeq);";
+	out << eb;
+    }
+    if(switchWrites)
+    {
+	out << nl << "Ice.ObjectIdMapHelper.write(__os, idMap);";
+    }
     out << nl << "__os.endWriteSlice();";
     if(preserving && !switchWrites)
     {
-	out << nl << "super.__writeImpl(__os);";
+	out << nl << "super.__writeImpl(__os, idMap);";
     }
     else 
     {
@@ -1202,7 +1254,31 @@
         writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), false, iter, false, metaData,
                                   patchParams.str());
     }
+    if(switchWrites)
+    {
+	out << nl << "__objectIdMap = Ice.ObjectIdMapHelper.read(__is);";
+    }
     out << nl << "__is.endReadSlice();";
+    if(switchWrites)
+    {
+	out << nl << "for(Ice.SkippedSlice i : __preserved)";
+	out << sb;
+	out << nl << "java.util.List<Ice.ObjectIdOffset> objs = __objectIdMap.get(i.typeId);";
+	out << nl << "if(objs != null)";
+	out << sb;
+	out << nl << "for(Ice.ObjectIdOffset offset : objs)";
+	out << sb;
+	out << nl << "Ice.ObjectPatcher mappedObj = __objectMap.get(offset.id);";
+	out << nl << "if(mappedObj == null)";
+	out << sb;
+	out << nl << "Ice.ObjectPatcher patcher = new Ice.ObjectPatcher();";
+	out << nl << "__objectMap.put(offset.id, patcher);";
+	out << nl << "__is.addPreservedPatcher(patcher, offset.id);";
+	out << eb;
+	out << eb;
+	out << eb;
+	out << eb;
+    }
     out << nl << "super.__read(__is, true);";
     out << eb;
 
@@ -2712,39 +2788,88 @@
 
 	if(switchWrites)
 	{
-	    out << sp << nl << "protected byte[] __preserved = null;";
+	    out << sp << nl << "protected java.util.ArrayList<Ice.SkippedSlice>  __preserved = null;";
+	    out << sp << nl << "protected java.util.Map<String, java.util.List<Ice.ObjectIdOffset> > __objectIdMap = new java.util.HashMap<String, java.util.List<Ice.ObjectIdOffset>>();";
+	    out << sp << nl << "protected java.util.Map<Integer, Ice.ObjectPatcher> __objectMap = new java.util.HashMap<Integer, Ice.ObjectPatcher>();";
 	}
 
         out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)";
         out << sb;
 	if(preserving)
 	{
-	    out << nl << "System.err.println(\"modded write called\");";
-	    out << nl << "System.err.flush();";
+	    out << nl << "java.util.Map<String, java.util.List<Ice.ObjectIdOffset>> idMap = new java.util.HashMap<String, java.util.List<Ice.ObjectIdOffset>>();";
 	    out << nl << "if(__preserved != null)";
 	    out << sb;
-	    out << nl << "__os.writeBlob(__preserved);";
+	    out << nl << "for(Ice.SkippedSlice i : __preserved)";
+	    out << sb;
+	    out << nl << "__os.writeTypeId(i.typeId);";
+	    out << nl << "java.util.List<Ice.ObjectIdOffset> offsets = __objectIdMap.get(i.typeId);";
+	    out << nl << "if(offsets != null)";
+	    out << sb;
+	    out << nl << "byte[] blob = new byte[i.slice.length];";
+	    out << nl << "java.lang.System.arraycopy(i.slice, 0, blob, 0, i.slice.length);";
+	    out << nl << "java.util.List<Ice.ObjectIdOffset> offsetSeq = new java.util.ArrayList<Ice.ObjectIdOffset>();";
+	    out << nl << "for(Ice.ObjectIdOffset offs : offsets)";
+	    out << sb;
+	    out << nl << "Ice.ObjectPatcher preservedObject = __objectMap.get(offs.id);";
+	    out << nl << "if(preservedObject != null)";
+	    out << sb;
+	    out << nl << "Ice.ObjectIdOffset newId = new Ice.ObjectIdOffset();";
+	    out << nl << "newId.id = __os.addPendingObject(preservedObject.obj);";
+	    out << nl << "newId.offset = offs.offset;";
+	    out << nl << "offsetSeq.add(newId);";
+	    out << nl << "Ice.SkippedSlice.updateObjectId(blob, newId.offset, -newId.id);";
 	    out << eb;
-	    out << nl << "__writeImpl(__os);";
+	    out << nl << "else";
+	    out << sb;
+	    out << nl << "throw new Ice.MarshalException(\"unable to locate preserved object\");";
 	    out << eb;
-
-	    out << sp << nl << "public void" << nl << "__writeImpl(IceInternal.BasicStream __os)";
+	    out << eb;
+	    out << nl << "idMap.put(i.typeId, offsetSeq);";
+	    out << nl << "__os.writeBlob(blob);";
+	    out << eb;
+	    out << nl << "else";
+	    out << sb;
+	    out << nl << "__os.writeBlob(i.slice);";
+	    out << eb;
+	    out << eb;
+	    out << eb;
+	    out << nl << "__writeImpl(__os, idMap);";
+	    out << eb;
+	    out << sp << nl << "public void" << nl << "__writeImpl(IceInternal.BasicStream __os, java.util.HashMap<String, java.util.ArrayList<Ice.ObjectIdOffset>> idMap)";
 	    out << sb;
 	}
         out << nl << "__os.writeString(\"" << scoped << "\");";
         out << nl << "__os.startWriteSlice();";
+	bool genOffsets = preserving && !members.empty();
+	if(genOffsets)
+	{
+	    out << nl << "Ice.ObjectIdOffset offset = null;";
+	    out << nl << "java.util.List<Ice.ObjectIdOffset> offsetSeq = new java.util.ArrayList<Ice.ObjectIdOffset>();";
+	}
         iter = 0;
         for(d = members.begin(); d != members.end(); ++d)
         {
             StringList metaData = (*d)->getMetaData();
             writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), true, iter, false, metaData);
         }
+	if(genOffsets)
+	{
+	    out << nl << "if(offsetSeq.size() > 0)";
+	    out << sb;
+	    out << nl << "idMap.put(ice_staticId(), offsetSeq);";
+	    out << eb;
+	}
+	if(switchWrites)
+	{
+	    out << nl << "Ice.ObjectIdMapHelper.write(__os, idMap);";
+	}
         out << nl << "__os.endWriteSlice();";
         if(base)
         {
 	    if(preserving && !switchWrites)
 	    {
-		out << nl << "super.__writeImpl(__os);";
+		out << nl << "super.__writeImpl(__os, idMap);";
 	    }
 	    else
 	    {
@@ -2845,8 +2970,6 @@
 	{
 	    out << nl << "if(__preserved == null)";
 	    out << sb;
-	    out << nl << "System.err.println(\"modded read called\");";
-	    out << nl << "System.err.flush();";
 	    out << nl << "__preserved = __is.getSkippedSlices();";
 	    out << eb;
 	}
@@ -2873,7 +2996,31 @@
             writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), false, iter, false, metaData,
                                       patchParams.str());
         }
+	if(switchWrites)
+	{
+	    out << nl << "__objectIdMap = Ice.ObjectIdMapHelper.read(__is);";
+	}
         out << nl << "__is.endReadSlice();";
+	if(switchWrites)
+	{
+	    out << nl << "for(Ice.SkippedSlice i : __preserved)";
+	    out << sb;
+	    out << nl << "java.util.ArrayList<Ice.ObjectIdOffset> objs = __objectIdMap.get(i.typeId);";
+	    out << nl << "if(objs != null)";
+	    out << sb;
+	    out << nl << "for(Ice.ObjectIdOffset offset : objs)";
+	    out << sb;
+	    out << nl << "Ice.ObjectPatcher mappedObj = __objectMap.get(offset.id);";
+	    out << nl << "if(mappedObj == null)";
+	    out << sb;
+	    out << nl << "Ice.ObjectPatcher patcher = new Ice.ObjectPatcher();";
+	    out << nl << "__objectMap.put(offset.id, patcher);";
+	    out << nl << "__is.addPreservedPatcher(patcher, offset.id);";
+	    out << eb;
+	    out << eb;
+	    out << eb;
+	    out << eb;
+	}
         if(base)
         {
             out << nl << "super.__read(__is, true);";

Modified: ice/branches/preserve-graphs/cs/src/Ice/.depend
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cs/src/Ice/.depend?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cs/src/Ice/.depend (original)
+++ ice/branches/preserve-graphs/cs/src/Ice/.depend Mon May 24 11:06:51 2010
@@ -2,6 +2,7 @@
 generated/Communicator.cs: $(slicedir)/Ice/Communicator.ice $(slicedir)/Ice/LoggerF.ice $(slicedir)/Ice/StatsF.ice $(slicedir)/Ice/ObjectAdapterF.ice $(slicedir)/Ice/ObjectFactoryF.ice $(slicedir)/Ice/RouterF.ice $(slicedir)/Ice/LocatorF.ice $(slicedir)/Ice/PluginF.ice $(slicedir)/Ice/ImplicitContextF.ice $(slicedir)/Ice/Current.ice $(slicedir)/Ice/ConnectionF.ice $(slicedir)/Ice/Identity.ice $(slicedir)/Ice/Properties.ice $(slicedir)/Ice/BuiltinSequences.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Connection.cs: $(slicedir)/Ice/Connection.ice $(slicedir)/Ice/ObjectAdapterF.ice $(slicedir)/Ice/Identity.ice $(slicedir)/Ice/Endpoint.ice $(slicedir)/Ice/BuiltinSequences.ice $(slicedir)/Ice/EndpointF.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Current.cs: $(slicedir)/Ice/Current.ice $(slicedir)/Ice/ObjectAdapterF.ice $(slicedir)/Ice/ConnectionF.ice $(slicedir)/Ice/Identity.ice $(SLICE2CS) $(SLICEPARSERLIB)
+generated/Preserve.cs: $(slicedir)/Ice/Preserve.ice $(slicedir)/Ice/BuiltinSequences.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Endpoint.cs: $(slicedir)/Ice/Endpoint.ice $(slicedir)/Ice/BuiltinSequences.ice $(slicedir)/Ice/EndpointF.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/EndpointTypes.cs: $(slicedir)/Ice/EndpointTypes.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/FacetMap.cs: $(slicedir)/Ice/FacetMap.ice $(SLICE2CS) $(SLICEPARSERLIB)
@@ -13,6 +14,7 @@
 generated/ObjectAdapter.cs: $(slicedir)/Ice/ObjectAdapter.ice $(slicedir)/Ice/CommunicatorF.ice $(slicedir)/Ice/ServantLocatorF.ice $(slicedir)/Ice/LocatorF.ice $(slicedir)/Ice/Identity.ice $(slicedir)/Ice/FacetMap.ice $(slicedir)/Ice/Endpoint.ice $(slicedir)/Ice/BuiltinSequences.ice $(slicedir)/Ice/EndpointF.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/ObjectFactory.cs: $(slicedir)/Ice/ObjectFactory.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Plugin.cs: $(slicedir)/Ice/Plugin.ice $(slicedir)/Ice/LoggerF.ice $(slicedir)/Ice/BuiltinSequences.ice $(SLICE2CS) $(SLICEPARSERLIB)
+generated/Preserve.cs: $(slicedir)/Ice/Preserve.ice $(slicedir)/Ice/BuiltinSequences.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Process.cs: $(slicedir)/Ice/Process.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Properties.cs: $(slicedir)/Ice/Properties.ice $(slicedir)/Ice/BuiltinSequences.ice $(SLICE2CS) $(SLICEPARSERLIB)
 generated/Router.cs: $(slicedir)/Ice/Router.ice $(slicedir)/Ice/BuiltinSequences.ice $(SLICE2CS) $(SLICEPARSERLIB)

Modified: ice/branches/preserve-graphs/cs/src/Ice/.depend.mak
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cs/src/Ice/.depend.mak?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cs/src/Ice/.depend.mak (original)
+++ ice/branches/preserve-graphs/cs/src/Ice/.depend.mak Mon May 24 11:06:51 2010
@@ -2,6 +2,7 @@
 generated/Communicator.cs: "$(slicedir)/Ice/Communicator.ice" "$(slicedir)/Ice/LoggerF.ice" "$(slicedir)/Ice/StatsF.ice" "$(slicedir)/Ice/ObjectAdapterF.ice" "$(slicedir)/Ice/ObjectFactoryF.ice" "$(slicedir)/Ice/RouterF.ice" "$(slicedir)/Ice/LocatorF.ice" "$(slicedir)/Ice/PluginF.ice" "$(slicedir)/Ice/ImplicitContextF.ice" "$(slicedir)/Ice/Current.ice" "$(slicedir)/Ice/ConnectionF.ice" "$(slicedir)/Ice/Identity.ice" "$(slicedir)/Ice/Properties.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Connection.cs: "$(slicedir)/Ice/Connection.ice" "$(slicedir)/Ice/ObjectAdapterF.ice" "$(slicedir)/Ice/Identity.ice" "$(slicedir)/Ice/Endpoint.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(slicedir)/Ice/EndpointF.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Current.cs: "$(slicedir)/Ice/Current.ice" "$(slicedir)/Ice/ObjectAdapterF.ice" "$(slicedir)/Ice/ConnectionF.ice" "$(slicedir)/Ice/Identity.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
+generated/Preserve.cs: "$(slicedir)/Ice/Preserve.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Endpoint.cs: "$(slicedir)/Ice/Endpoint.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(slicedir)/Ice/EndpointF.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/EndpointTypes.cs: "$(slicedir)/Ice/EndpointTypes.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/FacetMap.cs: "$(slicedir)/Ice/FacetMap.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
@@ -13,6 +14,7 @@
 generated/ObjectAdapter.cs: "$(slicedir)/Ice/ObjectAdapter.ice" "$(slicedir)/Ice/CommunicatorF.ice" "$(slicedir)/Ice/ServantLocatorF.ice" "$(slicedir)/Ice/LocatorF.ice" "$(slicedir)/Ice/Identity.ice" "$(slicedir)/Ice/FacetMap.ice" "$(slicedir)/Ice/Endpoint.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(slicedir)/Ice/EndpointF.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/ObjectFactory.cs: "$(slicedir)/Ice/ObjectFactory.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Plugin.cs: "$(slicedir)/Ice/Plugin.ice" "$(slicedir)/Ice/LoggerF.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
+generated/Preserve.cs: "$(slicedir)/Ice/Preserve.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Process.cs: "$(slicedir)/Ice/Process.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Properties.cs: "$(slicedir)/Ice/Properties.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"
 generated/Router.cs: "$(slicedir)/Ice/Router.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CS)" "$(SLICEPARSERLIB)"

Modified: ice/branches/preserve-graphs/cs/src/Ice/BasicStream.cs
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/cs/src/Ice/BasicStream.cs?view=diff&rev=633&r1=632&r2=633
==============================================================================
--- ice/branches/preserve-graphs/cs/src/Ice/BasicStream.cs (original)
+++ ice/branches/preserve-graphs/cs/src/Ice/BasicStream.cs Mon May 24 11:06:51 2010
@@ -464,6 +464,15 @@
             _buf.b.putInt(_writeSlice - 4, sz);
         }
 
+	public virtual int getWriteSliceOffset()
+	{
+	    if(_buf.size() < _writeSlice)
+	    {
+		throw new Ice.MarshalException("slice offsets are only valid within slices"); 
+	    }
+	    return _buf.size() - _writeSlice + 4;
+	}
+
         public virtual void startReadSlice()
         {
             int sz = readInt();
@@ -494,6 +503,21 @@
                 throw new Ice.UnmarshalOutOfBoundsException(ex);
             }
         }
+
+	public virtual void skipSlice(string typeId)
+	{
+	   Ice.SkippedSlice newSlice = new Ice.SkippedSlice { typeId = typeId };
+	   skipSlice();
+	   if(_currentObjectStart < _buf.b.position())
+	   {
+	       newSlice.slice = _buf.b.toArray(_currentObjectStart, _buf.b.position() - _currentObjectStart);
+	   }
+	   if(_skippedSlices == null)
+	   {
+	       _skippedSlices = new List<Ice.SkippedSlice>();
+	   }
+	   _skippedSlices.Add(newSlice);
+	}
 
         public int readAndCheckSeqSize(int minSize)
         {
@@ -648,22 +672,9 @@
             _buf.b.put(v);
         }
 
-	public virtual byte[] getSkippedSlices()
+	public virtual List<Ice.SkippedSlice> getSkippedSlices()
 	{
-	    if(_currentObjectStart < _currentSliceStart)
-	    {
-		byte[] result;
-		try
-		{
-		    result = _buf.b.toArray(_currentObjectStart, _currentSliceStart - _currentObjectStart);
-		}
-		finally
-		{
-		}
-
-		return result;
-	    }
-	    return null;
+	    return _skippedSlices;
 	}
 
         public virtual void readBlob(byte[] v)
@@ -2040,7 +2051,7 @@
             return instance_.proxyFactory().streamToProxy(this);
         }
 
-        public virtual void writeObject(Ice.Object v)
+        public virtual int writeObject(Ice.Object v)
         {
             if(_writeEncapsStack == null) // Lazy initialization
             {
@@ -2086,11 +2097,13 @@
                     p = q;
                 }
                 writeInt(-((int)p));
+		return (int)p;
             }
             else
             {
                 writeInt(0); // Write null reference
             }
+	    return 0;
         }
 
         public virtual void readObject(IPatcher patcher)
@@ -2156,8 +2169,9 @@
                 throw new Ice.MarshalException("Invalid class instance index");
             }
 
-	    _currentObjectStart = _currentSliceStart = _buf.b.position();
             string mostDerivedId = readTypeId();
+	    _skippedSlices.Clear();
+	    _currentObjectStart = _buf.b.position();
             string id = mostDerivedId;
 
             while(true)
@@ -2228,9 +2242,9 @@
                         {
                             TraceUtil.traceSlicing("class", id, _slicingCat, instance_.initializationData().logger);
                         }
-                        skipSlice(); // Slice off this derived part -- we don't understand it.
-			_currentSliceStart = _buf.b.position();
+                        skipSlice(id); // Slice off this derived part -- we don't understand it.
                         id = readTypeId(); // Read next id for next iteration.
+			_currentObjectStart = _buf.b.position();
                         continue;
                     }
                     else
@@ -2275,9 +2289,10 @@
         {
             bool usesClasses = readBool();
 
-	    _currentObjectStart = _currentSliceStart = _buf.b.position();
             string id = readString();
+	    _currentObjectStart = _buf.b.position();
             string origId = id;
+	    _skippedSlices.Clear();
 
             for(;;)
             {
@@ -2323,12 +2338,12 @@
                         TraceUtil.traceSlicing("exception", id, _slicingCat, instance_.initializationData().logger);
                     }
 
-                    skipSlice(); // Slice off what we don't understand.
-		    _currentSliceStart = _buf.b.position();
+                    skipSlice(id); // Slice off what we don't understand.
 
                     try
                     {
                         id = readString(); // Read type id for next slice.
+			_currentObjectStart = _buf.b.position();
                     }
                     catch(Ice.UnmarshalOutOfBoundsException ex)
                     {
@@ -2439,6 +2454,105 @@
         {
             _sliceObjects = b;
         }
+
+	public void addPreservedPatcher(IPatcher patcher, int index)
+	{
+            if(_readEncapsStack == null) // Lazy initialization
+            {
+                _readEncapsStack = _readEncapsCache;
+                if(_readEncapsStack != null)
+                {
+                    _readEncapsCache = _readEncapsCache.next;
+                }
+                else
+                {
+                    _readEncapsStack = new ReadEncaps();
+                }
+            }
+

[... 396 lines stripped ...]




More information about the asterisk-scf-commits mailing list