Переглянути джерело

* Identity.cs: Added support for dynamic properties.
* ObjRef.cs: Removed some [MonoTODO]
* TypeInfo.cs: Added support for interfaces.
* RemotingServices.cs: Several fixes to support interfaces in proxies.

svn path=/trunk/mcs/; revision=12714

Lluis Sanchez 23 роки тому
батько
коміт
a82c3d48b6

+ 7 - 0
mcs/class/corlib/System.Runtime.Remoting/ChangeLog

@@ -1,3 +1,10 @@
+2003-03-20  Lluis Sanchez Gual <[email protected]>
+
+	* Identity.cs: Added support for dynamic properties.
+	* ObjRef.cs: Removed some [MonoTODO]
+	* TypeInfo.cs: Added support for interfaces.
+	* RemotingServices.cs: Several fixes to support interfaces in proxies.
+
 2003-03-15  Lluis Sanchez Gual <[email protected]>
 
 	* RemotingServices.cs: fixes bugs #39380 and #39331.

+ 41 - 0
mcs/class/corlib/System.Runtime.Remoting/Identity.cs

@@ -31,6 +31,9 @@ namespace System.Runtime.Remoting
 
 		protected IMessageSink _envoySink = null;
 
+		DynamicPropertyCollection _clientDynamicProperties;
+		DynamicPropertyCollection _serverDynamicProperties;
+
 		// The ObjRef 
 		protected ObjRef _objRef;
 
@@ -76,6 +79,44 @@ namespace System.Runtime.Remoting
 		{
 			get { return _objectUri != null; }
 		}
+
+		public DynamicPropertyCollection ClientDynamicProperties
+		{
+			get { 
+				if (_clientDynamicProperties == null) _clientDynamicProperties = new DynamicPropertyCollection();
+				return _clientDynamicProperties; 
+			}
+		}
+
+		public DynamicPropertyCollection ServerDynamicProperties
+		{
+			get { 
+				if (_serverDynamicProperties == null) _serverDynamicProperties = new DynamicPropertyCollection();
+				return _serverDynamicProperties; 
+			}
+		}
+
+		public bool HasClientDynamicSinks
+		{
+			get { return (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties); }
+		}
+
+		public bool HasServerDynamicSinks
+		{
+			get { return (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties); }
+		}
+
+		public void NotifyClientDynamicSinks  (bool start, IMessage req_msg, bool client_site, bool async)
+		{
+			if (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties) 
+				_clientDynamicProperties.NotifyMessage (start, req_msg, client_site, async);
+		}
+
+		public void NotifyServerDynamicSinks  (bool start, IMessage req_msg, bool client_site, bool async)
+		{
+			if (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties) 
+				_serverDynamicProperties.NotifyMessage (start, req_msg, client_site, async);
+		}
 	}
 
 	internal class ClientIdentity : Identity

+ 0 - 2
mcs/class/corlib/System.Runtime.Remoting/ObjRef.cs

@@ -146,7 +146,6 @@ namespace System.Runtime.Remoting {
 			}
 		}
 		
