#
# Autogenerated by Thrift Compiler (0.9.2)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

require 'thrift'
require 'calculator_service_types'

module CalculatorService
  class Client
    include ::Thrift::Client

    def say_hello(name)
      send_say_hello(name)
      return recv_say_hello()
    end

    def send_say_hello(name)
      send_message('say_hello', Say_hello_args, :name => name)
    end

    def recv_say_hello()
      result = receive_message(Say_hello_result)
      return result.success unless result.success.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'say_hello failed: unknown result')
    end

    def add(value1, value2)
      send_add(value1, value2)
      return recv_add()
    end

    def send_add(value1, value2)
      send_message('add', Add_args, :value1 => value1, :value2 => value2)
    end

    def recv_add()
      result = receive_message(Add_result)
      return result.success unless result.success.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'add failed: unknown result')
    end

    def divide(dividend, divisor)
      send_divide(dividend, divisor)
      return recv_divide()
    end

    def send_divide(dividend, divisor)
      send_message('divide', Divide_args, :dividend => dividend, :divisor => divisor)
    end

    def recv_divide()
      result = receive_message(Divide_result)
      return result.success unless result.success.nil?
      raise result.ex unless result.ex.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'divide failed: unknown result')
    end

    def ping()
      send_ping()
      recv_ping()
    end

    def send_ping()
      send_message('ping', Ping_args)
    end

    def recv_ping()
      result = receive_message(Ping_result)
      return
    end

    def dwarves()
      send_dwarves()
      return recv_dwarves()
    end

    def send_dwarves()
      send_message('dwarves', Dwarves_args)
    end

    def recv_dwarves()
      result = receive_message(Dwarves_result)
      return result.success unless result.success.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'dwarves failed: unknown result')
    end

    def my_pets()
      send_my_pets()
      return recv_my_pets()
    end

    def send_my_pets()
      send_message('my_pets', My_pets_args)
    end

    def recv_my_pets()
      result = receive_message(My_pets_result)
      return result.success unless result.success.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'my_pets failed: unknown result')
    end

    def age(age_min, age_max)
      send_age(age_min, age_max)
      return recv_age()
    end

    def send_age(age_min, age_max)
      send_message('age', Age_args, :age_min => age_min, :age_max => age_max)
    end

    def recv_age()
      result = receive_message(Age_result)
      return result.success unless result.success.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'age failed: unknown result')
    end

    def snooze(sleep_time)
      send_snooze(sleep_time)
      recv_snooze()
    end

    def send_snooze(sleep_time)
      send_message('snooze', Snooze_args, :sleep_time => sleep_time)
    end

    def recv_snooze()
      result = receive_message(Snooze_result)
      return
    end

  end

  class Processor
    include ::Thrift::Processor

    def process_say_hello(seqid, iprot, oprot)
      args = read_args(iprot, Say_hello_args)
      result = Say_hello_result.new()
      result.success = @handler.say_hello(args.name)
      write_result(result, oprot, 'say_hello', seqid)
    end

    def process_add(seqid, iprot, oprot)
      args = read_args(iprot, Add_args)
      result = Add_result.new()
      result.success = @handler.add(args.value1, args.value2)
      write_result(result, oprot, 'add', seqid)
    end

    def process_divide(seqid, iprot, oprot)
      args = read_args(iprot, Divide_args)
      result = Divide_result.new()
      begin
        result.success = @handler.divide(args.dividend, args.divisor)
      rescue ::DivideByZeroException => ex
        result.ex = ex
      end
      write_result(result, oprot, 'divide', seqid)
    end

    def process_ping(seqid, iprot, oprot)
      args = read_args(iprot, Ping_args)
      result = Ping_result.new()
      @handler.ping()
      write_result(result, oprot, 'ping', seqid)
    end

    def process_dwarves(seqid, iprot, oprot)
      args = read_args(iprot, Dwarves_args)
      result = Dwarves_result.new()
      result.success = @handler.dwarves()
      write_result(result, oprot, 'dwarves', seqid)
    end

    def process_my_pets(seqid, iprot, oprot)
      args = read_args(iprot, My_pets_args)
      result = My_pets_result.new()
      result.success = @handler.my_pets()
      write_result(result, oprot, 'my_pets', seqid)
    end

    def process_age(seqid, iprot, oprot)
      args = read_args(iprot, Age_args)
      result = Age_result.new()
      result.success = @handler.age(args.age_min, args.age_max)
      write_result(result, oprot, 'age', seqid)
    end

    def process_snooze(seqid, iprot, oprot)
      args = read_args(iprot, Snooze_args)
      result = Snooze_result.new()
      @handler.snooze(args.sleep_time)
      write_result(result, oprot, 'snooze', seqid)
    end

  end

  # HELPER FUNCTIONS AND STRUCTURES

  class Say_hello_args
    include ::Thrift::Struct, ::Thrift::Struct_Union
    NAME = 1

    FIELDS = {
      NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Say_hello_result
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SUCCESS = 0

    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Add_args
    include ::Thrift::Struct, ::Thrift::Struct_Union
    VALUE1 = 1
    VALUE2 = 2

    FIELDS = {
      VALUE1 => {:type => ::Thrift::Types::I32, :name => 'value1'},
      VALUE2 => {:type => ::Thrift::Types::I32, :name => 'value2'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Add_result
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SUCCESS = 0

    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Divide_args
    include ::Thrift::Struct, ::Thrift::Struct_Union
    DIVIDEND = 1
    DIVISOR = 2

    FIELDS = {
      DIVIDEND => {:type => ::Thrift::Types::I32, :name => 'dividend'},
      DIVISOR => {:type => ::Thrift::Types::I32, :name => 'divisor'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Divide_result
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SUCCESS = 0
    EX = 1

    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::DOUBLE, :name => 'success'},
      EX => {:type => ::Thrift::Types::STRUCT, :name => 'ex', :class => ::DivideByZeroException}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Ping_args
    include ::Thrift::Struct, ::Thrift::Struct_Union

    FIELDS = {

    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Ping_result
    include ::Thrift::Struct, ::Thrift::Struct_Union

    FIELDS = {

    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Dwarves_args
    include ::Thrift::Struct, ::Thrift::Struct_Union

    FIELDS = {

    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Dwarves_result
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SUCCESS = 0

    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRING}}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class My_pets_args
    include ::Thrift::Struct, ::Thrift::Struct_Union

    FIELDS = {

    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class My_pets_result
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SUCCESS = 0

    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::SET, :name => 'success', :element => {:type => ::Thrift::Types::STRUCT, :class => ::Pet}}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Age_args
    include ::Thrift::Struct, ::Thrift::Struct_Union
    AGE_MIN = 1
    AGE_MAX = 2

    FIELDS = {
      AGE_MIN => {:type => ::Thrift::Types::I32, :name => 'age_min'},
      AGE_MAX => {:type => ::Thrift::Types::I32, :name => 'age_max'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Age_result
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SUCCESS = 0

    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Snooze_args
    include ::Thrift::Struct, ::Thrift::Struct_Union
    SLEEP_TIME = -1

    FIELDS = {
      SLEEP_TIME => {:type => ::Thrift::Types::I32, :name => 'sleep_time'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

  class Snooze_result
    include ::Thrift::Struct, ::Thrift::Struct_Union

    FIELDS = {

    }

    def struct_fields; FIELDS; end

    def validate
    end

    ::Thrift::Struct.generate_accessors self
  end

end

