rubyuno 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1263 @@
1
+
2
+ #include "rubyuno.hxx"
3
+
4
+ #include <cppuhelper/bootstrap.hxx>
5
+ #include <osl/file.hxx>
6
+ #include <osl/thread.h>
7
+ #include <rtl/textenc.h>
8
+ #include <rtl/ustrbuf.hxx>
9
+ #include <rtl/uuid.h>
10
+ #include <typelib/typedescription.hxx>
11
+
12
+ #include <com/sun/star/beans/PropertyAttribute.hpp>
13
+ #include <com/sun/star/beans/XMaterialHolder.hpp>
14
+ #include <com/sun/star/lang/WrappedTargetException.hpp>
15
+ #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
16
+ #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
17
+ #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
18
+ #include <com/sun/star/reflection/XIdlClass.hpp>
19
+ #include <com/sun/star/script/InvocationInfo.hpp>
20
+ #include <com/sun/star/script/MemberType.hpp>
21
+ #include <com/sun/star/uno/Type.hxx>
22
+
23
+ using com::sun::star::beans::XMaterialHolder;
24
+ using com::sun::star::lang::WrappedTargetException;
25
+ using com::sun::star::reflection::XConstantsTypeDescription;
26
+ using com::sun::star::reflection::XConstantTypeDescription;
27
+ using com::sun::star::reflection::XEnumTypeDescription;
28
+ using com::sun::star::reflection::XIdlClass;
29
+ using com::sun::star::reflection::XTypeDescription;
30
+ using com::sun::star::script::InvocationInfo;
31
+ using com::sun::star::script::MemberType;
32
+ using com::sun::star::script::XInvocation2;
33
+ using com::sun::star::uno::Any;
34
+ using com::sun::star::uno::Reference;
35
+ using com::sun::star::uno::Type;
36
+ using com::sun::star::uno::TypeDescription;
37
+ using com::sun::star::uno::XComponentContext;
38
+ using com::sun::star::uno::UNO_QUERY;
39
+
40
+ using namespace cppu;
41
+ using namespace rtl;
42
+
43
+ using namespace com::sun::star::uno;
44
+ using namespace com::sun::star::beans;
45
+ using namespace com::sun::star::script;
46
+
47
+ using rtl::OUString;
48
+ using rtl::OUStringBuffer;
49
+ using rtl::OUStringToOString;
50
+
51
+ using namespace rubyuno;
52
+
53
+ namespace
54
+ {
55
+
56
+ /*
57
+ * Make URL absolute from URL and relative path.
58
+ * p Rubyuno.absolutize("file:///home/ruby/Desktop", "../")
59
+ * #=> "file:///home/ruby/"
60
+ */
61
+ static VALUE
62
+ rubyuno_absolutize(VALUE self, VALUE base_url, VALUE rel_path)
63
+ {
64
+ rb_secure(2);
65
+ OUString baseUrl = rbString2OUString(base_url);
66
+ OUString relativePath = rbString2OUString(rel_path);
67
+ OUString absUrl;
68
+
69
+ osl::FileBase::RC e = osl::FileBase::getAbsoluteFileURL(baseUrl, relativePath, absUrl);
70
+ if (e != osl::FileBase::E_None)
71
+ {
72
+ rb_raise(rb_eArgError, "invalid url (%s) or invalid relative path (%s)", RSTRING_PTR(base_url), RSTRING_PTR(rel_path));
73
+ }
74
+ return ustring2RString(absUrl);
75
+ }
76
+
77
+ /*
78
+ * Convert system path to file URL. Multi-byte characters are escaped.
79
+ * p Rubyuno.system_path_to_file_url("/home/ruby/Desktop")
80
+ * #=> "file:///home/ruby/Desktop"
81
+ */
82
+ static VALUE
83
+ rubyuno_getSystemPathFromFileURL(VALUE self, VALUE file_url)
84
+ {
85
+ rb_secure(2);
86
+ OUString url = rbString2OUString(file_url);
87
+ OUString sysPath;
88
+ osl::FileBase::RC e = osl::FileBase::getSystemPathFromFileURL(url, sysPath);
89
+ if (e != osl::FileBase::E_None)
90
+ {
91
+ rb_raise(rb_eArgError, "invalid url (%s)", RSTRING_PTR(file_url));
92
+ }
93
+ return ustring2RString(sysPath);
94
+ }
95
+
96
+ /*
97
+ * Convert file URL to system path.
98
+ * p Rubyuno.file_url_to_system_path("file:///home/ruby/Desktop)
99
+ * #=> "/home/ruby/Desktop"
100
+ */
101
+ static VALUE
102
+ rubyuno_getFileURLFromSystemPath(VALUE self, VALUE path)
103
+ {
104
+ rb_secure(2);
105
+ OUString sysPath = rbString2OUString(path);
106
+ OUString url;
107
+ osl::FileBase::RC e = osl::FileBase::getFileURLFromSystemPath(sysPath, url);
108
+ if (e != osl::FileBase::E_None)
109
+ {
110
+ rb_raise(rb_eArgError, "invalid path (%s)", RSTRING_PTR(path));
111
+ }
112
+ return ustring2RString(url);
113
+ }
114
+
115
+ /*
116
+ * Generate UUID version 4
117
+ */
118
+ static VALUE
119
+ rubyuno_create_uuid(VALUE self)
120
+ {
121
+ Sequence< sal_Int8 > seq(16);
122
+ rtl_createUuid((sal_uInt8*)seq.getArray(), 0, sal_False);
123
+ VALUE ret;
124
+ try
125
+ {
126
+ Runtime runtime;
127
+ ret = runtime.any_to_VALUE(makeAny(seq));
128
+ }
129
+ catch (RuntimeException &e)
130
+ {
131
+ rb_raise(rb_eRuntimeError, "failed to create UUID.");
132
+ }
133
+ return ret;
134
+ }
135
+
136
+ /*
137
+ * Returns component contex and initialize bridge.
138
+ * ctx = Rubyuno.get_component_context
139
+ */
140
+ static VALUE
141
+ rubyuno_getComponentContext(VALUE self)
142
+ {
143
+ rb_secure(2);
144
+ Reference< XComponentContext > ctx;
145
+
146
+ if (Runtime::isInitialized())
147
+ {
148
+ Runtime r;
149
+ ctx = r.getImpl()->xComponentContext;
150
+ }
151
+ else
152
+ {
153
+ ctx = defaultBootstrap_InitialComponentContext();
154
+ if (ctx.is())
155
+ {
156
+ try
157
+ {
158
+ Runtime::initialize(ctx);
159
+ }
160
+ catch (RuntimeException &e)
161
+ {
162
+ rb_raise(rb_eTypeError, "wrong value in @rubyuno_runtime variable.");
163
+ }
164
+ }
165
+ else
166
+ {
167
+ rb_raise(rb_eRuntimeError, "failed to bootstrap.");
168
+ }
169
+ }
170
+ if (ctx.is()) {
171
+ Runtime runtime;
172
+ return runtime.any_to_VALUE(makeAny(ctx));
173
+ }
174
+ return Qnil;
175
+ }
176
+
177
+
178
+ /*
179
+ * Load UNO value.
180
+ */
181
+ static VALUE
182
+ rubyuno_uno_require(VALUE self, VALUE name)
183
+ {
184
+ VALUE ret = Qnil;
185
+ try
186
+ {
187
+ OUString typeName = rbString2OUString(name);
188
+ Runtime runtime;
189
+ Any a = runtime.getImpl()->xTypeDescription->getByHierarchicalName(typeName);
190
+ if (a.getValueTypeClass() == TypeClass_INTERFACE)
191
+ {
192
+ Reference< XTypeDescription > xTd(a, UNO_QUERY);
193
+ if (!xTd.is())
194
+ rb_raise(rb_eArgError, "unknown type (%s)", RSTRING_PTR(name));
195
+
196
+ // typeName is checked by the TypeDescriptionManager
197
+ VALUE module, klass;
198
+ ID id;
199
+ sal_Int32 ends;
200
+ OUString tmpName, moduleName;
201
+ char *className;
202
+ OUStringBuffer buf;
203
+
204
+ ends = typeName.lastIndexOfAsciiL(".", 1);
205
+ tmpName = typeName.copy(ends + 1);
206
+
207
+ module = create_module(typeName);
208
+
209
+ buf.append(tmpName.copy(0, 1).toAsciiUpperCase()).append(tmpName.copy(1));
210
+ className = (char*) OUStringToOString(buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ).getStr();
211
+ id = rb_intern(className);
212
+
213
+ if (xTd->getTypeClass() == TypeClass_STRUCT || xTd->getTypeClass() == TypeClass_EXCEPTION)
214
+ {
215
+ Any aStruct;
216
+ Reference< XIdlClass > xIdlClass(runtime.getImpl()->xCoreReflection->forName(typeName), UNO_QUERY);
217
+ if (xIdlClass.is())
218
+ {
219
+ // forName method breaks className
220
+ buf.append(tmpName.copy(0, 1).toAsciiUpperCase()).append(tmpName.copy(1));
221
+ className = (char*) OUStringToOString(
222
+ buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US).getStr();
223
+ if (rb_const_defined(module, id))
224
+ {
225
+ klass = rb_const_get(module, id);
226
+ }
227
+ else
228
+ {
229
+ if (xTd->getTypeClass() == TypeClass_STRUCT)
230
+ klass = rb_define_class_under(module, className, get_struct_class());
231
+ else
232
+ klass = rb_define_class_under(module, className, get_exception_class());
233
+
234
+ VALUE type_name = rb_str_new2(RSTRING_PTR(name));
235
+ rb_define_const(klass, "TYPENAME", type_name);
236
+ }
237
+ return klass;
238
+ }
239
+ rb_raise(rb_eArgError, "unknown type (%s)", RSTRING_PTR(name));
240
+ }
241
+ else if (xTd->getTypeClass() == TypeClass_CONSTANTS)
242
+ {
243
+ if (rb_const_defined(module, id))
244
+ klass = rb_const_get(module, id);
245
+ else
246
+ klass = rb_define_module_under(module, className);
247
+
248
+ VALUE value;
249
+ Reference< XConstantsTypeDescription > xDesc(a, UNO_QUERY);
250
+ Sequence< Reference< XConstantTypeDescription > > constants(xDesc->getConstants());
251
+ sal_Int32 nStart = typeName.getLength() + 1;
252
+ for (sal_Int32 i = 0; i < constants.getLength(); i++)
253
+ {
254
+ value = runtime.any_to_VALUE(constants[i]->getConstantValue());
255
+ rb_iv_set(klass, OUStringToOString(
256
+ constants[i]->getName().copy(nStart), RTL_TEXTENCODING_ASCII_US ), value);
257
+ }
258
+ return klass;
259
+ }
260
+ else if (xTd->getTypeClass() == TypeClass_ENUM)
261
+ {
262
+ // as module and module constants
263
+ if (rb_const_defined(module, id))
264
+ {
265
+ klass = rb_const_get(module, id);
266
+ }
267
+ else
268
+ {
269
+ klass = rb_define_module_under(module, className);
270
+ }
271
+ Reference< XEnumTypeDescription > xEnumDesc(a, UNO_QUERY);
272
+ Sequence< OUString > names(xEnumDesc->getEnumNames());
273
+
274
+ VALUE enum_class = get_enum_class();
275
+ VALUE obj;
276
+ VALUE type_name = ustring2RString(typeName);
277
+ OUString valueName;
278
+
279
+ TypeDescription desc(typeName);
280
+ if (!desc.is())
281
+ {
282
+ rb_raise(rb_eArgError, "unknown type name (%s)", RSTRING_PTR(type_name));
283
+ }
284
+ if (desc.get()->eTypeClass != typelib_TypeClass_ENUM)
285
+ {
286
+ rb_raise(rb_eArgError, "wrong type name (%s)", RSTRING_PTR(type_name));
287
+ }
288
+ desc.makeComplete();
289
+
290
+ typelib_EnumTypeDescription *pEnumDesc = (typelib_EnumTypeDescription*) desc.get();
291
+ int i = 0;
292
+ for (i = 0; i < pEnumDesc->nEnumValues; i++)
293
+ {
294
+ Any a = Any(&pEnumDesc->pEnumValues[i], desc.get()->pWeakRef);
295
+ RubyunoValue *ptr;
296
+ ptr = new RubyunoValue();
297
+ obj = rb_obj_alloc(enum_class);
298
+ DATA_PTR(obj) = ptr;
299
+ ptr->value = a;
300
+
301
+ valueName = (*((OUString*)&pEnumDesc->ppEnumNames[i]));
302
+ rb_iv_set(obj, "@type_name", type_name);
303
+ rb_iv_set(obj, "@value", ustring2RString(valueName));
304
+
305
+ rb_iv_set(klass, OUStringToOString(
306
+ valueName, RTL_TEXTENCODING_ASCII_US ).getStr(), obj);
307
+ }
308
+ return klass;
309
+ }
310
+ else if (xTd->getTypeClass() == TypeClass_INTERFACE)
311
+ {
312
+ VALUE klass;
313
+ klass = find_interface(xTd);
314
+ if (NIL_P(klass))
315
+ rb_raise(rb_eArgError, "unknown type name (%s)", RSTRING_PTR(name));
316
+ return klass;
317
+ }
318
+ else
319
+ {
320
+ rb_raise(rb_eRuntimeError, "unsupported type (%s)", RSTRING_PTR(name));
321
+ }
322
+ }
323
+ // direct values like enums and constants
324
+ OUString tmpTypeName, valueName;
325
+ sal_Int32 ends;
326
+ ends = typeName.lastIndexOfAsciiL(".", 1);
327
+ tmpTypeName = typeName.copy(0, ends);
328
+ valueName = typeName.copy(ends + 1);
329
+
330
+ Any desc = runtime.getImpl()->xTypeDescription->getByHierarchicalName(tmpTypeName);
331
+ if (desc.getValueTypeClass() == TypeClass_INTERFACE)
332
+ {
333
+ // constants group is not processed here
334
+ Reference< XTypeDescription > xTdm(desc, UNO_QUERY);
335
+ if (xTdm.is() && xTdm->getTypeClass() == TypeClass_ENUM)
336
+ {
337
+ return rb_funcall(get_enum_class(), rb_intern("new"), 2, ustring2RString(tmpTypeName), ustring2RString(valueName));
338
+ }
339
+ }
340
+ ret = runtime.any_to_VALUE(a);
341
+ }
342
+ catch (com::sun::star::container::NoSuchElementException &e)
343
+ {
344
+ rb_raise(rb_eArgError, "unknown value (%s)", RSTRING_PTR(name));
345
+ }
346
+ catch (com::sun::star::script::CannotConvertException &e)
347
+ {
348
+ rb_raise(rb_eRuntimeError, "failed to convert type for (%s)", RSTRING_PTR(name));
349
+ }
350
+ catch (com::sun::star::uno::RuntimeException &e)
351
+ {
352
+ rb_raise(rb_eArgError, "invalid name for value (%s)", RSTRING_PTR(name));
353
+ }
354
+ return ret;
355
+ }
356
+
357
+ /*
358
+ * Import somethings with a call.
359
+ * if argc == 1, value is returned and if multiple arguments are passed,
360
+ * returnes as Array.
361
+ */
362
+ static VALUE
363
+ rubyuno_uno_multiple_require(int argc, VALUE *argv, VALUE self)
364
+ {
365
+ if (argc == 0)
366
+ return Qnil;
367
+ VALUE args;
368
+ rb_scan_args(argc, argv, "*", &args);
369
+
370
+ if (argc == 1)
371
+ return rubyuno_uno_require(self, rb_ary_entry(args, 0));
372
+
373
+ VALUE ret = rb_ary_new2(argc);
374
+ for (int i = 0; i < argc; i++)
375
+ {
376
+ rb_ary_push(ret, rubyuno_uno_require(self, rb_ary_entry(args, i)));
377
+ }
378
+ return ret;
379
+ }
380
+
381
+
382
+ static void
383
+ rubyuno_proxy_free(RubyunoInternal *rubyuno)
384
+ {
385
+ if (rubyuno)
386
+ {
387
+ rubyuno->wrapped.clear();
388
+ //rubyuno->invocation.clear();
389
+ delete rubyuno;
390
+ }
391
+ }
392
+
393
+
394
+ static VALUE
395
+ rubyuno_proxy_alloc(VALUE klass)
396
+ {
397
+ return Data_Wrap_Struct(klass, 0, rubyuno_proxy_free, 0);
398
+ }
399
+
400
+
401
+ VALUE
402
+ proxy_attr(const VALUE *self, RubyunoInternal *rubyuno, VALUE *name, OUString propertyName, VALUE &args, int mode)
403
+ {
404
+ VALUE ret = Qnil;
405
+ Runtime r;
406
+ Any a;
407
+ try
408
+ {
409
+ if (!mode)
410
+ {
411
+ a = rubyuno->invocation->getValue(propertyName);
412
+ ret = r.any_to_VALUE(a);
413
+ }
414
+ else
415
+ {
416
+ a = r.value_to_any(rb_ary_entry(args, 0));
417
+ rubyuno->invocation->setValue(propertyName, a);
418
+ ret = Qnil;
419
+ }
420
+ }
421
+ catch (com::sun::star::beans::UnknownPropertyException &e)
422
+ {
423
+ raise_rb_exception(makeAny(e));
424
+ }
425
+ catch (com::sun::star::script::CannotConvertException &e)
426
+ {
427
+ raise_rb_exception(makeAny(e));
428
+ }
429
+ catch (com::sun::star::reflection::InvocationTargetException &e)
430
+ {
431
+ com::sun::star::uno::Exception ex;
432
+ e.TargetException >>= ex;
433
+ raise_rb_exception(e.TargetException);
434
+ }
435
+ catch (RuntimeException &e)
436
+ {
437
+ raise_rb_exception(makeAny(e));
438
+ }
439
+ return ret;
440
+ }
441
+
442
+
443
+ VALUE
444
+ proxy_call_method(VALUE *self, RubyunoInternal *rubyuno, VALUE *name, OUString methodName, VALUE &args)
445
+ {
446
+ VALUE ret;
447
+ Sequence< short > aOutParamIndex;
448
+ Sequence< Any > aParams;
449
+ Sequence< Any > aOutParams;
450
+ Sequence< Type > aParamTypes;
451
+ Any anyParams;
452
+ Any outParams;
453
+ Any retValue;
454
+ try
455
+ {
456
+ Runtime runtime;
457
+ anyParams = runtime.value_to_any(args);
458
+ if (anyParams.getValueTypeClass() == com::sun::star::uno::TypeClass_SEQUENCE)
459
+ {
460
+ anyParams >>= aParams;
461
+ }
462
+ else
463
+ {
464
+ aParams.realloc(1);
465
+ aParams[0] <<= anyParams;
466
+ }
467
+ retValue = rubyuno->invocation->invoke(methodName, aParams, aOutParamIndex, aOutParams);
468
+
469
+ VALUE tmp = runtime.any_to_VALUE(retValue);
470
+ if (aOutParams.getLength())
471
+ {
472
+ VALUE ret_array = rb_ary_new2(aOutParams.getLength() +1);
473
+ rb_ary_push(ret_array, tmp);
474
+ for (int i = 0; i < aOutParams.getLength(); i++)
475
+ {
476
+ rb_ary_push(ret_array, runtime.any_to_VALUE(aOutParams[i]));
477
+ }
478
+ ret = ret_array;
479
+ } else {
480
+ ret = tmp;
481
+ }
482
+ return ret;
483
+ }
484
+ catch (com::sun::star::reflection::InvocationTargetException &e)
485
+ {
486
+ com::sun::star::uno::Exception ex;
487
+ e.TargetException >>= ex;
488
+ raise_rb_exception(e.TargetException);
489
+ }
490
+ catch (com::sun::star::lang::IllegalArgumentException &e)
491
+ {
492
+ raise_rb_exception(makeAny(e));
493
+ }
494
+ catch (com::sun::star::script::CannotConvertException &e)
495
+ {
496
+ raise_rb_exception(makeAny(e));
497
+ }
498
+ catch (RuntimeException &e)
499
+ {
500
+ raise_rb_exception(makeAny(e));
501
+ }
502
+ return Qnil;
503
+ }
504
+
505
+
506
+ static VALUE
507
+ proxy_method_call(VALUE name_symbol, VALUE *args, VALUE self)
508
+ {
509
+ VALUE name;
510
+ OUString methodName;
511
+ Check_Type(name_symbol, T_SYMBOL);
512
+ #ifdef RUBY_RUBY_H
513
+ name = rb_id2str(rb_to_id(name_symbol));
514
+ #else
515
+ name = rb_str_new2(rb_id2name(rb_to_id(name_symbol)));
516
+ #endif
517
+ methodName = asciiVALUE2OUString(name);
518
+
519
+ RubyunoInternal *rubyuno;
520
+ Data_Get_Struct(self, RubyunoInternal, rubyuno);
521
+
522
+ if (methodName.endsWithAsciiL("=", 1))
523
+ {
524
+ OUString propertyName(methodName.copy(0, methodName.getLength() - 1));
525
+ if (rubyuno->invocation->hasProperty(propertyName))
526
+ return proxy_attr(&self, rubyuno, &name, propertyName, *args, 1);
527
+ }
528
+ else
529
+ {
530
+ if (rubyuno->invocation->hasMethod(methodName))
531
+ {
532
+ return proxy_call_method(&self, rubyuno, &name, methodName, *args);
533
+ }
534
+ else if (rubyuno->invocation->hasProperty(methodName))
535
+ {
536
+ return proxy_attr(&self, rubyuno, &name, methodName, *args, 0);
537
+ }
538
+ }
539
+ rb_raise(rb_eNameError, "unknown method `%s'", RSTRING_PTR(name));
540
+ return Qnil;
541
+ }
542
+
543
+
544
+ static VALUE
545
+ rubyuno_proxy_method_missing(int argc, VALUE *argv, VALUE self)
546
+ {
547
+ if (argc >= 1)
548
+ {
549
+ rb_secure(2);
550
+
551
+ VALUE name_symbol, args;
552
+ // get method symbol
553
+ rb_scan_args(argc, argv, "1*", &name_symbol, &args);
554
+
555
+ return proxy_method_call(name_symbol, &args, self);
556
+ }
557
+ rb_raise(rb_eRuntimeError, "unknown error");
558
+ return Qnil;
559
+ }
560
+
561
+ #ifdef HAVE_RUBY_RUBY_H
562
+ static VALUE
563
+ to_symbol(VALUE str, ID intern, int argc, VALUE *argv)
564
+ {
565
+ return rb_funcall(str, intern, 0);
566
+ }
567
+ #endif
568
+
569
+ static VALUE
570
+ rubyuno_uno_methods(VALUE self)
571
+ {
572
+ RubyunoInternal *rubyuno;
573
+ Data_Get_Struct(self, RubyunoInternal, rubyuno);
574
+ if (!rubyuno)
575
+ rb_raise(rb_eRuntimeError, "illegal instance (%s)", rb_obj_classname(self));
576
+
577
+ VALUE names, assignment;
578
+ assignment = rb_str_new("=", 1);
579
+ Reference< XInvocation2 > xInv = rubyuno->invocation;
580
+ Sequence< InvocationInfo > infos = xInv->getInfo();
581
+
582
+ names = rb_ary_new2((int)infos.getLength());
583
+
584
+ for (int i = 0; i < (int)infos.getLength(); i++)
585
+ {
586
+ if (infos[i].eMemberType == MemberType_METHOD)
587
+ {
588
+ rb_ary_push(names, asciiOUString2VALUE(infos[i].aName));
589
+ }
590
+ else if (infos[i].eMemberType == MemberType_PROPERTY)
591
+ {
592
+ if (infos[i].PropertyAttribute & PropertyAttribute::READONLY)
593
+ {
594
+ rb_ary_push(names, asciiOUString2VALUE(infos[i].aName));
595
+ }
596
+ else
597
+ {
598
+ rb_ary_push(names, asciiOUString2VALUE(infos[i].aName));
599
+ rb_ary_push(names, rb_str_cat(asciiOUString2VALUE(infos[i].aName), "=", 1));
600
+ }
601
+ }
602
+ else
603
+ {
604
+ rb_ary_push(names, asciiOUString2VALUE(infos[i].aName));
605
+ }
606
+ }
607
+ #ifdef HAVE_RUBY_RUBY_H
608
+ ID intern = rb_intern("intern");
609
+ rb_block_call(names, rb_intern("map!"), 0, 0, (VALUE(*)(...))to_symbol, intern);
610
+ return names;
611
+ #else
612
+ return names;
613
+ #endif
614
+ }
615
+
616
+
617
+ static VALUE
618
+ rubyuno_proxy_equal(VALUE self, VALUE object)
619
+ {
620
+ if (CLASS_OF(object) != get_proxy_class())
621
+ return Qfalse;
622
+
623
+ RubyunoInternal *self_rubyuno, *object_rubyuno;
624
+ Data_Get_Struct(self, RubyunoInternal, self_rubyuno);
625
+ Data_Get_Struct(object, RubyunoInternal, object_rubyuno);
626
+
627
+ if (self_rubyuno && object_rubyuno)
628
+ {
629
+ if (self_rubyuno->wrapped == object_rubyuno->wrapped)
630
+ return Qtrue;
631
+ }
632
+ return Qfalse;
633
+ }
634
+
635
+ static VALUE
636
+ rubyuno_proxy_inspect(VALUE self)
637
+ {
638
+ RubyunoInternal *rubyuno;
639
+ Data_Get_Struct(self, RubyunoInternal, rubyuno);
640
+ if (rubyuno)
641
+ {
642
+ OUStringBuffer buf;
643
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("#<Rubyuno::RubyunoProxy:"));
644
+ buf.append(rubyuno->wrapped.getValueType().getTypeName());
645
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(":"));
646
+ VALUE str;
647
+ #ifdef RUBY_RUBY_H
648
+ str = rb_sprintf("%p", (void*)self);
649
+ #else
650
+ size_t len;
651
+ len = 16;
652
+ str = rb_str_new(0, len);
653
+ snprintf(RSTRING_PTR(str), len, "0x%lx", self);
654
+ #endif
655
+ buf.append(rbString2OUString(str));
656
+ buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(">"));
657
+ return ustring2RString(buf.makeStringAndClear());
658
+ }
659
+ rb_raise(rb_eRuntimeError, "uninitializezd RubyunoProxy.");
660
+ return Qnil;
661
+ }
662
+
663
+ /*
664
+ * Check the UNO object implements specific interface.
665
+ */
666
+ static VALUE
667
+ rubyuno_proxy_has_interface(VALUE self, VALUE name)
668
+ {
669
+ StringValue(name);
670
+
671
+ RubyunoInternal *rubyuno;
672
+ Data_Get_Struct(self, RubyunoInternal, rubyuno);
673
+ if (rubyuno)
674
+ {
675
+ Runtime runtime;
676
+ OUString typeName;
677
+
678
+ typeName = rbString2OUString(name);
679
+ Reference < XInterface > xInterface = *(Reference < XInterface >*) rubyuno->wrapped.getValue();
680
+ Reference< XIdlClass > xIdlClass = runtime.getImpl()->xCoreReflection->forName(typeName);
681
+
682
+ if (xIdlClass.is())
683
+ {
684
+ OUString className = xIdlClass->getName();
685
+ Type classType(xIdlClass->getTypeClass(), className.getStr());
686
+
687
+ if (xInterface->queryInterface(classType).hasValue())
688
+ return Qtrue;
689
+ }
690
+ }
691
+ return Qfalse;
692
+ }
693
+
694
+ /*
695
+ * Call method of the object with arguments.
696
+ *
697
+ */
698
+ static VALUE
699
+ rubyuno_invoke(VALUE self, VALUE object, VALUE name, VALUE args)
700
+ {
701
+ if (! (rb_obj_is_kind_of(object, get_proxy_class()) ||
702
+ rb_obj_is_kind_of(object, get_struct_class()) ||
703
+ rb_obj_is_kind_of(object, get_exception_class())) )
704
+ rb_raise(rb_eArgError, "invalid object for source to invoke the function");
705
+
706
+ Check_Type(name, T_STRING);
707
+ Check_Type(args, T_ARRAY);
708
+ #ifdef HAVE_RUBY_RUBY_H
709
+ return proxy_method_call(ID2SYM(rb_intern_str(name)), &args, object);
710
+ #else
711
+ return proxy_method_call(ID2SYM(rb_intern(RSTRING_PTR(name))), &args, object);
712
+ #endif
713
+ }
714
+
715
+
716
+ static VALUE
717
+ rubyuno_struct_alloc(VALUE klass)
718
+ {
719
+ RubyunoInternal *rubyuno;
720
+ rubyuno = new RubyunoInternal();
721
+ return Data_Wrap_Struct(klass, 0, rubyuno_proxy_free, rubyuno);
722
+ }
723
+
724
+
725
+ /*
726
+ * Fill struct fields according to initial value.
727
+ */
728
+ sal_Int32 fill_struct(const typelib_CompoundTypeDescription *pCompType, VALUE *args, Reference< XInvocation2 > xInvocation, Runtime &runtime)
729
+ {
730
+ sal_Int32 nIndex = 0;
731
+ if (pCompType->pBaseTypeDescription)
732
+ nIndex = fill_struct(pCompType->pBaseTypeDescription, args, xInvocation, runtime);
733
+
734
+ sal_Int32 nLength = RARRAY_LEN(*args);
735
+
736
+ int i;
737
+ for (i = 0; i < pCompType->nMembers; i++)
738
+ {
739
+ if (i + nIndex >= nLength)
740
+ {
741
+ rb_raise(rb_eArgError, "too few arguments (%d for %d)", (int)nLength, (int)(nIndex + pCompType->nMembers));
742
+ }
743
+ VALUE item = rb_ary_entry(*args, i);
744
+ Any a = runtime.value_to_any(item);
745
+ xInvocation->setValue(pCompType->ppMemberNames[i], a);
746
+ }
747
+
748
+ return i + nIndex;
749
+ }
750
+
751
+ /*
752
+ * for structs inherits RubyunoStruct.
753
+ */
754
+ static VALUE
755
+ rubyuno_struct_initialize(int argc, VALUE *argv, VALUE self)
756
+ {
757
+ VALUE klass, type_name;
758
+ ID id = rb_intern("TYPENAME");
759
+ klass = CLASS_OF(self);
760
+ if (!rb_const_defined(klass, id))
761
+ rb_raise(rb_eRuntimeError, "wrongly initialized class `%s', type_name is not specified", rb_obj_classname(klass));
762
+ type_name = rb_const_get(klass, id);
763
+
764
+ Runtime runtime;
765
+ Any aStruct;
766
+ OUString typeName = rbString2OUString(type_name);
767
+ Reference< XIdlClass > idlClass(runtime.getImpl()->xCoreReflection->forName(typeName), UNO_QUERY);
768
+ if (!idlClass.is())
769
+ rb_raise(rb_eRuntimeError, "unknown type name (%s)", RSTRING_PTR(type_name));
770
+ idlClass->createObject(aStruct);
771
+
772
+ set_rubyuno_struct(aStruct, runtime.getImpl()->xInvocation, self);
773
+
774
+ // set initial values
775
+ if (argc > 1)
776
+ {
777
+ VALUE args;
778
+ rb_scan_args(argc, argv, "*", &args);
779
+
780
+ TypeDescription desc(typeName);
781
+ if (desc.is())
782
+ {
783
+ typelib_CompoundTypeDescription *pCompType = (typelib_CompoundTypeDescription *) desc.get();
784
+
785
+ RubyunoInternal *rubyuno;
786
+ Data_Get_Struct(self, RubyunoInternal, rubyuno);
787
+ fill_struct(pCompType, &args, rubyuno->invocation, runtime);
788
+ }
789
+ }
790
+ return self;
791
+ }
792
+
793
+ static VALUE
794
+ rubyuno_struct_equal(VALUE self, VALUE object)
795
+ {
796
+ if (! (rb_obj_is_kind_of(object, get_struct_class()) ||
797
+ rb_obj_is_kind_of(object, get_enum_class()) ) )
798
+ return Qfalse;
799
+
800
+ RubyunoInternal *rubyuno_self, *rubyuno_object;
801
+ Data_Get_Struct(self, RubyunoInternal, rubyuno_self);
802
+ Data_Get_Struct(object, RubyunoInternal, rubyuno_object);
803
+
804
+ Reference< XMaterialHolder > selfMaterial(rubyuno_self->invocation, UNO_QUERY);
805
+ Reference< XMaterialHolder > objectMaterial(rubyuno_object->invocation, UNO_QUERY);
806
+
807
+ if (selfMaterial->getMaterial() == objectMaterial->getMaterial())
808
+ return Qtrue;
809
+ return Qfalse;
810
+ }
811
+ /*
812
+ static VALUE
813
+ rubyuno_exception_alloc(VALUE klass)
814
+ {
815
+ return Data_Wrap_Struct(klass, 0, rubyuno_proxy_free, 0);
816
+ }
817
+ */
818
+ static VALUE
819
+ rubyuno_exception_initialize(VALUE self, VALUE message)
820
+ {
821
+ /*
822
+ VALUE klass, type_name;
823
+ ID id = rb_intern("TYPENAME");
824
+ klass = CLASS_OF(self);
825
+ if (!rb_const_defined(klass, id))
826
+ rb_raise(rb_eRuntimeError, "wrongly initialized class `%s', type_name is not specified", rb_obj_classname(klass));
827
+
828
+ type_name = rb_const_get(klass, id);
829
+ Runtime runtime;
830
+ Any aStruct;
831
+ OUString typeName = rbString2OUString(type_name);
832
+ Reference< XIdlClass > idlClass(runtime.getImpl()->xCoreReflection->forName(typeName), UNO_QUERY);
833
+
834
+ if (!idlClass.is())
835
+ rb_raise(rb_eRuntimeError, "unknown type name (%s)", RSTRING_PTR(type_name));
836
+ idlClass->createObject(aStruct);
837
+ set_rubyuno_struct(aStruct, runtime.getImpl()->xInvocation, self);
838
+
839
+ rb_iv_set(self, "mesg", message);
840
+ rb_iv_set(self, "bt", Qnil);
841
+ */
842
+ rb_call_super(1, &message);
843
+ return self;
844
+ }
845
+
846
+ /*
847
+ * Rubyuno::Enum class
848
+ */
849
+ static VALUE
850
+ rubyuno_enum_initialize(VALUE self, VALUE type_name, VALUE value)
851
+ {
852
+ // check args
853
+ Check_Type(type_name, T_STRING);
854
+ Check_Type(value, T_STRING);
855
+
856
+ OUString typeName = rbString2OUString(type_name);
857
+ char *strValue = RSTRING_PTR(value);
858
+
859
+ TypeDescription desc(typeName);
860
+ if (desc.is())
861
+ {
862
+ if (desc.get()->eTypeClass != typelib_TypeClass_ENUM)
863
+ rb_raise(rb_eArgError, "wrong type name (%s)", RSTRING_PTR(type_name));
864
+
865
+ desc.makeComplete();
866
+
867
+ typelib_EnumTypeDescription *pEnumDesc = (typelib_EnumTypeDescription*) desc.get();
868
+ int i = 0;
869
+ for (i = 0; i < pEnumDesc->nEnumValues; i++)
870
+ {
871
+ if ((*((OUString*)&pEnumDesc->ppEnumNames[i])).compareToAscii(strValue) == 0)
872
+ {
873
+ break;
874
+ }
875
+ }
876
+ if (i == pEnumDesc->nEnumValues)
877
+ rb_raise(rb_eArgError, "wrong value (%s)", strValue);
878
+
879
+ Any a = Any(&pEnumDesc->pEnumValues[i], desc.get()->pWeakRef);
880
+ RubyunoValue *ptr;
881
+ Data_Get_Struct(self, RubyunoValue, ptr);
882
+ ptr->value = a;
883
+ }
884
+ else
885
+ {
886
+ rb_raise(rb_eArgError, "unknown type name (%s)", RSTRING_PTR(type_name));
887
+ }
888
+
889
+ rb_iv_set(self, "@type_name", type_name);
890
+ rb_iv_set(self, "@value", value);
891
+ return self;
892
+ }
893
+
894
+ static VALUE
895
+ rubyuno_enum_equal(VALUE self, VALUE object)
896
+ {
897
+ if (! object == CLASS_OF(get_enum_class()))
898
+ return Qfalse;
899
+ ID id = rb_intern("==");
900
+ VALUE self_type_name, self_value;
901
+
902
+ self_type_name = rb_iv_get(self, "@type_name");
903
+ self_value = rb_iv_get(self, "@value");
904
+ if (rb_funcall(self_type_name, id, 1, rb_iv_get(object, "@type_name")) &&
905
+ rb_funcall(self_value, id, 1, rb_iv_get(object, "@value")))
906
+ return Qtrue;
907
+ return Qfalse;
908
+ }
909
+
910
+ static VALUE
911
+ rubyuno_enum_inspect(VALUE self)
912
+ {
913
+ VALUE desc, type_name, value;
914
+ type_name = rb_iv_get(self, "@type_name");
915
+ value = rb_iv_get(self, "@value");
916
+ Check_Type(type_name, T_STRING);
917
+ Check_Type(value, T_STRING);
918
+
919
+ desc = rb_tainted_str_new("#<Rubyuno::Enum:", 13);
920
+ rb_str_cat(desc, RSTRING_PTR(type_name), RSTRING_LEN(type_name));
921
+ rb_str_cat(desc, ".", 1);
922
+ rb_str_cat(desc, RSTRING_PTR(value), RSTRING_LEN(value));
923
+ rb_str_cat(desc, ">", 1);
924
+ return desc;
925
+ }
926
+
927
+
928
+ /*
929
+ * Rubyuno::Type class
930
+ */
931
+ static VALUE
932
+ rubyuno_type_initialize(int argc, VALUE *argv, VALUE self)
933
+ {
934
+ VALUE type_name, type_class;
935
+ TypeDescription desc;
936
+
937
+ if (argc == 1)
938
+ {
939
+ VALUE value;
940
+ rb_scan_args(argc, argv, "1", &value);
941
+
942
+ if (TYPE(value) == T_STRING)
943
+ {
944
+ type_name = value;
945
+
946
+ OUString typeName = rbString2OUString(type_name);
947
+ desc = TypeDescription(typeName);
948
+ if (!desc.is())
949
+ rb_raise(rb_eArgError, "wrong type name (%s)", RSTRING_PTR(type_name));
950
+
951
+ Runtime runtime;
952
+ type_class = runtime.any_to_VALUE(Any((com::sun::star::uno::TypeClass)desc.get()->eTypeClass));
953
+ }
954
+ else if (CLASS_OF(value) == get_enum_class())
955
+ {
956
+ type_class = value;
957
+ VALUE enum_type_name = rb_iv_get(type_class, "@type_name");
958
+
959
+ if (strcmp(RSTRING_PTR(enum_type_name), "com.sun.star.uno.TypeClass"))
960
+ rb_raise(rb_eArgError, "invalid enum (%s)", RSTRING_PTR(value));
961
+
962
+ type_name = rb_iv_get(type_class, "@value");
963
+ OUString typeName = rbString2OUString(type_name);
964
+ desc = TypeDescription(typeName.toAsciiLowerCase());
965
+ if (!desc.is())
966
+ rb_raise(rb_eRuntimeError, "wrong enum value (%s)", RSTRING_PTR(type_name));
967
+ }
968
+ else
969
+ rb_raise(rb_eArgError, "wrong type (%s for String or Rubyuno::Enum)", rb_obj_classname(value));
970
+ }
971
+ else if (argc == 2)
972
+ {
973
+ rb_scan_args(argc, argv, "11", &type_name, &type_class);
974
+
975
+ Check_Type(type_name, T_STRING);
976
+ if (! CLASS_OF(type_class) == get_enum_class())
977
+ rb_raise(rb_eArgError, "Rubyuno::Enum is desired for 2nd argument.");
978
+
979
+ RubyunoValue *value;
980
+ Data_Get_Struct(type_class, RubyunoValue, value);
981
+ Any enumValue = value->value;
982
+ OUString typeName = rbString2OUString(type_name);
983
+ desc = TypeDescription(typeName);
984
+ if (!desc.is())
985
+ rb_raise(rb_eArgError, "wrong type name (%s)", RSTRING_PTR(type_name));
986
+ if (desc.get()->eTypeClass != (typelib_TypeClass)* (sal_Int32*)enumValue.getValue())
987
+ rb_raise(rb_eArgError, "nomatch with type name (%s)", RSTRING_PTR(type_name));
988
+ }
989
+ else
990
+ rb_raise(rb_eArgError, "too much arguments (%d for maximum 2)", argc);
991
+
992
+
993
+ Type t = desc.get()->pWeakRef;
994
+ Any a;
995
+ a <<= t;
996
+ RubyunoValue *rubyuno;
997
+ Data_Get_Struct(self, RubyunoValue, rubyuno);
998
+ rubyuno->value = a;
999
+
1000
+ rb_iv_set(self, "@type_name", type_name);
1001
+ rb_iv_set(self, "@type_class", type_class);
1002
+ return self;
1003
+ }
1004
+
1005
+ static VALUE
1006
+ rubyuno_type_equal(VALUE self, VALUE object)
1007
+ {
1008
+ if (! object == CLASS_OF(get_type_class()))
1009
+ return Qfalse;
1010
+
1011
+ ID id = rb_intern("==");
1012
+ VALUE type_name, type_class;
1013
+ type_name = rb_iv_get(self, "@type_name");
1014
+ type_class = rb_iv_get(self, "@type_class");
1015
+ if (rb_funcall(self, id, 1, rb_iv_get(object, "@type_name")) &&
1016
+ rb_funcall(self, id, 1, rb_iv_get(object, "@type_class")))
1017
+ return Qtrue;
1018
+
1019
+ return Qfalse;
1020
+ }
1021
+
1022
+ static VALUE
1023
+ rubyuno_type_inspect(VALUE self)
1024
+ {
1025
+ VALUE desc, type_name, type_class, value;
1026
+ type_name = rb_iv_get(self, "@type_name");
1027
+ type_class = rb_iv_get(self, "@type_class");
1028
+ Check_Type(type_name, T_STRING);
1029
+ if (!CLASS_OF(type_class) == get_enum_class())
1030
+ {
1031
+ rb_raise(rb_eRuntimeError, "unknown value for type_class (%s for Rubyuno::RubyunoEnum)", rb_obj_classname(type_class));
1032
+ }
1033
+ value = rb_iv_get(type_class, "@value");
1034
+
1035
+ desc = rb_tainted_str_new("#<Rubyuno::Type:", 13);
1036
+ rb_str_cat(desc, RSTRING_PTR(type_name), RSTRING_LEN(type_name));
1037
+ rb_str_cat(desc, "(", 1);
1038
+ rb_str_cat(desc, RSTRING_PTR(value), RSTRING_LEN(value));
1039
+ rb_str_cat(desc, ")>", 2);
1040
+ return desc;
1041
+ }
1042
+
1043
+ /*
1044
+ * Rubyuno::Char class
1045
+ */
1046
+ static VALUE
1047
+ rubyuno_char_initialize(VALUE self, VALUE char_value)
1048
+ {
1049
+ Check_Type(char_value, T_STRING);
1050
+ if (RSTRING_LEN(char_value) != 1)
1051
+ {
1052
+ rb_raise(rb_eArgError, "wrong length (%ld for 1)", RSTRING_LEN(char_value));
1053
+ }
1054
+ sal_Unicode c = rbString2OUString(char_value).toChar();
1055
+ Any a;
1056
+ a.setValue(&c, getCharCppuType());
1057
+ RubyunoValue *rubyuno;
1058
+ Data_Get_Struct(self, RubyunoValue, rubyuno);
1059
+ rubyuno->value = a;
1060
+
1061
+ rb_iv_set(self, "@value", char_value);
1062
+ return self;
1063
+ }
1064
+
1065
+ static VALUE
1066
+ rubyuno_char_equal(VALUE self, VALUE object)
1067
+ {
1068
+ if (!(CLASS_OF(object) == get_char_class() ||
1069
+ TYPE(object) == T_STRING))
1070
+ return Qfalse;
1071
+
1072
+ ID id = rb_intern("==");
1073
+ if (rb_funcall(object, id, 1, rb_iv_get(self, "@value")))
1074
+ return Qtrue;
1075
+
1076
+ return Qfalse;
1077
+ }
1078
+
1079
+ static VALUE
1080
+ rubyuno_char_inspect(VALUE self)
1081
+ {
1082
+ VALUE desc, value;
1083
+ value = rb_iv_get(self, "@value");
1084
+ Check_Type(value, T_STRING);
1085
+
1086
+ desc = rb_tainted_str_new("#<Rubyuno::Char:", 13);
1087
+ rb_str_cat(desc, RSTRING_PTR(value), RSTRING_LEN(value));
1088
+ rb_str_cat(desc, ">", 1);
1089
+ return desc;
1090
+ }
1091
+
1092
+
1093
+ static VALUE
1094
+ rubyuno_any_alloc(VALUE klass)
1095
+ {
1096
+ return Data_Wrap_Struct(klass, 0, 0, 0);
1097
+ }
1098
+
1099
+ /*
1100
+ * Rubyuno::Any class
1101
+ * Any class is not well processed at the constructing time.
1102
+ */
1103
+ static VALUE
1104
+ rubyuno_any_initialize(VALUE self, VALUE type, VALUE value)
1105
+ {
1106
+ if (rb_obj_is_kind_of(type, get_type_class()))
1107
+ {
1108
+ rb_iv_set(self, "@type", type);
1109
+ }
1110
+ else if (TYPE(type) == T_STRING)
1111
+ {
1112
+ VALUE type_value;
1113
+ type_value = rb_funcall(get_type_class(), rb_intern("new"), 1, type);
1114
+ rb_iv_set(self, "@type", type_value);
1115
+ }
1116
+ else
1117
+ {
1118
+ rb_raise(rb_eArgError, "invalid type for type.");
1119
+ }
1120
+ rb_iv_set(self, "@value", value);
1121
+
1122
+ return self;
1123
+ }
1124
+
1125
+ static VALUE
1126
+ rubyuno_any_equal(VALUE self, VALUE object)
1127
+ {
1128
+ if (! CLASS_OF(self) == get_any_class())
1129
+ return Qfalse;
1130
+
1131
+ ID id = rb_intern("==");
1132
+ VALUE type, value;
1133
+ type = rb_iv_get(self, "@type");
1134
+ value = rb_iv_get(self, "@value");
1135
+
1136
+ if (rb_funcall(type, id, 1, rb_iv_get(object, "@type")) &&
1137
+ rb_funcall(value, id, 1, rb_iv_get(object, "@value")))
1138
+ return Qtrue;
1139
+
1140
+ return Qfalse;
1141
+ }
1142
+
1143
+
1144
+ static void
1145
+ rubyuno_value_free(RubyunoValue *rubyuno)
1146
+ {
1147
+ if (rubyuno)
1148
+ {
1149
+ rubyuno->value.clear();
1150
+ delete rubyuno;
1151
+ }
1152
+ }
1153
+
1154
+ static VALUE
1155
+ rubyuno_value_alloc(VALUE klass)
1156
+ {
1157
+ RubyunoValue *ptr;
1158
+ ptr = new RubyunoValue();
1159
+ return Data_Wrap_Struct(klass, 0, rubyuno_value_free, ptr);
1160
+ }
1161
+
1162
+ }
1163
+
1164
+ extern "C"
1165
+ {
1166
+ void
1167
+ Init_rubyuno(void)
1168
+ {
1169
+ VALUE Rubyuno;
1170
+ Rubyuno = rb_define_module("Rubyuno");
1171
+ rb_define_module_function(Rubyuno, "get_component_context", (VALUE(*)(...))rubyuno_getComponentContext, 0);
1172
+ rb_define_module_function(Rubyuno, "system_path_to_file_url", (VALUE(*)(...))rubyuno_getFileURLFromSystemPath, 1);
1173
+ rb_define_module_function(Rubyuno, "file_url_to_system_path", (VALUE(*)(...))rubyuno_getSystemPathFromFileURL, 1);
1174
+ rb_define_module_function(Rubyuno, "absolutize", (VALUE(*)(...))rubyuno_absolutize, 2);
1175
+ rb_define_module_function(Rubyuno, "uuid", (VALUE(*)(...))rubyuno_create_uuid, 0);
1176
+ rb_define_module_function(Rubyuno, "uno_require", (VALUE(*)(...))rubyuno_uno_multiple_require, -1);
1177
+ rb_define_module_function(Rubyuno, "invoke", (VALUE(*)(...))rubyuno_invoke, 3);
1178
+
1179
+ VALUE RubyunoProxy;
1180
+ RubyunoProxy = rb_define_class_under(Rubyuno, "RubyunoProxy", rb_cData);
1181
+ rb_define_alloc_func(RubyunoProxy, rubyuno_proxy_alloc);
1182
+ rb_define_method(RubyunoProxy, "method_missing", (VALUE(*)(...))rubyuno_proxy_method_missing, -1);
1183
+ rb_define_method(RubyunoProxy, "inspect", (VALUE(*)(...))rubyuno_proxy_inspect, 0);
1184
+ rb_define_method(RubyunoProxy, "==", (VALUE(*)(...))rubyuno_proxy_equal, 1);
1185
+ rb_define_method(RubyunoProxy, "uno_methods", (VALUE(*)(...))rubyuno_uno_methods, 0);
1186
+ rb_define_method(RubyunoProxy, "has_interface?", (VALUE(*)(...))rubyuno_proxy_has_interface, 1);
1187
+
1188
+ VALUE RubyunoEnum;
1189
+ RubyunoEnum = rb_define_class_under(Rubyuno, "Enum", rb_cObject);
1190
+ rb_define_alloc_func(RubyunoEnum, rubyuno_value_alloc);
1191
+ rb_define_method(RubyunoEnum, "initialize", (VALUE(*)(...))rubyuno_enum_initialize, 2);
1192
+ rb_define_method(RubyunoEnum, "==", (VALUE(*)(...))rubyuno_enum_equal, 1);
1193
+ rb_define_attr(RubyunoEnum, "type_name", 1, 0);
1194
+ rb_define_attr(RubyunoEnum, "value", 1, 0);
1195
+ rb_define_method(RubyunoEnum, "inspect", (VALUE(*)(...))rubyuno_enum_inspect, 0);
1196
+
1197
+ VALUE RubyunoType;
1198
+ RubyunoType = rb_define_class_under(Rubyuno, "Type", rb_cObject);
1199
+ rb_define_alloc_func(RubyunoType, rubyuno_value_alloc);
1200
+ rb_define_method(RubyunoType, "initialize", (VALUE(*)(...))rubyuno_type_initialize, -1);
1201
+ rb_define_method(RubyunoType, "==", (VALUE(*)(...))rubyuno_type_equal, 1);
1202
+ rb_define_attr(RubyunoType, "type_name", 1, 0);
1203
+ rb_define_attr(RubyunoType, "type_class", 1, 0);
1204
+ rb_define_method(RubyunoType, "inspect", (VALUE(*)(...))rubyuno_type_inspect, 0);
1205
+
1206
+ VALUE RubyunoChar;
1207
+ RubyunoChar = rb_define_class_under(Rubyuno, "Char", rb_cObject);
1208
+ rb_define_alloc_func(RubyunoChar, rubyuno_value_alloc);
1209
+ rb_define_method(RubyunoChar, "initialize", (VALUE(*)(...))rubyuno_char_initialize, 1);
1210
+ rb_define_method(RubyunoChar, "==", (VALUE(*)(...))rubyuno_char_equal, 1);
1211
+ rb_define_attr(RubyunoChar, "value", 1, 0);
1212
+ rb_define_method(RubyunoChar, "inspect", (VALUE(*)(...))rubyuno_char_inspect, 0);
1213
+
1214
+ VALUE RubyunoAny;
1215
+ RubyunoAny = rb_define_class_under(Rubyuno, "Any", rb_cObject);
1216
+ rb_define_alloc_func(RubyunoAny, rubyuno_any_alloc);
1217
+ rb_define_method(RubyunoAny, "initialize", (VALUE(*)(...))rubyuno_any_initialize, 2);
1218
+ rb_define_method(RubyunoAny, "==", (VALUE(*)(...))rubyuno_any_equal, 1);
1219
+ rb_define_attr(RubyunoAny, "type", 1, 1);
1220
+ rb_define_attr(RubyunoAny, "value", 1, 1);
1221
+
1222
+ VALUE RubyunoByteSequence;
1223
+ RubyunoByteSequence = rb_define_class_under(Rubyuno, "ByteSequence", rb_cString);
1224
+
1225
+ VALUE RubyunoStruct;
1226
+ RubyunoStruct = rb_define_class_under(Rubyuno, "RubyunoStruct", rb_cObject);
1227
+ rb_define_alloc_func(RubyunoStruct, rubyuno_struct_alloc);
1228
+ rb_define_method(RubyunoStruct, "initialize", (VALUE(*)(...))rubyuno_struct_initialize, -1);
1229
+ rb_define_method(RubyunoStruct, "method_missing", (VALUE(*)(...))rubyuno_proxy_method_missing, -1);
1230
+ rb_define_method(RubyunoStruct, "==", (VALUE(*)(...))rubyuno_struct_equal, 1);
1231
+ rb_define_method(RubyunoStruct, "uno_methods", (VALUE(*)(...))rubyuno_uno_methods, 0);
1232
+
1233
+ VALUE Com, Sun, Star, Uno;
1234
+ Com = rb_define_module_under(Rubyuno, "Com");
1235
+ Sun = rb_define_module_under(Com, "Sun");
1236
+ Star = rb_define_module_under(Sun, "Star");
1237
+
1238
+ Uno = rb_define_module_under(Star, "Uno");
1239
+
1240
+ VALUE RubyunoException;
1241
+ RubyunoException = rb_define_class_under(Uno, "Exception", rb_eStandardError);
1242
+ //rb_define_alloc_func(RubyunoException, rubyuno_struct_alloc);
1243
+ rb_define_method(RubyunoException, "initialize", (VALUE(*)(...))rubyuno_exception_initialize, 1);
1244
+ rb_define_method(RubyunoException, "method_missing", (VALUE(*)(...))rubyuno_proxy_method_missing, -1);
1245
+ rb_define_method(RubyunoException, "==", (VALUE(*)(...))rubyuno_struct_equal, 1);
1246
+ //rb_define_method(RubyunoException, "uno_methods", (VALUE(*)(...))rubyuno_uno_methods, 0);
1247
+ //rb_define_attr(RubyunoException, "uno", 1, 1);
1248
+
1249
+ /*
1250
+ VALUE RubyunoException2;
1251
+ RubyunoException2 = rb_define_class_under(Rubyuno, "Exception", rb_eStandardError);
1252
+ rb_define_alloc_func(RubyunoException2, rubyuno_struct_alloc);
1253
+ rb_define_method(RubyunoException2, "initialize", (VALUE(*)(...))rubyuno_exception2_initialize, 1);
1254
+ */
1255
+
1256
+ VALUE XInterface;
1257
+ XInterface = rb_define_module_under(Uno, "XInterface");
1258
+ rb_define_const(XInterface, "TYPENAME", rb_str_new("com.sun.star.uno.XInterface", 27));
1259
+
1260
+ init_external_encoding();
1261
+ }
1262
+ }
1263
+