dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Chan


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Channels CombinedDictionary.cs, NONE, 1.1 BaseChannelWithProperties.cs, 1.1, 1.2 ChannelServices.cs, 1.1, 1.2 ClientChannelSinkStack.cs, 1.1, 1.2 ServerChannelSinkStack.cs, 1.2, 1.3
Date: Tue, 05 Aug 2003 23:52:34 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Channels
In directory 
subversions:/tmp/cvs-serv27322/runtime/System/Runtime/Remoting/Channels

Modified Files:
        BaseChannelWithProperties.cs ChannelServices.cs 
        ClientChannelSinkStack.cs ServerChannelSinkStack.cs 
Added Files:
        CombinedDictionary.cs 
Log Message:


Outstanding TODO's in remoting functionality.


--- NEW FILE ---
/*
 * CombinedDictionary.cs - Implementation of the
 *      "System.Runtime.Remoting.Channels.CombinedDictionary" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Runtime.Remoting.Channels
{

#if CONFIG_REMOTING

using System.Collections;

// Class that combines multiple dictionaries into one.

internal class CombinedDictionary : IDictionary, ICollection, IEnumerable
{
        // Internal state.
        private ArrayList members;

        // Constructor.
        public CombinedDictionary(ArrayList members)
                        {
                                this.members = members;
                        }

        // Implement the IDictionary interface.
        public void Add(Object key, Object value)
                        {
                                throw new NotSupportedException();
                        }
        public void Clear()
                        {
                                throw new NotSupportedException();
                        }
        public bool Contains(Object key)
                        {
                                foreach(IDictionary dict in members)
                                {
                                        if(dict.Contains(key))
                                        {
                                                return true;
                                        }
                                }
                                return false;
                        }
        public IDictionaryEnumerator GetEnumerator()
                        {
                                return new CombinedEnumerator(this, Keys);
                        }
        public void Remove(Object key)
                        {
                                throw new NotSupportedException();
                        }
        public bool IsFixedSize
                        {
                                get
                                {
                                        return true;
                                }
                        }
        public bool IsReadOnly
                        {
                                get
                                {
                                        return false;
                                }
                        }
        public Object this[Object key]
                        {
                                get
                                {
                                        foreach(IDictionary dict in members)
                                        {
                                                if(dict.Contains(key))
                                                {
                                                        return dict[key];
                                                }
                                        }
                                        return null;
                                }
                                set
                                {
                                        foreach(IDictionary dict in members)
                                        {
                                                if(dict.Contains(key))
                                                {
                                                        dict[key] = value;
                                                }
                                        }
                                }
                        }
        public ICollection Keys
                        {
                                get
                                {
                                        ArrayList keys = new ArrayList();
                                        foreach(IDictionary dict in members)
                                        {
                                                IDictionaryEnumerator e = 
dict.GetEnumerator();
                                                while(e.MoveNext())
                                                {
                                                        keys.Add(e.Key);
                                                }
                                        }
                                        return keys;
                                }
                        }
        public ICollection Values
                        {
                                get
                                {
                                        ArrayList values = new ArrayList();
                                        foreach(IDictionary dict in members)
                                        {
                                                IDictionaryEnumerator e = 
dict.GetEnumerator();
                                                while(e.MoveNext())
                                                {
                                                        values.Add(e.Value);
                                                }
                                        }
                                        return values;
                                }
                        }

        // Implement the ICollection interface.
        public void CopyTo(Array array, int index)
                        {
                                throw new NotSupportedException();
                        }
        public int Count
                        {
                                get
                                {
                                        int count = 0;
                                        foreach(IDictionary dict in members)
                                        {
                                                count += dict.Count;
                                        }
                                        return count;
                                }
                        }
        public bool IsSynchronized
                        {
                                get
                                {
                                        return false;
                                }
                        }
        public Object SyncRoot
                        {
                                get
                                {
                                        return this;
                                }
                        }

        // Implement the IEnumerable interface.
        IEnumerator IEnumerable.GetEnumerator()
                        {
                                return GetEnumerator();
                        }

        // Enumerator class for "CombinedDictionary".
        private sealed class CombinedEnumerator : IDictionaryEnumerator
        {
                // Internal state.
                private CombinedDictionary dict;
                private ArrayList keys;
                private int index;

                // Constructor.
                public CombinedEnumerator(CombinedDictionary dict,
                                                                  ICollection 
keys)
                                {
                                        this.dict = dict;
                                        this.keys = (keys as ArrayList);
                                        this.index = -1;
                                }

                // Implement the IEnumerator interface.
                public bool MoveNext()
                                {
                                        ++index;
                                        return (index < keys.Count);
                                }
                public void Reset()
                                {
                                        index = -1;
                                }
                public Object Current
                                {
                                        get
                                        {
                                                return new DictionaryEntry(Key, 
Value);
                                        }
                                }

                // Implement the IDictionaryEnumerator interface.
                public DictionaryEntry Entry
                                {
                                        get
                                        {
                                                return new DictionaryEntry(Key, 
Value);
                                        }
                                }
                public Object Key
                                {
                                        get
                                        {
                                                if(index < 0 || index >= 
keys.Count)
                                                {
                                                        throw new 
InvalidOperationException
                                                                
(_("Invalid_BadEnumeratorPosition"));
                                                }
                                                return keys[index];
                                        }
                                }
                public Object Value
                                {
                                        get
                                        {
                                                if(index < 0 || index >= 
keys.Count)
                                                {
                                                        throw new 
InvalidOperationException
                                                                
(_("Invalid_BadEnumeratorPosition"));
                                                }
                                                return dict[keys[index]];
                                        }
                                }

        }; // class CombinedEnumerator

}; // class CombinedDictionary

#endif // CONFIG_REMOTING

}; // namespace System.Runtime.Remoting.Channels

Index: BaseChannelWithProperties.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Channels/BaseChannelWithProperties.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** BaseChannelWithProperties.cs        17 Apr 2003 10:36:08 -0000      1.1
--- BaseChannelWithProperties.cs        6 Aug 2003 03:52:31 -0000       1.2
***************
*** 37,47 ****
  
        // Get the properties associated with this object.
-       [TODO]
        public override IDictionary Properties
                        {
                                get
                                {
!                                       // TODO
!                                       return null;
                                }
                        }
--- 37,66 ----
  
        // Get the properties associated with this object.
        public override IDictionary Properties
                        {
                                get
                                {
!                                       // Collect up all dictionaries from the 
attached sinks.
!                                       ArrayList members = new ArrayList();
!                                       IChannelSinkBase sink;
!                                       IDictionary dict;
!                                       sink = SinksWithProperties;
!                                       while(sink != null)
!                                       {
!                                               dict = sink.Properties;
!                                               if(dict != null)
!                                               {
!                                                       members.Add(dict);
!                                               }
!                                               if(sink is IServerChannelSink)
!                                               {
!                                                       sink = 
((IServerChannelSink)sink).NextChannelSink;
!                                               }
!                                               else
!                                               {
!                                                       sink = 
((IClientChannelSink)sink).NextChannelSink;
!                                               }
!                                       }
!                                       return new CombinedDictionary(members);
                                }
                        }

Index: ChannelServices.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Channels/ChannelServices.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ChannelServices.cs  17 Apr 2003 10:36:08 -0000      1.1
--- ChannelServices.cs  6 Aug 2003 03:52:31 -0000       1.2
***************
*** 30,44 ****
  public sealed class ChannelServices
  {
        // This class cannot be instantiated.
        private ChannelServices() {}
  
        // Get the registered channels.
-       [TODO]
        public static IChannel[] RegisteredChannels
                        {
                                get
                                {
!                                       // TODO
!                                       return null;
                                }
                        }
--- 30,54 ----
  public sealed class ChannelServices
  {
+       // Internal state.
+       private static ArrayList channels;
+ 
        // This class cannot be instantiated.
        private ChannelServices() {}
  
        // Get the registered channels.
        public static IChannel[] RegisteredChannels
                        {
                                get
                                {
!                                       lock(typeof(ChannelServices))
!                                       {
!                                               if(channels == null)
!                                               {
!                                                       return new IChannel [0];
!                                               }
!                                               IChannel[] array = new IChannel 
[channels.Count];
!                                               channels.CopyTo(array, 0);
!                                               return array;
!                                       }
                                }
                        }
***************
*** 82,90 ****
  
        // Get a registered channel.
-       [TODO]
        public static IChannel GetChannel(String name)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 92,112 ----
  
        // Get a registered channel.
        public static IChannel GetChannel(String name)
                        {
!                               lock(typeof(ChannelServices))
!                               {
!                                       if(channels == null)
!                                       {
!                                               return null;
!                                       }
!                                       foreach(IChannel channel in channels)
!                                       {
!                                               if(channel.ChannelName == name)
!                                               {
!                                                       return channel;
!                                               }
!                                       }
!                                       return null;
!                               }
                        }
  
***************
*** 106,110 ****
  
        // Register a channel.
-       [TODO]
        public static void RegisterChannel(IChannel chnl)
                        {
--- 128,131 ----
***************
*** 113,117 ****
                                        throw new ArgumentNullException("chnl");
                                }
!                               // TODO
                        }
  
--- 134,175 ----
                                        throw new ArgumentNullException("chnl");
                                }
!                               String name = chnl.ChannelName;
!                               lock(typeof(ChannelServices))
!                               {
!                                       if(channels == null)
!                                       {
!                                               // This is the first channel.
!                                               channels = new ArrayList();
!                                               channels.Add(chnl);
!                                       }
!                                       else if(name == null || name == 
String.Empty ||
!                                               channels.IndexOf(name) == -1)
!                                       {
!                                               // Insert the channel in 
priority order.
!                                               int index = 0;
!                                               while(index < channels.Count)
!                                               {
!                                                       if((channels[index] as 
IChannel).ChannelPriority
!                                                                       < 
chnl.ChannelPriority)
!                                                       {
!                                                               break;
!                                                       }
!                                               }
!                                               if(index < channels.Count)
!                                               {
!                                                       channels.Insert(index, 
chnl);
!                                               }
!                                               else
!                                               {
!                                                       channels.Add(chnl);
!                                               }
!                                       }
!                                       else
!                                       {
!                                               // The channel is already 
registered.
!                                               throw new RemotingException
!                                                       
(_("Remoting_ChannelAlreadyRegistered"));
!                                       }
!                               }
                        }
  
***************
*** 129,140 ****
  
        // Unregister a channel.
-       [TODO]
        public static void UnregisterChannel(IChannel chnl)
                        {
!                               if(chnl == null)
                                {
!                                       throw new ArgumentNullException("chnl");
                                }
-                               // TODO
                        }
  
--- 187,206 ----
  
        // Unregister a channel.
        public static void UnregisterChannel(IChannel chnl)
                        {
!                               if(chnl != null)
                                {
!                                       lock(typeof(ChannelServices))
!                                       {
!                                               if(channels != null)
!                                               {
!                                                       int index = 
channels.IndexOf(chnl);
!                                                       if(index != -1)
!                                                       {
!                                                               
channels.RemoveAt(index);
!                                                       }
!                                               }
!                                       }
                                }
                        }
  

Index: ClientChannelSinkStack.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Channels/ClientChannelSinkStack.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ClientChannelSinkStack.cs   17 Apr 2003 10:36:08 -0000      1.1
--- ClientChannelSinkStack.cs   6 Aug 2003 03:52:31 -0000       1.2
***************
*** 31,80 ****
        : IClientChannelSinkStack, IClientResponseChannelSinkStack
  {
        // Constructors.
!       [TODO]
!       public ClientChannelSinkStack()
!                       {
!                               // TODO
!                       }
!       [TODO]
        public ClientChannelSinkStack(IMessageSink replySink)
                        {
!                               // TODO
                        }
  
        // Pop an item from the stack.
-       [TODO]
        public Object Pop(IClientChannelSink sink)
                        {
!                               // TODO
!                               return null;
                        }
  
        // Push an item onto the stack.
-       [TODO]
        public void Push(IClientChannelSink sink, Object state)
                        {
!                               // TODO
                        }
  
        // Request asynchronous processing of a response.
-       [TODO]
        public void AsyncProcessResponse(ITransportHeaders headers, Stream 
stream)
                        {
!                               // TODO
                        }
  
        // Dispatch an exception on the reply sink.
-       [TODO]
        public void DispatchException(Exception e)
                        {
!                               // TODO
                        }
  
        // Dispatch a reply message on the reply sink.
-       [TODO]
        public void DispatchReplyMessage(IMessage msg)
                        {
!                               // TODO
                        }
  
--- 31,124 ----
        : IClientChannelSinkStack, IClientResponseChannelSinkStack
  {
+       // Internal state.
+       private IMessageSink replySink;
+       private SinkStackEntry top;
+ 
+       // Structure of a sink state entry.
+       private sealed class SinkStackEntry
+       {
+               // Internal state.
+               public IClientChannelSink sink;
+               public Object state;
+               public SinkStackEntry below;
+ 
+               // Constructor.
+               public SinkStackEntry(IClientChannelSink sink, Object state,
+                                                         SinkStackEntry below)
+                               {
+                                       this.sink = sink;
+                                       this.state = state;
+                                       this.below = below;
+                               }
+ 
+       }; // class SinkStackEntry
+ 
        // Constructors.
!       public ClientChannelSinkStack() {}
        public ClientChannelSinkStack(IMessageSink replySink)
                        {
!                               this.replySink = replySink;
                        }
  
        // Pop an item from the stack.
        public Object Pop(IClientChannelSink sink)
                        {
!                               while(top != null)
!                               {
!                                       if(top.sink == sink)
!                                       {
!                                               break;
!                                       }
!                                       top = top.below;
!                               }
!                               if(top == null)
!                               {
!                                       throw new RemotingException
!                                               
(_("Remoting_SinkNotFoundOnStack"));
!                               }
!                               Object state = top.state;
!                               top = top.below;
!                               return state;
                        }
  
        // Push an item onto the stack.
        public void Push(IClientChannelSink sink, Object state)
                        {
!                               top = new SinkStackEntry(sink, state, top);
                        }
  
        // Request asynchronous processing of a response.
        public void AsyncProcessResponse(ITransportHeaders headers, Stream 
stream)
                        {
!                               if(replySink != null)
!                               {
!                                       if(top == null)
!                                       {
!                                               throw new RemotingException
!                                                       
(_("Remoting_SinkStackEmpty"));
!                                       }
!                                       SinkStackEntry entry = top;
!                                       top = top.below;
!                                       entry.sink.AsyncProcessResponse
!                                               (this, entry.state, headers, 
stream);
!                               }
                        }
  
        // Dispatch an exception on the reply sink.
        public void DispatchException(Exception e)
                        {
!                               if(replySink != null)
!                               {
!                                       replySink.SyncProcessMessage(new 
ReturnMessage(e, null));
!                               }
                        }
  
        // Dispatch a reply message on the reply sink.
        public void DispatchReplyMessage(IMessage msg)
                        {
!                               if(replySink != null)
!                               {
!                                       replySink.SyncProcessMessage(msg);
!                               }
                        }
  

Index: ServerChannelSinkStack.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Channels/ServerChannelSinkStack.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ServerChannelSinkStack.cs   23 Apr 2003 05:39:49 -0000      1.2
--- ServerChannelSinkStack.cs   6 Aug 2003 03:52:31 -0000       1.3
***************
*** 31,91 ****
        : IServerChannelSinkStack, IServerResponseChannelSinkStack
  {
        // Constructors.
!       [TODO]
!       public ServerChannelSinkStack()
!                       {
!                               // TODO
!                       }
  
        // Process a response asynchronously.
-       [TODO]
        public void AsyncProcessResponse
                (IMessage msg, ITransportHeaders headers, Stream stream)
                        {
!                               // TODO
                        }
  
        // Get the response stream.
-       [TODO]
        public Stream GetResponseStream(IMessage msg, ITransportHeaders headers)
                        {
!                               // TODO
!                               return null;
                        }
  
        // Pop an item from the stack.
-       [TODO]
        public Object Pop(IServerChannelSink sink)
                        {
!                               // TODO
!                               return null;
                        }
  
        // Push an item onto the stack.
-       [TODO]
        public void Push(IServerChannelSink sink, Object state)
                        {
!                               // TODO
                        }
  
        // Handle a server callback.
-       [TODO]
        public void ServerCallback(IAsyncResult ar)
                        {
!                               // TODO
                        }
  
        // Store into this sink stack.
-       [TODO]
        public void Store(IServerChannelSink sink, Object state)
                        {
!                               // TODO
                        }
  
!       // Store into this sink stack and then dispatch.
        [TODO]
        public void StoreAndDispatch(IServerChannelSink sink, Object state)
                        {
!                               // TODO
                        }
  
--- 31,189 ----
        : IServerChannelSinkStack, IServerResponseChannelSinkStack
  {
+       // Internal state.
+       private SinkStackEntry top;
+       private SinkStackEntry storeTop;
+ 
+       // Structure of a sink state entry.
+       private sealed class SinkStackEntry
+       {
+               // Internal state.
+               public IServerChannelSink sink;
+               public Object state;
+               public SinkStackEntry below;
+ 
+               // Constructor.
+               public SinkStackEntry(IServerChannelSink sink, Object state,
+                                                         SinkStackEntry below)
+                               {
+                                       this.sink = sink;
+                                       this.state = state;
+                                       this.below = below;
+                               }
+ 
+       }; // class SinkStackEntry
+ 
        // Constructors.
!       public ServerChannelSinkStack() {}
  
        // Process a response asynchronously.
        public void AsyncProcessResponse
                (IMessage msg, ITransportHeaders headers, Stream stream)
                        {
!                               if(top == null)
!                               {
!                                       throw new RemotingException
!                                               (_("Remoting_SinkStackEmpty"));
!                               }
!                               SinkStackEntry entry = top;
!                               top = top.below;
!                               entry.sink.AsyncProcessResponse
!                                       (this, entry.state, msg, headers, 
stream);
                        }
  
        // Get the response stream.
        public Stream GetResponseStream(IMessage msg, ITransportHeaders headers)
                        {
!                               if(top == null)
!                               {
!                                       throw new RemotingException
!                                               (_("Remoting_SinkStackEmpty"));
!                               }
! 
!                               // Remove the sink from the stack temporarily.
!                               SinkStackEntry entry = top;
!                               top = top.below;
! 
!                               // Get the stream.
!                               Stream stream = entry.sink.GetResponseStream
!                                       (this, entry.state, msg, headers);
! 
!                               // Push the sink back onto the stack.
!                               entry.below = top;
!                               top = entry;
!                               return stream;
                        }
  
        // Pop an item from the stack.
        public Object Pop(IServerChannelSink sink)
                        {
!                               while(top != null)
!                               {
!                                       if(top.sink == sink)
!                                       {
!                                               break;
!                                       }
!                                       top = top.below;
!                               }
!                               if(top == null)
!                               {
!                                       throw new RemotingException
!                                               
(_("Remoting_SinkNotFoundOnStack"));
!                               }
!                               Object state = top.state;
!                               top = top.below;
!                               return state;
                        }
  
        // Push an item onto the stack.
        public void Push(IServerChannelSink sink, Object state)
                        {
!                               top = new SinkStackEntry(sink, state, top);
                        }
  
        // Handle a server callback.
        public void ServerCallback(IAsyncResult ar)
                        {
!                               // Not used in this implementation.
                        }
  
        // Store into this sink stack.
        public void Store(IServerChannelSink sink, Object state)
                        {
!                               // Find the entry on the stack.
!                               while(top != null)
!                               {
!                                       if(top.sink == sink)
!                                       {
!                                               break;
!                                       }
!                                       top = top.below;
!                               }
!                               if(top == null)
!                               {
!                                       throw new RemotingException
!                                               
(_("Remoting_SinkNotFoundOnStack"));
!                               }
! 
!                               // Remove the entry from the main stack.
!                               SinkStackEntry entry = top;
!                               top = top.below;
! 
!                               // Push the entry onto the store stack.
!                               entry.below = storeTop;
!                               entry.state = state;
!                               storeTop = entry;
                        }
  
!       // Store into this sink stack and then dispatch async messages.
        [TODO]
        public void StoreAndDispatch(IServerChannelSink sink, Object state)
                        {
!                               // Find the entry on the stack.
!                               while(top != null)
!                               {
!                                       if(top.sink == sink)
!                                       {
!                                               break;
!                                       }
!                                       top = top.below;
!                               }
!                               if(top == null)
!                               {
!                                       throw new RemotingException
!                                               
(_("Remoting_SinkNotFoundOnStack"));
!                               }
! 
!                               // This entry must be the only one on the stack.
!                               if(top.below != null)
!                               {
!                                       throw new RemotingException
!                                               
(_("Remoting_SinkStackNonEmpty"));
!                               }
! 
!                               // Update the entry with the new state 
information.
!                               top.state = state;
! 
!                               // TODO: dispatch async messages
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]