You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2009/01/30 23:25:07 UTC

svn commit: r739432 [6/9] - in /incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp: ./ Msg/ Support/ Transport/ Transport/Filter/ Transport/Fmt/ Transport/Fmt/Binary/ Util/

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Connection.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Connection.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Connection.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Connection.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,328 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Implementation of runner which handles a network connection.
+    /// </summary>
+    abstract public class Connection<H> : Runner, 
+        Transport<H>, RunnerHandler where H : Session
+    {
+
+        #region QUERIES
+
+        /// <summary>
+        /// Source query to get the local address
+        /// </summary>
+        public const String LOCAL_ADDRESS = "LOCAL_ADDRESS";
+
+	    /// <summary>
+	    /// Source query to get the remote address.
+	    /// </summary>
+	    public const String REMOTE_ADDRESS = "REMOTE_ADDRESS";
+
+        #endregion  
+
+        #region EVENTS
+        
+        
+	    /// <summary>
+	    /// Host name to specify to select listening on all interfaces.
+        /// The value is "0.0.0.0".
+	    /// </summary>
+	    public const String ALL_INTFS = "0.0.0.0";
+
+        /// <summary>
+        /// Translates host name per well know names.
+        /// </summary>
+        /// <param name="s">input host name</param>
+        /// <returns></returns>
+        protected static String TranslateHost( String s )
+        {
+            if ( s != null && s.Equals( ALL_INTFS ) )
+                return null;
+            return s;
+        }
+
+        #endregion
+
+
+        /// <summary>
+        /// Constructs the Connection.
+        /// </summary>
+        public Connection()
+        {
+            SetHandler(this);
+        }
+      
+        public void Started( )
+        { 
+            // nothing to do.
+        }
+
+        public void Stopped( )
+        {
+            // nothing to do.
+        }
+
+        public void Exception( String what, Exception e )
+        {
+            TodoManager.AddTodo(new TodoDelegateImpl(
+                delegate(TodoManager mgr)
+                {
+                    session.SessionNotify(e);
+                },
+                delegate(TodoManager mgr, Exception e1)
+                {
+                    Console.WriteLine(e);
+                    if (e1 != e)
+                        Console.WriteLine(e1);
+                }));
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="first"></param>
+        /// <returns></returns>
+        /// Exception:
+        ///     throws Exception
+        protected override bool Run0( bool first )
+        {
+            bool ok = OpenSocket(!first);
+            if ( !ok )
+                return false;
+
+            try
+            {
+                SetUpSocket();
+            }
+            catch ( Exception e )
+            {
+                FireException( "setup", e );
+                Close( true );
+                return true;
+            }
+
+            try
+            {
+                FireUp();
+                ReadSocket();
+                return true;
+            }
+            catch (SocketException e)
+            {
+                // TODO ignore "socket closed" condition
+                FireException("run", e);
+                Close(true);
+                return true;
+            }
+            catch (Exception e)
+            {
+                FireException("run", e);
+                Close(true);
+                return true;
+            }
+            finally
+            {
+                FireDown();
+                Close( false );
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="reconnect">reconnect true if we are trying to reconnect, false if this
+        /// is the first time.</param>
+        /// <returns>true if we should reconnect, false if we should stop.</returns>
+        /// Exception:
+        ///     throws Exception
+        abstract protected bool OpenSocket( bool reconnect );
+        
+        /// <summary>
+        /// Sets up a newly opened socket. This may involve setting socket
+        /// options and opening input and output streams.
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        abstract protected void SetUpSocket();
+
+        /// <summary>
+        /// Performs the usual and customary operations on a socket, such
+        /// as read or accept.
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        abstract protected void ReadSocket();
+
+        /// <summary>
+        /// Terminates operations on the socket.
+        /// </summary>
+        /// <param name="reset">true if the socket should be terminated immediately.</param>
+        /// Exception:
+        ///     throws Exception
+        abstract public void Close( bool reset );
+
+        public void Close()
+        {
+            Close( false );
+        }
+
+        public virtual Object TransportQuery( Object query )
+        {
+            if ( query.Equals( LOCAL_ADDRESS ) )
+                return LocalAddress();
+
+            if ( query.Equals( REMOTE_ADDRESS ) )
+                return RemoteAddress();
+
+            if ( query is TransportConsts.WaitUp )
+            {
+                WaitUp( ( ( TransportConsts.WaitUp ) query )._maxDelay );
+                return null;
+            }
+
+            if ( query is TransportConsts.WaitDown )
+            {
+                WaitDown( ( ( TransportConsts.WaitDown ) query )._maxDelay );
+                return null;
+            }
+
+            throw new NotSupportedException("unknown query: " + query);
+        }
+
+        abstract public EndPoint LocalAddress();
+
+        abstract public EndPoint RemoteAddress();
+
+        public void TransportControl( Object control, Object value )
+        {
+            if ( control.Equals( TransportConsts.START ) )
+            {
+                Start();
+                return;
+            }
+
+            if ( control.Equals( TransportConsts.START_AND_WAIT_UP ) )
+            {
+                Start();
+                WaitUp( ( int ) value );
+                return;
+            }
+
+            if ( control.Equals( TransportConsts.STOP ) )
+            {
+                Stop();
+                return;
+            }
+
+            if ( control.Equals( TransportConsts.STOP_AND_WAIT_DOWN ) )
+            {
+                Stop();
+                WaitDown( ( int ) value );
+                return;
+            }
+
+            if (control.Equals( TransportConsts.RESET ))
+            {
+                Close(true);
+                return;
+            }
+
+            throw new NotSupportedException( "unknown control: " + control );
+        }
+
+        public void TransportNotify( Object eventObj )
+        {
+            //ignore
+        }
+
+        private void FireUp()
+	    {
+            status.Set(SessionConsts.UP);
+            TodoManager.AddTodo(new TodoDelegateImpl(
+                delegate(TodoManager mgr)
+                {
+                    session.SessionNotify(SessionConsts.UP);
+                },
+                delegate(TodoManager mgr, Exception e1)
+                {
+                    Console.WriteLine(e1);
+                }));
+          
+	    }
+
+        private void FireDown() 
+	    {
+            status.Set(SessionConsts.DOWN);
+            TodoManager.AddTodo(new TodoDelegateImpl(
+                delegate(TodoManager mgr)
+                {
+                    session.SessionNotify(SessionConsts.DOWN);
+                },
+               delegate(TodoManager mgr, Exception e1)
+               {
+                   Console.WriteLine(e1);
+               }));
+
+        }
+
+        public H GetSession()
+        {
+            return this.session;
+        }
+
+        public void SetSession(H session)
+        {
+            this.session = session;
+        }
+
+        /// <summary>
+        /// The session for the connection.
+        /// </summary>
+        protected H session;
+
+        /// <summary>
+        /// Waits until the connection is up.
+        /// </summary>
+        /// <param name="maxDelay">time in milliseconds to wait.</param>
+        /// Exception:
+        ///     throws ThreadInterruptedException
+        public void WaitUp( int maxDelay ) 
+	    {
+		    status.WaitUntilEq( SessionConsts.UP, maxDelay );
+	    }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="maxDelay">time in milliseconds to wait.</param>
+        /// Exception:
+        ///     throws InterruptedException
+        public void WaitDown( int maxDelay ) 
+	    {
+            status.WaitUntilEq(SessionConsts.DOWN, maxDelay);
+	    }
+
+        private readonly Monitor<String> status = new Monitor<String>( "status", SessionConsts.DOWN );
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Connection.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Connection.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/DateSerializer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/DateSerializer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/DateSerializer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/DateSerializer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,75 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{ 
+    /// <summary>
+    /// Serialize a DateTime into our network standard format, which
+    /// is the unix standard of milliseconds since jan 1, 1970 utc.
+    /// </summary>
+    public class DateSerializer : ImportExportHelper
+    {
+        private const String FIELD_NAME = "dateTime";
+
+        private readonly XType type;
+        private readonly Field field;
+
+        public DateSerializer( XType type, Field field )
+        {
+            this.type = type;
+            this.field = field;
+        }
+        
+        /// <summary>
+        /// Defines custom fields in the value factory so that the importer
+        /// can find them
+        /// </summary>
+        /// <param name="type"></param>
+        /// <param name="class2type"></param>
+        public static void Init( XType type, Class2TypeMap class2type )
+        {
+            Field field = type.GetField( FIELD_NAME );
+            class2type.Add( typeof( DateTime ), type );
+            type.SetComponentType( typeof( DateTime ) );
+            type.SetImportExportHelper( new DateSerializer( type, field ) );
+            type.PutValidator( field, Validator_long.Get( 0 ) );
+            type.Lock();
+        }
+
+        public override Object ImportValue( StructValue sv )
+        {
+            long ms = (long)sv.Get(field);
+            return new DateTime(epoch + ms * TICKS_PER_MS, DateTimeKind.Utc).ToLocalTime();
+        }
+
+        public override StructValue ExportValue( ValueFactory vf, Object value )
+        {
+            long ms = (((DateTime)value).ToUniversalTime().Ticks - epoch) / TICKS_PER_MS;
+            StructValue sv = new StructValue( type, vf );
+            sv.Add(field, ms);
+            return sv;
+        }
+
+        private const long TICKS_PER_MS = 10000;
+
+        private static readonly long epoch =
+            new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/DateSerializer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/DateSerializer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EmptyIterator.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EmptyIterator.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EmptyIterator.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EmptyIterator.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,62 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class EmptyIterator<E> : IEnumerator<E>
+    {
+
+        #region IEnumerator<E> Members
+
+        public E Current
+        {
+            get { throw new Exception( "No such element" ); }
+        }
+
+        #endregion
+
+        #region IDisposable Members
+
+        public void Dispose()
+        {
+            throw new Exception( "Invalid operation" );
+        }
+
+        #endregion
+
+        #region IEnumerator Members
+
+        object System.Collections.IEnumerator.Current
+        {
+            get { throw new Exception( "No such element" ); }
+        }
+
+        public bool MoveNext()
+        {
+            return false;
+        }
+
+        public void Reset()
+        {
+            throw new Exception( "Invalid operation" );
+        }
+
+        #endregion
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EmptyIterator.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EmptyIterator.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EqualsHelper.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EqualsHelper.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EqualsHelper.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EqualsHelper.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,26 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+        /// <param name="a"></param>
+        /// <param name="b"></param>
+        /// <returns>true if the value of a and b are equal even though the format is not 
+        /// (e.g., 23 as a Byte vs. Integer).</returns>
+        public delegate bool Equals(Object a, Object b);
+}
\ No newline at end of file

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EqualsHelper.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/EqualsHelper.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/FlexBuffer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/FlexBuffer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/FlexBuffer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/FlexBuffer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,762 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Diagnostics;
+using System.IO;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// A FlexBuffer wraps a byte array and manages the active region of
+    /// it (0..length). It also supports dynamically extending the buffer
+    /// as needed.
+    /// 
+    /// A FlexBuffer also has an index (read or write cursor). The various
+    /// Get and put operations always occur at the current index, with the
+    /// index adjusted appropriately afterward. Get will not move index past
+    /// length. If put needs to move index past length, length is also
+    /// adjusted. This may cause the byte array to be re-allocated to a
+    /// larger size.
+    /// </summary>
+    public sealed class FlexBuffer
+    {
+        /// <summary>
+        /// Constructs a FlexBuffer with initial length and index of 0.
+        /// </summary>
+        public FlexBuffer()
+        	: this(new byte[INIT_BUFFER_LEN], 0, 0)
+        {
+            
+        }
+
+        /// <summary>
+        /// Constructs the FlexBuffer out of an existing buffer, ready to
+        /// read, with the index set to 0 and length set to buffer.length. 
+        /// The buffer is adopted, not copied. If you want to copy, use one 
+        /// of the put methods instead.
+        /// 
+        /// Note: this is the same as FlexBuffer( buffer, 0, buffer.length ).
+        /// </summary>
+        /// <param name="buffer">the buffer to adopt.</param>
+        /// <see cref="put(byte[])"/>
+
+        public FlexBuffer(byte[] buffer)
+        	: this(buffer, 0, buffer.Length)
+        {
+            
+        }
+
+        /// <summary>
+        /// Constructs the FlexBuffer out of an existing buffer, ready to
+        /// read, with the index set to 0 and length set to buffer.length. 
+        /// The buffer is adopted, not copied. If you want to copy, use one 
+        /// of the put methods instead.
+        /// 
+        /// Note: this is the same as FlexBuffer( buffer, 0, length ).
+        /// </summary>
+        /// <param name="buffer">the buffer to adopt.</param>
+        /// <param name="length">the length of the data in the buffer (data presumed
+        /// to start at 0).</param>
+        /// <see cref="put(byte[], int, int)"/>
+
+        public FlexBuffer(byte[] buffer, int length)
+        	: this(buffer, 0, length)
+        {
+            
+        }
+
+        /// <summary>
+        /// Constructs the FlexBuffer out of an existing buffer, ready to
+        /// read, with the index set to 0 and length set to buffer.length. 
+        /// The buffer is adopted, not copied. If you want to copy, use one 
+        /// of the put methods instead.
+        /// 
+        /// Note: if you want to start off writing to the end of the buffer
+        /// and not reading it, specify index as the place to start writing, 
+        /// and length as the amount of data that is valid after index ( which 
+        /// might reasonably be 0 )
+        /// </summary>
+        /// <param name="buffer">the buffer to adopt.</param>
+        /// /// <param name="index">the index to start reading or writing.</param>
+        /// <param name="length">the length of the valid data in the buffer, 
+        /// starting at the index.</param>
+        /// 
+        
+        public FlexBuffer(byte[] buffer, int index, int length )
+        {
+            if ( buffer == null )
+                throw new NullReferenceException( "buffer == null" );
+            if ( index < 0 )
+                throw new ArgumentException( " index < 0 " );
+            if ( length < 0 )
+                throw new ArgumentException( "length < 0 " );
+            if ( index + length > buffer.Length )
+                throw new ArgumentException( "index + length > buffer.Length" );
+
+            this.buffer = buffer;
+            this.index = index;
+            this.length = index + length;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>the current byte array. Might change if any operation
+        /// needs to extend length past the end of the array.</returns>
+        public byte[] GetBuf()
+        {
+            return buffer;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="len"></param>
+        /// Exception:
+        ///     throws IOException
+
+        private void EnsureLength( int len ) 
+	    {
+		    int n = buffer.Length;
+		    if (len <= n)
+			    return;
+    		
+            // the buffer is not big enough, expand it
+
+		    int k = n;
+            if ( k < INIT_BUFFER_LEN )
+                k = INIT_BUFFER_LEN;
+
+            while ( len > k && k < MAX_BUFFER_LEN )
+                k = k << 1;
+    		
+		    if (len > k)
+			    throw new IOException( "buffer overflow" );
+    		
+		    byte[] b = new byte[k];
+            Array.Copy( buffer, 0, b, 0, n );
+		    buffer = b;
+	    }
+
+        private byte[] buffer;
+	
+	    private const int INIT_BUFFER_LEN = 32;
+	    
+	    private const int TRIM_BUFFER_LEN = 16*1024;
+	
+	    private const int MAX_BUFFER_LEN = 4*1024*1024;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>the current value of length. This is the last
+        /// index of valid data in the buffer.</returns>
+        public int Length()
+        {
+            return length;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="length">length the new value of length. Length must be >= 0.
+        /// If length is less than index, index is also set to length. If length
+        /// is larger than the current buffer, the buffer is expanded.</param>
+        /// <returns>this flex buffer object.</returns>
+        /// Exception:
+        ///     throws ArgumentOutOfRangeException, IOException
+        public FlexBuffer SetLength( int length ) 
+	    {
+		    if (length < 0)
+			    throw new ArgumentOutOfRangeException( "length < 0" );
+    		
+		    EnsureLength( length );
+    		
+		    this.length = length;
+    		
+		    if (index > length)
+			    index = length;
+    		
+		    return this;
+	    }
+
+        private int length;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>the current value of index.</returns>
+        public int Index()
+        {
+            return index;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="index">index the new value of index. Index must be >= 0.</param>
+        /// <returns>this flex buffer object.</returns>
+        /// Exception:
+        ///     throws ArgumentOutOfRangeException
+
+        public FlexBuffer SetIndex( int index ) 
+	    {
+		    if (index < 0 || index > length)
+			    throw new ArgumentOutOfRangeException( "index < 0 || index > length" );
+    		
+		    this.index = index;
+    		
+		    return this;
+	    }
+
+        private int index;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>length() - index(). Result is always >= 0. This is the amount
+        /// of data that could be read using the various forms of Get. It doesn't
+        /// really mean anything in relation to put.</returns>
+
+        public int Avail()
+        {
+            return length - index;
+        }
+
+        /// <summary>
+        /// Sets both length and index to 0.
+        /// 
+        /// Shorthand for SetLength( 0 ).
+        /// </summary>
+        /// <returns>this flex buffer object.</returns>
+
+        public FlexBuffer Reset()
+        {
+            index = 0;
+            length = 0;
+		
+			if (buffer.Length > TRIM_BUFFER_LEN)
+				buffer = new byte[TRIM_BUFFER_LEN];
+
+            return this;
+        }
+
+        /// <summary>
+        /// Compacts the buffer by moving remaining data (from index to length)
+        /// to the front of the buffer. Sets index to 0, and sets length to
+        /// Avail (before index was changed).
+        /// </summary>
+        /// <returns>this flex buffer object.</returns>
+
+        public FlexBuffer Compact()
+        {
+            if(index == 0)
+                return this;
+
+            int n = Avail();
+            if(n == 0)
+            {
+                Reset();
+                return this;
+            }
+
+            Array.Copy(buffer, index, buffer, 0, n);
+
+            index = 0;
+            length = n;
+
+            return this;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>the byte value at index, and adjusts index
+        /// by adding one.</returns>
+        /// Exception:
+        ///     End of File exception / NullReferenceException
+
+        public int Get() 
+	    {
+		    CheckAvail( 1 );
+
+		    return buffer[index++] & 255;
+	    }
+
+        /// <summary>
+        /// Copies data from the byte array to buf as if by repeated
+        /// calls to Get().
+        /// </summary>
+        /// <param name="buf">a buffer to receive the data. At most
+        /// min( buf.length, Avail() ) bytes are transferred.</param>
+        /// <returns>the amount of data transferred.</returns>
+        /// Exception:
+        ///     End of File exception / NullReferenceException
+
+        public int Get( byte[] buf ) 
+	    {
+            return Get( buf, 0, buf.Length );
+	    }
+
+
+        /// <summary>
+        /// Copies data from the byte array to buf as if by repeated
+        /// calls to Get().
+        /// </summary>
+        /// <param name="buf">a buffer to receive the data. At most
+        /// min( len, Avail() ) bytes are transferred, starting
+        /// at off.</param>
+        /// <param name="off">the index in buf to receive the data.
+        /// off must be >= 0 && less than or equal to buf.length.</param>
+        /// <param name="len">the max amount of data to transfer. Len
+        /// must be >= 0 and less than or equal to buf.length - off.</param>
+        /// <returns>the amount of data transferred.</returns>
+        /// Exception:
+        ///     End of File exception / NullReferenceException
+
+        public int Get( byte[] buf, int off, int len ) 
+	    {
+		    CheckBuf( buf, off, len );
+    		
+		    if (len == 0)
+			    return 0;
+
+            CheckAvail( 1 );
+    		
+		    int n = Math.Min( len, Avail() );
+    		
+	//	    Array.Copy( buffer, index, buf, off, n );
+            Buffer.BlockCopy(buffer, index, buf, off, n);
+		    index += n;
+    		
+		    return n;
+	    }
+
+        public sbyte GetByte()
+        {
+            CheckAvail( 1 );
+            return (sbyte)buffer[ index++ ];
+        }
+        public readonly static bool littleEndian = false;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>a short composed from the next 2 bytes. Little-endian.</returns>
+        /// Exception:
+        ///     throws Exception if avail() < 2
+        public short GetShort()
+        {
+            CheckAvail( 2 );
+
+            if ( littleEndian )
+            {
+                // little-endian
+                int value = buffer[ index++ ] & 255;
+                return ( short ) ( value + ( ( buffer[ index++ ] & 255 ) << 8 ) );
+            }
+            else
+            {
+                // big-endian
+                int value = buffer[ index++ ];
+                return ( short ) ( ( value << 8 ) + ( buffer[ index++ ] & 255 ) );
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>an integer composed of 4 bytes from
+        /// the buffer, with the first byte being the least
+        /// significant and the last being the most significant.</returns>
+        /// Exception:
+        ///     End of File exception / NullReferenceException
+
+        public int GetInt() 
+	    {
+            CheckAvail( 4 );
+
+            if ( littleEndian )
+            {
+                // little-endian
+                int value = buffer[ index++ ] & 255;
+                value += ( ( buffer[ index++ ] & 255 ) << 8 );
+                value += ( ( buffer[ index++ ] & 255 ) << 16 );
+                return value + ( ( buffer[ index++ ] & 255 ) << 24 );
+            }
+            else
+            {
+                // big-endian
+                int value = buffer[ index++ ];
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                return ( value << 8 ) + ( buffer[ index++ ] & 255 );
+            }
+	    }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>a long comprised of the next 8 bytes. Little-endian</returns>
+        public long GetLong()
+        {
+            CheckAvail( 8 );
+            if ( littleEndian )
+            {
+                // little-endian
+                long value = buffer[ index++ ] & 255;
+                value += ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 8 );
+                value += ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 16 );
+                value += ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 24 );
+                value += ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 32 );
+                value += ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 40 );
+                value += ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 48 );
+                return value + ( ( ( long ) ( buffer[ index++ ] & 255 ) ) << 56 );
+            }
+            else
+            {
+                // big-endian
+                long value = buffer[ index++ ];
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                value = ( value << 8 ) + ( buffer[ index++ ] & 255 );
+                return ( value << 8 ) + ( buffer[ index++ ] & 255 );
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>a float from the next available bytes</returns>
+        public float GetFloat()
+        {
+            return BitConverter.ToSingle( BitConverter.GetBytes( GetInt() ), 0 );
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>a double from the next available bytes</returns>
+        public double GetDouble()
+        {
+            return BitConverter.Int64BitsToDouble( GetLong() );
+        }
+
+
+        public void GetFully( byte[] b )
+        {
+            CheckAvail( b.Length );
+            int n = Get( b, 0, b.Length );
+            Debug.Assert( n == b.Length );
+        }
+
+        
+        /// <summary>
+        /// Puts a byte into the buffer at the current index,
+        /// then adjusts the index by one. Adjusts the length
+        /// as necessary. The buffer is expanded if needed.
+        /// </summary>
+        /// <param name="b">byte to be put</param>
+        /// <returns>this flex buffer object.</returns>
+        /// Exception: 
+        ///     IOException if the buffer overflows its max length.
+
+        public FlexBuffer Put( int b ) 
+	    {
+		    EnsureLength( index+1 );
+		    buffer[index++] = (byte) b;
+		    FixLength();
+    		
+		    return this;
+	    }
+
+        /// <summary>
+        /// Puts some bytes into the buffer as if by repeated
+        /// calls to put().
+        /// </summary>
+        /// <param name="buf">the source of the bytes to put. The entire
+        /// array of bytes is put.</param>
+        /// <returns>flex buffer object.</returns>
+        /// Exception: 
+        ///     IOException if the buffer overflows its max length.
+        public FlexBuffer Put( byte[] buf ) 
+	    {
+            return Put( buf, 0, buf.Length );
+	    }
+
+        /// <summary>
+        /// Puts some bytes into the buffer as if by repeated
+        /// calls to Put().
+        /// </summary>
+        /// <param name="buf">the source of the bytes to put.</param>
+        /// <param name="off">the index to the first byte to put.</param>
+        /// <param name="len">the number of bytes to put.</param>
+        /// <returns>flex buffer object.</returns>
+        /// Exception:
+        ///     IOException if the buffer overflows its max length.
+
+        public FlexBuffer Put( byte[] buf, int off, int len ) 
+	    {
+		    CheckBuf( buf, off, len );
+    		
+		    if (len == 0)
+			    return this;
+    		
+		    EnsureLength( index+len );
+	//	    Array.Copy( buf, off, buffer, index, len );
+            Buffer.BlockCopy(buf, off, buffer, index, len);
+		    index += len;
+		    FixLength();    
+    		
+		    return this;
+	    }
+
+        /// <summary>
+        /// Copies the Available bytes from buf into buffer as if by
+        /// repeated execution of put( buf.Get() ).
+        /// </summary>
+        /// <param name="buf">the source of the bytes to put. All Available
+        /// bytes are copied.</param>
+        /// <returns>flex buffer object.</returns>
+        /// Exception: 
+        ///     IOException if the buffer overflows its max length.
+
+        public FlexBuffer Put( FlexBuffer buf ) 
+	    {
+            int n = buf.Avail();
+            Put( buf.buffer, buf.index, n );
+            buf.Skip( n, false );
+		    return this;
+	    }
+
+        /// <summary>
+        /// Copies the specified number of bytes from buf into buffer
+        /// as if by repeated execution of Put( buf.Get() ).
+        /// </summary>
+        /// <param name="buf">the source of the bytes to put.</param>
+        /// <param name="len"></param>len the number of bytes to put. Len must be 
+        /// less than or equal to buf.Avail().
+        /// <returns>flex buffer object.</returns>
+        /// Exception:
+        ///     IOException if the buffer overflows its max length.
+
+        public FlexBuffer Put( FlexBuffer buf, int len ) 
+	    {
+		    if (len > buf.Avail())
+			    throw new ArgumentOutOfRangeException( "len > buf.Avail()" );
+
+            Put( buf.buffer, buf.index, len );
+            buf.Skip( len, false );
+		    return this;
+	    }
+
+        public void PutByte( byte value )
+        {
+            EnsureLength( index + 1 );
+            buffer[ index++ ] = ( byte ) value;
+            FixLength();
+        }
+
+        public void PutByte( sbyte value )
+        {
+            EnsureLength( index + 1 );
+            buffer[ index++ ] = ( byte ) value;
+            FixLength();
+        }
+
+        /// <summary>
+        /// Put short as the next 2 bytes. Little-endian
+        /// </summary>
+        /// <param name="value"></param>
+        public void PutShort( short value )
+        {
+            EnsureLength( index + 2 );
+            if ( littleEndian )
+            {
+                buffer[ index++ ] = ( byte ) value;
+                buffer[ index++ ] = ( byte ) ( value >> 8 );
+            }
+            else
+            {
+                /// In C#, since we're using the byte (which is unsigned),
+                /// it doesn't matter whether you do logical or arithmetic 
+                /// shift. Hence, an equivalent of the Java >>> operator is 
+                /// not required here. 
+                buffer[ index++ ] = ( byte ) ( value >> 8 );
+                buffer[ index++ ] = ( byte ) value;
+            }
+            FixLength();
+        }
+
+        public void PutInt( int value )
+        {
+            EnsureLength( length + 4 );
+
+            if ( littleEndian )
+            {
+                buffer[ index++ ] = ( byte ) value;
+                buffer[ index++ ] = ( byte ) ( value >> 8 );
+                buffer[ index++ ] = ( byte ) ( value >> 16 );
+                buffer[ index++ ] = ( byte ) ( value >> 24 );
+            }
+            else
+            {
+
+                buffer[ index++ ] = ( byte ) ( value >> 24 );
+                buffer[ index++ ] = ( byte ) ( value >> 16 );
+                buffer[ index++ ] = ( byte ) ( value >> 8 );
+                buffer[ index++ ] = ( byte ) value;
+                
+            }
+            FixLength();
+        }
+
+        public void PutLong( long value )
+        {
+            EnsureLength( index+8 );
+
+            if ( littleEndian )
+            {
+                buffer[ index++ ] = ( byte ) value;
+                buffer[ index++ ] = ( byte ) ( value >> 8 );
+                buffer[ index++ ] = ( byte ) ( value >> 16 );
+                buffer[ index++ ] = ( byte ) ( value >> 24 );
+                buffer[ index++ ] = ( byte ) ( value >> 32 );
+                buffer[ index++ ] = ( byte ) ( value >> 40 );
+                buffer[ index++ ] = ( byte ) ( value >> 48 );
+                buffer[ index++ ] = ( byte ) ( value >> 56 );
+            }
+            else
+            {
+
+                buffer[ index++ ] = ( byte ) ( value >> 56 );
+                buffer[ index++ ] = ( byte ) ( value >> 48 );
+                buffer[ index++ ] = ( byte ) ( value >> 40 );
+                buffer[ index++ ] = ( byte ) ( value >> 32 );
+                buffer[ index++ ] = ( byte ) ( value >> 24 );
+                buffer[ index++ ] = ( byte ) ( value >> 16 );
+                buffer[ index++ ] = ( byte ) ( value >> 8 );
+                buffer[ index++ ] = ( byte ) value;
+                
+            }
+            FixLength();
+        }
+
+        public void PutFloat( float value )
+        {
+            PutInt( BitConverter.ToInt32( BitConverter.GetBytes( value ), 0 ) );
+        }
+
+        public void PutDouble( double value )
+        {
+            PutLong( BitConverter.DoubleToInt64Bits( value ) );
+        }
+
+
+        /// <summary>
+        /// Adjusts index as if by a Get or put but without transferring
+        /// any data. This could be used to skip over a data item in an
+        /// input or output buffer.
+        /// </summary>
+        /// <param name="len">len the number of bytes to skip over. Len must be
+        /// greater than or equal to 0. If put is false, it is an error if len >Avail(). 
+        /// If put is true, the buffer 
+        /// may be extended (and the buffer length adjusted).</param>
+        /// <param name="put">put if true it is ok to extend the length of the
+        /// buffer.</param>
+        /// <returns>this Flexbuffer object.</returns>
+        /// Exception:
+        ///     IOException 
+        public FlexBuffer Skip( int len, bool put ) 
+	    {
+		    if (len < 0)
+			    throw new ArgumentException( "count < 0" );
+    		
+		    if (len == 0)
+			    return this;
+    		
+		    if (put)
+		    {
+			    EnsureLength( index+len );
+    			
+			    index += len;
+			    FixLength();
+    			
+			    return this;
+		    }
+
+            CheckAvail( len );
+    		
+		    index += len;
+    		
+		    return this;
+	    }
+
+        
+        /// <summary>
+        /// If index has moved past length during a put, then adjust length
+        /// to track index.
+        /// </summary>
+        private void FixLength()
+        {
+            if(index > length)
+                length = index;
+        }
+
+
+        private void CheckBuf(byte[] buf, int off, int len)
+        {
+            if(buf == null)
+                throw new NullReferenceException("buf == null");
+
+            if(off < 0 || off > buf.Length)
+                throw new ArgumentOutOfRangeException("off < 0 || off > buf.length");
+
+            if(len < 0)
+                throw new ArgumentOutOfRangeException("len < 0");
+
+            if(off+len > buf.Length)
+                throw new ArgumentOutOfRangeException("off+len > buf.length");
+        }
+
+        /// <summary>
+        /// Return the currently Available bytes.
+        /// </summary>
+        /// <returns>the currently Available bytes.</returns>
+        /// Exception: 
+        ///     throws an IO Exception
+        public byte[] GetAvailBytes() 
+	    {
+		    byte[] buf = new byte[Avail()];
+		    Get( buf );
+		    return buf;
+	    }
+
+        /// <summary>
+        /// Checks that there are enough bytes to for a read.
+        /// </summary>
+        /// <param name="len">the length required by a read operation.</param>
+        private void CheckAvail( int len )
+        {
+            if ( len > Avail() )
+                throw new EndOfStreamException( " len > Avail() " );
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/FlexBuffer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/FlexBuffer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/HPTimer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/HPTimer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/HPTimer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/HPTimer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,113 @@
+/* $Id$
+ *
+ * Copyright 2007-2008 Cisco Systems Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+	public abstract class HPTimer
+	{
+		[DllImport("kernel32.dll")]
+		private static extern bool QueryPerformanceCounter(out long x);
+
+		[DllImport("kernel32.dll")]
+		private static extern bool QueryPerformanceFrequency(out long x);
+
+		static HPTimer()
+		{
+			long freq = 0;
+
+			if (!QueryPerformanceFrequency(out freq))
+				throw new Exception( "QueryPerformanceFrequency not supported" );
+			
+			// freq is ticks / second.
+			// we wanna compute seconds from ticks.
+			// the easy computation is seconds = ticks / freq
+			// to Get ns, we compute ns = ticks * 1,000,000,000 / freq
+			// the problem is ticks * 1,000,000,000 will likely overflow.
+			// what we want to do is precompute nsPerTick = 1,000,000,000 / freq
+			// and then compute ns = ticks * nsPerTick.
+
+			//Console.WriteLine( "HPTimer: freq = "+freq );
+			nsPerTick = ((double) NS_PER_SECOND)/freq;
+			//Console.WriteLine( "HPTimer: nsPerTick = "+nsPerTick );
+		}
+
+        public const long NS_PER_MICROSECOND = 1000;
+        public const long NS_PER_MILLISECOND = 1000 * NS_PER_MICROSECOND;
+        public const double NS_PER_SECOND = 1000.0 * NS_PER_MILLISECOND;
+
+		/// <summary>
+		/// Returns the current high precision timer value in nanos.
+		/// </summary>
+		/// <returns></returns>
+		public static long Now()
+		{
+			long x = 0;
+			
+			if (!QueryPerformanceCounter(out x))
+				throw new Exception( "QueryPerformanceCounter not supported" );
+
+			return (long) (x * nsPerTick);
+		}
+
+		/// <summary>
+		/// Returns the difference in nanos between the current timer value and
+		/// a timer value previously returned by Now.
+		/// </summary>
+		/// <param name="y"></param>
+		/// <returns></returns>
+		public static long NsSince( long y )
+		{
+			return Now() - y;
+		}
+
+		/// <summary>
+		/// Returns the difference in millis between the current timer value and
+		/// a timer value previously returned by Now.
+		/// </summary>
+		/// <param name="y"></param>
+		/// <returns></returns>
+		public static long MillisSince( long y )
+		{
+            return NsSince(y) / NS_PER_MILLISECOND;
+		}
+
+		/// <summary>
+		/// Returns the difference in seconds between the current timer value and
+		/// a timer value previously returned by Now.
+		/// </summary>
+		/// <param name="y"></param>
+		/// <returns></returns>
+		public static double SecondsSince( long y )
+		{
+            return NsSince(y) / NS_PER_SECOND;
+		}
+
+		/// <summary>
+		/// Returns the number of high precision clock ticks per nano.
+		/// </summary>
+		/// <returns></returns>
+		public static double NsPerTick()
+		{
+			return nsPerTick;
+		}
+
+		private static double nsPerTick;
+	}
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/HPTimer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/HPTimer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IdGenerator.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IdGenerator.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IdGenerator.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IdGenerator.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,78 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Synchronously generates long id numbers. 
+    /// </summary>
+    public sealed class IdGenerator 
+    {
+        /// <summary>
+        /// Constructs the IdGenerator with the default starting point of 1
+        /// and the default stride of 1.
+        /// </summary>
+        public IdGenerator() : this( 1, 1 )
+        {
+            
+        }
+
+        /// <summary>
+        /// Constructs the IdGenerator with the specified starting point
+        /// and the default stride of 1.
+        /// </summary>
+        /// <param name="nextId"></param>
+        public IdGenerator( long nextId ) : this( nextId, 1 )
+        {
+            
+        }
+
+        /// <summary>
+        /// Constructs the IdGenerator with the specified starting point
+        /// and the specified stride.
+        /// </summary>
+        /// <param name="nextId"></param>
+        /// <param name="stride"></param>
+        public IdGenerator( long nextId, int stride )
+        {
+            if ( stride <= 0 )
+                throw new ArgumentException( "stride <= 0" );
+
+            this.nextId = nextId;
+            this.stride = stride;
+        }
+
+        private long nextId;
+	
+	    private readonly int stride;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>The next Id in sequence</returns>
+        [MethodImpl(MethodImplOptions.Synchronized)]
+        public long Next()
+        {
+            long id = nextId;
+            nextId += stride;
+            return id;
+        }
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IdGenerator.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IdGenerator.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/InputStream.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/InputStream.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/InputStream.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/InputStream.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,61 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public interface InputStream
+    {
+        /// <summary>
+        /// Returns the number of bytes that can be read (or skipped over) 
+        /// from this input stream without blocking by the next caller of a 
+        /// method for this input stream.
+        /// </summary>
+        /// <returns></returns>
+         int Available();
+
+        /// <summary>
+        /// Closes this input stream and releases any system resources 
+        /// associated with the stream.
+        /// </summary>
+         void Close();
+
+        /// <summary>
+        /// Reads the next byte of data from the input stream.
+        /// </summary>
+        /// <returns>the next byte of data, or -1 if the end of 
+        /// the stream is reached.</returns>
+         int Read();
+
+        /// <summary>
+        ///  Reads some number of bytes from the input stream and stores them 
+        /// into the buffer array b.
+        /// </summary>
+        /// <param name="buf">the buffer into which the data is read.</param>
+        /// <returns>the total number of bytes read into the buffer, or -1 is 
+        /// there is no more data because the end of the stream has been reached.</returns>
+         int Read(byte[] buf);
+
+        /// <summary>
+        /// Reads up to len bytes of data from the input stream into an array of bytes.
+        /// </summary>
+        /// <param name="b">the buffer into which the data is read.</param>
+        /// <param name="off">the start offset in array b  at which the data is written.</param>
+        /// <param name="len">the maximum number of bytes to read.</param>
+        /// <returns>the total number of bytes read into the buffer, or -1 if there is no more
+        /// data because the end of the stream has been reached.</returns>
+         int Read(byte[] b, int off, int len);
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/InputStream.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/InputStream.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IntCounter.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IntCounter.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IntCounter.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IntCounter.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,50 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System.Runtime.CompilerServices;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    ///  A safe integer counter
+    /// </summary>
+    public class IntCounter
+    {
+        /// <summary>
+        /// Adjusts the value of the counter by k
+        /// </summary>
+        /// <param name="k">the adjustment to the counter.</param>
+        /// <returns>the new value of the counter.</returns>
+        /// 
+        [MethodImpl( MethodImplOptions.Synchronized )]
+        public int Adjust( int k )
+        {
+            value += k;
+            return value;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>the value of the counter</returns>
+        public int Get()
+        {
+            return value;
+        }
+
+        private int value;
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IntCounter.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/IntCounter.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Integer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Integer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Integer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Integer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,187 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class Integer : IComparable, IComparable<Integer>, IEquatable<Integer>, IConvertible
+    {
+        public Integer(Integer other)
+        {
+            this.value = other.value;
+        }
+
+        public Integer(int value)
+        {
+            this.value = value;
+        }
+
+        private readonly int value;
+
+        public override string ToString()
+        {
+            return value.ToString();
+        }
+
+        public static implicit operator Integer(int value)
+        {
+            return new Integer(value);
+        }
+
+        public static implicit operator int(Integer value)
+        {
+            return value.value;
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (obj == this)
+                return true;
+
+            if (obj == null || obj.GetType() != GetType())
+                return false;
+
+            Integer other = (Integer)obj;
+            return value == other.value;
+        }
+
+        public override int GetHashCode()
+        {
+            return value;
+        }
+
+        #region IComparable Members
+
+        public int CompareTo(object obj)
+        {
+            if (obj is Integer)
+                return CompareTo((Integer)obj);
+            throw new ArgumentException("obj is not Integer");
+        }
+
+        #endregion
+
+        #region IComparable<Integer> Members
+
+        public int CompareTo(Integer other)
+        {
+            if (value < other.value) return -1;
+            if (value > other.value) return 1;
+            return 0;
+        }
+
+        #endregion
+
+        #region IEquatable<Integer> Members
+
+        public bool Equals(Integer other)
+        {
+            return other != null && value == other.value;
+        }
+
+        #endregion
+
+        #region IConvertible Members
+
+        TypeCode IConvertible.GetTypeCode()
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        bool IConvertible.ToBoolean(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        byte IConvertible.ToByte(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        char IConvertible.ToChar(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        DateTime IConvertible.ToDateTime(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        decimal IConvertible.ToDecimal(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        double IConvertible.ToDouble(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        short IConvertible.ToInt16(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        int IConvertible.ToInt32(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        long IConvertible.ToInt64(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        sbyte IConvertible.ToSByte(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        float IConvertible.ToSingle(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        string IConvertible.ToString(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        object IConvertible.ToType(Type conversionType, IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        ushort IConvertible.ToUInt16(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        uint IConvertible.ToUInt32(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        ulong IConvertible.ToUInt64(IFormatProvider provider)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Integer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Integer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/ListSerializer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/ListSerializer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/ListSerializer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/ListSerializer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,93 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class ListSerializer : ImportExportHelper
+    {
+        private static String FIELD_NAME = "values";
+
+         /// <summary>
+        /// Defines custom fields in the value factory so that the importer
+        /// can find them.
+        /// </summary>
+        /// <param name="type"></param>
+        /// <param name="class2type"></param>
+        public static void Init( XType type, Class2TypeMap class2type )
+        {
+            Field field = type.GetField( FIELD_NAME );
+     /*       class2type.Add( typeof( List<object> ), type );
+            type.SetClass(typeof(List<object>)); */
+            class2type.Add(typeof(ArrayList), type);
+            type.SetComponentType(typeof(ArrayList));
+            type.SetImportExportHelper( new ListSerializer( type, field ) );
+            type.PutValidator( field, Validator_object.Get( 1 ) );
+            type.Lock();
+        }
+
+        public ListSerializer( XType type, Field field )
+        {
+            this.type = type;
+            this.field = field;
+        }
+
+        private readonly XType type;
+        private readonly Field field;
+
+
+        public override Object ImportValue( StructValue sv )
+        {
+       //    List<object> list = new List<object>();
+            ArrayList list = new ArrayList();
+            Object[] values = ( Object[] ) sv.Get( field );
+            int n = values.Length;
+            int index = 0;
+            while ( index < n )
+            {
+               
+                object value = ( object ) values[ index++ ];
+                list.Add( value );
+            }
+
+            return list;
+        }
+
+        public override StructValue ExportValue(ValueFactory vf, Object value)
+        {
+     //       List<object> list = (List<object>)value;
+            ArrayList list = (ArrayList)value;
+            Object[] values = new Object[ list.Count];
+            int index = 0;
+
+            foreach ( object me in list )
+            {
+                values[ index++ ] = me;
+              
+            }
+
+            StructValue sv = new StructValue(type, vf);
+            sv.Add( field, values );
+            return sv;
+
+        }
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/ListSerializer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/ListSerializer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/MapSerializer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/MapSerializer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/MapSerializer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/MapSerializer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,95 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class MapSerializer : ImportExportHelper
+    {
+        private static String FIELD_NAME = "keysAndValues";
+
+         /// <summary>
+        /// Defines custom fields in the value factory so that the importer
+        /// can find them.
+        /// </summary>
+        /// <param name="type"></param>
+        /// <param name="class2type"></param>
+        public static void Init( XType type, Class2TypeMap class2type )
+        {
+            Field field = type.GetField( FIELD_NAME );
+      /*      class2type.Add( typeof( Dictionary<object,object> ), type );
+            type.SetClass(typeof(Dictionary<object, object>)); */
+            class2type.Add(typeof(Hashtable), type);
+            type.SetComponentType(typeof(Hashtable));
+            type.SetImportExportHelper( new MapSerializer( type, field ) );
+            type.PutValidator( field, Validator_object.Get( 1 ) );
+            type.Lock();
+        }
+
+        public MapSerializer( XType type, Field field )
+        {
+            this.type = type;
+            this.field = field;
+        }
+
+        private readonly XType type;
+        private readonly Field field;
+
+
+        public override Object ImportValue( StructValue sv )
+        {
+     //      Dictionary<object,object> map = new Dictionary<object,object>();
+           Hashtable map = new Hashtable();
+            Object[] keysAndValues = ( Object[] ) sv.Get( field );
+            int n = keysAndValues.Length;
+            int index = 0;
+            while ( index < n )
+            {
+                object key = ( object ) keysAndValues[ index++ ];
+                object value = ( object ) keysAndValues[ index++ ];
+                map.Add( key, value );
+            }
+
+            return map;
+        }
+
+        public override StructValue ExportValue(ValueFactory vf, Object value)
+        {
+       //     Dictionary<object, object> map = (Dictionary<object, object>)value;
+
+            Hashtable map = (Hashtable)value;
+
+            Object[] keysAndValues = new Object[ map.Count * 2];
+            int index = 0;
+
+            foreach ( DictionaryEntry me in map )
+            {
+                keysAndValues[ index++ ] = me.Key;
+                keysAndValues[ index++ ] = me.Value;
+            }
+
+            StructValue sv = new StructValue( type, vf );
+            sv.Add( field, keysAndValues );
+            return sv;
+
+        }
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/MapSerializer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/MapSerializer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Monitor.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Monitor.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Monitor.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Monitor.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,298 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Threading;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// A class which we can use to monitor conditions.
+    /// </summary>
+    /// <typeparam name="T">Type of object that can be stored in the monitor</typeparam>
+    public class Monitor<T>
+    {
+        /// <summary>
+        /// Constructs the Monitor.
+        /// </summary>
+        /// <param name="description">a description of this monitor</param>
+        /// <param name="initialValue">the initial value of this monitor</param>
+        public Monitor( String description, T initialValue )
+        {
+            this.description = description;
+            this.value = initialValue;
+        }
+        /// <summary>
+        /// Constructs the Monitor with null initial value
+        /// </summary>
+        /// <param name="description">a description of this monitor</param>
+        
+        public Monitor( String description ) : this( description, default( T ) )
+        {   
+        }
+
+        /// <summary>
+        /// Get the description of the Monitor
+        /// </summary>
+        /// <returns> return the description of this monitor</returns>
+
+        public String GetDescription()
+        {
+            return description;
+        }
+
+        private String description;
+	    private T value;
+
+        public override string ToString()
+        {
+            return "Monitor "+description+": "+value;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>The current value of the monitor</returns>
+        public T Get()
+        {
+            return value;
+        }
+
+        /// <summary>
+        /// Sets the current value.
+        /// </summary>
+        /// <param name="newValue"> the value to be set</param>
+        /// <returns>the old value.</returns>
+        [MethodImpl(MethodImplOptions.Synchronized)]
+        public T Set( T newValue )
+	    {
+		    T oldValue = value;
+		    value = newValue;
+		    System.Threading.Monitor.PulseAll(this);
+		    return oldValue;
+	    }
+
+        /// <summary>
+        /// Waits until monitor value is set
+        ///  the value. Will wait forever
+        /// </summary>
+        /// <param name="maxDelay">the max amount of time in ms to wait.
+        /// If 0 is specified, we will wait forever.</param>
+        /// <returns>the current value of the monitor.</returns>
+        /// Exception:
+        ///     throws ThreadInterruptedException if we waited too long.
+        [MethodImpl( MethodImplOptions.Synchronized )]
+        private T WaitUntilSet( long maxDelay )
+		{
+            System.Threading.Monitor.Wait( this, (int) maxDelay );
+            return value;
+	    }
+
+
+        /// <summary>
+        /// Waits until value equals the desired value and
+        /// then sets the value. Will wait forever.
+        /// </summary>
+        /// <param name="desiredValue">the value we want</param>
+        /// <param name="newValue">the value to be set</param>
+        /// <returns>The old value</returns>
+        /// Exception: 
+        ///     throws Exception
+        public T WaitUntilEqAndSet( T desiredValue, T newValue )
+        {
+            return WaitUntilEqAndSet( desiredValue, 0, newValue );
+        }
+
+        /// <summary>
+        /// Waits until value equals the desired value and
+        /// then sets the value
+        /// </summary>
+        /// <param name="desiredValue">the value we want.</param>
+        /// <param name="maxDelay">the max amount of time in ms to wait
+        ///  If 0 is specified, we will wait forever.
+        /// </param>
+        /// <param name="newValue">the value to be set</param>
+        /// <returns>Old Value</returns>
+        /// Exception:  
+        ///     throws ThreadInterruptedException
+        [MethodImpl( MethodImplOptions.Synchronized )]
+        public T WaitUntilEqAndSet( T desiredValue, int maxDelay, T newValue )
+        {
+            WaitUntilEq(desiredValue, maxDelay);
+            return Set(newValue);
+        }
+
+        /// <summary>
+        /// Waits forever until the value is set to the specified value.
+        /// </summary>
+        /// <param name="desiredValue">The value we are waiting for.</param>
+        /// Exception:  
+        ///     throws ThreadInterruptedException
+        public void WaitUntilEq( T desiredValue )
+        { 
+            WaitUntilEq( desiredValue, 0 );
+        }
+
+        /// <summary>
+        /// Waits until the value equals the desired value
+        /// </summary>
+        /// <param name="desiredValue">The value we want</param>
+        /// <param name="maxDelay">the max amount of time in ms to wait.
+        /// If 0 is specified, we will wait forever.</param>
+        /// Exception:
+        ///     throws ThreadInterruptedException if we waited too long.
+        [MethodImpl(MethodImplOptions.Synchronized)]
+        public void WaitUntilEq(T desiredValue, int maxDelay)
+        {
+            CheckDelay(maxDelay);
+            
+            long now = HPTimer.Now(); 
+            long end = EndTime(now, maxDelay);
+ 
+            int d;
+            while (!Eq(value, desiredValue) && (d = RemTime(end, now)) > 0)
+            {
+                System.Threading.Monitor.Wait(this, d);
+                now = HPTimer.Now(); 
+            }
+
+            if (!Eq(value, desiredValue))
+                throw new ThreadInterruptedException("timeout");
+        }
+        
+        
+        /// <summary>
+        /// Waits until value does not equal the undesired value and then
+        /// sets the value. Will wait forever
+        /// </summary>
+        /// <param name="undesiredValue">the value we do not want</param>
+        /// <param name="newValue">the value to be set</param>
+        /// <returns>Old value</returns>
+        /// Exception:
+        ///     throws ThreadInterruptedException
+        public T WaitUntilNotEqAndSet( T undesiredValue, T newValue )
+        {
+            return WaitUntilNotEqAndSet( undesiredValue, 0, newValue );
+        }
+
+        /// <summary>
+        /// Waits until value does not equal the undesired value and then
+        /// sets the value. 
+        /// </summary>
+        /// <param name="undesiredValue">the value we do not want</param>
+        /// <param name="maxDelay">the max amount of time in ms to wait.
+        /// If 0 is specified, we will wait forever.</param>
+        /// <param name="newValue">New value</param>
+        /// <returns>The old value</returns>
+        /// Exception:
+        ///     throws ThreadInterrupedException
+        [MethodImpl( MethodImplOptions.Synchronized )]
+        public T WaitUntilNotEqAndSet( T undesiredValue,
+            int maxDelay, T newValue )
+        {
+            WaitUntilNotEq( undesiredValue, maxDelay );
+            return Set( newValue );
+        }
+
+        /// <summary>
+        /// Waits until value does not equal the undesired value. Will
+        /// wait forever
+        /// </summary>
+        /// <param name="undesiredValue">The value we do not want</param>
+        /// <returns>Curretn value of the monitor</returns>
+        /// Exception:
+        ///     throws ThreadInterruptedException if we waited too long.
+        public T WaitUntilNotEq( T undesiredValue )
+        {
+            return WaitUntilNotEq( undesiredValue, 0 );
+        }
+
+        /// <summary>
+        /// Waits until the value is not the specified value.
+        /// </summary>
+        /// <param name="undesiredValue">the value we do not want.</param>
+        /// <param name="maxDelay">the max amount of time in ms to wait.
+        /// If 0 is specified, we will wait forever.</param>
+        /// <returns>the current value of the monitor</returns>
+        /// Exception:
+        ///     throws ThreadInterruptedException if we waited too long.
+        [MethodImpl(MethodImplOptions.Synchronized)]
+        public T WaitUntilNotEq(T undesiredValue, int maxDelay)
+        {
+            CheckDelay(maxDelay);
+
+            long now = HPTimer.Now();
+            long end = EndTime(now, maxDelay);
+            
+            int d;
+            while (Eq(value, undesiredValue) && (d = RemTime(end, now)) > 0)
+            {
+                System.Threading.Monitor.Wait(this, d);
+                now = HPTimer.Now();              
+            }
+
+            if (Eq(value, undesiredValue))
+                throw new ThreadInterruptedException("timeout");
+
+            return value;
+        }
+
+        private void CheckDelay(int maxDelay)
+        {
+            if (maxDelay < 0)
+                throw new ArgumentException("maxDelay < 0");
+        }
+
+        private long EndTime(long now, int maxDelay)
+        {
+        	if (maxDelay == 0 || maxDelay == int.MaxValue)
+        		return long.MaxValue;
+            
+            return now + maxDelay * HPTimer.NS_PER_MILLISECOND;
+        }
+
+        private int RemTime(long end, long now)
+        {
+        	if (end == long.MaxValue)
+        		return int.MaxValue;
+        	
+        	long ms = (end - now) / HPTimer.NS_PER_MILLISECOND;
+        	if (ms > int.MaxValue)
+        		return int.MaxValue;
+            
+            return (int) ms;
+        }
+
+        /// <summary>
+        /// Compares the specified values.
+        /// </summary>
+        /// <param name="v1">a value to compare, which may be null.</param>
+        /// <param name="v2">another value to compare, which may be null.</param>
+        /// <returns>true if the values are equal, false otherwise. If both
+        /// values are null, they are considered equal.</returns>
+        private bool Eq( T v1, T v2 )
+        {
+            if ( v1 != null && v2 != null )
+                return v1.Equals(v2);
+
+            if ( v1 == null && v2 == null ) 
+                return true;
+
+            return false;
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Monitor.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Monitor.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/OutputStream.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/OutputStream.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/OutputStream.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/OutputStream.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,53 @@
+// $Id$
+// 
+// Copyright 2007-2008 Cisco Systems Inc.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//  
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public interface OutputStream
+    {
+        /// <summary>
+        /// Closes this output stream and releases any system resources associated with this stream.
+        /// </summary>
+        void Close();
+
+        /// <summary>
+        /// Writes b.length bytes from the specified byte array to this output stream.
+        /// </summary>
+        /// <param name="b">the data</param>
+        void Write(byte[] b);
+
+        /// <summary>
+        /// Writes len bytes from the specified byte array starting at offset off to this output stream.
+        /// </summary>
+        /// <param name="b">the data</param>
+        /// <param name="off">the start offset in the data.</param>
+        /// <param name="len">the number of bytes to write</param>
+        void Write(byte[] b, int off, int len);
+
+        /// <summary>
+        /// Writes the specified byte to this output stream.
+        /// </summary>
+        /// <param name="b">the byte</param>
+        void Write(int b);
+
+        /// <summary>
+        /// Get bytes from this output stream.
+        /// </summary>
+        /// <returns></returns>
+        byte[] GetBytes();
+    
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/OutputStream.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/OutputStream.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"