-		[MonoTODO]
 		public virtual IEnvoyInfo EnvoyInfo {
 			get {
 				return envoyInfo;
@@ -156,7 +155,6 @@ namespace System.Runtime.Remoting {
 			}
 		}
 		
-		[MonoTODO]
 		public virtual IRemotingTypeInfo TypeInfo {
 			get {
 				return typeInfo;

+ 21 - 16
mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs

@@ -54,7 +54,7 @@ namespace System.Runtime.Remoting
 		{
 			ReturnMessage result;
 			
-			MonoMethod method = (MonoMethod)reqMsg.MethodBase;
+			MonoMethod method = (MonoMethod) target.GetType().GetMethod(reqMsg.MethodName, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, (Type[]) reqMsg.MethodSignature, null);
 
 			try {
 				object [] out_args;
@@ -85,13 +85,13 @@ namespace System.Runtime.Remoting
 		public static object Connect (Type classToProxy, string url)
 		{
 			ObjRef objRef = new ObjRef (classToProxy, url, null);
-			return GetRemoteObject(objRef);
+			return GetRemoteObject (objRef, classToProxy);
 		}
 
 		public static object Connect (Type classToProxy, string url, object data)
 		{
 			ObjRef objRef = new ObjRef (classToProxy, url, data);
-			return GetRemoteObject(objRef);
+			return GetRemoteObject (objRef, classToProxy);
 		}
 
 		public static bool Disconnect (MarshalByRefObject obj)
@@ -126,25 +126,27 @@ namespace System.Runtime.Remoting
 
 		public static object Unmarshal (ObjRef objref)
 		{
-			return Unmarshal(objref, false);
+			return Unmarshal(objref, true);
 		}
 
 		public static object Unmarshal (ObjRef objref, bool fRefine)
 		{
 			// FIXME: use type name when fRefine==true
 
+			Type classToProxy = fRefine ? objref.ServerType : typeof (MarshalByRefObject);
+
 			if (objref.IsReferenceToWellKnow)
-				return GetRemoteObject(objref);
+				return GetRemoteObject(objref, classToProxy);
 			else
 			{
-				if (objref.ServerType.IsContextful)
+				if (classToProxy.IsContextful)
 				{
 					// Look for a ProxyAttribute
-					ProxyAttribute att = (ProxyAttribute) Attribute.GetCustomAttribute (objref.ServerType, typeof(ProxyAttribute),true);
+					ProxyAttribute att = (ProxyAttribute) Attribute.GetCustomAttribute (classToProxy, typeof(ProxyAttribute),true);
 					if (att != null)
-						return att.CreateProxy (objref, objref.ServerType, null, null).GetTransparentProxy();
+						return att.CreateProxy (objref, classToProxy, null, null).GetTransparentProxy();
 				}
-				return GetProxyForRemoteObject (objref, fRefine);
+				return GetProxyForRemoteObject (objref, classToProxy);
 			}
 		}
 
@@ -339,7 +341,7 @@ namespace System.Runtime.Remoting
 				return obj.ObjectIdentity;
 		}
 
-		internal static ClientIdentity GetOrCreateClientIdentity(ObjRef objRef, RealProxy proxyToAttach)
+		internal static ClientIdentity GetOrCreateClientIdentity(ObjRef objRef, Type proxyType)
 		{
 			// This method looks for an identity for the given url. 
 			// If an identity is not found, it creates the identity and 
@@ -367,8 +369,11 @@ namespace System.Runtime.Remoting
 				identity = new ClientIdentity (objectUri, objRef);
 				identity.ChannelSink = sink;
 
-				if (proxyToAttach == null) proxyToAttach = new RemotingProxy (objRef.ServerType, identity);
-				identity.ClientProxy = (MarshalByRefObject) proxyToAttach.GetTransparentProxy();
+				if (proxyType != null)
+				{
+					RemotingProxy proxy = new RemotingProxy (proxyType, identity);
+					identity.ClientProxy = (MarshalByRefObject) proxy.GetTransparentProxy();
+				}
 
 				// Registers the identity
 				uri_hash [objRef.URI] = identity;
@@ -435,16 +440,16 @@ namespace System.Runtime.Remoting
 			}
 		}
 
-		internal static object GetProxyForRemoteObject (ObjRef objref, bool fRefine)
+		internal static object GetProxyForRemoteObject (ObjRef objref, Type classToProxy)
 		{
 			ClientActivatedIdentity identity = uri_hash [objref.URI] as ClientActivatedIdentity;
 			if (identity != null) return identity.GetServerObject ();
-			else return GetRemoteObject (objref);
+			else return GetRemoteObject (objref, classToProxy);
 		}
 
-		internal static object GetRemoteObject(ObjRef objRef)
+		internal static object GetRemoteObject(ObjRef objRef, Type proxyType)
 		{
-			ClientIdentity id = GetOrCreateClientIdentity (objRef, null);
+			ClientIdentity id = GetOrCreateClientIdentity (objRef, proxyType);
 			return id.ClientProxy;
 		}
 

+ 85 - 76
mcs/class/corlib/System.Runtime.Remoting/TypeInfo.cs

@@ -4,79 +4,88 @@
 // Author: Lluis Sanchez Gual ([email protected])
 //
 // (C) 2003, Lluis Sanchez Gual
-//
-
-using System;
-
-namespace System.Runtime.Remoting
-{
-	[Serializable]
-	internal class TypeInfo : IRemotingTypeInfo
-	{
-		string serverType;
-		string[] serverHierarchy;
-		string[] interfacesImplemented;
-
-		public TypeInfo(Type type)
-		{
-			serverType = type.AssemblyQualifiedName;
-
-			// base class info
-
-			int baseCount = 0;
-			Type baseType = type.BaseType;
-			while (baseType != typeof (MarshalByRefObject) && baseType != typeof(object))
-			{
-				baseType = baseType.BaseType;
-				baseCount++;
-			}
-
-			serverHierarchy = new string[baseCount];
-			baseType = type.BaseType;
-			for (int n=0; n<baseCount; n++) 
-			{
-				serverHierarchy[n] = baseType.AssemblyQualifiedName;
-				baseType = baseType.BaseType;
-			}
-
-			// Interfaces info
-
-			Type[] interfaces = type.GetInterfaces();
-			interfacesImplemented = new string[interfaces.Length];
-			for (int n=0; n<interfaces.Length; n++)
-				interfacesImplemented[n] = interfaces[n].AssemblyQualifiedName;
-		}
-
-		public string TypeName 
-		{
-			get { return serverType; }
-			set { serverType = value; }
-		}
-
-		public bool CanCastTo (Type fromType, object o)
-		{
-			if (fromType == typeof (object)) return true;
-			if (fromType == typeof (MarshalByRefObject)) return true;
-
-			string fromName = fromType.AssemblyQualifiedName;
-
-			// Find the type comparing the name of the type and the name of the assembly,
-			// excluding version and other assembly info
-
-			int i = fromName.IndexOf (",");
-			if (i != -1) i = fromName.IndexOf (",", i+1);
-			if (i != -1) fromName = fromName.Substring (0,i+1);
-			else fromName += ",";
-
-			if ( (serverType + ",").StartsWith (fromName)) return true;
-
-			foreach (string basec in serverHierarchy)
-				if ( (basec + ",").StartsWith (fromName)) return true;
-
-			foreach (string basec in interfacesImplemented)
-				if ( (basec + ",").StartsWith (fromName)) return true;
-
-			return false;
-		}
-	}
-}
+//
+
+using System;
+
+namespace System.Runtime.Remoting
+{
+	[Serializable]
+	internal class TypeInfo : IRemotingTypeInfo
+	{
+		string serverType;
+		string[] serverHierarchy;
+		string[] interfacesImplemented;
+
+		public TypeInfo(Type type)
+		{
+			if (type.IsInterface)
+			{
+				serverType = typeof (MarshalByRefObject).AssemblyQualifiedName;
+				serverHierarchy = new string[0];
+				interfacesImplemented = new string[] { type.AssemblyQualifiedName };
+			}
+			else
+			{
+				serverType = type.AssemblyQualifiedName;
+
+				// base class info
+
+				int baseCount = 0;
+				Type baseType = type.BaseType;
+				while (baseType != typeof (MarshalByRefObject) && baseType != typeof(object))
+				{
+					baseType = baseType.BaseType;
+					baseCount++;
+				}
+
+				serverHierarchy = new string[baseCount];
+				baseType = type.BaseType;
+				for (int n=0; n<baseCount; n++) 
+				{
+					serverHierarchy[n] = baseType.AssemblyQualifiedName;
+					baseType = baseType.BaseType;
+				}
+
+				// Interfaces info
+
+				Type[] interfaces = type.GetInterfaces();
+				interfacesImplemented = new string[interfaces.Length];
+				for (int n=0; n<interfaces.Length; n++)
+					interfacesImplemented[n] = interfaces[n].AssemblyQualifiedName;
+			}
+		}
+
+		public string TypeName 
+		{
+			get { return serverType; }
+			set { serverType = value; }
+		}
+
+		public bool CanCastTo (Type fromType, object o)
+		{
+			if (fromType == typeof (object)) return true;
+			if (fromType == typeof (MarshalByRefObject)) return true;
+
+			string fromName = fromType.AssemblyQualifiedName;
+
+			// Find the type comparing the name of the type and the name of the assembly,
+			// excluding version and other assembly info
+
+			int i = fromName.IndexOf (",");
+			if (i != -1) i = fromName.IndexOf (",", i+1);
+			if (i != -1) fromName = fromName.Substring (0,i+1);
+			else fromName += ",";
+
+			if ( (serverType + ",").StartsWith (fromName)) return true;
+
+			foreach (string basec in serverHierarchy)
+				if ( (basec + ",").StartsWith (fromName)) return true;
+
+			foreach (string basec in interfacesImplemented)
+				if ( (basec + ",").StartsWith (fromName)) return true;
+
+			return false;
+		}
+	}
+}