Class: NWRFC::Connection

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

Overview

Represents a client 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', ... }


73
74
75
76
77
78
79
80
81
82
# 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

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



68
69
70
# File 'lib/nwrfc.rb', line 68

def handle
  @handle
end

Instance Method Details

#connection_infoHash

Return details about the current connection and the system

Returns:

  • (Hash)

    information about the current connection



101
102
103
104
105
106
107
108
109
110
# 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

#disconnectObject Also known as: close

TODO:

Write test to check that handle is invalidated and causes subsequent calls to fail

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



88
89
90
91
# File 'lib/nwrfc.rb', line 88

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

#get_function(function_name) ⇒ Function

Get the description of a given function module from the system to which we are connected

Returns:

  • (Function)

    function module description



95
96
97
# File 'lib/nwrfc.rb', line 95

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

#start_transaction(queue_name = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
# 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