* CADMessages.cs: Enabled smuggeling of primitive type parameters (as suggested
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / CallContext.cs
1 // 
2 // System.Runtime.Remoting.Messaging.CallContext.cs
3 //
4 // Author: Jaime Anguiano Olarra (jaime@gnome.org)
5 //         Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // (c) 2002, Jaime Anguiano Olarra
8 //
9 ///<summary>
10 ///Provides several properties that come with the execution code path.
11 ///This class is sealed.
12 ///</summary>
13
14 using System;
15 using System.Threading;
16 using System.Collections;
17
18 namespace System.Runtime.Remoting.Messaging 
19 {
20         
21         [Serializable]
22         public sealed class CallContext 
23         {
24                 // public methods
25                 public static void FreeNamedDataSlot (string name) 
26                 {
27                         Datastore.Remove (name);
28                 }
29
30                 public static object GetData (string name) 
31                 {
32                         return Datastore [name];
33                 }
34
35                 public static Header[] GetHeaders () 
36                 {
37                         return (Header[]) Datastore ["__Headers"];
38                 }
39
40                 public static void SetData (string name, object data) 
41                 {
42                         Datastore [name] = data;
43                 }
44
45                 public static void SetHeaders (Header[] headers) 
46                 {
47                         Datastore ["__Headers"] = headers;
48                 }
49
50                 internal static LogicalCallContext CreateLogicalCallContext ()
51                 {
52                         LocalDataStoreSlot ds = Thread.GetNamedDataSlot ("__CallContext");
53                         Hashtable res = (Hashtable) Thread.GetData (ds);
54
55                         LogicalCallContext ctx = new LogicalCallContext();
56                         if (res == null) return ctx;
57
58                         foreach (DictionaryEntry entry in res)
59                                 if (entry.Value is ILogicalThreadAffinative)
60                                         ctx.SetData ((string)entry.Key, entry.Value);
61
62                         return ctx;
63                 }
64
65                 internal static void SetCurrentCallContext (LogicalCallContext ctx)
66                 {
67                         Hashtable data = ctx.Datastore;
68                         if (data == null) return;
69
70                         foreach (DictionaryEntry entry in data)
71                                 SetData ((string)entry.Key, entry.Value);
72                 }
73
74                 internal static void ResetCurrentCallContext ()
75                 {
76                         LocalDataStoreSlot ds = Thread.GetNamedDataSlot ("__CallContext");
77                         Thread.SetData (ds, null);
78                 }
79
80                 private static Hashtable Datastore
81                 {
82                         get {
83                                 LocalDataStoreSlot ds = Thread.GetNamedDataSlot ("__CallContext");
84                                 Hashtable res = (Hashtable) Thread.GetData (ds);
85                                 if (res == null) {
86                                         res = new Hashtable ();
87                                         Thread.SetData (ds, res);
88                                 }
89                                 return res;
90                         }
91                 }
92         }
93
94         public interface ILogicalThreadAffinative
95         {
96         }
97 }