Class: NWRFC::Server
- Inherits:
-
Object
- Object
- NWRFC::Server
- Defined in:
- lib/nwrfc/server.rb
Overview
Implementation of a server to host RFC functions to be called from an ABAP system
Constant Summary collapse
- TIMEOUT =
0
Instance Method Summary collapse
-
#disconnect ⇒ Object
(also: #close)
Disconnect from the server.
-
#initialize(params) ⇒ Server
constructor
Register a server with the given gateway and program ID.
-
#serve(function, &block) ⇒ Object
Start serving an RFC function, given the definition and the block, to which the connection and functions are yielded.
Constructor Details
#initialize(params) ⇒ Server
Register a server with the given gateway and program ID
9 10 11 12 13 14 15 16 |
# File 'lib/nwrfc/server.rb', line 9 def initialize(params) raise "Rarameters must be a Hash" unless params.instance_of? Hash @rparams = NWRFC.make_conn_params(params) raise "Could not create valid pointer from parameters" unless @rparams.instance_of? FFI::MemoryPointer @error = NWRFCLib::RFCError.new @handle = NWRFCLib.register_server(@rparams, params.size, @error) NWRFC.check_error(@error) end |
Instance Method Details
#disconnect ⇒ Object Also known as: close
Disconnect from the server
37 38 39 40 |
# File 'lib/nwrfc/server.rb', line 37 def disconnect NWRFCLib.close_connection(@handle, @error) NWRFC.check_error(@error) end |
#serve(function, &block) ⇒ Object
Start serving an RFC function, given the definition and the block, to which the connection and functions are yielded
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nwrfc/server.rb', line 21 def serve(function, &block) # Establish callback handler callback = Proc.new do |connection, function_handle, error| function_call = FunctionCall.new(function_handle) yield(function_call) end rc = NWRFCLib.install_server_function(nil, function.desc, callback, @error) NWRFC.check_error(@error) if rc > 0 # Server loop while (rc==NWRFCLib::RFC_RC[:RFC_OK] || rc==NWRFCLib::RFC_RC[:RFC_RETRY] || rc==NWRFCLib::RFC_RC[:RFC_ABAP_EXCEPTION]) rc = NWRFCLib.listen_and_dispatch(@handle, TIMEOUT, @error) end end |