Class: NWRFC::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/nwrfc.rb,
lib/nwrfc.old.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', ... }


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

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

#errorObject (readonly)

Returns the value of attribute error.



139
140
141
# File 'lib/nwrfc.old.rb', line 139

def error
  @error
end

#handleObject (readonly)

Returns the value of attribute handle.



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

def handle
  @handle
end

Instance Method Details

#check_errorObject

Check the status of the error structure; raise an exception if it contains an error TODO - Raise a more meaningful error



184
185
186
# File 'lib/nwrfc.old.rb', line 184

def check_error
  raise "Error code #{@error[:code]} group #{@error[:group]}" if @error[:code] > 0
end

#connection_infoObject

Return details about the current connection and the system



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

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



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

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

#get_function(func_name) ⇒ Object



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

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