Class: NWRFC::Function
- Inherits:
-
Object
- Object
- NWRFC::Function
- Defined in:
- lib/nwrfc.rb
Overview
Represents a remote-enabled function module for RFC, can be instantiated either by the caller or by calling Connection#get_function. This only represents the description of the function; to call a function, an instance of a function call must be obtained with #get_function_call
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#function_name ⇒ Object
readonly
Returns the value of attribute function_name.
Instance Method Summary collapse
-
#add_parameter(parameter) ⇒ Object
Add a parameter to a function module.
-
#get_function_call ⇒ Object
Create and return a callable instance of this function module.
-
#initialize(*args) ⇒ Function
constructor
Get a function module instance; can also be obtained by calling Connection#get_function Takes either: (connection, function_name) or (function_name) When passed only ‘function_name`, creates a new function description locally, instead of fetching it form the server pointed to by connection.
-
#parameter_count ⇒ Object
Get the number of parameters this function has.
-
#parameters ⇒ Object
Return the description of parameters associated with this Function.
Constructor Details
#new(connection, function_name) ⇒ Function #new(function_name) ⇒ Function
Get a function module instance; can also be obtained by calling Connection#get_function Takes either: (connection, function_name) or (function_name) When passed only ‘function_name`, creates a new function description locally, instead of fetching it form the server pointed to by connection
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/nwrfc.rb', line 219 def initialize(*args)#(connection, function_name) raise("Must initialize function with 1 or 2 arguments") if args.size != 1 && args.size != 2 @error = NWRFCLib::RFCError.new if args.size == 2 @function_name = args[1] #function_name @desc = NWRFCLib.get_function_desc(args[0].handle, args[1].cU, @error.to_ptr) NWRFC.check_error(@error) @connection = args[0] else @function_name = args[0] #function_name @desc = NWRFCLib::create_function_desc(args[0].cU, @error) NWRFC.check_error(@error) @connection = nil end end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
204 205 206 |
# File 'lib/nwrfc.rb', line 204 def connection @connection end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
203 204 205 |
# File 'lib/nwrfc.rb', line 203 def desc @desc end |
#function_name ⇒ Object (readonly)
Returns the value of attribute function_name.
203 204 205 |
# File 'lib/nwrfc.rb', line 203 def function_name @function_name end |
Instance Method Details
#add_parameter(parameter) ⇒ Object
Add a parameter to a function module. Ideally to be used in the case where a function definition is built up in the client code, rather than fetching it from the server for a remote call
238 239 240 241 |
# File 'lib/nwrfc.rb', line 238 def add_parameter(parameter) rc = NWRFCLib.add_parameter(@desc, parameter.handle, @error) NWRFC.check_error(@error) if rc > 0 end |
#get_function_call ⇒ Object
Create and return a callable instance of this function module
244 245 246 |
# File 'lib/nwrfc.rb', line 244 def get_function_call FunctionCall.new(self) end |
#parameter_count ⇒ Object
Get the number of parameters this function has
249 250 251 252 253 254 |
# File 'lib/nwrfc.rb', line 249 def parameter_count pcount = FFI::MemoryPointer.new(:uint) rc = NWRFCLib.get_parameter_count(@desc, pcount, @error) NWRFC.check_error(@error) if rc > 0 pcount.read_uint end |
#parameters ⇒ Object
Return the description of parameters associated with this Function
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/nwrfc.rb', line 257 def parameters parameter_count.times.inject({}) do |params, index| param = NWRFCLib::RFCFuncParam.new NWRFCLib.get_parameter_desc_by_index(@desc, index, param.to_ptr, @error.to_ptr) params[param[:name].get_str] = { :type => NWRFCLib::RFC_TYPE[param[:type]], :direction => NWRFCLib::RFC_DIRECTION[param[:direction]], :nucLength => param[:nucLength], :ucLength => param[:ucLength], :decimals => param[:decimals], :typeDescHandle => param[:typeDescHandle], :defaultValue => param[:defaultValue].get_str, :parameterText => param[:parameterText].get_str, :optional => param[:optional] } params end end |