Module: Uno::Connector
- Defined in:
- lib/rubyuno/uno/connector.rb
Overview
Helps to connect to the office by RPC with UNO protocol.
These environmental variables should be set before to load ‘runo’ module. URE_BOOTSTRAP specifies to fundamental(rc|.ini) placed under
openoffice.org3/program directory.
LD_LIBRARY_PATH path to URE library and program directory of the office.
Defined Under Namespace
Classes: NoConnectionError
Constant Summary collapse
- PIPE_NAME_PREFIX =
"rubypipe_"
- @@sleep_time =
2.0
- @@retry =
5
Instance Attribute Summary collapse
-
#retry ⇒ Object
Returns the value of attribute retry.
-
#sleep_time ⇒ Object
Returns the value of attribute sleep_time.
Class Method Summary collapse
-
.bootstrap(options = {}) ⇒ Object
Read Professional UNO chapter of Developer’s Guide about UNO Remote protocol.
- .connect(url, resolver = nil) ⇒ Object
- .resolver_get ⇒ Object
- .url_construct(type = "socket", host = "127.0.0.1", port = 2083, pipe_name = nil, nodelay = false) ⇒ Object
Instance Attribute Details
#retry ⇒ Object
Returns the value of attribute retry.
43 44 45 |
# File 'lib/rubyuno/uno/connector.rb', line 43 def retry @retry end |
#sleep_time ⇒ Object
Returns the value of attribute sleep_time.
43 44 45 |
# File 'lib/rubyuno/uno/connector.rb', line 43 def sleep_time @sleep_time end |
Class Method Details
.bootstrap(options = {}) ⇒ Object
Read Professional UNO chapter of Developer’s Guide about UNO Remote protocol.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rubyuno/uno/connector.rb', line 47 def self.bootstrap( = {}) = { :office => 'soffice', :type => 'socket', :host => '127.0.0.1', :port => 2083, :nodelay => false }.merge() url, argument = self.url_construct([:type], [:host], [:port], [:pipe_name], [:nodelay]) r = self.resolver_get c = nil n = 0 begin c = self.connect(url, r) rescue Rubyuno::Com::Sun::Star::Uno::Exception => e raise e if e.instance_of?(Rubyuno::Com::Sun::Star::Connection::ConnectionSetupException) n += 1 (raise NoConnectionError,"") if n > @@retry if [:spawn_cmd] system [:spawn_cmd] else spawn(ENV, [:office], argument) end sleep(@@sleep_time) retry end return c end |
.connect(url, resolver = nil) ⇒ Object
84 85 86 87 |
# File 'lib/rubyuno/uno/connector.rb', line 84 def self.connect(url, resolver = nil) resolver = self.resolver_get unless resolver return resolver.resolve(url) end |
.resolver_get ⇒ Object
108 109 110 111 |
# File 'lib/rubyuno/uno/connector.rb', line 108 def self.resolver_get ctx = Rubyuno.get_component_context return ctx.getServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", ctx) end |
.url_construct(type = "socket", host = "127.0.0.1", port = 2083, pipe_name = nil, nodelay = false) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rubyuno/uno/connector.rb', line 89 def self.url_construct(type = "socket", host = "127.0.0.1", port = 2083, pipe_name = nil, nodelay = false) case type when "socket" part = "socket,host=#{host},port=#{port}," + "tcpNoDelay=#{nodelay ? 1 : 0};urp;" url = "uno:#{part}StarOffice.ComponentContext" argument = "-headless -nologo -nofirststartwizard -accept=#{part}StarOffice.ServiceManager" when "pipe" pipe_name = "#{PIPE_NAME_PREFIX}#{srand * 10000}" unless pipe_name part = "pipe,name=#{pipe_name};urp;" url = "uno:#{part}StarOffice.ServiceManager" argument = "-headless -nologo -nofirststartwizard -accept=#{part}StarOffice.ComponentContext" else raise ArgumentError, "Illegal connection type (#{type})" end return url, argument end |