Class: NWRFC::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/nwrfc.rb

Overview

Represents a connection to a SAP system that can be used to invoke remote-enabled functions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn_params) ⇒ Connection

Opens a connection to the SAP system with the given connection parameters (described in the NW RFC SDK document), passed in the form of a Hash, e.g.

Connection.new { 'ashost' :=> 'ajax.domain.com', ... }


54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nwrfc.rb', line 54

def initialize(conn_params)
  conn_params.untaint #For params loaded from file, e.g.
  raise "Connection parameters must be a Hash" unless conn_params.instance_of? Hash
  #NWRFCLib.init
  @cparams = NWRFCLib.make_conn_params(conn_params)
  raise "Could not create valid pointer from parameters" unless @cparams.instance_of? FFI::MemoryPointer
  #@errp = FFI::MemoryPointer.new(NWRFCLib::RFCError)
  @error =  NWRFCLib::RFCError.new #@errp
  @handle = NWRFCLib.open_connection(@cparams, conn_params.length, @error.to_ptr)
  NWRFC.check_error(@error)
  self
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



49
50
51
# File 'lib/nwrfc.rb', line 49

def handle
  @handle
end

Instance Method Details

#connection_infoObject

Return details about the current connection and the system



80
81
82
83
84
85
86
87
88
89
# File 'lib/nwrfc.rb', line 80

def connection_info
  return @get_connection_attributes if @get_connection_attributes
  conn_info = NWRFCLib::RFCConnection.new
  rc = NWRFCLib.get_connection_attributes(@handle, conn_info.to_ptr, @error)
  NWRFC.check_error(@error) if rc > 0
  @get_connection_attributes = conn_info.members.inject({}) {|hash, member|
    hash[member] = conn_info[member].get_str #get_str, own definition in nwrfclib.rb, FFI::StructLayout::CharArray#get_str
    hash
  }
end

#disconnectObject

Call the NW RFC SDK’s RfcCloseConnection() function with the current connection; this (should - TODO - check) invalidate the connection handle and cause an error on any subsequent use of this connection



70
71
72
73
# File 'lib/nwrfc.rb', line 70

def disconnect
  NWRFCLib.close_connection(@handle, @error.to_ptr)
  NWRFC.check_error(@error)
end

#get_function(function_name) ⇒ Object



75
76
77
# File 'lib/nwrfc.rb', line 75

def get_function(function_name)
  Function.new(self, function_name)
end