Class: RRT_RUBY::RRTFinder
- Inherits:
-
Object
- Object
- RRT_RUBY::RRTFinder
- Includes:
- Finder, RivaLib::RivaLogger
- Defined in:
- lib/rrt_ruby.rb
Overview
RRTFinder provides the primary interface for read-only access of RRT models using OLE Automation.
It will create an OLE instance of RRT on initialization.
In order to properly release this instance RRTFinder#stop must be called prior to exiting the Ruby application.
Alternatively RRTFinder#open can be used with a block.
RRT under Windows XP (not tested on other versions) only allows three instances. Unfortunately, once an OLE Automation instance is accessed, references prevent the instances from being destroyed even after stopping RRTFinder.
This effectively limits the number of possible RRTFinder instances per application to three.
Notice that you still need to call stop or use open with a block otherwise the RRT application will remain in memory after termination of the Ruby application.
See the Finder module for a description of the actual read interface.
Direct Known Subclasses
Constant Summary
Constants included from Finder
Finder::TYPE_CAPSULE, Finder::TYPE_CLASS, Finder::TYPE_COMPONENT_PACKAGE, Finder::TYPE_DEPLOYMENT_PACKAGE, Finder::TYPE_LOGICAL_PACKAGE, Finder::TYPE_PROTOCOL
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#modelname ⇒ Object
readonly
Returns the value of attribute modelname.
Attributes included from RivaLib::RivaLogger
Class Method Summary collapse
-
.open(modelname, logger = nil) ⇒ Object
open is used in conjuction with a block.
Instance Method Summary collapse
-
#hide ⇒ Object
Hides the RRT UI for the associated OLE instance.
-
#initialize(modelname = "", logger = nil) ⇒ RRTFinder
constructor
Initialize will throw an exception if the model cannot be opened.
-
#name ⇒ Object
Returns the name of the model with which the RRTFinder is connected.
-
#reload(modelname) ⇒ Object
Instructs the RRTFinder to load a new model into it’s associated RRT instance.
-
#show ⇒ Object
Shows the RRT UI for the associated OLE instance Makes the RRT UI associated with the RRTFinder visible.
-
#stop ⇒ Object
Stops the RRTFinder releasing the OLE interface and invalidating this RRTFinder instance.
- #to_s ⇒ Object
Methods included from Finder
#component_names, #components, #executables, #external_libraries, #find_capsule, #find_class, #find_component_package, #find_deployment_package, #find_logical_package, #libraries, #ole_element, #processors, #root_component_package, #root_deployment_package, #root_logical_package
Methods included from RivaLib::RivaLogger
Constructor Details
#initialize(modelname = "", logger = nil) ⇒ RRTFinder
Initialize will throw an exception if the model cannot be opened.
RRTFinder uses Logger to log on STDOUT. Optionally you can pass a Logger instance and it will be used.
84 85 86 87 88 89 90 91 92 |
# File 'lib/rrt_ruby.rb', line 84 def initialize modelname="",logger=nil logger_init(logger) @modelname=modelname @logger.debug("Opening model #{@modelname}") @app=WIN32OLE.new(OLEAPP_NAME) @model=@app.OpenModel(@modelname) unless modelname.empty? @model=@app.CurrentModel if modelname.empty? raise FinderException.new(@modelname),"Model not loaded" unless @model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
79 80 81 |
# File 'lib/rrt_ruby.rb', line 79 def model @model end |
#modelname ⇒ Object (readonly)
Returns the value of attribute modelname.
79 80 81 |
# File 'lib/rrt_ruby.rb', line 79 def modelname @modelname end |
Class Method Details
.open(modelname, logger = nil) ⇒ Object
open is used in conjuction with a block.
It creates a RRTFinder instance and passes it to the block. At the end of the block the RRTFinder is stopped and invalidated.
You can optionally pass a Logger instance to be used by the RRTFinder.
Without a block the method is just an alias for RRTFinder#new
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rrt_ruby.rb', line 102 def self.open modelname,logger=nil #:yields: self begin fndr=self.new(modelname,logger) if block_given? begin yield fndr ensure fndr.stop end else return fndr end end end |
Instance Method Details
#hide ⇒ Object
Hides the RRT UI for the associated OLE instance.
Throws a FinderException if no instance exists
157 158 159 160 |
# File 'lib/rrt_ruby.rb', line 157 def hide raise FinderException.new(@modelname),"This Finder instance is invalid" unless @app @app.visible=false end |
#name ⇒ Object
Returns the name of the model with which the RRTFinder is connected
Alias for Finder#modelname
164 165 166 |
# File 'lib/rrt_ruby.rb', line 164 def name return @modelname end |
#reload(modelname) ⇒ Object
Instructs the RRTFinder to load a new model into it’s associated RRT instance.
If modelname matches the current modelname or the RRTFinder is invalid…well, nothing will happen.
119 120 121 122 123 124 125 126 |
# File 'lib/rrt_ruby.rb', line 119 def reload modelname begin @modelname=modelname @model=@app.openmodel(@modelname) raise FinderException.new(@modelname),"Model not loaded" unless @model raise FinderException.new(@modelname),"Model not loaded" unless @model.GetFileName.upcase==modelname.upcase end if @app && @app.CurrentModel.GetFileName.upcase!=modelname.upcase end |
#show ⇒ Object
Shows the RRT UI for the associated OLE instance Makes the RRT UI associated with the RRTFinder visible.
Throws a FinderException if no instance exists
150 151 152 153 |
# File 'lib/rrt_ruby.rb', line 150 def show raise FinderException.new(@modelname),"This Finder instance is invalid" unless @app @app.visible=true end |
#stop ⇒ Object
Stops the RRTFinder releasing the OLE interface and invalidating this RRTFinder instance.
This method must be called to clean up resources unless you used RRTFinder#open with a block.
If you don’t call this method you will end up with a zombie RoseRT instance and a couple of MBs less memory.
After calling stop the RRTFinder instance cannot be used again (most methods throw a FinderException).
Unfortunately, there is no control on when the RRT instance is going to exit.
Usually RRT instances that have been accessed will not exit until the application/script ends. Since RRT only allows three running instances, this means you can only reload a stopped finder twice.
139 140 141 142 143 144 145 |
# File 'lib/rrt_ruby.rb', line 139 def stop @logger.debug("Stopping Finder") @app.exit if @app @app.ole_free() @model=nil @app=nil end |
#to_s ⇒ Object
167 168 169 170 |
# File 'lib/rrt_ruby.rb', line 167 def to_s return "Active on #{@modelname}" if @model return "Invalid for #{@modelname}" end |