* RemotingServices.cs: Changed GetMethodBaseFromMethodMessage so its code
[mono.git] / mcs / class / corlib / System.Runtime.Remoting / Identity.cs
index 44d343af14f3799f116dbeef2687391fe313bccd..23bb45392ea9f95e6fa58a070737f0b7439ffbce 100644 (file)
@@ -1,18 +1,42 @@
 //
 // System.Runtime.Remoting.Identity.cs
 //
-// Author: Lluis Sanchez Gual (lsg@ctv.es)
+// Author: Lluis Sanchez Gual (lluis@ideary.com)
 //
 // (C) 2002, Lluis Sanchez Gual
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.Runtime.Remoting.Messaging;
 using System.Runtime.Remoting.Proxies;
 using System.Runtime.Remoting.Contexts;
+using System.Runtime.Remoting.Lifetime;
 
 namespace System.Runtime.Remoting
 {
-       internal class Identity
+       internal abstract class Identity
        {
                // An Identity object holds remoting information about
                // an object. It can be used to store client side information
@@ -20,83 +44,131 @@ namespace System.Runtime.Remoting
                // and also to store server side information (information
                // about how to dispatch messages to the object in the server).
 
-               // The object that this identity represents. Can be a MarshalByRefObject
-               // (if it is a server object) or a transparent proxy (if it is a client
-               // proxy to a remote object).
-               object _realObject;
-
-               Type _objectType;
-
                // URI of the object
-               string _objectUri;
+               protected string _objectUri;
 
                // Message sink to use to send a message to the remote server
-               IMessageSink _clientSink = null;
+               protected IMessageSink _channelSink = null;
 
-               // Message sink used in the server to dispatch a message
-               // to the server object
-               IMessageSink _serverSink = null;
-               Context _context;
+               protected IMessageSink _envoySink = null;
 
-               ObjRef _objRef = null;
+               DynamicPropertyCollection _clientDynamicProperties;
+               DynamicPropertyCollection _serverDynamicProperties;
 
-               public Identity(string objectUri, Context context, Type objectType)
+               // The ObjRef 
+               protected ObjRef _objRef;
+               
+               // This flag is set when the identity is removed from the uri table.
+               // It is needed because in some scenarios the runtime may try to
+               // dispose the identity twice.
+               bool _disposed = false;
+
+               public Identity(string objectUri)
                {
                        _objectUri = objectUri;
-                       _context = context;
-                       _objectType = objectType;
                }
 
-               public ObjRef CreateObjRef (Type requestedType)
-               {
-                       // fixme: handle requested_type         
-                       if (requestedType == null) requestedType = _objectType;
-                       ObjRef res = new ObjRef ((MarshalByRefObject)_realObject, requestedType);
-                       res.URI = _objectUri;
-                       _objRef = res;
-                       return res;
-               }
+               public abstract ObjRef CreateObjRef (Type requestedType);
 
                public bool IsFromThisAppDomain
                {
                        get
                        {
-                               // fixme: what if it is contextbound?
-                               return (_clientSink == null);
+                               return (_channelSink == null);
                        }
                }
 
-               public object RealObject
+               public IMessageSink ChannelSink
                {
-                       get     { return _realObject; }
-                       set { _realObject = value; }
+                       get { return _channelSink; }
+                       set { _channelSink = value; }
+               }
+
+               public IMessageSink EnvoySink
+               {
+                       get { return _envoySink; }
                }
 
                public string ObjectUri
                {
                        get { return _objectUri; }
+                       set { _objectUri = value; }
+               }
+
+               public bool IsConnected
+               {
+                       get { return _objectUri != null; }
+               }
+               
+               public bool Disposed
+               {
+                       get { return _disposed; }
+                       set { _disposed = true; }
                }
 
-               public IMessageSink ClientSink
+               public DynamicPropertyCollection ClientDynamicProperties
                {
-                       get { return _clientSink; }
-                       set { _clientSink = value; }
+                       get { 
+                               if (_clientDynamicProperties == null) _clientDynamicProperties = new DynamicPropertyCollection();
+                               return _clientDynamicProperties; 
+                       }
                }
 
-               public IMessageSink ServerSink
+               public DynamicPropertyCollection ServerDynamicProperties
                {
-                       get 
-                       { 
-                               if (_serverSink == null) {
-                                       _serverSink = _context.CreateServerObjectSinkChain((MarshalByRefObject)_realObject);
-                               }
-                               return _serverSink; 
+                       get { 
+                               if (_serverDynamicProperties == null) _serverDynamicProperties = new DynamicPropertyCollection();
+                               return _serverDynamicProperties; 
                        }
                }
 
-               public Context Context
+               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
+       {
+               WeakReference _proxyReference;
+
+               public ClientIdentity (string objectUri, ObjRef objRef): base (objectUri)
+               {
+                       _objRef = objRef;
+                       _envoySink = (_objRef.EnvoyInfo != null) ? _objRef.EnvoyInfo.EnvoySinks : null;
+               }
+
+               public MarshalByRefObject ClientProxy
+               {
+                       get     { return (MarshalByRefObject) _proxyReference.Target; }
+                       set { _proxyReference = new WeakReference (value); }
+               }
+
+               public override ObjRef CreateObjRef (Type requestedType)
+               {
+                       return _objRef;
+               }
+
+               public string TargetUri
                {
-                       get { return _context; }
+                       get { return _objRef.URI; }
                }
        }
 }