Class: SAPNW::RFC::Server

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Server

Returns a new instance of Server.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sapnwrfc/server.rb', line 61

def initialize(args = nil)
  @connection_parameters = []
  case args
  when nil
  when Hash
    args.each_pair { |key, val|
      @connection_parameters << { 'name' => key.to_s, 'value' => val.to_s }
    }
  else
    raise "Wrong parameters for Server Connection - must pass a Hash\n"
  end
  SAP_LOGGER.debug("In #{self.class} initialize: #{@connection_parameters.inspect} ...")
  @functions = {}
  @attributes = nil
  @handle = SAPNW::RFC::ServerHandle.new(self)
end

Instance Attribute Details

#connection_parametersObject (readonly)

Returns the value of attribute connection_parameters.



59
60
61
# File 'lib/sapnwrfc/server.rb', line 59

def connection_parameters
  @connection_parameters
end

#functionsObject (readonly)

Returns the value of attribute functions.



59
60
61
# File 'lib/sapnwrfc/server.rb', line 59

def functions
  @functions
end

#handleObject

Returns the value of attribute handle.



58
59
60
# File 'lib/sapnwrfc/server.rb', line 58

def handle
  @handle
end

Class Method Details

.handler(callback = nil, attributes = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/sapnwrfc/server.rb', line 100

def self.handler(callback=nil,attributes=nil)
  return if callback == nil
  begin
    return callback.call(attributes)
  rescue SAPNW::RFC::ServerException => e
    #$stderr.print "ServerException => #{e.error.inspect}\n"
    return e
  rescue StandardError => e
    #$stderr.print "StandardError => #{e.inspect}/#{e.message}\n"
    return SAPNW::RFC::ServerException.new({'code' => 3, 'key' => 'RUBY_RUNTIME', 'message' => e.message})
  end
end

Instance Method Details

#accept(wait = 120, callback = nil) ⇒ Object

fire the accept loop taking optionally a wait time for each loop, and a global callback to be triggered after each loop/loop timeout. Callback - if supplied - must be a Proc object, that takes a simgle parameter, which is a hash of the system connection attributes.



118
119
120
121
# File 'lib/sapnwrfc/server.rb', line 118

def accept(wait=120, callback=nil)
  trap('INT', 'EXIT')
  return @handle.accept_loop(wait, callback);
end

#closeObject

terminate an established RFC connection. This will invalidate any currently in-scope FunctionDescriptors associated with this Connection.



141
142
143
144
145
146
147
148
149
# File 'lib/sapnwrfc/server.rb', line 141

def close
  SAP_LOGGER.debug("In #{self.class} close ...")
  return nil unless self.handle
  SAP_LOGGER.debug("In #{self.class} handle: #{self.handle} ...")
  res = self.handle.close()
  self.handle = nil
  # XXX Should destroy all cached functions and structures and types tied to handle ?
  return true
end

#connection_attributesObject

Returns a Hash of the connections attributes of this server connection.



134
135
136
137
# File 'lib/sapnwrfc/server.rb', line 134

def connection_attributes
  SAP_LOGGER.debug("In #{self.class} connection_attributes ...")
  return @attributes = self.handle.connection_attributes()
end

#installFunction(*args) ⇒ Object

installs a SAPNW::RFC::FunctionDescriptor object, and optionally associates this with a particular SysId.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sapnwrfc/server.rb', line 80

def installFunction(*args)
  args = args.first if args.class == Array and args.first.class == Hash
  case args
  when Hash
    raise "Must pass an instance of SAPNW::RFC::FunctionDescriptor to installFunction()\n" unless args.has_key?(:descriptor) and args[:descriptor].class == SAPNW::RFC::FunctionDescriptor
    func = args[:descriptor]
    sysid = args.has_key?(:sysid) ? args[:sysid] : ""
  when Array
    raise "Must pass an instance of SAPNW::RFC::FunctionDescriptor to installFunction()\n" unless args.first.class == SAPNW::RFC::FunctionDescriptor
    func = args.first
    sysid = args.length > 1 ? args[1] : ""
  else
    raise "Must pass an instance of SAPNW::RFC::FunctionDescriptor to installFunction()\n"
  end
  #$stderr.print "sysid: #{sysid}\n"
  res = func.install(sysid)
  @functions[func.name] = func
  return res
end

#process(wait = 120) ⇒ Object

similar to the accept() loop only that it does a single RfcListenAndDispatch() on the SAPNW::RFC::Server connection handle. The result is the RFC return code as per the SAPNW::RFC::RFC_* return code constants. process() optionally takes asingle parameter which is the wait-time.



128
129
130
131
# File 'lib/sapnwrfc/server.rb', line 128

def process(wait=120)
  trap('INT', 'EXIT')
  return @handle.process_loop(wait);
end