MarshalByRefObject.cs: Implemented GetLifetimeService() and
[mono.git] / mcs / class / corlib / System / MarshalByRefObject.cs
1 //
2 // System.MarshalByRefObject.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Lluis Sanchez Gual (lsg@ctv.es)
7 //   Patrik Torstensson (totte_mono@yahoo.com)
8 //
9 // (C) Ximian, Inc.  http://www.ximian.com
10 //
11 using System.Threading;
12 using System.Runtime.Remoting;
13
14 namespace System {
15
16         [Serializable]
17         public abstract class MarshalByRefObject {
18                 private ServerIdentity _identity;               // Holds marshalling iformation of the object
19
20                 internal Identity GetObjectIdentity(MarshalByRefObject obj, out bool IsClient) {
21                         IsClient = false;
22                         Identity objId = null;
23
24                         if (RemotingServices.IsTransparentProxy(obj)) 
25                         {
26                                 objId = RemotingServices.GetRealProxy(obj).ObjectIdentity;
27                                 IsClient = true;
28                         } else 
29                         {
30                                 objId = obj.ObjectIdentity;
31                         }
32
33                         return objId;
34                 }
35
36                 internal ServerIdentity ObjectIdentity
37                 {
38                         get { return _identity; }
39                         set { _identity = value; }
40                 }
41
42                 public virtual ObjRef CreateObjRef (Type type)
43                 {
44                         // This method can only be called when this object has been marshalled
45                         if (_identity == null) throw new RemotingException ("No remoting information was found for the object");
46                         return _identity.CreateObjRef (type);
47                 }
48
49                 public object GetLifetimeService ()
50                 {
51                         if (_identity == null) return null;
52                         else return _identity.Lease;
53                 }
54
55                 public virtual object InitializeLifetimeService ()
56                 {
57                         return new System.Runtime.Remoting.Lifetime.Lease();
58                 }
59
60                 protected MarshalByRefObject ()
61                 {
62                 }
63         }
64 }