class NWRFC::Connection
Represents a client connection to a SAP system that can be used to invoke remote-enabled functions
Attributes
handle[R]
Public Class Methods
new(conn_params)
click to toggle source
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', ... }
# File lib/nwrfc.rb, line 73 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 @cparams = NWRFC.make_conn_params(conn_params) raise "Could not create valid pointer from parameters" unless @cparams.instance_of? FFI::MemoryPointer @error = NWRFCLib::RFCError.new @handle = NWRFCLib.open_connection(@cparams, conn_params.length, @error.to_ptr) NWRFC.check_error(@error) self end
Public Instance Methods
connection_info()
click to toggle source
Return details about the current connection and the system @return [Hash] information about the current connection
# File lib/nwrfc.rb, line 101 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
disconnect()
click to toggle source
Call the NW RFC SDK's RfcCloseConnection() function with the current connection; this *should* invalidate the connection handle and cause an error on any subsequent use of this connection
@todo Write test to check that handle is invalidated and causes subsequent calls to fail
# File lib/nwrfc.rb, line 88 def disconnect NWRFCLib.close_connection(@handle, @error.to_ptr) NWRFC.check_error(@error) end
Also aliased as: close
get_function(function_name)
click to toggle source
Get the description of a given function module from the system to which we are connected @return [Function] function module description
# File lib/nwrfc.rb, line 95 def get_function(function_name) Function.new(self, function_name) end
start_transaction(queue_name = nil)
click to toggle source
# File lib/nwrfc.rb, line 114 def start_transaction(queue_name = nil) @tid = FFI::MemoryPointer.new(:char, 50) rc = NWRFCLib.get_transaction_id(@handle, @tid, @error) NWRFC.check_error(@error) if rc > 0 queue_name = FFI::MemoryPointer.from_string(queue_name.to_s.cU) if queue_name transaction_handle = NWRFCLib.create_transaction(@handle, @tid, queue_name, @error) NWRFC.check_error(@error) Transaction.new(transaction_handle) end