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
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/nwrfc.rb', line 188 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.
173 174 175 |
# File 'lib/nwrfc.rb', line 173 def connection @connection end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
172 173 174 |
# File 'lib/nwrfc.rb', line 172 def desc @desc end |
#function_name ⇒ Object (readonly)
Returns the value of attribute function_name.
172 173 174 |
# File 'lib/nwrfc.rb', line 172 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
207 208 209 210 |
# File 'lib/nwrfc.rb', line 207 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
213 214 215 |
# File 'lib/nwrfc.rb', line 213 def get_function_call FunctionCall.new(self) end |
#parameter_count ⇒ Object
Get the number of parameters this function has
218 219 220 221 222 223 |
# File 'lib/nwrfc.rb', line 218 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
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/nwrfc.rb', line 226 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 |