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 [2/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/msg/test/test_struct_value.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_struct_value.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_struct_value.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_struct_value.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,234 @@
+require 'test/unit'
+require 'etch/bindings/ruby/msg/array_value'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/msg/struct_value'
+require 'etch/bindings/ruby/msg/tagged_data_input'
+require 'etch/bindings/ruby/msg/tagged_data_output'
+
+class TestStructValue < Test::Unit::TestCase
+ def setup
+ @mt1 = IdName.new( 1, "one" )
+ @mt2 = IdName.new( 2, "two" )
+ @mt3 = IdName.new( 3, "three" )
+ @mf1 = IdName.new( 4, "four" )
+ @mf2 = IdName.new( 5, "five" )
+ end
+
+ def testStype
+ sv = StructValue.new( @mt1 )
+ assert_same( @mt1, sv.stype )
+ assert_not_same( @mt2, sv.stype )
+
+ sv = StructValue.new( @mt2 )
+ assert_same( @mt2, sv.stype )
+ assert_not_same( @mt1, sv.stype )
+ end
+
+ def testStype?
+ sv = StructValue.new( @mt1 )
+ assert( sv.stype?( @mt1 ) )
+ assert( !sv.stype?( @mt2 ) )
+
+ sv = StructValue.new( @mt2 )
+ assert( sv.stype?( @mt2 ) )
+ assert( !sv.stype?( @mt1 ) )
+ end
+
+
+ def testPutArrayValue
+ sv = StructValue.new( @mt1 )
+ assert( sv.empty? )
+ assert_equal( 0, sv.length )
+
+ av1 = sv.putArrayValue( @mf1 )
+ assert_not_nil( av1 )
+ assert_not_same( sv, av1 )
+ assert_instance_of( ArrayValue, av1 )
+ assert( !sv.empty? )
+ assert_equal( 1, sv.length )
+ assert_same( av1, sv[@mf1] )
+
+ av2 = sv.putArrayValue( @mf2 )
+ assert_not_nil( av2 )
+ assert_not_same( sv, av2 )
+ assert_not_same( av1, av2 )
+ assert_instance_of( ArrayValue, av2 )
+ assert( !sv.empty? )
+ assert_equal( 2, sv.length )
+ assert_same( av1, sv[@mf1] )
+ assert_same( av2, sv[@mf2] )
+ end
+
+ def testPutStructValue
+ sv = StructValue.new( @mt1 )
+ assert( sv.empty? )
+ assert_equal( 0, sv.length )
+
+ sv1 = sv.putStructValue(@mf1, @mt2)
+ assert_not_nil( sv1 )
+ assert_not_same( sv, sv1 )
+ assert_instance_of( StructValue, sv1 )
+ assert( !sv.empty? )
+ assert_equal( 1, sv.length )
+ assert_same( sv1, sv[@mf1] )
+
+ sv2 = sv.putStructValue(@mf2, @mt3)
+ assert_not_nil( sv2 )
+ assert_not_same( sv, sv2 )
+ assert_not_same( sv1, sv2 )
+ assert_instance_of( StructValue, sv2 )
+ assert( !sv.empty? )
+ assert_equal( 2, sv.length )
+ assert_same( sv1, sv[@mf1] )
+ assert_same( sv2, sv[@mf2] )
+ end
+
+ def testRead
+ readHelper( @mt )
+ readHelper( @mt, @mf1, 3 )
+ readHelper( @mt, @mf1, 3, @mf2, 4 )
+ end
+
+ def readHelper( mt, *keyVals )
+ tdi = FakeTdi.new( mt, keyVals )
+ sv = StructValue.read tdi
+ assert_not_nil( sv )
+ tdi.close
+ end
+
+ def testWriteStruct
+ sv = StructValue.new @mt1
+ writeHelper( sv )
+
+ sv.store( @mf1, 123 )
+ writeHelper( sv )
+
+ sv.store( @mf2, 234 )
+ writeHelper( sv )
+ end
+
+ def writeHelper( sv )
+ tdo = FakeTdo.new( sv )
+ sv.writeStruct( tdo )
+ tdo.close
+ end
+
+ def testReadKeysAndValues
+ assert( true )
+ end
+
+ def testWriteKeysAndValues
+ assert( true )
+ end
+end
+
+class FakeTdi
+ include TaggedDataInput
+ include Test::Unit::Assertions
+
+ def initialize( mt, keyVals )
+ @mt = mt
+ @keyVals = keyVals
+ @started = false
+ @done = false
+ @ended = false
+ end
+
+ def startStruct
+ assert( !@started )
+ assert( !@done )
+ assert( !@ended )
+
+ @started = true
+ @index = 0
+ @xstruct = StructValue.new( @mt )
+
+ return @xstruct
+ end
+
+ def readStructElement( se )
+ assert( @started )
+ assert( !@done )
+ assert( !@ended )
+ assert( @index <= @keyVals.length )
+
+ if @index < @keyVals.length
+ se.key = @keyVals[@index]
+ se.value = @keyVals[@index+1]
+ @index += 2
+ return true
+ end
+
+ @done = true
+ return false
+ end
+
+ def endStruct( struct )
+ assert_same( @xstruct, struct )
+ assert( @started )
+ assert( @done )
+ assert( !@ended )
+
+ @ended = true
+ end
+
+ def close
+ assert( @started )
+ assert( @done )
+ assert( @ended )
+
+ assert_same( @mt, @xstruct.stype )
+ assert_equal( @keyVals.length/2, @xstruct.length )
+
+ index = 0
+ while index < @keyVals.length
+ key = @keyVals[index]
+ value = @keyVals[index+1]
+ assert_same( value, @xstruct[key] )
+ index += 2
+ end
+ end
+end
+
+class FakeTdo
+ include TaggedDataOutput
+ include Test::Unit::Assertions
+
+ def initialize( struct )
+ @xstruct = struct
+ @started = false
+ @ended = false
+ end
+
+ def startStruct( struct )
+ assert_same( @xstruct, struct )
+ assert( !@started )
+ assert( !@ended )
+
+ @started = true
+ @items = {}
+ end
+
+ def writeStructElement( key, value )
+ assert( @started )
+ assert( !@ended )
+ @items[key] = value
+ end
+
+ def endStruct ( struct )
+ assert_same( @xstruct, struct )
+ assert( @started )
+ assert( !@ended )
+
+ @ended = true
+ end
+
+ def close
+ assert( @started )
+ assert( @ended )
+
+ assert_equal( @xstruct.length, @items.length )
+ assert_equal( @xstruct, @items )
+ end
+end
+
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_struct_value.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,22 @@
+# package 'etch/bindings/ruby/msg'
+
+class Type < IdName
+
+
+ # Constructs the Type.
+ # @param id the id of the field.
+ # @param name the name of the field.
+
+ def initialize(id, name)
+ super(id, name)
+ end
+
+ # Constructs the Type, computing the appropriate value
+ # for the id.
+ # @param name the name of the type.
+=begin
+ def initialize(name)
+ super(name)
+ end
+=end
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,141 @@
+# package 'etch/bindings/ruby/msg'
+
+# Interface which defines the value factory which helps
+# the idl compiler serialize and deserialize messages,
+# convert values, etc.
+#
+module ValueFactory
+
+ # Adds a type to the set of types.
+ #
+ # @param type a type to add.
+ #
+ # @return the argument. If there is a collision with
+ # an id and name, both associated with the same type,
+ # then that type is returned instead of the argument.
+ #
+ def addType( type )
+ raise "subclasser responsibility"
+ end
+
+ # Translates a type id into the appropriate Type
+ # object.
+ # @param id a type id.
+ # @return id translated into the appropriate Type.
+ #
+ def getType( xid )
+ raise "subclasser responsibility"
+ end
+
+ # @return a collection of all the types.
+ def getTypes()
+ raise "subclasser responsibility"
+ end
+
+ # Adds a field to the set of fields.
+ #
+ # @param field a field to add.
+ #
+ # @return the argument. If there is a collision with
+ # an id and name, both associated with the same field,
+ # then that field is returned instead of the argument.
+ #
+ def addField( field )
+ raise "subclasser responsibility"
+ end
+
+ # Translates a field id into the appropriate Field object.
+ # @param id a field id.
+ #
+ def getField( xid )
+ raise "subclasser responsibility"
+ end
+
+ # Get a collection of fields
+ def getFields()
+ raise "subclasser responsibility"
+ end
+
+ # @return the encoding to use for strings
+ def getStringEncoding
+ raise "subclasser responsibility"
+ end
+
+ # @param msg the message whose well-known message-id field is to be
+ # returned.
+ # @return the value of the well-known message-id field. This is a
+ # unique identifier for this message on a particular transport
+ # during a particular session. If there is no well-known message-id
+ # field defined, or if the message-id field has not been set, then
+ # return null.
+ def getMessageId( msg )
+ raise "subclasser responsibility"
+ end
+
+ # Sets the value of the well-known message-id field. This is a
+ # unique identifier for this message on a particular transport
+ # during a particular session. If there is no well-known message-id
+ # field defined then nothing is done. If msgid is null, then the
+ # field is cleared.
+ # @param msg the message whose well-known message-id field is to
+ # be set.
+ # @param msgid the value of the well-known message-id field.
+ #
+ def setMessageId( msg, msgid )
+ raise "subclasser responsibility"
+ end
+
+ # @param msg the message whose well-known in-reply-to field is to
+ # be returned.
+ # @return the value of the in-reply-to field, or null if there is
+ # none or if there is no such field defined.
+ #
+ def getInReplyTo( msg )
+ raise "subclasser responsibility"
+ end
+
+ # @param msg the message whose well-known in-reply-to field is to
+ # be set.
+ # @param msgid the value of the well-known in-reply-to field. If
+ # there is no well-known in-reply-to field defined then nothing
+ # is done. If msgid is null, then the field is cleared.
+ #
+ def setInReplyTo( msg, msgid )
+ raise "subclasser responsibility"
+ end
+
+ # Converts a value to a struct value representation to be exported
+ # to a tagged data output.
+ # @param value a custom type defined by a service, or a well-known
+ # standard type (e.g., date).
+ # @return a struct value representing the value.
+ #
+ def exportCustomValue( value )
+ raise "subclasser responsibility"
+ end
+
+ # Converts a struct value imported from a tagged data input to
+ # a normal type.
+ # @param sv a struct value representation of a custom type, or a
+ # well known standard type.
+ # @return a custom type, or a well known standard type.
+ #
+ def importCustomValue( sv )
+ raise "subclasser responsibility"
+ end
+
+ # @param c the class of a custom value.
+ # @return the struct type of a custom value class.
+ #
+ def getCustomStructType( type )
+ raise "subclasser responsibility"
+ end
+
+ # @param type the type of a custom value
+ # @return the class of a custom struct value type.
+ #
+ def getCustomType( type )
+ raise "subclasser responsibility"
+ end
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,17 @@
+# package etch/bindings/ruby/support
+
+# Interface which a service implementation may implement which
+# is used by the service stub to give notice of a closed message
+# source.
+
+module Close
+
+ # Notifies the service implementation that the message
+ # source is closed.
+ # @param src the message source that is closed.
+ #
+ def _close( src )
+ raise "subclasser responsibility"
+ end
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,7 @@
+# package etch/bindings/ruby/support
+
+module Converter
+ def convert( obj )
+ raise "subclasser responsibility"
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,231 @@
+# package etch/bindings/ruby/support
+require 'etch/bindings/ruby/msg/value_factory'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/support/id_name_map'
+require 'etch/bindings/ruby/msg/type'
+require 'etch/bindings/ruby/msg/field'
+require 'etch/bindings/ruby/support/etch__auth_exception'
+
+# Default implementation of ValueFactory which provides some
+# dynamic type and field support, as well as standard
+# value conversions and import and export.
+#
+class DefaultValueFactory
+ include ValueFactory
+
+ attr :types, true
+ attr :fields, true
+
+ MT__Etch_RuntimeException = Type.new( nil, "_Etch_RuntimeException" )
+ MT__Etch_AuthException = Type.new( nil, "_Etch_AuthException" )
+ MT__Etch_Date = Type.new( nil, "_Etch_Date" )
+ MT__exception = Type.new( nil, "_exception" )
+
+ MF_msg = Field.new( nil, "msg" )
+ MF_ticks = Field.new( nil, "ticks" )
+ MF_messageId = Field.new( nil, "_messageId" )
+ MF_inReplyTo = Field.new( nil, "_inReplyTo" )
+
+ def initialize( *params )
+
+
+ # Call parametrized constructor
+ temp = 100
+ temp = params.first unless params.nil?
+ paramInitialize( temp )
+
+ end
+
+ def paramInitialize( maxAutoCount )
+
+ @types = IdNameMap.new( maxAutoCount )
+
+ # verify anonymous class technique
+ def @types.makeNew( id, name )
+ return Type.new( id, name )
+ end
+
+ # verify anonymous class technique
+ @fields = IdNameMap.new( maxAutoCount )
+ def @fields.makeNew( id, name )
+ return Field.new(id, name )
+ end
+
+ addType( MT__Etch_RuntimeException );
+ addType( MT__Etch_AuthException );
+ addType( MT__Etch_Date );
+ addType( MT__exception );
+
+ addField( MF_msg );
+ addField( MF_ticks );
+ addField( MF_messageId );
+ addField( MF_inReplyTo );
+
+ end
+
+ #
+ # Types
+ #
+
+ def addType( type )
+ return @types.add( type )
+ end
+
+ def getType( xid )
+
+ if ( xid.class != Fixnum )
+ if ( xid.class == String )
+ getTypeByName( xid )
+ end
+ end
+
+ case ( xid )
+ when MT__Etch_RuntimeException.xid then return MT__Etch_RuntimeException
+ when MT__Etch_AuthException.xid then return MT__Etch_AuthException
+ when MT__Etch_Date.xid then return MT__Etch_Date
+ when MT__exception.xid then return MT__exception
+ end
+
+ return @types.get( xid )
+ end
+
+ def getTypeByName( name )
+ @types.get( name )
+ end
+
+ def getTypes()
+ return @types.values()
+ end
+
+ #
+ # Fields
+ #
+
+ def addField( mf )
+ return @fields.add( mf )
+ end
+
+ def getField( xid )
+
+ if ( xid.class == String )
+ getFieldByName( xid )
+ else
+ case ( xid )
+ when MF_msg.xid then return MF_msg
+ when MF_ticks.xid then return MF_ticks
+ when MF_messageId.xid then return MF_messageId
+ when MF_inReplyTo.xid then return MF_inReplyTo
+ end
+ return @fields.get( xid )
+
+ end
+ end
+
+ def getFieldByName( name )
+ return @fields.get( name )
+ end
+
+ def getFields()
+ return @fields.values()
+ end
+
+ # Figure out the encoding implementation
+ def getStringEncoding()
+ raise "not implemented as yet"
+ end
+
+ #
+ # MessageID
+ #
+
+ def getMessageId( msg )
+ return msg[MF_messageId]
+ end
+
+ def setMessageId( msg, msgid )
+
+ if (msgid != nil)
+ msg[MF_messageId] = msgid
+ else
+ msg.delete(MF_messageId)
+ end
+
+ end
+
+ #
+ # InReplyTo
+ #
+ def getInReplyTo( msg )
+ return msg[MF_inReplyTo]
+ end
+
+ def setInReplyTo( msg, msgid )
+
+ if (msgid != nil)
+ msg[MF_inReplyTo] = msgid
+ else
+ msg.delete(MF_inReplyTo)
+ end
+ end
+
+ #
+ # Value Conversion
+ #
+ def exportCustomValue( value )
+
+ c = value.class
+
+ if ( c == Time )
+ sv = StructValue.new( MT__Etch_Date )
+ sv.store( MF_ticks, value.to_i )
+ return sv
+ end
+
+ if ( c == Etch_AuthException )
+ sv = StructValue.new( MT__Etch_AuthException )
+ sv.store( MF_msg, v.to_s() )
+ return sv
+ end
+
+ # catch any exception which wasn't otherwise
+ # handled and pass it through.
+ #
+ if ( c == Exception )
+ sv = StructValue.new( MT__Etch_RuntimeException )
+ sv.store( MF_msg, value.to_s )
+ return sv
+ end
+
+ return nil
+ end
+
+ def importCustomValue( sv )
+
+ type = sv.getType()
+
+ case ( type.xid )
+ when MT__Etch_RuntimeException.xid then return Etch_RuntimeException.new( sv[ MF_msg ] )
+ when MT__Etch_AuthException.xid then return Etch_AuthException.new( sv[ MF_msg ])
+ when MT__Etch_Date.xid then return Time.at( sv[ MF_ticks ] )
+ end
+
+ return nil
+ end
+
+ def getCustomStructType( c )
+ if (c == DateTime )
+ return MT__Etch_Date
+ end
+ return nil
+ end
+
+ def getCustomType( type )
+
+ case ( type.xid )
+ when MT__Etch_Date then return DateTime
+ end
+
+ return nil
+ end
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,59 @@
+# package etch/bindings/ruby/support
+
+
+# Adapter between remote and message source.
+#
+module DeliveryService
+
+ # Sends the message to the recipient, but does not wait for
+ # any response.
+ # @param msg the message to send
+ # @throws Exception if there is a problem sending
+ #
+ def send( msg )
+ raise "subclasser responsibility"
+ end
+
+ # Sends the message which begins a call sequence.
+ # @param msg the message to send.
+ # @return a mailbox which can be used to read response
+ #
+ def begincall( msg )
+ raise "subclasser responsibility"
+ end
+
+ # @param mb the mailbox returned by begincall( msg )}.
+ # @param responseType the type of the expected response.
+ # @param responseField the field of the expected response
+ # which would contain any result value or thrown exception.
+ # @param timeout time in ms to wait for a response.
+ # @throws Exception if there is a problem sending or a timeout
+ # waiting or if the result value was an exception.
+ #
+ def endvoidcall( mb, responseType, responseField, timeout )
+ raise "subclasser responsibility"
+ end
+
+ # @param mb
+ # @param responseType the type of the expected response.
+ # @param responseField the field of the expected response
+ # which would contain any result value or thrown exception.
+ # @param timeout time in ms to wait for a response.
+ # @return the value of the response field if it isn't an exception.
+ # @throws Exception if there is a problem sending or a timeout
+ # waiting or if the result value was an exception.
+ #
+ def endcall( mb, responseType, responseField, timeout )
+ raise "subclasser responsibility"
+ end
+
+ # Shuts down output so no more messages may be sent. The
+ # other end should see the input message stream close, and
+ # would in turn shutdown its output (which we would then see).
+ # @throws Exception if there is a problem shutting down out
+ # output stream.
+ #
+ def shutdownOutput
+ raise "subclasser responsibility"
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,10 @@
+# package etch/bindings/ruby/support
+
+class Element
+
+ def initialize( sender, msg )
+ @sender = sender
+ @msg = msg
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,33 @@
+# package etch/bindings/ruby/support
+
+class Enum
+ include Comparable
+
+ def initialize( name, ord )
+ @name = name
+ @ord = ord
+ end
+
+ def <=>( other )
+ return @ord<=>( other.ord )
+ end
+
+ def to_s
+ return @name.to_s
+ end
+
+ attr :name
+ attr :ord
+
+ alias :to_int :ord
+ alias :to_i :ord
+
+ protected :initialize
+end
+
+# Usage:
+#class PrimaryColor < Enum
+# RED = PrimaryColor.new( :RED, 0 )
+# GREEN = PrimaryColor.new( :GREEN, 1 )
+# BLUE = PrimaryColor.new( :BLUE, 2 )
+#end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,10 @@
+# package 'etch/bindings/ruby/support'
+require 'etch/bindings/ruby/support/etch__runtime_exception'
+
+class Etch_AuthException < Etch_RuntimeException
+
+ def initialize( msg )
+ super( msg )
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,18 @@
+# package etch/bindings/ruby/support
+
+class Etch_RuntimeException < Exception
+
+ attr :msg, true
+
+ # Constructs the EtchRuntimeException.
+ # @param msg description of the exception that was caught by the stub
+ #
+ def initialize( msg )
+ @msg = msg
+ end
+
+ def message()
+ return msg
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,21 @@
+
+# Adding Enum capability to ruby
+
+module EtchEnum
+
+ def self.enum( *syms )
+
+ syms.each { |s| const_set( s, s.to_s ) }
+ const_set( :DEFAULT, syms.first ) unless ( syms.nil? || const_defined?( :DEFAULT ) )
+ end
+
+ def self.enum2( *syms )
+
+ order = 0
+ syms.each { |s|
+ const_set( s.to_s, order )
+ order += 1
+ } unless ( syms.nil? || syms.length == 0 )
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,38 @@
+require 'thread'
+
+# Check whether the mutex is
+# being held by the current thread itself,
+# in which case, don't try to lock again.
+# @param threadId holds the information
+# regarding "which" thread holds the lock
+
+class EtchMutex < Mutex
+
+ def synchronize
+
+ # do checking here
+ if (@threadId == nil)
+ # no thread holds lock
+ @threadId = Thread.current
+ super
+ else
+ if (@threadId == Thread.current)
+ # don't call synchronize again
+ # because this thread already holds lock
+ # just yield !
+ yield
+ else
+ # another thread wants the lock
+ # proceed normal locking operation
+ super
+ end
+ end
+ end
+
+ # When unlock is called, threadId should be set back
+ # nil.
+ def unlock
+ @threadId = nil
+ super
+ end
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,166 @@
+require 'thread'
+require 'etch/bindings/ruby/support/etch_mutex'
+# Map by id and name of IdNames (or subclasses thereof).
+#
+class IdNameMap
+
+ attr :maxAutoCount, true
+ attr :byId, true
+ attr :byName, true
+ attr :autocount, true
+
+ # Constructs the IdNameMap.
+ # @param maxAutoCount the maximum number of automatically
+ # declared IdNames allowed. Set to 0 if you don't want any,
+ # but this may prevent working with a slightly different
+ # version of a service.
+ #
+ def initialize( maxAutoCount )
+
+ @mutex = EtchMutex.new
+
+ @maxAutoCount = maxAutoCount
+ @byId = Hash.new
+ @byName = Hash.new
+ @autocount = 0
+ end
+
+ # Gets the IdName subclass which corresponds to the specified
+ # id, or creates it if it isn't found and if autoCount <
+ # maxAutoCount. If created, the IdName is given the name which
+ # is id.toString().
+ # @param id the id of an IdName.
+ # @return the IdName subclass found or created.
+ #
+
+ def get( id )
+
+ if ( id.class == String )
+
+ # print "getByName() call"
+ getByName( id )
+ else
+ # Check if the synchronization is correct !
+ @mutex.synchronize do
+ t = @byId[id]
+
+ if (t == nil)
+ # print "autocount = ", @autocount, "maxAutocount = ", @maxAutoCount
+ if ( @autocount >= @maxAutoCount )
+ raise "maxAutoCount would be exceeded"
+ end
+
+ @autocount += 1
+
+ var = add( makeNew( id, id.to_s() ) )
+ return var
+ end
+
+ return t
+ end
+ end
+ end
+
+ # Gets the IdName subclass which corresponds to the specified
+ # name, or creates it if it isn't found and if autoCount <
+ # maxAutoCount. If created, the IdName is given the id which
+ # is IdName.hash( name ).
+ # @param name the name of an IdName.
+ # @return the IdName subclass found or created.
+ #
+ def getByName( name )
+ @mutex.synchronize do
+
+ t = @byName[ name ]
+ if (t == nil)
+ if (@autocount >= @maxAutoCount)
+ raise "maxAutoCount would be exceeded"
+ end
+ @autocount += 1
+
+ return add( makeNew( IdName.hashit( name ), name ) )
+ end
+
+ return t
+
+ end # mutex end
+ end
+
+ # Adds the IdName subclass to the map. If the entry matches
+ # a current entry (both id and name), then return the current
+ # entry instead.
+ #
+ # @param t the IdName subclass to add.
+ #
+ # @return the IdName from the map, either the new one or a current
+ # one.
+ #
+ # @throws IllegalArgumentException if there is a collision with
+ # id or name, or a collision with id and name where they are not
+ # associated with the same object.
+ #
+ def add( t )
+ @mutex.synchronize do
+
+ # four cases:
+ # 1) t.id and t.name do not exist (no collision)
+ # 2) t.id exists but t.name does not (collision)
+ # 3) t.id does not exist but t.name does (collision)
+ # 4) t.id and t.name exist (possible collision)
+
+ sameId = @byId[ t.xid ]
+ sameName = @byName[ t.name ]
+ if ( sameId!=nil || sameName!=nil )
+ # sameId has the same id as t.
+ # sameName has the same name as t.
+ # the only way this isn't a problem is if sameId == sameName,
+ # because that is the only case where there is a single
+ # entry which has both the same id and name as t.
+ if (sameId != sameName)
+
+ if (sameId != nil && sameName != nil)
+ raise "id & name collision"
+ else
+ if (sameId != nil)
+ raise "id collision"
+ end
+ if (sameName != nil )
+ raise "id collision"
+ end
+ end
+
+ end
+
+ return sameId
+ end
+
+ @byId.store( t.xid, t )
+ @byName.store( t.name, t )
+
+ return t
+
+ end # mutex end
+
+ end
+
+ def values()
+
+ @mutex.synchronize do
+
+ return @byId.values()
+
+ end # mutex end
+
+ end
+
+ # Makes a new subclass of IdName to put in this map.
+ # @param id the id of the new subclass of IdName.
+ # @param name the name of the new subclass of IdName.
+ # @return a newly constructed subclass of IdName to put in
+ # this map.
+ #
+ def makeNew( id, name )
+ raise "subclasser responsibility"
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,40 @@
+# package etch/bindings/ruby/support
+require 'etch/bindings/ruby/support/message_handler'
+
+# An interface used to deliver responses to a message. Support for
+# the mechanism is somewhat dependent upon properties of the transport
+# and message format.
+#
+module Mailbox
+ include MessageHandler
+
+ def getMessageId()
+ raise "subclasser responsibility"
+ end
+
+ # @param maxDelay the maximum amount of time in milliseconds to
+ # wait to read a message from an empty mailbox. 0 means wait
+ # forever, -1 means don't wait at all.
+ # @return the next message to be read from the mailbox, or null if
+ # the mailbox is empty and closed. Wait forever for such a message
+ # to be delivered.
+ #
+ def read( maxDelay )
+ raise "subclasser responsibility"
+ end
+
+ # Closes the mailbox so that no more messages can be delivered.
+ # Queued messages remain to be read. Reading an empty closed
+ # mailbox returns null.
+ def closeDelivery()
+ raise "subclasser responsibility"
+ end
+
+ # Closes the mailbox so that no more messages will be delivered or
+ # read. Any remaining queued messages are delivered to a default
+ # handler.
+ def closeRead()
+ raise "subclasser responsibility"
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,15 @@
+# package etch/bindings/ruby/support
+
+module MessageHandler
+
+ # Delivers a message from a message source.
+ # @param src the message source
+ # @param sender the message sender (meaning depends upon the message
+ # source).
+ # @param msg the message from the message source.
+ # @return true if the message was processed.
+ #
+ def message( src, sender, msg )
+ raise "subclasser responsibility"
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,23 @@
+# package 'etch/bindings/ruby/support'
+
+# A message source is used to model the origin of a message to a
+# stub so that a reply might be sent.
+#
+module MessageSource
+
+ # Sends a message to a message source. The message is encoded
+ # in some way (e.g., compressed binary format or xml), and then delivered
+ # to a transport (e.g., packetized data stream or http response).
+ #
+ # @param recipient a transport specific opaque value which identifies
+ # the sender of a message. Delivered by a message handler to the stub
+ # and may be passed here to send a message back to the original sender.
+ # Passing null means "use the default recipient".
+ #
+ # @param msg the message to send.
+
+ def message( recipient, msg )
+ raise "subclasser responsibility"
+ end
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,7 @@
+# package etch/bindings/ruby/support
+
+module Pool
+
+ # Figure Pool out ...
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,25 @@
+# package etch/bindings/ruby/support
+
+# Base class for call to message translators.
+#
+require 'etch/bindings/ruby/msg/message'
+class RemoteBase
+
+ attr :_svc, true
+ attr :_vf, true
+
+ def initialize( svc, vf )
+ @_svc = svc
+ @_vf = vf
+ end
+
+ def _newMessage( type )
+ return Message.new( type, @_vf )
+ end
+
+ # Shuts down output on this remote object. No more
+ # messges may be sent.
+ def _shutdownOutput()
+ return @_svc.shutdownOutput()
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,32 @@
+# package etch/bindings/ruby/support
+require 'etch/bindings/ruby/support/message_handler'
+
+
+# Base class of stub implementations.
+#
+class StubBase
+ include MessageHandler
+
+
+ attr :_obj
+ attr :_free
+ attr :_pool
+
+ def initialize( obj, pool, free )
+ @_obj = obj
+ @_free = free
+ @_pool = pool
+ end
+
+
+ def message( src, sender, msg )
+
+ if (msg == nil)
+ if ( @_obj.class.method_defined? :_close )
+ @_obj._close( src )
+ end
+ return true
+ end
+ return false
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,335 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/id_name_map'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/support/etch_enum'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/support/default_value_factory'
+require 'etch/bindings/ruby/support/remote_base'
+require 'etch/bindings/ruby/support/close'
+require 'etch/bindings/ruby/support/unwanted'
+require 'etch/bindings/ruby/support/message_source'
+require 'etch/bindings/ruby/support/stub_base'
+require 'etch/bindings/ruby/support/who'
+require 'etch/bindings/ruby/support/default_value_factory'
+
+class TestDefaultValueFactory < Test::Unit::TestCase
+
+ def setup
+ @vf = DefaultValueFactory.new( 3 )
+ end
+
+ def test_add_type
+
+ #
+ # a
+ #
+
+ a = @vf.addType( Type.new( nil, "a" ) )
+ assert_not_nil( a )
+
+ x = @vf.addType( @vf.getType( "a" ) )
+ assert_not_nil( x )
+ assert_same( a, x )
+
+ x = @vf.addType( Type.new( nil, "a" ) )
+ assert_not_nil( x )
+ assert_same( a, x )
+
+ #
+ # b
+ #
+
+ b = @vf.addType( Type.new( nil, "b" ) )
+ assert_not_nil( b )
+
+ y = @vf.addType( @vf.getType( "b" ) )
+ assert_not_nil( y )
+ assert_same( b, y )
+
+ y = @vf.addType( Type.new( nil, "b" ) )
+ assert_not_nil( y )
+ assert_same( b, y )
+
+ #
+ # c
+ #
+
+ c = @vf.addType( Type.new( nil, "c" ) )
+ assert_not_nil( c )
+
+ z = @vf.addType( @vf.getType( "c" ) )
+ assert_not_nil( z )
+ assert_same( c, z )
+
+ z = @vf.addType( Type.new( nil, "c" ) )
+ assert_not_nil( z )
+ assert_same( c, z )
+
+ end
+
+ def test_getType_id_Etch_Runtime_Exception
+ x = @vf.getType( DefaultValueFactory::MT__Etch_RuntimeException.xid )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MT__Etch_RuntimeException, x )
+ end
+
+ def test_getType_name_Etch_Runtime_Exception
+ x = @vf.getType( "_Etch_RuntimeException" )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MT__Etch_RuntimeException, x )
+ end
+
+ def test_just_enough
+ @vf.getType( "a" )
+ @vf.getType( "b" )
+ @vf.getType( "c" )
+ end
+
+ def test_too_many
+
+ @vf.getType( "a" )
+ @vf.getType( "b" )
+ @vf.getType( "c" )
+
+ exceptionCaught = false
+ begin
+ @vf.getType( "d" )
+ rescue Exception
+ exceptionCaught = true
+ end
+
+ flunk "test should have failed" if ( exceptionCaught == false )
+ end
+
+ def test_getTypes
+ list = Array.new
+ list << @vf.getType( "a" )
+ list << @vf.getType( "b" )
+ list << @vf.getType( "c" )
+ list << DefaultValueFactory::MT__Etch_RuntimeException
+ list << DefaultValueFactory::MT__Etch_AuthException
+ list << DefaultValueFactory::MT__Etch_Date
+ list << DefaultValueFactory::MT__exception
+
+ c = @vf.getTypes
+
+ # Check for inclusivity.
+ list.each { |element| assert( c.include?( element ) ) }
+ c.each{ |element| assert( list.include?( element ) ) }
+
+ end
+
+ def test_add_field()
+
+ #
+ # a
+ #
+
+ a = @vf.addField( Field.new( nil, "a" ) )
+ assert_not_nil( a )
+
+ x = @vf.getField( "a" )
+ assert_not_nil( x )
+ assert_same( a, x )
+
+ #
+ # b
+ #
+
+ b = @vf.addField( Field.new( nil, "b" ) )
+ assert_not_nil( b )
+
+ y = @vf.getField( "b" )
+ assert_not_nil( y )
+ assert_same( b, y )
+
+ #
+ # c
+ #
+
+ c = @vf.addField( Field.new( nil, "c" ) )
+ assert_not_nil( c )
+
+ z = @vf.getField( "c" )
+ assert_not_nil( z )
+ assert_same( c, z )
+
+ end
+
+ def test_get_field_id_messageId
+ x = @vf.getField( DefaultValueFactory::MF_messageId.xid )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_messageId, x )
+ end
+
+ def test_get_field_id_inReplyTo
+ x = @vf.getField( DefaultValueFactory::MF_inReplyTo.xid )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_inReplyTo, x )
+ end
+
+ def test_get_field_id_msg
+ x = @vf.getField( DefaultValueFactory::MF_msg.xid )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_msg, x )
+ end
+
+ def test_get_field_name_messageId
+ x = @vf.getField( "_messageId" )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_messageId, x )
+ end
+
+ def test_get_field_name_inReplyTo
+ x = @vf.getField( "_inReplyTo" )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_inReplyTo, x )
+ end
+
+ def test_get_field_name_msg
+ x = @vf.getField( "msg" )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_msg, x )
+ end
+
+ def test_get_field_name_ticks
+ x = @vf.getField( "ticks" )
+ assert_not_nil( x )
+ assert_same( DefaultValueFactory::MF_ticks, x )
+ end
+
+ def test_getField_auto_just_enough
+ @vf.getField( "a" )
+ @vf.getField( "b" )
+ @vf.getField( "c" )
+ end
+
+ def test_getField_auto_too_many
+
+ @vf.getField( "a" )
+ @vf.getField( "b" )
+ @vf.getField( "c" )
+
+ exceptionCaught = false
+ begin
+ @vf.getField( "d" )
+ rescue Exception
+ exceptionCaught = true
+ end
+ flunk "test should have failed" if ( exceptionCaught == false )
+
+ end
+
+ def test_getFields
+ list = Array.new
+ list << @vf.getField( "a" )
+ list << @vf.getField( "b" )
+ list << @vf.getField( "c" )
+ list << DefaultValueFactory::MF_msg
+ list << DefaultValueFactory::MF_ticks
+ list << DefaultValueFactory::MF_messageId
+ list << DefaultValueFactory::MF_inReplyTo
+
+ c = @vf.getFields
+
+ # Check for inclusivity.
+ list.each { |element| assert( c.include?( element ) ) }
+ c.each{ |element| assert( list.include?( element ) ) }
+
+ end
+
+ def test_get_type_and_fields_are_distinct
+
+ # verify that the type and field maps are distinct
+ mta = @vf.getType( "a" )
+ assert_not_nil( mta )
+ mfa = @vf.getField( "a" )
+ assert_not_nil( mfa )
+
+ assert_not_same( mta, mfa )
+ end
+
+ # TODO: Test for string encoding
+
+ def test_messageId
+
+ msg = Message.new( nil, @vf )
+ assert_nil( @vf.getMessageId( msg ) )
+
+ @vf.setMessageId( msg, 234 )
+ msgId = @vf.getMessageId( msg )
+ assert_not_nil( msgId )
+ assert_equal( 234, msgId )
+
+ @vf.setMessageId( msg, nil )
+ assert_nil( @vf.getMessageId( msg ) )
+ end
+
+ def test_inReplyTo
+
+ msg = Message.new( nil, @vf )
+ assert_nil( @vf.getInReplyTo( msg ) )
+
+ @vf.setInReplyTo( msg, 234 )
+ msgId = @vf.getInReplyTo( msg )
+ assert_not_nil( msgId )
+ assert_equal( msgId, 234 )
+
+ @vf.setInReplyTo( msg, nil )
+ assert_nil( @vf.getInReplyTo( msg ) )
+ end
+
+ def test_exportcustomvalue_runtimeexception
+
+ value = Exception.new()
+ sv = @vf.exportCustomValue( value )
+ sv.checkType( DefaultValueFactory::MT__Etch_RuntimeException )
+
+ assert_equal( 1, sv.size )
+ assert_equal( sv[ DefaultValueFactory::MF_msg ], "Exception" )
+ end
+
+ def test_exportcustomvalue_runtimeexception_msg
+
+ value = Exception.new( "foo!=null" )
+ sv = @vf.exportCustomValue( value )
+ sv.checkType( DefaultValueFactory::MT__Etch_RuntimeException )
+
+ assert_equal( 1, sv.size )
+ assert_equal( sv[ DefaultValueFactory::MF_msg ], "foo!=null" )
+ end
+
+ def test_exportcustomvalue_date
+
+ # the argument gives the no. of seconds since epoch
+ value = Time.at(12395)
+ sv = @vf.exportCustomValue( value )
+ sv.checkType( DefaultValueFactory::MT__Etch_Date )
+ assert_equal( 1, sv.size )
+ assert_equal( 12395, sv[ DefaultValueFactory::MF_ticks ])
+ end
+
+ def test_importcustomvalue_etch_runtimeexception
+ sv = StructValue.new( DefaultValueFactory::MT__Etch_RuntimeException )
+ e = @vf.importCustomValue( sv )
+ assert_not_nil( e )
+ assert_nil( e.message() )
+ end
+
+ def test_importcustomvalue_etch_runtimeexception_msg
+ sv = StructValue.new( DefaultValueFactory::MT__Etch_RuntimeException )
+ sv.store( DefaultValueFactory::MF_msg, "foo")
+ e = @vf.importCustomValue( sv )
+ assert_not_nil( e )
+ assert_equal( "foo", e.message())
+ end
+
+ def test_importcustomvalue_etch_date
+ sv = StructValue.new( DefaultValueFactory::MT__Etch_Date )
+ sv.store( DefaultValueFactory::MF_ticks, 12345)
+ e = @vf.importCustomValue( sv )
+ assert_not_nil( e )
+ assert_equal( 12345, e.to_i)
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,219 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/id_name_map'
+require 'etch/bindings/ruby/msg/id_name'
+
+class TestIdNameMap < Test::Unit::TestCase
+
+ def setup
+
+ @map = IdNameMap.new( 3 )
+ def @map.makeNew( id, name )
+
+ # print "makeNew called with ", id, " & ", name, "\n"
+ return IdName.new( id, name )
+ end
+
+ @a = @map.add( IdName.new( 1, "a" ) )
+ @b = @map.add( IdName.new( 2, "b" ) )
+ end
+
+ def testget_1
+ x = @map.get( 1 )
+ assert_not_nil( x )
+ assert_same( @a, x )
+ assert_equal( 1, x.xid )
+ assert_equal( "a", x.name() )
+ end
+
+ def testget_a
+ x = @map.get( "a" )
+ assert_not_nil( x )
+ assert_same( @a, x )
+ assert_equal( 1, x.xid )
+ assert_equal( "a", x.name )
+ end
+
+ def testget_2
+ x = @map.get( 2 )
+ assert_not_nil( x )
+ assert_same( @b, x )
+ assert_equal( 2, x.xid )
+ assert_equal( "b", x.name() )
+ end
+
+ def testget_b
+ x = @map.get( "b" )
+ assert_not_nil( x )
+ assert_same( @b, x )
+ assert_equal( 2, x.xid )
+ assert_equal( "b", x.name )
+ end
+
+ def testget_3
+ x = @map.get( 3 )
+ assert_not_nil( x )
+ assert_not_same( @a, x )
+ assert_not_same( @b, x )
+ assert_equal( 3, x.xid )
+ assert_equal( "3", x.name )
+
+ y = @map.get( 3 )
+ assert_same( x, y )
+ end
+
+ def testget_c
+ x = @map.get( "c" )
+ assert_not_same( @a, x )
+ assert_not_same( @b, x )
+ assert_equal( 352988318, x.xid )
+ assert_equal( "c", x.name )
+
+ y = @map.get( "c" )
+ assert_same( x, y )
+ end
+
+ def testjustgetenough
+ c = @map.get( "c" )
+ assert_not_nil( c )
+ assert_not_same( @a, c )
+ assert_not_same( @b, c )
+
+ d = @map.get( "d" )
+ assert_not_nil( d )
+ assert_not_same( @a, d )
+ assert_not_same( @b, d )
+ assert_not_same( c, d )
+
+ e = @map.get( "e" )
+ assert_not_nil( e )
+ assert_not_same( @a, e )
+ assert_not_same( @b, e )
+ assert_not_same( c, e )
+ assert_not_same( d, e )
+
+ end
+
+ def testgettoomany1
+
+ c = @map.get( "c" )
+ assert_not_nil( c )
+ assert_not_same( @a, c )
+ assert_not_same( @b, c )
+
+ d = @map.get( "d" )
+ assert_not_nil( d )
+ assert_not_same( @a, d )
+ assert_not_same( @b, d )
+ assert_not_same( c, d )
+
+ e = @map.get( "e" )
+ assert_not_nil( e )
+ assert_not_same( @a, e )
+ assert_not_same( @b, e )
+ assert_not_same( c, e )
+ assert_not_same( d, e )
+
+ exceptionCaught = false
+ begin
+ @map.get( "f" )
+ rescue Exception
+ exceptionCaught = true
+ end
+
+ flunk "test should have failed" if ( exceptionCaught == false )
+ end
+
+ def testgettoomany2
+
+ c = @map.get( 3 )
+ assert_not_nil( c )
+ assert_not_same( @a, c )
+ assert_not_same( @b, c )
+
+ d = @map.get( 4 )
+ assert_not_nil( d )
+ assert_not_same( @a, d )
+ assert_not_same( @b, d )
+ assert_not_same( c, d )
+
+ e = @map.get( 5 )
+ assert_not_nil( e )
+ assert_not_same( @a, e )
+ assert_not_same( @b, e )
+ assert_not_same( c, e )
+ assert_not_same( d, e )
+
+ exceptionCaught = false
+ begin
+ @map.get( 6 )
+ rescue Exception
+ exceptionCaught = true
+ end
+
+ flunk "test should have failed" if ( exceptionCaught == false )
+ end
+
+ def testgettoomany3
+
+ c = @map.get( 3 )
+ assert_not_nil( c )
+ assert_not_same( @a, c )
+ assert_not_same( @b, c )
+
+ d = @map.get( "d" )
+ assert_not_nil( d )
+ assert_not_same( @a, d )
+ assert_not_same( @b, d )
+ assert_not_same( c, d )
+
+ e = @map.get( 5 )
+ assert_not_nil( e )
+ assert_not_same( @a, e )
+ assert_not_same( @b, e )
+ assert_not_same( c, e )
+ assert_not_same( d, e )
+
+ exceptionCaught = false
+ begin
+ @map.get( "f" )
+ rescue Exception
+ exceptionCaught = true
+ end
+
+ flunk "test should have failed" if ( exceptionCaught == false )
+ end
+
+ def testadd
+ assert_same( @a, @map.add( @a ))
+ assert_same( @b, @map.add( @b ))
+ end
+
+ def test_id_coll
+
+ exceptionCaught = false
+ begin
+ @map.add( IdName.new( 1, "c" ) )
+ rescue Exception
+ exceptionCaught = true
+ end
+ end
+
+ def test_name_coll
+ exceptionCaught = false
+ begin
+ @map.add( IdName.new( 3, "a" ) )
+ rescue Exception
+ exceptionCaught = true
+ end
+ end
+
+ def test_id_name_coll
+ exceptionCaught = false
+ begin
+ @map.add( IdName.new( 2, "a" ) )
+ rescue Exception
+ exceptionCaught = true
+ end
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,130 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/id_name_map'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/support/etch_enum'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/support/default_value_factory'
+require 'etch/bindings/ruby/support/remote_base'
+
+class TestRemoteBase < Test::Unit::TestCase
+
+ def setup
+ @svc = MyDeliveryService.new()
+ @vf = DefaultValueFactory.new()
+ @rb = RemoteBase.new( @svc, @vf )
+ @mt = Type.new( nil, "foo" )
+ @rmt = Type.new( nil, "bar" )
+ @rmf = Field.new( nil, "baz" )
+ end
+
+ def test_new_message
+ msg = @rb._newMessage( @mt )
+ msg.checkType( @mt )
+ assert_same( @vf, msg.vf )
+ assert_nil( @svc.what )
+ assert_nil( @svc.xmsg )
+ assert_nil( @svc.xresponseType )
+ assert_nil( @svc.xresponseField )
+ assert_nil( @svc.xtimeout )
+ end
+
+ def test_send
+ msg = @rb._newMessage( @mt )
+ @rb._svc.send( msg )
+ assert_same( @svc.what, :SEND )
+ assert_same( @svc.xmsg, msg )
+ assert_nil( @svc.xresponseType )
+ assert_nil( @svc.xresponseField )
+ assert_nil( @svc.xtimeout )
+ end
+
+ def test_void_call
+ msg = @rb._newMessage( @mt )
+ @rb._svc.endvoidcall( @rb._svc.begincall( msg ), @rmt, @rmf, 99 )
+
+ assert_same( @svc.what, :VOIDCALL )
+ assert_same( @svc.xmsg, msg )
+ assert_same( @svc.xresponseType, @rmt )
+ assert_same( @svc.xresponseField, @rmf )
+ assert_equal( @svc.xtimeout, 99 )
+ end
+
+ def test_call
+ msg = @rb._newMessage( @mt )
+ result = @rb._svc.endcall( @rb._svc.begincall( msg ), @rmt, @rmf, 98 )
+
+ assert_same( @svc.what, :CALL )
+ assert_same( @svc.xmsg, msg )
+ assert_same( @svc.xresponseType, @rmt )
+ assert_same( @svc.xresponseField, @rmf )
+ assert_same( @svc.xtimeout, 98 )
+ assert_equal( result, 23 )
+ end
+
+ def test_close
+ @rb._shutdownOutput()
+
+ assert_same( @svc.what, :SHUTDOWN )
+ assert_nil( @svc.xmsg )
+ assert_nil( @svc.xresponseType )
+ assert_nil( @svc.xresponseField )
+ assert_nil( @svc.xtimeout )
+ end
+
+ class MyDeliveryService
+ include DeliveryService
+ include Test::Unit::Assertions
+
+ attr :what, true
+ attr :xmsg, true
+ attr :xresponseType, true
+ attr :xresponseField, true
+ attr :xtimeout, true
+
+ def initialize()
+ @what = EtchEnum.enum
+ end
+
+ def send( msg )
+ assert_nil( @what )
+ @what = :SEND
+ @xmsg = msg
+ end
+
+ def begincall( msg )
+ assert_nil( @what )
+ @what = :BEGINCALL
+ @xmsg = msg
+ @xmb = nil # replace with PlainMailbox( ... ), look in Java side
+ return @xmb
+ end
+
+ def endvoidcall( mb, responseType, responseField, timeout )
+ assert_same( :BEGINCALL, @what )
+ assert_same( @xmb, mb ) # probably not
+ @what = :VOIDCALL
+ @xmb = nil
+ @xresponseType = responseType
+ @xresponseField = responseField
+ @xtimeout = timeout
+ end
+
+ def endcall( mb, responseType, responseField, timeout )
+ assert_same( :BEGINCALL, @what )
+ assert_same( @xmb, mb )
+ @what = :CALL
+ @xmb = nil
+ @xresponseType = responseType
+ @xresponseField = responseField
+ @xtimeout = timeout
+ return 23
+ end
+
+ def shutdownOutput()
+ assert_nil( @what )
+ @what = :SHUTDOWN
+ end
+
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,139 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/id_name_map'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/support/etch_enum'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/support/default_value_factory'
+require 'etch/bindings/ruby/support/remote_base'
+require 'etch/bindings/ruby/support/close'
+require 'etch/bindings/ruby/support/unwanted'
+require 'etch/bindings/ruby/support/message_source'
+require 'etch/bindings/ruby/support/stub_base'
+require 'etch/bindings/ruby/support/who'
+
+class TestStubBase < Test::Unit::TestCase
+
+ def test_close1
+ obj = MyUnwantedClose.new()
+ sb = StubBase.new( obj, nil, nil )
+ src = MyMessageSource.new()
+
+ sb.message( src, nil, nil )
+
+ assert_equal( :CLOSE, obj.what )
+ assert_same( src, obj.src )
+ assert_nil( obj.sender )
+ assert_nil( obj.msg )
+ end
+
+ def test_close2
+ obj = MyClose.new()
+ sb = StubBase.new( obj, nil, nil )
+ src = MyMessageSource.new()
+
+ sb.message( src, nil, nil )
+
+ assert_equal( :CLOSE, obj.what )
+ assert_same( src, obj.src )
+ end
+
+ def test_close3
+ obj = MyUnwanted.new()
+ sb = StubBase.new( obj, nil, nil )
+ src = MyMessageSource.new()
+
+ sb.message( src, nil, nil )
+
+ assert_nil( obj.what )
+ assert_nil( obj.src )
+ assert_nil( obj.sender )
+ assert_nil( obj.msg )
+ end
+
+
+ class MyMessageSource
+ include MessageSource
+ include Test::Unit::Assertions
+
+ def message( recipient, msg )
+ flunk( "not needed" )
+ end
+
+ def vf()
+ flunk( "not needed" )
+ return nil
+ end
+ end
+
+ class MyUnwantedClose
+ include Close
+ include Unwanted
+ include Test::Unit::Assertions
+
+ attr :what, true
+ attr :src, true
+ attr :sender, true
+ attr :msg, true
+
+ def initialize()
+ @what = EtchEnum.enum
+ end
+
+ def _unwanted( src, sender, msg )
+ assert_nil( @what )
+ @what = :UNWANTED
+ @src = src
+ @sender = sender
+ @msg = msg
+ end
+
+ def _close( src )
+ assert_nil( @what )
+ @what = :CLOSE
+ @src = src
+ @sender = nil
+ @msg = nil
+ end
+ end
+
+ class MyClose
+ include Close
+ include Test::Unit::Assertions
+
+ attr :what, true
+ attr :src, true
+
+ def initialize()
+ @what = EtchEnum.enum
+ end
+
+ def _close( src )
+ assert_nil( @what )
+ @what = :CLOSE
+ @src = src
+ end
+ end
+
+ class MyUnwanted
+ include Unwanted
+ include Test::Unit::Assertions
+
+ attr :what, true
+ attr :src, true
+ attr :sender, true
+ attr :msg, true
+
+ def initialize()
+ @what = EtchEnum.enum
+ end
+
+ def _unwanted( src, sender, msg )
+ assert_nil( @what )
+ @what = :UNWANTED
+ @src = src
+ @sender = sender
+ @msg = msg
+ end
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,21 @@
+# package etch/bindings/ruby/support
+
+# Interface which a service implementation may implement which
+# is used by the service stub to give notice of an unwanted
+# message. This is a message which was not wanted by the service
+# stubs (its id did not match any service method).
+#
+module Unwanted
+
+ # Notifies the service implementation that the message
+ # is unwanted, that is, its id does not match any defined
+ # message.
+ # @param src the message source.
+ # @param sender the transport defined sender.
+ # @param msg the message that was not wanted.
+ #
+ def _unwanted( src, sender, msg )
+ raise "subclasser responsibility"
+ end
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,10 @@
+# package etch/bindings/ruby/support
+
+# Abstraction of sender used by the various sources of data,
+# packets, or messages.
+module Who
+
+ def initialize()
+ # nothin else
+ end
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,43 @@
+require 'socket'
+
+class AbstractStartable
+ include Startable
+
+ attr :started, true
+
+ private :started
+
+ def start()
+ if( isStarted() )
+ raise "isStarted"
+ end
+ @started = true
+ throw :Exception1 => e unless start0()
+ end
+
+ catch :Exception1 => e do
+ started = false
+ throw e
+ end
+
+ def stop()
+ if( !isStarted() )
+ raise "!isStarted"
+ end
+ @started = false
+ stop0()
+ end
+
+ def isStarted()
+ return @started
+ end
+
+ def start0()
+ raise "Subclasser responsibility"
+ end
+
+ def stop0()
+ raise "Subclasser responsibility"
+ end
+end
+
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,11 @@
+require 'socket'
+
+ $port = 4001
+
+ clientSocket = TCPServer.new( 'localhost', $port )
+
+ while( newSession = clientSocket.accept )
+ data = newSession.gets
+ newSession.print data
+ end
+
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,115 @@
+require 'etch/bindings/ruby/transport/monitor.rb'
+require 'etch/bindings/ruby/transport/runner.rb'
+require 'etch/bindings/ruby/transport/runner_handler.rb'
+require 'socket'
+
+class Connection < Runner
+ include Source, RunnerHandler
+
+ attr_writer :handler, true
+
+ protected :handler
+
+ def initialize( handler )
+ Runner.setRunnerHandler( handler )
+ @handler = handler
+ end
+
+ def setHandler( handler )
+ Runner.setRunnerHandler( handler )
+ @handler = handler
+ end
+
+ def started( runner )
+ # do nothing
+ end
+
+ def stopped( runner )
+ # do nothing
+ end
+
+ def exception( runner, what, e )
+ e = Exception.new
+ e.message
+ end
+
+ def run0
+ if( !openSocket?(!first) )
+ return false
+ end
+
+ throw :Exception1 unless setUpSocket()
+
+ throw :Exception2 unless fireUP()
+ throw :Exception2 unless readSocket()
+ return true
+ end
+
+ catch :Exception1 => e do
+ fireException( "setup", e )
+ return true
+ end
+
+ catch :Exception2 => e do
+ fireException( "run", e )
+ close( true )
+ return true
+ end
+
+ ensure
+ begin
+ close( false )
+ fireDown()
+ end
+
+ def openSocket( reconnect )
+ raise "subclass responsibility"
+ end
+
+ def setUpSocket()
+ raise "subclass responsibility"
+ end
+
+ def readSocket()
+ raise "subclass responsibility"
+ end
+
+ def close( reset )
+ raise "subclass responsibility"
+ end
+
+ def fireUp()
+ notifyUp()
+ if( @handler != nil )
+ @handler.up( handler )
+ end
+ end
+
+ def fireDown()
+ notifyUp()
+ if( @handler != nil )
+ @handler.down( handler )
+ end
+ end
+
+ def notifyUp()
+ @status.set( $UP )
+ end
+
+ def notifyDown()
+ @status.set( $DOWN )
+ end
+
+ def waitUp( maxdelay )
+ @status.waitUntilEq( $UP, maxdelay )
+ end
+
+ def waitDown( maxdelay )
+ @status.waitUntilEq( $DOWN, maxdelay )
+ end
+
+ @status = Monitor.new( @status, $DOWN )
+ $DOWN = "down"
+ $UP = "up"
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,16 @@
+module DataHandler
+
+ #Interface used to deliver data from a stream source.
+ #
+ # Delivers data from a stream source.
+ # @param src
+ # @param sender
+ # @param buf
+ # @throws Exception
+ #
+
+ def data( src, sender, buf )
+ raise "subclass responsibility"
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,19 @@
+require 'etch/bindings/ruby/transport/source.rb'
+
+module DataSource
+ include Source
+
+ # Interface used to model a stream source to a data recipient, which
+ # allows the recipient to send data to the peer.
+ #
+ # Delivers data to the peer via the data stream.
+ # @param recipient
+ # @param buf
+ # @throws Exception
+ #
+ def data( recipient, buf )
+ raise "Subclass responsibility"
+ end
+
+end
+
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,3 @@
+module DataTypeValues
+ $INTEGER_MAX_VALUE = ( 1 << 31 ) - 1
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,47 @@
+ # $Id$
+ #
+ # Created by Champakesan, Badri Narayanan on Aug 13, 2007.
+ #
+ # Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
+
+require 'etch/bindings/ruby/transport/message'
+require 'etch/bindings/ruby/transport/stub_base'
+
+# Description of DefaultMessageHandler.
+# * @param <T> The type of the stub
+
+class DefaultMessageHandler < MessageHandler
+ #Constructs the DefaultMessageHandler.
+
+ def DefaultMessageHandler()
+ # nothing to do
+ end
+
+ def up( src )
+ Log.report( "messageHandlerUp", "who", this, "src", src )
+ stub = newStub( src )
+ return src
+ end
+
+ #@param src
+ # @return new stub
+
+ def newStub( src )
+ end
+
+ @Override
+ def toString()
+ end
+
+ #private T stub;
+
+ def message( src, sender, msg )
+ return stub.message( src, sender, msg )
+ end
+
+ def down( src )
+ Log.report( "messageHandlerDown", "who", this, "src", src )
+ stub.message( src, null, null )
+ stub = null
+ end
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,14 @@
+def callBlock
+ yield
+ yield
+end
+
+callBlock { puts "Hai Badri" }
+
+a = %w( Badri Narayanan Champakesan )
+a.each { | name | print name, " " }
+
+line = gets
+#print line
+puts line
+print
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"