require 'romp'

class Bar
    attr_reader :i
    
    def initialize(i, romp)
        @i = i
        @romp = romp
    end
    
    def release()
        @romp.delete_reference(self)
    end
end

class Foo < Bar
    # Initialize @i to 0
    def initialize(romp)
        super(0, romp)
        @romp = romp
    end

    # Set @i
    def foo(i)
        @i = i
    end

    # Return a reference to a new Bar object with Bar.i = @i + 1
    def bar()
        b = Bar.new(@i + 1, @romp)
        obj = @romp.create_reference(b)
        return obj
    end

    # Test iteration
    def each()
        yield 1
        yield 2
        yield 3
    end

    def throw_exception2()
        raise RuntimeError
    end

    # Test exception
    def throw_exception()
        throw_exception2()
    end
end

# server = ROMP::Server.new('tcpromp://localhost:4242', nil, true)
# server = ROMP::Server.new('udpromp://localhost:4242', nil, true)
server = ROMP::Server.new('unixromp:///tmp/foo', nil, true)
f = Foo.new(server)
server.bind(f, "foo")
server.thread.join
