2 // System.Runtime.Remoting.Identity.cs
4 // Author: Lluis Sanchez Gual (lluis@ideary.com)
6 // (C) 2002, Lluis Sanchez Gual
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Runtime
.Remoting
.Messaging
;
33 using System
.Runtime
.Remoting
.Proxies
;
34 using System
.Runtime
.Remoting
.Contexts
;
35 using System
.Runtime
.Remoting
.Lifetime
;
37 namespace System
.Runtime
.Remoting
39 internal abstract class Identity
41 // An Identity object holds remoting information about
42 // an object. It can be used to store client side information
43 // (information about how to reach the remote server),
44 // and also to store server side information (information
45 // about how to dispatch messages to the object in the server).
48 protected string _objectUri
;
50 // Message sink to use to send a message to the remote server
51 protected IMessageSink _channelSink
= null;
53 protected IMessageSink _envoySink
= null;
55 DynamicPropertyCollection _clientDynamicProperties
;
56 DynamicPropertyCollection _serverDynamicProperties
;
59 protected ObjRef _objRef
;
61 // This flag is set when the identity is removed from the uri table.
62 // It is needed because in some scenarios the runtime may try to
63 // dispose the identity twice.
64 bool _disposed
= false;
66 public Identity(string objectUri
)
68 _objectUri
= objectUri
;
71 public abstract ObjRef
CreateObjRef (Type requestedType
);
73 public bool IsFromThisAppDomain
77 return (_channelSink
== null);
81 public IMessageSink ChannelSink
83 get { return _channelSink; }
84 set { _channelSink = value; }
87 public IMessageSink EnvoySink
89 get { return _envoySink; }
92 public string ObjectUri
94 get { return _objectUri; }
95 set { _objectUri = value; }
98 public bool IsConnected
100 get { return _objectUri != null; }
105 get { return _disposed; }
106 set { _disposed = value; }
109 public DynamicPropertyCollection ClientDynamicProperties
112 if (_clientDynamicProperties
== null) _clientDynamicProperties
= new DynamicPropertyCollection();
113 return _clientDynamicProperties
;
117 public DynamicPropertyCollection ServerDynamicProperties
120 if (_serverDynamicProperties
== null) _serverDynamicProperties
= new DynamicPropertyCollection();
121 return _serverDynamicProperties
;
125 public bool HasClientDynamicSinks
127 get { return (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties); }
130 public bool HasServerDynamicSinks
132 get { return (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties); }
135 public void NotifyClientDynamicSinks (bool start
, IMessage req_msg
, bool client_site
, bool async)
137 if (_clientDynamicProperties
!= null && _clientDynamicProperties
.HasProperties
)
138 _clientDynamicProperties
.NotifyMessage (start
, req_msg
, client_site
, async);
141 public void NotifyServerDynamicSinks (bool start
, IMessage req_msg
, bool client_site
, bool async)
143 if (_serverDynamicProperties
!= null && _serverDynamicProperties
.HasProperties
)
144 _serverDynamicProperties
.NotifyMessage (start
, req_msg
, client_site
, async);
148 internal class ClientIdentity
: Identity
150 WeakReference _proxyReference
;
152 public ClientIdentity (string objectUri
, ObjRef objRef
): base (objectUri
)
155 _envoySink
= (_objRef
.EnvoyInfo
!= null) ? _objRef
.EnvoyInfo
.EnvoySinks
: null;
158 public MarshalByRefObject ClientProxy
160 get { return (MarshalByRefObject) _proxyReference.Target; }
161 set { _proxyReference = new WeakReference (value); }
164 public override ObjRef
CreateObjRef (Type requestedType
)
169 public string TargetUri
171 get { return _objRef.URI; }