rubyuno 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/CHANGES +16 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README +46 -0
- data/Rakefile +603 -0
- data/ext/rubyuno/adapter.cxx +271 -0
- data/ext/rubyuno/extconf.rb +125 -0
- data/ext/rubyuno/libruno.def +26 -0
- data/ext/rubyuno/loader.cxx +184 -0
- data/ext/rubyuno/module.cxx +1263 -0
- data/ext/rubyuno/rubyuno.hxx +263 -0
- data/ext/rubyuno/runo.def +2 -0
- data/ext/rubyuno/runtime.cxx +524 -0
- data/ext/rubyuno/string.cxx +252 -0
- data/ext/rubyuno/type.cxx +358 -0
- data/lib/rubyloader.rb +302 -0
- data/lib/rubyscriptprovider.rb +1025 -0
- data/lib/rubyuno.rb +20 -0
- data/lib/rubyuno/uno.rb +105 -0
- data/lib/rubyuno/uno/connector.rb +97 -0
- data/lib/rubyuno/version.rb +3 -0
- data/rubyuno.gemspec +17 -0
- data/sample/calc-chart.rb +66 -0
- data/sample/dialog_listener.rb +70 -0
- data/sample/filter-names.rb +123 -0
- data/sample/inputbox.rb +74 -0
- data/sample/mri.rb +17 -0
- data/sample/open-doc1.rb +20 -0
- metadata +89 -0
@@ -0,0 +1,271 @@
|
|
1
|
+
|
2
|
+
#include "rubyuno.hxx"
|
3
|
+
|
4
|
+
#include <cppuhelper/typeprovider.hxx>
|
5
|
+
#include <rtl/ustrbuf.hxx>
|
6
|
+
|
7
|
+
#include <com/sun/star/beans/MethodConcept.hpp>
|
8
|
+
#include <com/sun/star/reflection/ParamMode.hpp>
|
9
|
+
#include <com/sun/star/uno/TypeClass.hpp>
|
10
|
+
#include <com/sun/star/beans/XMaterialHolder.hpp>
|
11
|
+
#include <com/sun/star/beans/XIntrospectionAccess.hpp>
|
12
|
+
|
13
|
+
using com::sun::star::beans::UnknownPropertyException;
|
14
|
+
using com::sun::star::beans::XIntrospectionAccess;
|
15
|
+
using com::sun::star::beans::XMaterialHolder;
|
16
|
+
using com::sun::star::lang::IllegalArgumentException;
|
17
|
+
using com::sun::star::reflection::InvocationTargetException;
|
18
|
+
using com::sun::star::script::CannotConvertException;
|
19
|
+
using com::sun::star::uno::Any;
|
20
|
+
using com::sun::star::uno::RuntimeException;
|
21
|
+
using com::sun::star::uno::Sequence;
|
22
|
+
using com::sun::star::uno::Type;
|
23
|
+
|
24
|
+
using rtl::OUString;
|
25
|
+
using rtl::OUStringBuffer;
|
26
|
+
using namespace com::sun::star::uno;
|
27
|
+
using namespace com::sun::star::reflection;
|
28
|
+
|
29
|
+
namespace rubyuno
|
30
|
+
{
|
31
|
+
|
32
|
+
ID
|
33
|
+
oustring2ID(const OUString &aName)
|
34
|
+
{
|
35
|
+
return rb_intern(OUStringToOString(aName, RTL_TEXTENCODING_ASCII_US).getStr());
|
36
|
+
}
|
37
|
+
|
38
|
+
Adapter::Adapter(const VALUE &obj, const Sequence< Type > &types)
|
39
|
+
: m_wrapped(obj),
|
40
|
+
m_types(types)
|
41
|
+
{
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE
|
45
|
+
Adapter::getWrapped()
|
46
|
+
{
|
47
|
+
return m_wrapped;
|
48
|
+
}
|
49
|
+
|
50
|
+
Sequence< Type >
|
51
|
+
Adapter::getWrappedTypes()
|
52
|
+
{
|
53
|
+
return m_types;
|
54
|
+
}
|
55
|
+
|
56
|
+
Adapter::~Adapter()
|
57
|
+
{
|
58
|
+
// Adapter is deleted by the adapter factory.
|
59
|
+
// remove from adapterMap
|
60
|
+
Runtime runtime;
|
61
|
+
runtime.getImpl()->adapterMap.erase(m_wrapped);
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
void
|
66
|
+
raiseUnoException(VALUE arg)
|
67
|
+
throw (InvocationTargetException)
|
68
|
+
{
|
69
|
+
VALUE exc = rb_gv_get("$!");
|
70
|
+
|
71
|
+
if (rb_obj_is_kind_of(exc, get_exception_class()))
|
72
|
+
{
|
73
|
+
Any a;
|
74
|
+
RubyunoInternal *rubyuno;
|
75
|
+
Data_Get_Struct(exc, RubyunoInternal, rubyuno);
|
76
|
+
Reference < XMaterialHolder > xHolder(rubyuno->invocation, UNO_QUERY);
|
77
|
+
if (xHolder.is())
|
78
|
+
throw xHolder->getMaterial().getValue();
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
VALUE
|
83
|
+
call_apply(VALUE argv)
|
84
|
+
{
|
85
|
+
return rb_apply(rb_ary_entry(argv, 0), rb_intern_str(rb_ary_entry(argv, 1)), rb_ary_entry(argv, 2));
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
Sequence< sal_Int16 >
|
90
|
+
Adapter::getOutParamIndexes(const OUString &methodName)
|
91
|
+
{
|
92
|
+
Sequence< sal_Int16 > ret;
|
93
|
+
|
94
|
+
Runtime runtime;
|
95
|
+
Reference< XInterface > adapter = runtime.getImpl()->xAdapterFactory->createAdapter(this, m_types);
|
96
|
+
Reference< XIntrospectionAccess > introspection = runtime.getImpl()->xIntrospection->inspect(makeAny(adapter));
|
97
|
+
|
98
|
+
if (! introspection.is())
|
99
|
+
{
|
100
|
+
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("rubyuno: failed to create adapter.")), Reference< XInterface >());
|
101
|
+
}
|
102
|
+
Reference< XIdlMethod > method = introspection->getMethod(methodName, com::sun::star::beans::MethodConcept::ALL);
|
103
|
+
if (! method.is())
|
104
|
+
{
|
105
|
+
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("rubyuno: Failed to get reflection for ")) + methodName, Reference< XInterface >());
|
106
|
+
}
|
107
|
+
Sequence< ParamInfo > info = method->getParameterInfos();
|
108
|
+
|
109
|
+
int out = 0;
|
110
|
+
int i = 0;
|
111
|
+
for (i = 0; i < info.getLength(); i++)
|
112
|
+
{
|
113
|
+
if (info[i].aMode == ParamMode_OUT ||
|
114
|
+
info[i].aMode == ParamMode_INOUT)
|
115
|
+
out++;
|
116
|
+
}
|
117
|
+
if (out)
|
118
|
+
{
|
119
|
+
sal_Int16 j = 0;
|
120
|
+
ret.realloc(out);
|
121
|
+
for (i = 0; i < info.getLength(); i++)
|
122
|
+
{
|
123
|
+
if (info[i].aMode == ParamMode_OUT ||
|
124
|
+
info[i].aMode == ParamMode_INOUT)
|
125
|
+
{
|
126
|
+
ret[j] = i;
|
127
|
+
j++;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return ret;
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
Reference< XIntrospectionAccess >
|
136
|
+
Adapter::getIntrospection()
|
137
|
+
throw (RuntimeException)
|
138
|
+
{
|
139
|
+
return Reference< XIntrospectionAccess >();
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
Any
|
144
|
+
Adapter::invoke(const OUString & aFunctionName, const Sequence < Any > &aParams, Sequence < sal_Int16 > &aOutParamIndex, Sequence < Any > &aOutParam)
|
145
|
+
throw (IllegalArgumentException, CannotConvertException,
|
146
|
+
InvocationTargetException, RuntimeException)
|
147
|
+
{
|
148
|
+
if (aParams.getLength() == 1 && aFunctionName.compareToAscii("getSomething") == 0)
|
149
|
+
{
|
150
|
+
Sequence < sal_Int8 > id;
|
151
|
+
if (aParams[0] >>= id)
|
152
|
+
return makeAny(getSomething(id));
|
153
|
+
}
|
154
|
+
|
155
|
+
Any retAny;
|
156
|
+
try
|
157
|
+
{
|
158
|
+
Runtime runtime;
|
159
|
+
VALUE args = rb_ary_new2(aParams.getLength());
|
160
|
+
for (int i = 0; i < aParams.getLength(); i++)
|
161
|
+
{
|
162
|
+
rb_ary_push(args, runtime.any_to_VALUE(aParams[i]));
|
163
|
+
}
|
164
|
+
|
165
|
+
VALUE argv = rb_ary_new2(3);
|
166
|
+
rb_ary_push(argv, m_wrapped);
|
167
|
+
rb_ary_push(argv, ustring2RString(aFunctionName));
|
168
|
+
rb_ary_push(argv, args);
|
169
|
+
VALUE ret = rb_rescue((VALUE(*)(...))call_apply, argv, (VALUE(*)(...))raiseUnoException, 0);
|
170
|
+
|
171
|
+
//ID id = oustring2ID(aFunctionName);
|
172
|
+
//VALUE ret = rb_apply(m_wrapped, id, args);
|
173
|
+
Any retAny = runtime.value_to_any(ret);
|
174
|
+
|
175
|
+
if (retAny.getValueTypeClass() == com::sun::star::uno::TypeClass_SEQUENCE &&
|
176
|
+
aFunctionName.compareToAscii("getTypes") != 0 &&
|
177
|
+
aFunctionName.compareToAscii("getImplementationId"))
|
178
|
+
{
|
179
|
+
aOutParamIndex = getOutParamIndexes(aFunctionName);
|
180
|
+
if (aOutParamIndex.getLength())
|
181
|
+
{
|
182
|
+
Sequence< Any > seq;
|
183
|
+
if (! (retAny >>= seq))
|
184
|
+
{
|
185
|
+
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("rubyuno: failed to extract out values for method ")) + aFunctionName, Reference< XInterface >());
|
186
|
+
}
|
187
|
+
|
188
|
+
if (! (seq.getLength() == aOutParamIndex.getLength() + 1))
|
189
|
+
{
|
190
|
+
throw RuntimeException(OUString( RTL_CONSTASCII_USTRINGPARAM("rubyuno: illegal number of out values for method ")) + aFunctionName, Reference< XInterface >());
|
191
|
+
}
|
192
|
+
|
193
|
+
aOutParam.realloc(aOutParamIndex.getLength());
|
194
|
+
retAny = seq[0];
|
195
|
+
for (int i = 0; i < aOutParamIndex.getLength(); i++)
|
196
|
+
{
|
197
|
+
aOutParam[i] = seq[i + 1];
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
catch (RuntimeException &e)
|
203
|
+
{
|
204
|
+
printf("%s\n", OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
|
205
|
+
}
|
206
|
+
return retAny;
|
207
|
+
}
|
208
|
+
|
209
|
+
void
|
210
|
+
Adapter::setValue(const OUString &aPropertyName, const Any &aValue)
|
211
|
+
throw (UnknownPropertyException, CannotConvertException,
|
212
|
+
InvocationTargetException, RuntimeException)
|
213
|
+
{
|
214
|
+
Runtime runtime;
|
215
|
+
OUStringBuffer buf(aPropertyName);
|
216
|
+
buf.appendAscii("=");
|
217
|
+
rb_funcall(m_wrapped, oustring2ID(buf.makeStringAndClear()), 1, runtime.any_to_VALUE(aValue));
|
218
|
+
}
|
219
|
+
|
220
|
+
Any
|
221
|
+
Adapter::getValue(const OUString &aPropertyName)
|
222
|
+
throw (UnknownPropertyException, RuntimeException)
|
223
|
+
{
|
224
|
+
Runtime runtime;
|
225
|
+
return runtime.value_to_any(rb_funcall(m_wrapped, oustring2ID(aPropertyName), 0));
|
226
|
+
}
|
227
|
+
|
228
|
+
sal_Bool
|
229
|
+
Adapter::hasMethod(const OUString &aName)
|
230
|
+
throw (RuntimeException)
|
231
|
+
{
|
232
|
+
if (rb_respond_to(m_wrapped, oustring2ID(aName)))
|
233
|
+
return sal_True;
|
234
|
+
return sal_False;
|
235
|
+
}
|
236
|
+
|
237
|
+
sal_Bool
|
238
|
+
Adapter::hasProperty(const OUString &aName)
|
239
|
+
throw (RuntimeException)
|
240
|
+
{
|
241
|
+
if (rb_respond_to(m_wrapped, oustring2ID(aName)))
|
242
|
+
return sal_True;
|
243
|
+
else
|
244
|
+
{
|
245
|
+
OUStringBuffer buf(aName);
|
246
|
+
buf.appendAscii("=");
|
247
|
+
if (rb_respond_to(m_wrapped, oustring2ID(buf.makeStringAndClear())))
|
248
|
+
return sal_True;
|
249
|
+
}
|
250
|
+
return sal_False;
|
251
|
+
}
|
252
|
+
|
253
|
+
static cppu::OImplementationId g_Id(sal_False);
|
254
|
+
|
255
|
+
Sequence < sal_Int8 >
|
256
|
+
Adapter::getTunnelImplId()
|
257
|
+
{
|
258
|
+
return g_Id.getImplementationId();
|
259
|
+
}
|
260
|
+
|
261
|
+
sal_Int64
|
262
|
+
Adapter::getSomething(const Sequence < sal_Int8 > &aIdentifier)
|
263
|
+
throw (RuntimeException)
|
264
|
+
{
|
265
|
+
if (aIdentifier == g_Id.getImplementationId())
|
266
|
+
return reinterpret_cast< sal_Int64 >(this);
|
267
|
+
return 0;
|
268
|
+
}
|
269
|
+
|
270
|
+
}
|
271
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
# IDL Headers
|
5
|
+
IDL_TYPES = [
|
6
|
+
"com.sun.star.beans.MethodConcept",
|
7
|
+
"com.sun.star.beans.PropertyAttribute",
|
8
|
+
"com.sun.star.beans.XIntrospection",
|
9
|
+
"com.sun.star.beans.XIntrospectionAccess",
|
10
|
+
"com.sun.star.beans.XMaterialHolder",
|
11
|
+
"com.sun.star.container.XEnumerationAccess",
|
12
|
+
"com.sun.star.container.XHierarchicalNameAccess",
|
13
|
+
"com.sun.star.container.XIndexContainer",
|
14
|
+
"com.sun.star.container.XNameContainer",
|
15
|
+
"com.sun.star.lang.XMultiServiceFactory",
|
16
|
+
"com.sun.star.lang.XServiceInfo",
|
17
|
+
"com.sun.star.lang.XSingleComponentFactory",
|
18
|
+
"com.sun.star.lang.XSingleServiceFactory",
|
19
|
+
"com.sun.star.lang.XTypeProvider",
|
20
|
+
"com.sun.star.lang.XUnoTunnel",
|
21
|
+
"com.sun.star.reflection.InvocationTargetException",
|
22
|
+
"com.sun.star.reflection.ParamMode",
|
23
|
+
"com.sun.star.reflection.XConstantTypeDescription",
|
24
|
+
"com.sun.star.reflection.XConstantsTypeDescription",
|
25
|
+
"com.sun.star.reflection.XEnumTypeDescription",
|
26
|
+
"com.sun.star.reflection.XIdlReflection",
|
27
|
+
"com.sun.star.reflection.XInterfaceTypeDescription2",
|
28
|
+
"com.sun.star.reflection.XTypeDescription",
|
29
|
+
"com.sun.star.registry.XRegistryKey",
|
30
|
+
"com.sun.star.script.InvocationInfo",
|
31
|
+
"com.sun.star.script.MemberType",
|
32
|
+
"com.sun.star.script.XInvocation2",
|
33
|
+
"com.sun.star.script.XInvocationAdapterFactory2",
|
34
|
+
"com.sun.star.script.XTypeConverter",
|
35
|
+
"com.sun.star.script.provider.ScriptFrameworkErrorException",
|
36
|
+
"com.sun.star.uno.XAggregation",
|
37
|
+
"com.sun.star.uno.TypeClass",
|
38
|
+
"com.sun.star.uno.XComponentContext",
|
39
|
+
"com.sun.star.uno.XWeak",
|
40
|
+
]
|
41
|
+
|
42
|
+
CPPU_INCLUDE = './include'
|
43
|
+
CPPUMAKER = 'cppumaker'
|
44
|
+
CPPUMAKER_FLAG = "#{CPPU_INCLUDE}/flag"
|
45
|
+
SETSDKENV = 'setsdkenv_unix'
|
46
|
+
|
47
|
+
def missing(item)
|
48
|
+
die "couldn't find #{item} (required)"
|
49
|
+
end
|
50
|
+
|
51
|
+
def die(msg)
|
52
|
+
puts msg
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_environment(var)
|
57
|
+
checking_for checking_message(var, "environment") do
|
58
|
+
!ENV[var].nil?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
c = RbConfig::CONFIG
|
63
|
+
host = c['host']
|
64
|
+
|
65
|
+
missing(CPPUMAKER) unless find_executable(CPPUMAKER)
|
66
|
+
setsdkenv_path = checking_for checking_message(SETSDKENV) do
|
67
|
+
`find / -name #{SETSDKENV} &2>/dev/null`.chomp
|
68
|
+
end
|
69
|
+
missing(SETSDKENV) unless setsdkenv_path
|
70
|
+
|
71
|
+
# Collected needed environment variables
|
72
|
+
sdk_home = ENV['OO_SDK_HOME']
|
73
|
+
ure_home = ENV['OO_SDK_URE_HOME']
|
74
|
+
base_path = ENV['OFFICE_BASE_PROGRAM_PATH']
|
75
|
+
environment_ready = true
|
76
|
+
%w(OO_SDK_HOME OO_SDK_URE_HOME OFFICE_BASE_PROGRAM_PATH).each do |env|
|
77
|
+
#environment_ready &&= find_environment(env)
|
78
|
+
res = find_environment(env)
|
79
|
+
environment_ready &&= res
|
80
|
+
end
|
81
|
+
|
82
|
+
unless environment_ready
|
83
|
+
message "collecting ENV values:\n"
|
84
|
+
IO.popen("#{setsdkenv_path} >/dev/null", "w") {} # Ensure the SDK is set up
|
85
|
+
res = Open3.popen3("/opt/openoffice.org/basis3.4/sdk/setsdkenv_unix") do |i, o, e|
|
86
|
+
i.puts "echo $OO_SDK_HOME"
|
87
|
+
i.puts "echo $OO_SDK_URE_HOME"
|
88
|
+
i.puts "echo $OFFICE_BASE_PROGRAM_PATH"
|
89
|
+
i.close_write
|
90
|
+
o.readlines
|
91
|
+
end
|
92
|
+
sdk_home, ure_home, base_path = res[-5..-2].map(&:chomp)
|
93
|
+
message "$OO_SDK_HOME=#{sdk_home}\n"
|
94
|
+
message "$OO_SDK_URE_HOME=#{ure_home}\n"
|
95
|
+
message "$OFFICE_BASE_PROGRAM_PATH=#{base_path}\n"
|
96
|
+
end
|
97
|
+
|
98
|
+
unless File.exists?(CPPUMAKER_FLAG)
|
99
|
+
message "generating C++ representation for OpenOffice IDL types... "
|
100
|
+
ure_types = host['linux'] ? "#{ure_home}/share/misc/types.rdb" : "#{ure_home}/misc/types.rdb"
|
101
|
+
office_types = "#{base_path}/offapi.rdb"
|
102
|
+
IO.popen("/opt/openoffice.org/basis3.4/sdk/setsdkenv_unix >/dev/null", "w") do |shell|
|
103
|
+
shell.puts "#{CPPUMAKER} -Gc -BUCR -O#{CPPU_INCLUDE} -T\"#{IDL_TYPES.join(';')}\" \"#{ure_types}\" \"#{office_types}\""
|
104
|
+
shell.puts "touch #{CPPUMAKER_FLAG}"
|
105
|
+
end
|
106
|
+
|
107
|
+
message "ok\n"
|
108
|
+
end
|
109
|
+
|
110
|
+
if host['mswin']
|
111
|
+
sdk_lib = "/LIBPATH:\"#{sdk_home}/lib\""
|
112
|
+
ure_lib = ""
|
113
|
+
sdk_libs = " icppuhelper.lib icppu.lib isal.lib isalhelper.lib msvcprt.lib msvcrt.lib kernel32.lib" #
|
114
|
+
else
|
115
|
+
sdk_lib = "-L\"#{sdk_home}/lib\""
|
116
|
+
ure_lib = "-L\"#{ure_home}/lib\""
|
117
|
+
sdk_libs = " -luno_cppuhelpergcc3 -luno_cppu -luno_salhelpergcc3 -luno_sal -lm "
|
118
|
+
end
|
119
|
+
|
120
|
+
$warnflags = $warnflags.split.reject{|w| w['declaration-after-statement'] || w['implicit-function-declaration'] }.join(" ") # Remove invalid warnings
|
121
|
+
$INCFLAGS << " -I#{sdk_home}/include -I#{CPPU_INCLUDE} "
|
122
|
+
$LOCAL_LIBS << "#{sdk_lib} #{ure_lib} #{sdk_libs}"
|
123
|
+
$CFLAGS << " -fno-strict-aliasing -DUNX -DGCC -DLINUX -DCPPU_ENV=gcc3 "
|
124
|
+
|
125
|
+
create_makefile('rubyuno/rubyuno')
|
@@ -0,0 +1,26 @@
|
|
1
|
+
EXPORTS
|
2
|
+
oustring_to_rb_str
|
3
|
+
rb_str_to_oustring
|
4
|
+
ascii_rb_str_to_oustring
|
5
|
+
ascii_oustring_to_rb_str
|
6
|
+
bytes_to_rb_str
|
7
|
+
init_external_encoding
|
8
|
+
get_uno_module
|
9
|
+
get_proxy_class
|
10
|
+
get_enum_class
|
11
|
+
get_type_class
|
12
|
+
get_char_class
|
13
|
+
get_struct_class
|
14
|
+
get_exception_class
|
15
|
+
get_any_class
|
16
|
+
get_bytes_class
|
17
|
+
get_interface_class
|
18
|
+
get_css_uno_exception_class
|
19
|
+
get_uno_error_class
|
20
|
+
create_module
|
21
|
+
find_class
|
22
|
+
runo_new_type
|
23
|
+
runo_new_enum
|
24
|
+
valueToOUString
|
25
|
+
any_to_VALUE
|
26
|
+
|
@@ -0,0 +1,184 @@
|
|
1
|
+
/**************************************************************
|
2
|
+
* Copyright 2011 Tsutomu Uchino
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing,
|
11
|
+
* software distributed under the License is distributed on an
|
12
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
13
|
+
* KIND, either express or implied. See the License for the
|
14
|
+
* specific language governing permissions and limitations
|
15
|
+
* under the License.
|
16
|
+
*
|
17
|
+
*************************************************************/
|
18
|
+
|
19
|
+
#include "rubyuno.hxx"
|
20
|
+
|
21
|
+
#include <osl/module.hxx>
|
22
|
+
#include <osl/process.h>
|
23
|
+
#include <osl/thread.h>
|
24
|
+
#include <osl/file.hxx>
|
25
|
+
|
26
|
+
#include <cppuhelper/implementationentry.hxx>
|
27
|
+
#include <rtl/ustrbuf.hxx>
|
28
|
+
|
29
|
+
#include <com/sun/star/uno/XInterface.hpp>
|
30
|
+
|
31
|
+
using com::sun::star::uno::Reference;
|
32
|
+
using com::sun::star::uno::Sequence;
|
33
|
+
using com::sun::star::uno::XComponentContext;
|
34
|
+
using com::sun::star::uno::XInterface;
|
35
|
+
|
36
|
+
using rtl::OUString;
|
37
|
+
using rtl::OUStringToOString;
|
38
|
+
using rtl::OUStringBuffer;
|
39
|
+
|
40
|
+
#define IMPLE_NAME "mytools.loader.Ruby"
|
41
|
+
#define SERVICE_NAME "com.sun.star.loader.Ruby"
|
42
|
+
|
43
|
+
namespace rubyunoloader
|
44
|
+
{
|
45
|
+
|
46
|
+
static void
|
47
|
+
getLibraryPath(OUString &path) throw (com::sun::star::uno::RuntimeException)
|
48
|
+
{
|
49
|
+
OUString libUrl;
|
50
|
+
::osl::Module::getUrlFromAddress(
|
51
|
+
reinterpret_cast< oslGenericFunction >(getLibraryPath), libUrl);
|
52
|
+
libUrl = libUrl.copy(0, libUrl.lastIndexOf('/'));
|
53
|
+
osl::FileBase::RC e = osl::FileBase::getSystemPathFromFileURL(libUrl, path);
|
54
|
+
if (e != osl::FileBase::E_None)
|
55
|
+
{
|
56
|
+
throw com::sun::star::uno::RuntimeException(
|
57
|
+
OUString(RTL_CONSTASCII_USTRINGPARAM(
|
58
|
+
"failed to retrieve path to the loader.")),
|
59
|
+
Reference< XInterface >());
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
static int ruby_state = 1;
|
64
|
+
|
65
|
+
static void
|
66
|
+
load_modules(VALUE args)
|
67
|
+
{
|
68
|
+
rb_require(RSTRING_PTR(rb_ary_entry(args, 0)));
|
69
|
+
rb_require(RSTRING_PTR(rb_ary_entry(args, 1)));
|
70
|
+
rb_require(RSTRING_PTR(rb_ary_entry(args, 2)));
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
Reference< XInterface >
|
75
|
+
createInstanceWithContext(const Reference< XComponentContext > &ctx)
|
76
|
+
{
|
77
|
+
Reference< XInterface > ret;
|
78
|
+
if (ruby_state == 1)
|
79
|
+
{
|
80
|
+
OUStringBuffer buf;
|
81
|
+
OUString sysPath;
|
82
|
+
getLibraryPath(sysPath);
|
83
|
+
|
84
|
+
RUBY_INIT_STACK;
|
85
|
+
ruby_init();
|
86
|
+
ruby_init_loadpath();
|
87
|
+
|
88
|
+
if (! rubyuno::Runtime::isInitialized())
|
89
|
+
{
|
90
|
+
try
|
91
|
+
{
|
92
|
+
rubyuno::Runtime::initialize(ctx);
|
93
|
+
}
|
94
|
+
catch (com::sun::star::uno::RuntimeException &e)
|
95
|
+
{
|
96
|
+
return ret;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
VALUE argv = rb_ary_new2(3);
|
100
|
+
buf.append(sysPath);
|
101
|
+
buf.appendAscii("/rubyuno.so");
|
102
|
+
rb_ary_store(argv, 0, rubyuno::oustring_to_rb_str(buf.makeStringAndClear()));
|
103
|
+
buf.append(sysPath);
|
104
|
+
buf.appendAscii("/lib.rb");
|
105
|
+
rb_ary_store(argv, 1, rubyuno::oustring_to_rb_str(buf.makeStringAndClear()));
|
106
|
+
buf.append(sysPath);
|
107
|
+
buf.appendAscii("/rubyloader.rb");
|
108
|
+
rb_ary_store(argv, 2, rubyuno::oustring_to_rb_str(buf.makeStringAndClear()));
|
109
|
+
int state;
|
110
|
+
rb_protect((VALUE(*)(VALUE))load_modules, argv, &state);
|
111
|
+
ruby_state = state; // 0 sucess
|
112
|
+
if (state)
|
113
|
+
{
|
114
|
+
rb_p(rb_gv_get("$!"));
|
115
|
+
}
|
116
|
+
}
|
117
|
+
if (ruby_state == 0 && rubyuno::Runtime::isInitialized())
|
118
|
+
{
|
119
|
+
rubyuno::Runtime runtime;
|
120
|
+
VALUE loader_module = rb_const_get(
|
121
|
+
rb_cObject, rb_intern("RubyLoader"));
|
122
|
+
VALUE loader_imple = rb_const_get(
|
123
|
+
loader_module, rb_intern("RubyLoaderImpl"));
|
124
|
+
VALUE ctx_val = runtime.any_to_VALUE(makeAny(ctx));
|
125
|
+
VALUE args[1];
|
126
|
+
args[0] = ctx_val;
|
127
|
+
VALUE loader = rb_class_new_instance(1, args, loader_imple);
|
128
|
+
runtime.value_to_any(loader) >>= ret;
|
129
|
+
}
|
130
|
+
return ret;
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
OUString
|
135
|
+
getImplementationName()
|
136
|
+
{
|
137
|
+
return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLE_NAME));
|
138
|
+
}
|
139
|
+
|
140
|
+
Sequence< OUString >
|
141
|
+
getSupportedServiceNames()
|
142
|
+
{
|
143
|
+
OUString name(RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME));
|
144
|
+
return Sequence< OUString >(&name, 1);
|
145
|
+
}
|
146
|
+
|
147
|
+
} // rubyunoloader
|
148
|
+
|
149
|
+
static struct cppu::ImplementationEntry g_entries[] =
|
150
|
+
{
|
151
|
+
{
|
152
|
+
rubyunoloader::createInstanceWithContext,
|
153
|
+
rubyunoloader::getImplementationName,
|
154
|
+
rubyunoloader::getSupportedServiceNames,
|
155
|
+
cppu::createSingleComponentFactory,
|
156
|
+
0,
|
157
|
+
0
|
158
|
+
},
|
159
|
+
{0, 0, 0, 0, 0, 0}
|
160
|
+
};
|
161
|
+
|
162
|
+
|
163
|
+
extern "C"
|
164
|
+
{
|
165
|
+
|
166
|
+
void SAL_CALL
|
167
|
+
component_getImplementationEnvironment(const sal_Char **ppEnvTypeName, uno_Environment **)
|
168
|
+
{
|
169
|
+
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
|
170
|
+
}
|
171
|
+
/*
|
172
|
+
sal_Bool SAL_CALL
|
173
|
+
component_writeInfo(void *pServiceManager, void *pRegistryKey)
|
174
|
+
{
|
175
|
+
return cppu::component_writeInfoHelper(pServiceManager, pRegistryKey, g_entries);
|
176
|
+
}
|
177
|
+
*/
|
178
|
+
void* SAL_CALL
|
179
|
+
component_getFactory(const sal_Char *pImplName, void *pServiceManager, void *pRegistryKey)
|
180
|
+
{
|
181
|
+
return cppu::component_getFactoryHelper(pImplName, pServiceManager, pRegistryKey, g_entries);
|
182
|
+
}
|
183
|
+
|
184
|
+
}
|