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/04/24 18:05:57 UTC

svn commit: r768343 [3/4] - in /incubator/etch/branches/ruby/binding-ruby: ./ src/ src/main/ src/main/ruby/ src/main/ruby/idl/ src/main/ruby/idl/test/ src/main/ruby/msg/ src/main/ruby/msg/test/ src/main/ruby/support/ src/main/ruby/support/test/ src/mai...

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,346 @@
+class FlexBuffer
+    
+    attr :buffer, :length, :index, :is, :os
+    
+    private :is, :os
+    
+    $MAX_BUFFER_LEN = 4*1024*1024
+    $INIT_BUFFER_LEN = 32
+    
+    def initialize( length, buffer = [] )
+        FlexBuffer( length, 0, buffer )
+    end
+    
+    def FlexBuffer( length, index, buffer = [] )
+        @length = length
+        @index = index
+        @buffer = buffer
+    end
+    
+    def getBuf()
+        return @buffer
+    end
+    
+    def ensureLength( len )
+        n = buffer.length
+        if( len <= n )
+            return 
+        end
+        
+        k = n
+        if( k < 1 )
+            k = 1
+        end
+        
+        while( len > k && k < $MAX_BUFFER_LEN )
+            k *= 2           
+        end
+        
+        if( len > k )
+            raise "Buffer overflow exception"
+        end
+        
+        b = Array.new
+        arraycopy( buffer, 0, b, 0, n )
+        @buffer = b
+    end
+    
+    def length()
+        return @length
+    end
+    
+    def setLength()
+        if( length < 0 ) 
+            raise "length < 0"
+        end
+        
+        ensureLength( length )
+        
+        @length = length
+        if( @index > length )
+            @index = length
+        end
+        
+        return 
+    end
+    
+    def index()
+        return @index
+    end
+    
+    def setIndex( index )
+        if( index < 0 || index > @length )
+            raise "index < 0 || index > length"
+        end
+        
+        @index = index
+        
+        return 
+    end
+    
+    def avail()
+        return @length - @index 
+    end
+    
+    def reset()
+        @index = 0
+        @length = 0
+        return 
+    end
+    
+    def compact()
+        if( @index == 0 )
+            return 
+        end
+        
+        n = avail()
+        if( n == 0 )
+            reset()
+            return
+        end
+        
+        arraycopy( @buffer, @index, @buffer, 0, n )
+        @index = 0
+        @length = n
+        return
+    end
+    
+    def get()
+        if( avail() < 1 )
+            raise "IOException"
+        end
+        
+        return @buffer[@index + 1] & 255
+    end
+    
+    def get( buf = Array.new )
+        checkBuf( buf )
+        len = buf.length
+        if( len == 0 )
+            return 0
+        end
+        
+        k = avail()
+        if( k < 1 )
+            raise "IOException"
+        end
+        n = Math.min( len, k )
+        arraycopy( @buffer, @index, buf, 0, n )
+        @index += n
+        
+        return n
+    end
+    
+    def get( off, len, buf = [] )
+        checkBuf( off, len, buf )
+                if( len == 0 )
+            return 0
+        end
+        
+        k = avail()
+        if( k < 1 )
+            raise "IOException"
+        end
+        n = Math.min( len, k )
+        arraycopy( @buffer, @index, buf, 0, n )
+        index += n;
+    
+        return n;
+    end
+    
+    def getInt()
+        if( avail() < 4 )
+            raise "EOFException"
+        end
+        
+        b0 = @buffer[@index + 1] & 255
+        b1 = @buffer[@index + 1] & 255
+        b2 = @buffer[@index + 1] & 255
+        b3 = @buffer[@index + 1] & 255  
+        
+        return b0 + (b1 << 8) + (b2 << 16) + (b3 << 24)
+    end
+    
+    def inputStream()
+        if( @is != nil )
+            return @is
+        end
+        
+        @is = IO.new
+        
+        def @is.available()
+          return avail()
+        end
+        
+        def @is.read()
+           if( avail() < 1 )
+                return -1
+           end
+           return get()
+        end
+        
+        def @is.read( b = Array.new )
+          return get( b )
+        end
+        
+        def @is.read( off, len, b = Array.new )
+          return get( off, len, b )
+        end
+        
+        return @is
+    end
+    
+    def put( b )
+        ensureLength( @index + 1 )
+       @buffer[@index + 1] = b
+        fixLength()
+        
+        return
+    end
+    
+    def put( buf = Array.new )
+        checkBuf( buf )
+        len = buf.length
+        if( len == 0 )
+            return 
+        end
+        
+        ensureLength( @index + len )
+        arraycopy( buf, 0, @buffer, @index, len )
+        @index += len 
+        return 
+    end
+    
+    def put( off, len, buf = Array.new )
+        checkBuf( off, len, buf )
+        if( len == 0 )
+           return 
+        end
+        ensureLength( @index + len )
+        arraycopy( buf, off, @buffer, @index, len )
+        @index += len 
+        fixLength()
+        return 
+    end
+    
+    def put( buf )
+        len = FlexBuffer.avail()
+        if( len == 0 )
+            return 
+        end
+        
+        ensureLength( index+len );
+        arraycopy( FlexBuffer.buffer, FlexBuffer.index, @buffer, @index, len )
+        FlexBuffer.index += len;
+        @index += len;
+        fixLength();    
+        return
+    end
+    
+    def put( buf, len )
+        if( len > FlexBuffer.avail() )
+            raise "IllegalArgumentException (len > FlexBuffer.avail() )"
+        end 
+        
+            ensureLength( @index + len );
+            System.arraycopy( @buffer, @index, @buffer, @index, len )
+            FlexBuffer.index += len;
+            @index += len;
+            fixLength();   
+            return
+    end
+    
+    def putInt( value )
+            ensureLength( @index + 4 )
+    
+            @buffer[index + 1] =  value
+            @buffer[index + 1] = (value >> 8)
+            @buffer[index + 1] = (value >> 16)
+            @buffer[index + 1] = (value >> 24)   
+             fixLength()
+             return
+    end
+    
+    def skip( len, put )
+       if(len < 0)
+         raise "IllegalArgumentException"
+       end
+       
+      if(len == 0)
+        return 0
+      end
+      
+      if(put)
+          ensureLength( @index + len )      
+          @index += len;
+          fixLength();      
+          return len           
+      end
+      
+      k = avail();
+      if (k < 1)
+        raise "EOFException()"
+      end
+      
+      n = Math.min( len, k );
+      @index += n;
+      return n
+    end
+    
+    def outputStream()
+        if( @os != nil )
+            return @os
+        end
+        
+        @os = IO.new
+        def @os.write( b )
+            put( b )
+        end
+        
+        def @os.write( b = Array.new )
+            put( b )
+        end
+        
+        def @os.write( off, len, buf = Array.new )
+            put( off, len, buf )
+        end
+        
+        return @os
+    end
+    
+    def fixLength()
+       if( @index > @length )
+          @length = @index
+       end
+    end
+    
+    def checkBuf( buf = Array.new )
+        if( buf == nil )
+           raise "NullPointerException ( buf == nil )"
+        end
+    end
+    
+    def checkBuf( off, len, buf = Array.new )
+        if( buf == nil )
+           raise "NullPointerException ( buf == nil )"
+        end
+ 
+        if( off < 0 || off > @length )
+            raise "IllegalArgumentException"
+        end
+        
+        if( len < 0 )
+            raise "IllegalArgumentException( len < 0 )"
+        end
+        
+        if (off+len > buf.length)
+            raise "IllegalArgumentException( off+len > buf.length )"
+        end
+    end
+    
+    def getAvailByte()
+         buf = Array.new 
+         get( buf )
+         return buf
+    end
+end

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,11 @@
+require 'socket'
+require 'etch/bindings/ruby/msg/array_value.rb'
+require 'etch/bindings/ruby/msg/struct_value.rb'
+require 'etch/bindings/ruby/msg/type.rb'
+require 'etch/bindings/ruby/msg/value_factory.rb'
+require 'etch/bindings/ruby/transport/fmt/tagged_data.rb'
+require 'etch/bindings/ruby/transport/fmt/type_code.rb'
+
+
+
+

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,268 @@
+require 'etch/bindings/ruby/msg/array_value.rb'
+require 'etch/bindings/ruby/msg/message.rb'
+require 'etch/bindings/ruby/msg/struct_value.rb'
+require 'etch/bindings/ruby/msg/tagged_data_input.rb'
+require 'etch/bindings/ruby/msg/type.rb'
+require 'etch/bindings/ruby/msg/value_factory.rb'
+require 'etch/bindings/ruby/support/message_source.rb'
+require 'etch/bindings/ruby/transport/fmt/type_code.rb'
+require 'socket'
+
+class BinaryTaggedDataInput < BinaryTaggedData
+        include TaggedDataInput
+        
+      attr :is, :vf
+      private :is, :vf
+      
+      def initialize( vf, is )
+          super( vf )
+          @is = is
+      end
+      
+      def setInputStream( is )
+          @is = is
+      end
+      
+      def startMessage()
+          version = readByte()
+          if( version != VERSION )
+                raise "IOException"
+          end
+          
+          String.to_str( "binary tagged data version mismatch: got %d expected %d",
+          version, VERSION )
+          msg = Message.new( readStructType(), vf )
+          return msg
+      end
+      
+      def endMessage( msg )
+#            // nothing to do.
+      end
+      
+      def startStruct()
+          strct = StructValue.new( readStructType())
+          return strct
+      end
+      
+      def readStructType()
+          id = readValue()
+          return @vf.getType( id )
+      end
+      
+      def readStructElement( se )
+          obj = readValue()
+          if (obj == BinaryTaggedData.NONE)
+            return false
+          end
+          
+          id = obj
+          se.key = vf.getField( id )
+          se.value = readValue()
+          return true
+      end    
+      
+      def endStruct( struct )
+            #    // nothing to do
+      end
+      
+      def startArray()
+          type = readType()
+          if (type == TypeCode.CUSTOM)
+              customStructType = readStructType()
+          else
+              customStructType = null
+              dim = readValue()
+#//    System.out.printf( "startArray (input) %d %s %d\n", type, customStructType, dim )
+          end
+          arr = ArrayValue.new( type, customStructType, dim )
+          return arr    
+      end
+      
+      def readArrayElement( ae )
+          ae = ArrayValue.new
+          ae.value = readValue()
+          if (ae.value == BinaryTaggedData.NONE)
+            return false
+          end  
+          return true
+      end
+      
+      def endArray( array )
+#    // nothing to do.
+      end
+  
+      def close()
+        @is.close()
+      end
+
+#    Reads a Message from the data buffer.
+#    @param ms the message source.
+#    @param vf the value factor for the message.
+#    @param buf the data buffer.
+#    @return the message read.
+#    @throws IOException if there is a problem reading the message.
+#   
+      def readMessage( vf, ms, buf = Array.new )
+          bais = ByteArrayInputStream.new( buf )
+          return readMessage( vf, ms, bais )
+      end
+      
+      def readMessage( vf, off, len, ms, buf = Array.new )
+          bais = ByteArrayInputStream.new( buf, off, len )
+          return readMessage( vf, bais, ms )
+      end
+      
+      def readMessage( vf, is, ms )
+          btdi = BinaryTaggedDataInput.new( vf, is )           
+          return Message.read( btdi )
+      end
+      
+      def readByte()
+         b = is.read()
+#            // is.read() returns 0-255 value or -1 if eof
+         if (b < 0)
+            raise "EOFException"
+         end
+         return b
+      end
+      
+      def readUByte()
+            b = @is.read()
+#    // is.read() returns 0-255 value or -1 if eof
+            if (b < 0)
+                raise "EOFException"
+            end
+            return b
+      end
+      
+      def readShort()
+          a = readUByte()
+          b = readUByte()
+          return (a | (b << 8))
+      end
+      
+      def readUShort()
+          a = readUByte()
+          b = readUByte()
+          return a | (b << 8)
+      end
+      
+      def readInt()
+          a = readUShort()
+          b = readUShort()
+          return a | (b << 16)
+      end
+      
+      def readUInt()
+          a = readUShort()
+          b = readUShort()
+          return a | (b << 16)
+      end
+      
+      def readLong()
+          long a = readUInt()
+          long b = readUInt()
+          return a | (b << 32)
+      end
+      
+      # readFloat & readDouble to be done!
+      
+      def readBytes( b = Array.new )
+          n = b.length
+          for i in (0..n)
+            b[i] = readByte()
+          end
+      end
+      
+      def readType()
+          return readByte()
+      end
+      
+      def readValue()
+          type = readType()
+          case(type)
+            when( TypeCode.NULL)
+              return null
+            when( TypeCode.BOOLEAN_FALSE)
+              return Boolean.FALSE
+            when TypeCode.BOOLEAN_TRUE:
+              return Boolean.TRUE     
+            when TypeCode.BYTE1:
+              return readByte()          
+            when TypeCode.SHORT1:
+              return readByte()          
+            when TypeCode.INT1:
+              return readByte()          
+            when TypeCode.LONG1:
+              return readByte()          
+            when TypeCode.SHORT2:
+              return readShort()          
+            when TypeCode.INT2:
+              return readShort()          
+            when TypeCode.LONG2:
+              return readShort()          
+            when TypeCode.INT4:
+              return readInt()          
+            when TypeCode.LONG4:
+              return readInt()          
+            when TypeCode.LONG8:
+              return readLong()          
+            when TypeCode.FLOAT4:
+              return readFloat()          
+            when TypeCode.FLOAT8:
+              return readDouble()            
+            when TypeCode.BYTES:
+              return readBytes()          
+            when TypeCode.EMPTY_STRING:
+              return ""          
+            when TypeCode.STRING:
+              return String.new( readBytes(), @vf.getStringEncoding() )          
+            when TypeCode.ARRAY:
+              return fromArrayValue( ArrayValue.read( this ) )          
+            when TypeCode.STRUCT:
+              return StructValue.read( this )          
+            when TypeCode.CUSTOM:
+              return @vf.importCustomValue( StructValue.read( this ) )          
+            when TypeCode.NONE:
+              return BinaryTaggedData.NONE
+            end  
+            if ((type & TypeCode.PSMASK) == TypeCode.PSVALUE)
+#            // positive small integers
+                value = type & TypeCode.PVMASK
+                dt = (type >> TypeCode.PDTSHIFT) & TypeCode.DTMASK
+                if (dt == TypeCode.BYTE_DT) 
+                    return value
+                end
+                if (dt == TypeCode.SHORT_DT) 
+                  return value
+                end
+                if (dt == TypeCode.INT_DT) 
+                    return value 
+                end
+                return value
+            else if ((type & TypeCode.NSMASK) == TypeCode.NSVALUE)
+#            // negative small integers
+                value = -(type & TypeCode.NVMASK)-1
+                dt = (type >> TypeCode.NDTSHIFT) & TypeCode.DTMASK
+                if (dt == TypeCode.BYTE_DT) 
+                    return value
+                end
+                if (dt == TypeCode.SHORT_DT) 
+                    return value
+                end
+                if (dt == TypeCode.INT_DT) 
+                    return value
+                end
+                return value
+            end
+            raise "UnsupportedOperationException #{type} "
+       end
+    end
+    
+    def readBytes()
+        n = readValue()
+        b = Array.new
+        readBytes( b )
+        return b
+    end
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,198 @@
+require 'etch/bindings/ruby/msg/array_value.rb'
+require 'etch/bindings/ruby/msg/field.rb'
+require 'etch/bindings/ruby/msg/message.rb'
+require 'etch/bindings/ruby/msg/struct_value.rb'
+require 'etch/bindings/ruby/msg/tagged_data_output.rb'
+require 'etch/bindings/ruby/msg/type.rb'
+require 'etch/bindings/ruby/msg/value_factory.rb'
+require 'etch/bindings/ruby/transport/fmt/type_code.rb'
+# require 'socket'
+
+class BinaryTaggedDataOutput < BinaryTaggedData
+              include TaggedDataOutput
+        
+     attr :os
+     private :os
+     
+     def initialize( os, vf )
+        super( vf )
+        @os = os
+     end
+     
+     def startMessage( msg )
+        writeByte( VERSION )
+        writeStructType( msg.type() )
+     end
+     
+     def endMessage( msg )
+        writeValue( BinaryTaggedData.NONE )
+     end
+     
+     def startStruct( struct )
+        writeStructType( struct.type() )
+     end
+     
+     def writeStructElement( key, value )
+        key = Field.new
+        writeValue( key.getId() )
+        writeValue( value )
+     end
+     
+     def endStruct( struct )
+          writeValue( BinaryTaggedData.NONE )
+     end
+     
+     def startArray( array )
+#    // the caller has already written a type code to indicate an
+#    // array is starting.
+            array = ArrayValue .new
+            byte type = array.typeCode()
+            writeType( type )
+            if (type == TypeCode.CUSTOM)
+              writeStructType( array.customStructType() )
+            end
+            writeValue( array.dim() )
+     end
+     
+     def writeStructType( type )
+          type = Type.new
+          writeValue( type.getId() )
+     end
+     
+     def writeArrayElement( value )
+          writeValue( value )
+     end
+     
+     def endArray( array )
+          writeValue( BinaryTaggedData.NONE )
+     end
+     
+     def close()
+        @os.close()
+     end
+     
+     def writeType( type )
+        writeByte( type )
+     end
+     
+     def writeValue( value )
+         byte type = checkValue( value )
+         writeType( type )
+
+         case(type)
+            when TypeCode.NULL
+            when TypeCode.BOOLEAN_FALSE
+            when TypeCode.BOOLEAN_TRUE
+            when TypeCode.EMPTY_STRING
+            when TypeCode.NONE
+              return
+      
+            when TypeCode.BYTE1
+            when TypeCode.SHORT1
+            when TypeCode.INT1
+            when TypeCode.LONG1
+              writeByte( value.byteValue() )
+              return
+            
+            when TypeCode.SHORT2
+            when TypeCode.INT2
+            when TypeCode.LONG2
+              writeShort( value.shortValue() )
+              return
+      
+            when TypeCode.INT4
+            when TypeCode.LONG4
+              writeInt(value.intValue() )
+              return
+            
+            when TypeCode.LONG8
+              writeLong( value.longValue() )
+              return
+            
+            when TypeCode.FLOAT4
+              writeFloat(value.floatValue() )
+              return
+            
+            when TypeCode.FLOAT8
+              writeDouble( value.doubleValue() )
+              return
+            
+            when TypeCode.BYTES
+              writeBytes(value)
+              return
+            
+            when TypeCode.STRING
+              writeBytes( value.getBytes( @vf.getStringEncoding() ) )
+              return
+            
+            when TypeCode.STRUCT
+              (value.writeStruct( this ))
+              return
+            
+            when TypeCode.ARRAY
+              if (value.class == ArrayValue)
+                (value.write( this ))
+              else
+                toArrayValue( value ).write( this )
+              end
+              return
+              
+            when TypeCode.CUSTOM
+              struct = @vf.exportCustomValue( value )
+              
+              if (struct == null)
+                raise "UnsupportedOperationException"
+              end
+              
+              struct.writeStruct( this )
+              return
+          end
+#        // type is either "small" integer or unused...
+          return
+       end
+       
+       def writeByte( value )
+            @os.write( value )
+       end
+       
+       def writeShort( value )
+          writeByte(value )
+          writeByte( (value >> 8) )
+       end
+       
+       def writeInt( value )
+          writeShort( value )
+          writeShort((value >> 16) )
+       end
+       
+       def writeLong( value )
+            writeInt( value );
+            writeInt( (value >> 32) )
+       end
+       
+       def writeFloat( value )
+           writeInt( Float.floatToIntBits( value ) )
+       end
+       
+       def writeDouble( value )
+           writeLong( Double.doubleToLongBits( value ) )
+       end
+       
+       def writeBytes( value = Array.new )
+          n = value.length;
+          writeValue( n );
+          value.each { |value| writeByte( value ) }
+       end
+       
+       def getBytes( msg, vf )
+           baos = ByteArrayOutputStream.new();
+           tdo = BinaryTaggedDataOutput.new( baos, vf );
+           msg.writeMessage( tdo );
+           tdo.close();
+           return baos.toByteArray()
+       end
+       
+       def setOutputStream( os )
+          @os = os
+       end
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,9 @@
+
+class ByteArrayOutputStream
+
+    def byteArrayDefinition()
+        byte = Array.new
+        return byte
+    end
+    
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,27 @@
+require 'socket'
+
+require 'etch/bindings/ruby/msg/array_value.rb'
+require 'etch/bindings/ruby/msg/type.rb'
+require 'etch/bindings/ruby/msg/value_factory.rb'
+
+class TaggedData
+    attr :vf
+    protected :vf
+    
+    def initialize( vf )
+        @vf = vf
+    end
+    
+    def getValueFactory()
+        return @vf
+    end
+    
+    def toArrayValue( value )
+        c = value.class
+        dim = 0
+        while( c.is_a?(Array))
+          dim += 1
+          c = c.getComponentType() # to be found what to do!
+        end  
+    end
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,160 @@
+module TypeCode
+    
+#  /**
+#   * A code denoting a null value.
+#   */
+  NULL = -1;
+#  /**
+#   * A code denoting a false boolean value.
+#   */
+  BOOLEAN_FALSE = -2;
+#  /**
+#   * A code denoting a true boolean value.
+#   */
+  BOOLEAN_TRUE = -3;
+#  /**
+#   * A code denoting a signed byte.
+#   */
+  BYTE1 = -4;
+#  /**
+#   * A code denoting a single byte signed short.
+#   */
+  SHORT1 = -5;
+#  /**
+#   * A code denoting a two byte signed short, lsb first.
+#   */
+  SHORT2 = -6;
+#  /**
+#   * A code denoting a single byte signed integer.
+#   */
+  INT1 = -7;
+#  /**
+#   * A code denoting a two byte signed integer, lsb first.
+#   */
+  INT2 = -8;
+#  /**
+#   * A code denoting a four byte signed integer, lsb first.
+#   */
+  INT4 = -9;
+#  /**
+#   * A code denoting a single byte signed long.
+#   */
+  LONG1 = -10;
+#  /**
+#   * A code denoting a two byte signed long, lsb first.
+#   */
+  LONG2 = -11;
+#  /**
+#   * A code denoting a four byte signed long, lsb first.
+#   */
+  LONG4 = -12;
+#  /**
+#   * A code denoting an eight byte signed long, lsb first.
+#   */
+  LONG8 = -13;
+#  /**
+#   * A code denoting a four byte ieee floating format number.
+#   */
+  FLOAT4 = -14;
+#  /**
+#   * A code denoting an eight byte ieee floating format number.
+#   */
+  FLOAT8 = -15;
+#  /**
+#   * A code denoting an array of bytes.
+#   */
+  BYTES = -16;
+#  /**
+#   * A code denoting an empty string.
+#   */
+  EMPTY_STRING = -17;
+#  /**
+#   * A code denoting a utf-8 encoded string.
+#   */
+  STRING = -18;
+#  /**
+#   * A code denoting a sequence of key / value pairs.
+#   */
+  STRUCT = -19;
+#  /**
+#   * A code denoting a sequence of values.
+#   */
+  ARRAY = -20;
+#  /**
+#   * A code denoting a custom value from a value factory. An integer
+#   * value follows which identifies the specific type.
+#   */
+  CUSTOM = -21;
+#  /**
+#   * A code denoting no value, which is different than NULL. For
+#   * example, an array is a sequence of values (some of which may
+#   * be NULL), terminated by a NONE.
+#   */
+  NONE = -22;
+
+#  ////////////////////
+#  // SMALL INTEGERS //
+#  ////////////////////
+#  
+#  /**
+#   * Minimum "small" integer.
+#   */
+  MIN_SMALL_INT = -16;
+#  /**
+#   * Maximum "small" integer. Small integers are encoded asis
+#   * (with embedded type code)
+#   */
+  MAX_SMALL_INT = 31;
+#  /**
+#   * Positive sentinal mask.
+#   */
+  PSMASK = 0x80;
+#  /**
+#   * Positive sentinal value.
+#   */
+  PSVALUE = 0x00;
+#  /**
+#   * Shift for positive data type value.
+#   */
+  PDTSHIFT = 5;
+#  /**
+#   * Mask for positive value.
+#   */
+  PVMASK = 31;
+#  /**
+#   * Negative sentinal mask.
+#   */
+  NSMASK = 0xC0;
+#  /**
+#   * Negative sentinal value.
+#   */
+  NSVALUE = 0x80;
+#  /**
+#   * Shift for negative data type value.
+#   */
+  NDTSHIFT = 4;
+#  /**
+#   * Mask for negative value.
+#   */
+  NVMASK = 15;
+#  /**
+#   * Mask for data type value.
+#   */
+  DTMASK = 0x03;
+#  /**
+#   * Data type value for small integer from byte.
+#   */
+  BYTE_DT = 0;
+#  /**
+#   * Data type value for small integer from short.
+#   */
+  SHORT_DT = 1;
+#  /**
+#   * Data type value for small integer from int.
+#   */
+  INT_DT = 2;
+#  /**
+#   * Data type value for small integer from long.
+#   */
+  LONG_DT = 3;    
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,127 @@
+require 'socket'
+require 'etch/bindings/ruby/transport/runner.rb'
+
+class Listener
+  
+    attr :backlog
+    attr :host 
+    attr :port
+    attr :delay
+    attr :serverSocket
+    private :backlog, :host, :port, :delay, :serverSocket
+
+
+	def initialize( handler, backlog, host, port, delay )
+		super( handler )
+    
+    if( port < 0 || port > 65536 )
+        raise "port < 0 || port > 65535" 
+    end 
+    
+    if( delay < 0 )
+        raise "IllegalArgumentError"
+    end
+    
+    @backlog = backlog
+    @host = host
+    @port = port
+    @delay = delay
+  end
+    
+    def stop0()
+      close( true )
+      super.stop0()
+    end
+    
+    def checkSocket()
+      ss = @serverSocket
+      if( ss == nil ) 
+          raise "closed" 
+      end
+      return ss
+    end
+    
+    def to_s
+      if( @serverSocket == nil )
+          return String.to_str( "Listener(down, %s, %d)", host, port )
+      end
+      return String.to_str( "Listener(up, %s, %d)",
+      @serverSocket.gethostbyaddr(), @serverSocket.getaddrinfo() )
+    end
+    
+    def openSocket( reconnect ) # to be synchronized
+        first  = true
+        
+        while(isStarted())
+            if( reconnect || !first )
+                if( delay == 0 )
+                    return false
+                end
+                
+                wait( delay )
+                
+                if(!isStarted())
+                  break
+                end
+            end
+            
+            throw :Exception1 => e unless @serverSocket = ServerSocket.new( @port, @delay, 
+                                           @host != nil ? gethostbyname( @host ): nil )
+            return true   
+        end
+        return false
+    end
+    
+    catch :Exception1 do
+      first = true
+      if( first )
+          first  = false
+          Runner.fireException( "open", :Exception )
+      end
+    end
+    
+    def setupSocket()
+      # do nothing
+    end
+    
+    def readSocket()
+      ss = checkSocket()
+      
+      while( isStarted())
+          s = Socket.accept()
+          throw :Exception1 => e unless fireException( s )
+      end
+    end
+    
+    catch :Exception1 => e do
+        s.close
+        fireException( "accepted", e.message )
+    end
+    
+    def fireAccepted( s )
+        @handler.accepted( handler, s )
+    end
+    
+    def close( reset )
+      ss = @serverSocket
+      if( ss != nil )
+          ss.close
+      end
+    end
+    
+    def localAddress()
+      return IPSocket.getaddress
+    end
+    
+    def remoteAddress()
+      return null
+    end
+    
+    def shutdownInput()
+      # do nothing
+    end
+    
+    def shutdownOutput()
+      # do nothing
+    end   
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,16 @@
+require 'socket'
+ #
+ # Interface used to report listener events.
+ #
+module ListenerHandler include
+			SourceHandler
+	#
+	# Reports that the listener has accepted a connection.
+	# @param t event originator
+	# @param s the socket of the connection.
+	# @throws Exception 
+	#
+	def accepted( t, s ) 
+		raise "Subclass responsibility"
+	end
+end

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,161 @@
+class Monitor
+    attr :description, :initialValue, :value
+    private :description, :initialValue, :value
+    
+    def initialize( description, initialValue )
+        @description = description
+        @initialValue = initialValue
+    end
+    
+    def getDescription()
+        return @description
+    end
+    
+    def to_s()
+          return "Monitor ", description, ": ", @value
+    end
+    
+    def get()
+        return @value
+    end
+    
+    def set( newValue )
+      @mutex.synchronize do
+          oldValue = @value
+          @value = newValue
+          notifyAll()
+          return oldValue
+      end
+    end
+    
+    def waitUntilSet( maxDelay )
+      @mutex.synchronize do
+          wait( maxDelay )
+          return @value
+      end
+    end
+    
+    def waitUntilEqAndSet( desiredValue, newValue )
+      @mutex.synchronize do
+          return waitUntilEqAndSet( desiredValue, 0, newValue )
+      end
+    end
+    
+    def waitUntilEqAndSet( desiredValue, maxDelay, newValue )
+        waitUntilEq( desiredValue, maxDelay )
+        return set( newValue )
+    end
+    
+    def waitUntilEq( desiredValue )
+        waitUntilEq( desiredValue, 0 )
+    end
+    
+#   /**
+#   * Waits until the value is set to the specified value.
+#   * 
+#   * @param desiredValue the value we are waiting for.
+#   * 
+#   * @param maxDelay the max amount of time in ms to wait.
+#   * If 0 is specified, we will wait forever.
+#   * 
+#   * @throws InterruptedException if we waited too long.
+#   */
+    def waitUntilEq( desiredValue, maxDelay )
+      @mutex.synchronize do
+            long now = Timer.currentTimeMillis()
+            long endTime = maxDelay > 0 ?
+              now + maxDelay : Long.MAX_VALUE
+            
+            while (!eq( @value, desiredValue ) && now < endTime)
+                waitUntilSet( endTime - now )
+                now = DateTime.usec # returns time in microseconds
+            end
+            if (!eq( @value, desiredValue ))
+              raise "InterruptedException"
+            end
+      end
+    end
+    
+#      /**
+#   * @param undesiredValue
+#   * @param newValue
+#   * @return the old value
+#   * @throws InterruptedException
+#   */
+    def waitUntilNotEqAndSet( undesiredValue, newValue )
+      @mutex.synchronize do
+         return waitUntilNotEqAndSet( undesiredValue, 0, newValue )
+      end
+    end
+
+#  /**
+#   * @param undesiredValue
+#   * @param maxDelay
+#   * @param newValue
+#   * @return the old value
+#   * @throws InterruptedException
+#   */
+    def waitUntilNotEqAndSet( undesiredValue, maxDelay, newValue )
+        waitUntilNotEq( undesiredValue )
+        return set( newValue )
+    end
+    
+#      /**
+#   * Waits forever until the value is not the specified value.
+#   * 
+#   * @param undesiredValue the value we do not want.
+#   * 
+#   * @return the current value of the monitor.
+#   * 
+#   * @throws InterruptedException if we waited too long.
+#   */
+    def  waitUntilNotEq( undesiredValue )
+        return waitUntilNotEq( undesiredValue, 0 )
+    end
+    
+#  /**
+#   * Waits until the value is not the specified value.
+#   * 
+#   * @param undesiredValue the value we do not want.
+#   * 
+#   * @param maxDelay the max amount of time in ms to wait.
+#   * If 0 is specified, we will wait forever.
+#   * 
+#   * @return the current value of the monitor.
+#   * 
+#   * @throws InterruptedException if we waited too long.
+#   */
+    def waitUntilNotEq( undesiredValue, maxDelay )
+      @mutex.synchronize do
+        long now = Timer.currentTimeMillis()
+        long endTime = maxDelay > 0 ?
+          now + maxDelay : Long.MAX_VALUE
+        
+        while (eq( @value, undesiredValue ) && now < endTime)
+          waitUntilSet( endTime - now )
+          now = Timer.usec
+        end
+        
+        if (eq( @value, undesiredValue ))
+          raise "timeout"
+        end
+        return @value
+    end
+    
+#  /**
+#   * Compares the specified values.
+#     * 
+#   * @param v1 a value to compare, which may be null.
+#   * 
+#   * @param v2 another value to compare, which may be null.
+#   * 
+#   * @return true if the values are equal, false otherwise. If both
+#   * values are null, they are considered equal.
+#   */
+    def eq( v1, v2 )
+        if (v1 != nil && v2 != nil)
+          return v1.equals( v2 )
+        end 
+        return v1 == v2
+    end
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,19 @@
+require 'socket'
+require 'etch/bindings/ruby/transport/Who'
+require 'etch/bindings/ruby/transport/FlexBuffer'
+
+ #
+ # Interface used to deliver packets from a packet source.
+ #
+module PacketHandler include SourceHandler
+	#
+	# Delivers a packet from a packet source.
+	# @param src
+	# @param sender
+	# @param buf
+	# @throws Exception
+	#
+	def packet( src, sender, buf ) 
+		raise "Subclass responsibility"
+	end
+end

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,10 @@
+require 'etch/bindings/ruby/transport/who.rb'
+require 'etch/bindings/ruby/transport/flex_buffer.rb'
+
+module PacketSource include Source  
+  def headerSize()    
+  end
+  
+  def packet( recipient, buf )    
+  end  
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,187 @@
+require 'socket'
+require 'etch/bindings/ruby/transport/who.rb'
+require 'etch/bindings/ruby/transport/flex_buffer.rb'
+require 'etch/bindings/ruby/transport/data_type_values.rb'
+
+class Packetizer 
+      include DataHandler, PacketSource, DataTypeValues
+      
+    attr :handler, :maxPktSize, :dataSrc
+    private :handler, :maxPktSize, :dataSrc
+    
+    @savedBuf = FlexBuffer.new
+      
+    $DEFAULT_MAX_PKT_SIZE = 10240
+    $USE_DEFAULT_MAX_PKT_SIZE = -1
+    $USE_UNLIMITED_MAX_PKT_SIZE = 0
+    $HEADER_SIZE = 8
+    $SIG = 0xdeadbeef
+    
+    def initialize( handler, maxPktSize )
+        @handler = handler
+        if ( maxPktSize == $USE_DEFAULT_MAX_PKT_SIZE )
+            maxPktSize = $DEFAULT_MAX_PKT_SIZE
+        else if ( maxPktSize == $USE_UNLIMITED_MAX_PKT_SIZE )
+                maxPktSize = $INTEGER_MAX_VALUE
+        @maxPktSize = maxPktSize
+        end
+    end
+    
+    def Packetizer( handler )
+         initialize( handler, $USE_DEFAULT_MAX_PKT_SIZE )
+    end
+    
+   def Packetizer( maxPktSize )
+        initialize( nil, maxPktSize )
+   end
+   
+   def Packetizer()
+        initialize( nil, $DEFAULT_MAX_PKT_SIZE )
+   end
+    
+   def setHandler( handler )
+        @handler = handler
+   end
+    
+   def to_s
+        str.to_str( "Packetizer/%s", dataSrc )
+   end
+    
+   def setDataSource( src )
+       if( src == nil || @dataSrc == nil )
+            @dataSrc = src
+       else if( src != @dataSrc )
+            raise "IllegalArgumentException"
+       end
+   end
+    
+   def data( src, sender, buf = FlexBuffer.new )
+        setDataSource( src )
+        
+        while( FlexBuffer.avail() > 0 )
+            if( @wantHeader )
+                if( @savedBuf.length() + buf.avail() >= HEADER_SIZE )
+                    if( @savedBuf.length() == 0 )
+                        sig = buf.getint()
+                        if( sig != $SIG )
+                            raise "IOException"
+                        end
+                        
+                        len = buf.getInt()
+                        if( len == 0 )
+                           continue
+                        end
+                        
+                        if( len < 0 || len > @maxPktSize )
+                            raise "IOException (len < 0 || len > maxPktSize) "
+                        end
+                        
+                        @bodyLen = len
+                        @wantHeader = false
+                    else 
+                        needFromBuf = $HEADER_SIZE - @savedBuf.length()
+                        @savedBuf.put( buf, needFromBuf )
+                        @savedBuf.setIndex( 0 )
+                        
+                        sig = @savedBuf.getInt()
+                        if( sig != $SIG )
+                           raise "IOException bad SIG"
+                        end
+                        
+                        len = @savedBuf.length()
+                        @savedBuf.reset()
+                        if( len == 0 )
+                            continue
+                        end
+                        
+                        if (len < 0 || len > maxPktSize)
+                             raise " IOException len < 0 || len > maxPktSize"
+                        end
+                        
+                        @bodyLen = len
+                        @wantHeader = false
+                    end
+                else
+                    @savedBuf.setIndex( @savedBuf.length() )
+                    @savedBuf.put( buf )
+                end
+            else if( @savedBuf.length() + buf.avail() >= bodyLen)
+                    assert savedBuf.length() < bodyLen
+                    if( @savedBuf.length() == 0 )
+                         length = buf.length();
+                         index = buf.index();
+                         buf.setLength( index + @bodyLen );
+                         @handler.packet( this, sender, buf );
+                         buf.setLength( length );
+                         buf.setIndex( index + @bodyLen );          
+                         @wantHeader = true;
+                    else
+                        needFromBuf = @bodyLen - @savedBuf.length()
+                        @savedBuf.put( buf, needFromBuf )
+                        @savedBuf.setIndex( 0 )
+          
+                        @handler.packet( this, sender, @savedBuf )
+          
+                        @savedBuf.reset()
+                        @wantHeader = true
+                    end
+                 else
+                      @savedBuf.put( buf )
+                 end
+            end
+          end
+        end
+      end
+    end
+    
+    def firePacket( sender, buf )
+        @handler.packet( this, sender, buf )
+    end
+    
+    def packet( recipient = who.new, buf = FlexBuffer.new )
+        len = buf.avail()
+        if (len < $HEADER_SIZE)
+            raise "IllegalArgumentException( \"len < HEADER_SIZE\" )"
+        end
+        
+        index = buf.index()
+        buf.putInt( $SIG )
+        buf.putInt( len - $HEADER_SIZE )
+        buf.setIndex( index )
+        @dataSrc.data( recipient, buf )
+    end
+    
+    def headerSize()
+        return $HEADER_SIZE 
+    end
+    
+    def up( src )
+        setDataSource( src )
+        @handler.down( this ) # this?
+    end
+    
+    def close( reset )
+        @dataSrc.close( reset )
+    end
+    
+    def localAddress()
+        return @dataSrc.localAddress()
+    end
+    
+    def remoteAddress()
+        return @dataSrc.remoteAddress()
+    end
+    
+    def shutdownInput()
+        @dataSrc.shutdownInput()
+    end
+    
+    def shutdownOutput()
+        @dataSrc.shutdownOutput()
+    end
+    
+    def stop()
+        @dataSrc.stop()
+    end
+
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,71 @@
+require 'socket'
+require 'etch/bindings/ruby/transport/runner_handler.rb'
+
+class Runner < AbstractStartable
+             include RunnerHandler
+
+      attr :handler, :thread
+      
+      private :handler, :thread
+      
+      def initialize()
+        # do nothing
+      end
+      
+      def setRunnerHandler( handler )
+        @handler = handler
+      end
+      
+      def start0()
+        @thread = Thread.new( newThread )
+        @thread.start()
+      end
+      
+      def stop0()
+        t = @thread
+        if( t != nil )
+            @thread = nil
+            t.join()
+        end
+      end
+      
+      def run()
+            fireStarted()
+            first = true
+            throw :Exception1 => e unless isStarted()
+            while(isStarted())
+                throw :Exception1 => e unless (!run0?( first ))
+                  if( !run0?(first))
+                      break
+                  end
+                  first = false
+            end            
+      end
+      
+      catch :Exception1 => e do
+        fireException( "run", e )
+      end
+      
+      ensure fireStopped()
+      end
+      
+      def fireStarted()
+          if( @handler != nil )
+              @handler.started( this )
+      end 
+      
+      def fireException( what, e )
+         if( @handler != nil )
+            @handler.exception( r, what, e )
+      end
+      
+      def fireStopped()
+          if( @handler != nil )
+              @handler.stopped( this )
+      end 
+      
+      def run0()
+        raise "subclasser responsibility"
+      end
+
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,12 @@
+module RunnerHandler
+  
+  def started( r )
+  end
+  
+  def stopped( r )
+  end
+  
+  def exception( r, what, e )
+  end
+  
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,10 @@
+require 'socket'
+port = 4001
+server = TCPServer.new('localhost', port)
+while (session = server.accept)
+  puts "Request: #{session.gets}"
+  session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
+  session.print "<html><body><h1>#{Time.now}</h1></body></html>\r\n"
+  session.close
+end
+

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,78 @@
+require 'socket'
+
+#
+# Common interface to sources of data, packets, or messages. Models
+# the various handler's view of a communication channel.
+# @param <H> The handler type of this source.
+#
+module Source
+	#
+	# @return the local socket address of the source if there
+	# is one. Generally this is where the source receives
+	# data, packets, or messages.
+	# @throws Exception
+	#
+	def localAddress()
+			raise "Subclass responsibility"
+	end 
+  
+	#
+	# @return the remote socket address of the source if
+	# there is one. Generally this is where the source
+	# sends data, packets, or messages.
+	# @throws Exception
+	 #
+	def remoteAddress() 
+     raise "Subclass responsibility"
+  end
+  
+	#
+	# Shuts down reception of data, packets, or messages. This
+	# has the most local effect, and does not apply to shared
+	# resources such as web servers.
+	# @throws Exception
+	#
+	def shutdownInput() 
+    raise "Subclass responsibility"
+  end
+  
+	#
+	# Shuts down sending of data, packets, or messages. This
+	# has the most local effect, and does not apply to shared
+	# resources such as web servers.
+	# @throws Exception
+	#
+	def shutdownOutput() 
+      raise "Subclass responsibility"
+  end
+  
+	#
+	 # Shuts down the entire communication channel and releases
+	 # all associated resources. Certain persistent channels will
+	 # start up again after a short delay.
+	 # @param reset if true means do not shut down nicely, but
+	 # instead close the channel immediately.
+	 # @throws Exception
+	 #
+	def close( reset ) 
+      raise "Subclass responsibility"
+  end 
+  
+	#
+	 # Shuts down the entire communication channel and releases
+	 # all associated resources. Certain persistent channels will
+	 # which would start up again after a short delay are prevented
+	 # from doing so.
+	 # @throws Exception
+	 #
+	def stop() 
+    raise "Subclass responsibility"
+  end
+	
+	#
+	 # @param handler 
+	 #
+	def setHandler( handler )
+    raise "Subclass responsibility" 
+  end
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,37 @@
+require 'socket'
+
+#
+ # SourceHandler receives notification of source events.
+ # @param <S> event originator
+ #
+module SourceHandler
+	#
+	 # Reports the source is up.
+	 # @param src event originator
+	 # @throws Exception 
+	 #
+	def up( src ) 
+		raise "Subclass responsibility"
+	end
+	
+	#
+	 # Reports the source is down.
+	 # @param src event originator
+	 # @throws Exception 
+	 #
+	def down( src ) 
+		raise "Subclass responsibility"
+	end
+	
+	@Deprecated
+	def started( r )
+	end
+	
+	@Deprecated
+	def stopped( r )
+	end
+	
+	@Deprecated
+	def exception( r, what, e )
+	end
+end

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,16 @@
+
+module Startable
+  
+  def start()
+    raise "subclasser responsibility"
+  end
+  
+  def stop()
+    raise "subclasser responsibility"
+  end
+  
+  def isStarted()
+    # do nothing
+  end
+  
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,12 @@
+require 'socket'
+
+$port = 4001
+class StreamIO
+  
+  streamSocket = TCPSocket::new( '127.0.0.1', $port )
+  streamSocket.send( "Badri\n", 5 )
+  streamOutput = streamSocket.recv( 100 )
+  puts streamOutput
+  streamSocket.close
+  
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,252 @@
+require 'etch/bindings/ruby/transport/connection.rb'
+require 'socket'
+
+class TcpConnection < Connection
+              include DataSource
+              
+  attr_writer :socket, true
+  attr_writer :port, true
+  attr_writer :host, true
+  attr_writer :delay, true
+  attr_writer :keepalive, false
+  attr_writer :solinger, true
+  attr_writer :solingertime, 30
+  attr_writer :tcpnodelay, true
+  attr_writer :trafficclass, 0 
+  attr_writer :usebuffer, false 
+  attr_writer :autoflush, true
+  attr_writer :outputstream, true
+  
+  private :socket
+  private :host 
+  private :port 
+  private :delay 
+  private :keepalive
+  private :solinger
+  private :solingertime
+  private :tcpnodelay
+  private :trafficclass
+  private :usebuffer
+  private :autoflush
+  private :outputstream
+  
+  def tcpConnection( handler, socket )
+     super( handler )
+     
+     raise "IllegalArgumentError" if socket == nil
+     
+     @socket = socket
+     @host = nil
+     @port = 0     
+     @delay = 0     
+  end
+  
+  def tcpConnection( handler, host, port, delay )  
+      super( handler )
+        
+      raise "IllegalArgumentException" if host == nil
+      raise "IllegalArgumentException" if port <= 0 
+      raise "IllegalArgumentException" if delay < 0     
+  end
+  
+  def to_s
+    if( socket != nil )
+        return String.format("Tcp(up, %s, %d)", socket.gethostbyname(), socket.getport())
+    else
+        return String.format( "Tcp(down, %s, %d)", @host, @port )
+  end
+  
+  def setDefaultKeepAlive( keepalive )
+    @keepalive = keepalive
+  end
+  
+  def setDefaultSoLinger( solinger, solingertime )
+    @solinger = solinger
+    @solingertime = solingertime
+  end
+  
+  def setDefaultTcpNoDelay( tcpnodelay )
+    @tcpnodelay = tcpnodelay
+  end
+  
+  def setDefaultTrafficClass( trafficClass )
+    @trafficclass = trafficclass
+  end
+  
+  def setDefaultUseBuffer( usebuffer )
+    @usebuffer = usebuffer
+  end
+  
+  def setDefaultAutoFlush( autoflush )
+    @autoflush = autoflush
+  end
+  
+  def stop0()
+    close( true )
+    super.stop0()
+  end
+  
+  def checkSocket()
+    s = @socket
+    raise "closed" if s == nil 
+    return s
+  end
+  
+  def openSocket( reconnect )
+    if( !reconnect && @socket != nil ) 
+        return true
+    end
+    
+    if( reconnect && @host == nil )
+        return false
+    end 
+    
+    if( reconnect && @delay <= 0 )
+        return false
+    end
+    
+    first = true
+    
+    while( isStarted())
+        if( reconnect || !first )
+            if( @delay == 0 )
+              return false
+            end            
+            wait( @delay )            
+            if (!isStarted())
+              break
+            end            
+        end  
+        throw :SocketException unless @socket = Socket.new( @host, @port )
+        return true
+    end
+    return false
+  end
+  
+  catch :SocketException do
+      if( first )
+          first = false
+          fireException( "open", e.message )
+      end
+  end
+ 
+  def setupSocket()
+    s = TcpConnection.checkSocket()
+    s.keepAlive( @keepalive )
+    s.setSoLinger( @solinger, @solingertime )
+    s.setTcpNoDelay( @tcpnodelay )
+    s.setTrafficClass( @trafficclass )    
+    
+    @outputstream = s.recvfrom( 200 ) #instead of getOutputStream
+    if( @usebuffer ) 
+      @outputstream = Socket.new( recvfrom( 200 ))  
+    end
+  end
+  
+  def readSocket()
+      tcpConn = TcpConnection.new
+      t = tcpConn.checkSocket()  
+      data = t.recvfrom( 200 )
+      arr = FlexBuffer.new( Array.new )
+      throw :SocketException unless isStarted()
+          while( isStarted() )
+              n = t.readlin@e
+              if( n >= 0 ) 
+                  break
+              end
+              arr = FlexBuffer.setLength( n )
+              arr2 = FlexBuffer.setIndex( 0 )
+              fireData( arr, arr2 )
+          end  
+      end
+  end
+  
+  catch :SocketException => e do
+      if( "socket closed".eql?(e.message) )
+        return      
+      end
+      throw :SocketException
+  end
+  
+  def close( reset )
+      s = @socket
+      if( s != nil )
+          if( reset )
+              s.setsockopt( Socket.SO_LINGER )
+          else
+              flush()
+          end
+      end
+      
+      @outputstream = nil
+      @socket = nil
+      s.close
+  end
+  
+  
+  def send( buf = [] )
+      send( 0, buf.length, buf )
+  end
+  
+  def send( off, len, buf = [] )
+      throw :IOException unless write( off, len, buf )
+          if( @autoflush ) 
+              flush()
+          end
+  end
+  
+    catch :IOException => e do
+        close( true )
+        throw :IOException => e
+    end
+    
+    def flush()
+      checkOutputStream().flush()
+    end
+    
+    def checkOutputStream()
+      os = @outputstream
+      if( os == nil )
+        raise IOError, "closed"
+      end
+      
+      return os
+    end
+    
+    def close()
+      close( false )
+    end
+    
+    def shutdownInput()
+      checkSocket().shutdownInput()
+    end
+    
+    def shutdownOutput()
+      checkSocket().shutdownOutput()
+    end
+    
+    def getRemoteSocketAddress()
+      s = TCPSocket.new
+      return s.getaddress.AF_INET
+    end
+    
+    def fireData( buf, buf1 )
+      if( @handler != nil )
+          @handler.data( handler, nil, buf )
+      end 
+    end
+    
+    def data( recipient, buf )
+      send( buf.index(), buf.avail(), buf.getBuf())
+    end
+    
+    def localAddress()
+      s = IPSocket.new
+      return s.peeraddr
+    end
+    
+    def remoteAddress()
+      s = IPSocket.new
+      return s.addr
+    end
+end
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,442 @@
+require 'test/unit'
+require 'etch/bindings/ruby/transport/who.rb'
+require 'etch/bindings/ruby/transport/data_handler.rb'
+require 'etch/bindings/ruby/transport/data_source'
+require 'etch/bindings/ruby/transport/packet_handler.rb'
+require 'etch/bindings/ruby/transport/packet_source.rb'
+require 'etch/bindings/ruby/transport/packetizer.rb'
+require 'etch/bindings/ruby/transport/flex_buffer.rb'
+
+class TestPacketizer
+    
+      @@mph = MyPacketHandler.new
+      @@p  = Packetizer.new( mph, Packetizer.USE_DEFAULT_MAX_PKT_SIZE )
+      
+    def setUp() 
+        p.setDataSource( @@mph )
+    end
+    
+    def sendPacket()
+        buf = FlexBuffer.new( Array.new( 0,0,0,0,0,0,0,0 ))
+        result = Array.new{Array.new( -17, -66, -83, -34, 0, 0, 0, 0 )}
+        @@p.packet(nil, buf)
+        assert_same( @@mph.what, what::DATA )
+#        assert_true(mph.check(result))
+        assert_nil(@@mph.xsender)
+        assert_nil(@@mph.xsrc)
+        assert_nil(@@mph.xbuf)
+    end
+    
+    def sendPacket1()
+        buf = FlexBuffer.new(Array.new( 0, 0, 0, 0, 0, 0, 0, 0, 1 ))
+        result = Array.new{Array.new( -17, -66, -83, -34, 1, 0, 0, 0, 1 )}
+        @@p.packet(nil, buf)
+        assert_same( @@mph.what, what.DATA )
+#        assertTrue(mph.check(result))
+        assert_nil(@@mph.xsender)
+        assert_nil(@@mph.xsrc)
+        assert_nil(@@mph.xbuf)
+    end
+    
+      def sendPacket2()
+#       Create packet to send
+         buf = FlexBuffer.new(Array.new( 0, 0, 0, 0, 0, 0, 0, 0, 2, 3 ))
+         result = Array.new{Array.new( -17, -66, -83, -34, 2, 0, 0, 0, 2, 3 )}
+    
+         @@p.packet(nil, buf)
+         assert_same( @@mph.what, what::DATA )
+#        assertTrue(@@mph.check(result))
+         assert_nil(@@mph.xsender)
+         assert_nil(@@mph.xsrc)
+         assert_nil(@@mph.xbuf)
+      end
+      
+      def  sendSingleSingleData0()
+#    // Create data to send
+          buf = FlexBuffer.new(Array.new(-17, -66, -83, -34, 0, 0, 0, 0 ))
+          result = Array.new{Array.new}
+    
+          @@p.data(@@mph, nil, buf)
+          assertTrue(@@mph.check(result))
+    
+          assert_nil(@@mph.what)
+          assert_nil(@@mph.xsender)
+          assert_nil(@@mph.xsrc)
+          assert_nil(@@mph.xbuf)
+      end
+      
+        def sendSingleSingleData1()
+#           length = 1
+            buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 1, 0, 0, 0, 1 ))
+            result = Array.new{Array.new( 1 ) }
+            
+            @@p.data(@@mph, nil, buf)
+#            assertTrue(@@mph.check(result))
+            
+            assert_same(@@mph.what, what::PACKET)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        def sendSingleSingleData2()
+#            // length = 2
+            buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 2, 0, 0, 0, 3, 4 ))
+            result = Array.new{Array.new( 3, 4 )}
+            
+            @@p.data(@@mph, nil, buf)
+#            assertTrue(mph.check(result))
+            
+            assert_same(@@mph.what, what::PACKET)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        def sendDoubleSingleData0()
+#              // length = 0
+              buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 0, 0, 0, 0, -17, -66, -83, -34, 0, 0, 0, 0 ))
+              result = Array.new{Array.new}
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(@@mph.check(result))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xbuf)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xsender)
+        end
+        
+        def sendDoubleSingleData1()
+#              // length = 1
+              buf = FlexBuffer.new(Array.new(-17, -66, -83, -34, 1, 0, 0, 0, 1, -17, -66, -83, -34, 1, 0, 0, 0, 2 ))
+              result = Array.new{Array.new((1), (2))}
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(@@mph.check(result))
+              assert_same(@@mph.what, what::PACKET)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def sendDoubleSingleData2()
+#          // length = 2
+              buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 2, 0, 0, 0, 3, 4, -17, -66, -83, -34, 2, 0, 0, 0, 5, 6 ))
+              result = Array.new{Array.new({3, 4}, {5, 6})} 
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(@@mph.check(result))
+              assert_same(@@mph.what, what::PACKET)
+              assert_nil(@@mph.xbuf)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xsender)
+        end
+        
+        def sendDoubleSingle_HeaderSplit_Data0()
+#              // length = 0
+              buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 0, 0 ))
+              result = Array.new{Array.new} 
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(@@mph.check(result))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+              
+              buf2 = FlexBuffer.new(Array.new( 0, 0, -17, -66, -83, -34, 0, 0, 0, 0))
+              result2 = Array.new{Array.new}
+              
+              @@p.data(@@mph, nil, buf2)
+              
+#              assertTrue(mph.check(result2))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def sendDoubleSingle_HeaderSplit_Data1()
+#              // length = 1
+              buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 1, 0 ))
+              result = Array.new{Array.new} 
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(@@mph.check(result))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+              
+              buf2 = FlexBuffer.new(Array.new( 0, 0, 1, -17, -66, -83, -34, 1, 0, 0, 0, 2 ))
+              result2 = Array.new{Array.new(( 1 ), ( 2 ))}
+              
+              @@p.data(@@mph, nil, buf2)
+              
+#              assertTrue(mph.check(result2))
+              assert_same(@@mph.what, what::PACKET)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def sendDoubleSingle_HeaderSplit_Data2()
+#              // length = 2
+              buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 2, 0 ))
+              result = Array.new{Array.new}
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(mph.check(result))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+              
+              buf2 = FlexBuffer.new(Array.new(0, 0, 3, 4, -17, -66, -83, -34, 2, 0, 0, 0, 5, 6 ))
+              result2 = Array.new{Array.new({3, 4}, {5, 6}) }
+              
+              @@p.data(@@mph, nil, buf2)
+              
+#              assertTrue(mph.check(result2))
+              assert_same(@@mph.what, what::PACKET)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def sendDoubleSingle_BodySplit_Data2()
+#              // length = 2
+              buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 2, 0, 0, 0, 1 ))
+              result = Array.new{Array.new} 
+              
+              @@p.data(@@mph, nil, buf)
+              
+#              assertTrue(@@mph.check(result))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+              
+              buf2 = FlexBuffer.new(Array.new( 2, -17, -66, -83, -34, 2, 0, 0, 0, 3, 4  ))
+              result2 = Array.new{ Array.new({ 1, 2 }, { 3, 4 })}
+              
+              @@p.data(@@mph, nil, buf2)
+              
+#              assertTrue(mph.check(result2))
+              assert_same(@@mph.what, what::PACKET)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def sendDoubleSingle_BodySplit_Data3()
+#                  // length = 3
+             buf = FlexBuffer.new(Array.new( -17, -66, -83, -34, 3, 0, 0, 0, 5, 6 ))
+             result = Array.new{Array.new} 
+                  
+             @@p.data(@@mph, nil, buf)
+                  
+#              assertTrue(mph.check(result))
+              assert_nil(@@mph.what)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+                  
+              buf2 = FlexBuffer.new(Array.new( 7, -17, -66, -83, -34, 3, 0, 0, 0, 8, 9, 10 ))
+              result2 = Array.new{Array.new({ 5, 6, 7, 0 }, { 8, 9, 10, 0 })} # odd number list for hash
+                  
+              @@p.data(@@mph, nil, buf2)
+                  
+#              assertTrue(mph.check(result2))
+              assert_same(@@mph.what, what::PACKET)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def up()        
+           @@p.up(@@mph)              
+           assert_same(@@mph.what, what::UP)
+           assert_nil(@@mph.xbuf)
+           assert_nil(@@mph.xsrc)
+           assert_nil(@@mph.xsender)
+        end
+        
+        def down()
+            @@p.down(@@mph)
+            assert_same(@@mph.what, what::DOWN)
+            assert_nil(@@mph.xbuf)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xsender)
+        end
+        
+        def close()
+            @@p.close(true)            
+            assert_same(@@mph.what, what::RESET)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        def localAddress()
+              @@p.localAddress()
+              assert_same(@@mph.what, what::LOCALADDRESS)
+              assert_nil(@@mph.xsender)
+              assert_nil(@@mph.xsrc)
+              assert_nil(@@mph.xbuf)
+        end
+        
+        def remoteAddress()
+            @@p.remoteAddress()
+            assert_same(@@mph.what, what::REMOTEADDRESS)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        def shutdownInput()
+            @@p.shutdownInput()
+            
+            assert_same(@@mph.what, what::SHUTDOWNINPUT)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        def shutdownOutput()
+            @@p.shutdownOutput() 
+            assert_same(@@mph.what, what::SHUTDOWNOUTPUT)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        def stop()
+            @@p.stop()            
+            assert_same(@@mph.what, what::STOP)
+            assert_nil(@@mph.xsender)
+            assert_nil(@@mph.xsrc)
+            assert_nil(@@mph.xbuf)
+        end
+        
+        $what = Enum.new(:DATA, :PACKET, :UP, :DOWN, :RESET, :LOCALADDRESS, :REMOTEADDRESS, 
+                          :SHUTDOWNINPUT, :SHUTDOWNOUTPUT, :STOP, :STARTED, :STOPPED, :EXCEPTION)
+                          
+        class MyPacketHandler 
+              include DataSource, PacketHandler
+            
+            attr :what
+#             public Enum what
+             public @@xsrc = PacketSource.new 
+             public @@xsender = Who.new
+             public @@xbuf = FlexBuffer.new
+             @@list = Array.new
+              
+             def clear()
+                return @list.clear()
+             end
+             
+             def check(result = Array.new{Array.new})
+                    flag = check( @@list.size() == result.length )
+                    if (flag == false)
+                      return flag
+                    end
+                    
+                    for i in ( 0..list.size ) 
+                      flag = check( @@list.get( i ), result[i] )
+                      if (flag == false)
+                        return flag
+                      end
+                    end
+                    return true
+             end
+             
+             def check( a = Array.new, b = Array.new )
+                 flag = check( a.length == b.length )
+                  if (flag == false)
+                    return flag
+                  end
+                  
+                  for i in (0..a.length) 
+                    flag = check( a[i] == b[i] )
+                    if (flag == false)
+                      return flag
+                    end
+                  end
+                  return true
+             end  
+             
+             def check(ok )
+                return ok
+             end
+             
+             def packet( src, sender, buf )
+                  @what = What::PACKET; 
+                  buf = FlexBuffer.new
+                  @@list.add( buf.getAvailBytes() );
+             end
+             
+             def up( s )
+                @what = $what::UP
+             end
+             
+             def down(s)
+                @what = $what::DOWN
+             end
+
+             def started( r )
+                @what = $what::STARTED
+             end
+             
+            def stopped( r )
+                @what = $what::STOPPED
+            end
+            
+            def exception( r, string, e )
+                @what = $what::EXCEPTION
+            end
+            
+            def data( recipient, buf )
+                @what = $what::DATA
+                buf = FlexBuffer.new
+                @@list.add( buf.getAvailBytes() )
+            end
+            
+            def localAddress()
+                @what = $what::LOCALADDRESS;
+                return nil
+            end
+            
+            def remoteAddress()
+                @what = $what::REMOTEADDRESS;
+                return nil
+            end
+            
+            def shutdownInput()
+                @what = $what::SHUTDOWNINPUT
+            end
+            
+            def shutdownOutput()
+                @what = $what::SHUTDOWNOUTPUT
+            end
+            
+            def close( reset )
+#                assertTrue(reset);
+                @what = $what::RESET
+            end
+            
+            def stop()
+                @what = $what::STOP
+            end
+            
+            def setHandler(handler)
+                # do nothing 
+            end
+        end
+end 
\ No newline at end of file

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"