2 // System.Runtime.Remoting.Messaging.CallContext.cs
4 // Author: Jaime Anguiano Olarra (jaime@gnome.org)
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // (c) 2002, Jaime Anguiano Olarra
10 ///Provides several properties that come with the execution code path.
11 ///This class is sealed.
15 using System.Threading;
16 using System.Collections;
18 namespace System.Runtime.Remoting.Messaging
22 public sealed class CallContext
25 public static void FreeNamedDataSlot (string name)
27 Datastore.Remove (name);
30 public static object GetData (string name)
32 return Datastore [name];
35 public static Header[] GetHeaders ()
37 return (Header[]) Datastore ["__Headers"];
40 public static void SetData (string name, object data)
42 Datastore [name] = data;
45 public static void SetHeaders (Header[] headers)
47 Datastore ["__Headers"] = headers;
50 internal static LogicalCallContext CreateLogicalCallContext ()
52 LocalDataStoreSlot ds = Thread.GetNamedDataSlot ("__CallContext");
53 Hashtable res = (Hashtable) Thread.GetData (ds);
55 LogicalCallContext ctx = new LogicalCallContext();
56 if (res == null) return ctx;
58 foreach (DictionaryEntry entry in res)
59 if (entry.Value is ILogicalThreadAffinative)
60 ctx.SetData ((string)entry.Key, entry.Value);
65 internal static void SetCurrentCallContext (LogicalCallContext ctx)
67 Hashtable data = ctx.Datastore;
68 if (data == null) return;
70 foreach (DictionaryEntry entry in data)
71 SetData ((string)entry.Key, entry.Value);
74 internal static void ResetCurrentCallContext ()
76 LocalDataStoreSlot ds = Thread.GetNamedDataSlot ("__CallContext");
77 Thread.SetData (ds, null);
80 private static Hashtable Datastore
83 LocalDataStoreSlot ds = Thread.GetNamedDataSlot ("__CallContext");
84 Hashtable res = (Hashtable) Thread.GetData (ds);
86 res = new Hashtable ();
87 Thread.SetData (ds, res);
94 public interface ILogicalThreadAffinative