-
Notifications
You must be signed in to change notification settings - Fork 2
/
clorb-ifr.lisp
1411 lines (1100 loc) · 47 KB
/
clorb-ifr.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;; clorb-ifr.lisp -- An Interface Repository Implementation
(in-package :clorb)
;;;; Registry of Ir class for DefinitionKind
(defun register-ir-class (def-kind class)
(setf (get def-kind 'ir-class) class))
;;;; Generics
(defgeneric moveto (contained container new-name new-version)
(:documentation "Move the contained object to the container,
with new-name and new-version. Checks that the name does not collide
with the contents of container and check the container allows the type
of contained."))
;;;; Base Clases
(defmacro define-ir-class (name supers
&rest args
&key id def_kind &allow-other-keys)
(declare (ignore id))
(setq args
(loop for x on args by #'cddr
unless (member (car x) '(:id :def_kind))
nconc (list (car x) (cadr x))))
`(progn (define-corba-class ,name ,supers ,@args)
,@(if def_kind
`((define-method def_kind ((x ,name)) ,def_kind)
(register-ir-class ,def_kind ',name)))))
(define-ir-class IRObject (CORBA:IRObject)
:id "IDL:omg.org/CORBA/IRObject:1.0"
:attributes ()
:defaults ())
(define-method op:destroy ((obj IRObject))
nil)
(defclass IRTypeCode-Mixin ()
((type)))
(defgeneric idltype-tc (irtypecode-mixin)
(:documentation
"Compute the TypeCode from the attributes other than type."))
(define-method type ((def irtypecode-mixin))
;; Get the typecode for an IDL construct.
;; The typecode is lazily constructed and recursive typecodes handled.
;; The specific typcodes are handled by the idltype-tc function.
(cond ((slot-boundp def 'type)
;; Either the typecode is computed already or this is a recursive call
;; during computation.
(let ((tc (slot-value def 'type)))
(cond ((eq t tc)
;; Beeing computed, make a placeholder typecode.
;; This typecode will be filled when the computation is done.
(setf (slot-value def 'type) (make-typecode :recursive)))
(t
tc))))
(t
;; Typecode not defined, start computation
;; mark computation with a t in the slot
(setf (slot-value def 'type) t)
(let* ((new-tc (idltype-tc def))
(old-tc (slot-value def 'type)))
(cond ((eq old-tc t)
(setf (slot-value def 'type) new-tc))
(t
;; therse was a recurive access during computation
(typecode-smash old-tc new-tc)
old-tc))))))
(defmethod slot-updated :after ((obj irtypecode-mixin))
(slot-makunbound obj 'type))
(define-ir-class IDLType (CORBA:IDLType IRObject irtypecode-mixin)
:id "IDL:omg.org/CORBA/IDLType:1.0"
:attributes ()
:defaults ())
;;;; Contained
(define-ir-class Contained (CORBA:Contained irobject)
:attributes ((id :readonly ; setter defined below
:initarg :subject-id
:accessor subject-id)
(name "")
(version "1.0")
(defined_in nil :readonly)
;;(absolute_name "" :readonly)
(containing_repository :readonly))
:slots ((absolute_name :initarg :absolute_name)
(package-prefix :initform "" :accessor package-prefix)))
(defmethod print-object ((obj contained) stream)
(print-unreadable-object (obj stream :type t :identity t)
(format stream "~A" (slot-value obj 'name))))
(defmethod (setf op:id) (new-id (obj contained))
(let ((repository (op:containing_repository obj))
(old-id (op:id obj)))
(unless (equal new-id old-id)
(when (gethash new-id (idmap repository))
(error (system-exception 'CORBA:BAD_PARAM 2)))
(remhash old-id (idmap repository))
(setf (gethash new-id (idmap repository)) obj)
(setf (slot-value obj 'id) new-id))))
(defmethod (setf op:name) :before (value (obj contained))
(loop for peer in (contents (op:defined_in obj))
unless (eq obj peer)
do (when (string-equal value (op:name peer))
(raise-system-exception 'CORBA:bad_param 1))))
(define-method absolute_name ((obj contained))
(unless (and (slot-boundp obj 'absolute_name)
(not (equal (slot-value obj 'absolute_name)
"")))
(setf (slot-value obj 'absolute_name)
(concatenate 'string
(op:absolute_name (op:defined_in obj)) "::" (op:name obj))))
(slot-value obj 'absolute_name))
(defmethod slot-updated :after ((obj contained))
(slot-makunbound obj 'absolute_name))
(define-method describe ((obj contained))
(CORBA:Contained/Description
:kind (op:def_kind obj)
:value (describe-contained obj)))
(define-method "MOVE" ((obj contained) to-container new-name new-version)
(check-type to-container CORBA:Container)
(check-type new-name string)
(check-type new-version string)
(unless (eql (op:containing_repository obj)
(op:containing_repository to-container))
(raise-system-exception 'CORBA:BAD_PARAM 4))
(moveto to-container obj new-name new-version))
(define-method op:destroy ((obj contained))
(remhash (subject-id obj) (idmap (op:containing_repository obj)))
(let ((container (op:defined_in obj)))
(when container
(setf (contents container)
(delete obj (contents container))))))
;;;; Container
(define-ir-class Container (CORBA:Container irobject)
:slots ((contents :initarg :contents
:initform '()
:accessor contents)))
(defmethod slot-updated :after ((obj Container))
(dolist (c (contents obj)) (slot-updated c)))
(defun addto (container object)
"Add a contained object to a container"
(let ((repository (op:containing_repository container))
(id (op:id object)))
;; A BAD_PARAM exception is raised with minor code 2 if an object with
;; the specified id already exists in the Repository.
(when (gethash id (idmap repository))
(raise-system-exception 'CORBA:BAD_PARAM 2))
(moveto container object (op:name object) (op:version object))
(setf (gethash id (idmap repository)) object)))
(defmethod moveto ((c container) (object contained) new-name new-version)
;; A BAD_PARAM exception with minor code 3 is raised if the specified
;; name already exists within this Container and multiple versions are
;; not supported.
(when (member new-name (contents c) :key #'op:name :test #'string-equal)
(raise-system-exception 'CORBA:bad_param 3))
(with-slots (defined_in containing_repository name version)
object
(let ((old-container defined_in))
(when old-container
(setf (contents old-container) (delete object (contents old-container)))))
(setf (contents c) (nconc (contents c) (list object)))
(setf containing_repository (op:containing_repository c))
(setf defined_in c)
(setf name new-name)
(setf version new-version)
(slot-updated object))
object)
(define-method contents ((obj container) limit-type exclude-inherit)
(declare (ignore exclude-inherit))
;; exclude-inherit only aplicable for operations???
(loop for contained in (contents obj)
when (and (or (eql limit-type :dk_all)
(eql limit-type (op:def_kind contained))))
collect contained))
(define-method lookup_name
((obj container) search-name levels-to-search limit-type exclude-inherit)
(loop for contained in (op:contents obj limit-type exclude-inherit)
when (equal search-name (op:name contained))
collect contained into top-level
when (and (containerp contained)
(or (> levels-to-search 1) (= levels-to-search -1)))
collect (op:lookup_name contained search-name
(if (= levels-to-search -1)
-1
(1- levels-to-search))
limit-type exclude-inherit)
into sub-levels
finally (return (mapcan #'identity (cons top-level sub-levels)))))
(defgeneric containerp (x)
(:method ((x t)) nil)
(:method ((x container)) t))
(define-method lookup ((obj null) search_name)
(declare (ignore search_name))
nil)
(define-method lookup ((obj container) search_name)
(cond ((string-starts-with search_name "::")
(op:lookup (op:containing_repository obj)
(subseq search_name 2)))
(t
(multiple-value-bind (first-name rest-name)
(split-name search_name)
(let ((contained
(find first-name (op:contents obj :dk_all nil)
:key #'op:name
:test #'string-equal)))
(cond ((null contained)
(op:lookup (op:defined_in obj) search_name))
(rest-name
(op:lookup contained rest-name))
(t
contained)))))))
(defun split-name (str)
(let ((method-end (position #\: str)))
(if method-end
(values (subseq str 0 method-end)
(subseq str (+ method-end 2)))
str )))
(define-method op:describe_contents ((self container) limit-type exclude-inherited max-return-objects)
(when (eql max-return-objects -1)
(setq max-return-objects most-positive-fixnum))
(loop for c in (op:contents self limit-type exclude-inherited)
repeat max-return-objects
collect (CORBA:Container/Description
:contained_object c
:kind (op:def_kind c)
:value (describe-contained c))))
;;; ModuleDef create_module (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version
(define-method create_module ((self container) id name version)
(addto self (make-instance 'module-def
:id id :name name :version version)))
;;; ConstantDef create_constant (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in IDLType type,
;;; in any value )
(define-method create_constant ((self container)
id name version type value)
(addto self (make-instance 'constant-def
:id id :name name :version version
:type_def type :value value)))
;;; StructDef create_struct (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in StructMemberSeq members
(define-method create_struct ((self container)
id name version members)
(let ((obj (make-instance 'struct-def
:id id :name name :version version)))
(setf (op:members obj) members)
(addto self obj)))
;;; /* This operation is missing in the CORBA2 spec! */
;;; ExceptionDef create_exception (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in StructMemberSeq members
;;; );
(define-method create_exception ((self container)
id name version members)
(addto self (make-instance 'exception-def
:id id
:name name
:version version
:members members)))
;;; UnionDef create_union (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in IDLType discriminator_type,
;;; in UnionMemberSeq members );
(define-method create_union ((self container)
id name version discriminator_type members)
(check-type discriminator_type CORBA:IDLType)
(assert (and (typep members 'sequence)
(every (lambda (x) (typep x 'CORBA:UnionMember))
members))
(members)
'type-error :datum 'members :expected-type 'corba:unionmemberseq)
(addto self (make-instance 'union-def
:id id :name name :version version
:discriminator_type_def discriminator_type
:members members)))
;;; EnumDef create_enum (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in EnumMemberSeq members
;;; );
(define-method create_enum ((self container)
id name version members)
(addto self (make-instance 'enum-def
:id id :name name :version version
:members members)))
;;; AliasDef create_alias (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in IDLType original_type );
(define-method create_alias ((self container)
id name version original_type)
(addto self (make-instance 'alias-def
:id id :name name :version version
:original_type_def original_type)))
;;; InterfaceDef create_interface (
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in InterfaceDefSeq base_interfaces );
(define-method create_interface ((self container)
id name version base_interfaces)
(addto self (make-instance 'interface-def
:id id :name name :version version
:base_interfaces base_interfaces)))
;;; ValueBoxDef create_value_box(
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in IDLType original_type_def
(define-method create_value_box ((self container)
id name version original_type_def)
(addto self (make-instance 'valuebox-def
:id id :name name :version version
:original_type_def original_type_def)))
;;; NativeDef create_native(
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version
(define-method create_native ((self container) id name version )
(addto self (make-instance 'native-def
:id id :name name :version version )))
;;; AbstractInterfaceDef create_abstract_interface(
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in AbstractInterfaceDefSeq base_interfaces
(define-method create_abstract_interface ((self container)
id name version base_interfaces)
(addto self (make-instance 'abstractinterface-def
:id id :name name :version version
:base_interfaces base_interfaces)))
;;; LocalInterfaceDef create_local_interface(
;;; in RepositoryId id,
;;; in Identifier name,
;;; in VersionSpec version,
;;; in InterfaceDefSeq base_interfaces
(define-method create_local_interface ((self container)
id name version base_interfaces)
(addto self (make-instance 'localinterface-def
:id id :name name :version version
:base_interfaces base_interfaces)))
;;; ValueDef create_value
(define-method create_value ((self container)
id name version is_custom is_abstract
base_value is_truncatable abstract_base_values
supported_interfaces initializers)
(check-type id CORBA:RepositoryId)
(check-type name CORBA:Identifier)
(check-type version CORBA:VersionSpec)
(check-type is_custom CORBA:boolean)
(check-type is_abstract CORBA:boolean)
(check-type base_value (or null CORBA:ValueDef))
(check-type is_truncatable CORBA:boolean)
(check-type abstract_base_values CORBA:ValueDefSeq)
(check-type supported_interfaces CORBA:InterfaceDefSeq)
(check-type initializers CORBA:InitializerSeq)
(addto self (make-instance 'value-def
:id id :name name :version version
:is_custom is_custom :is_abstract is_abstract
:base_value base_value :is_truncatable is_truncatable
:abstract_base_values abstract_base_values
:supported_interfaces supported_interfaces
:initializers initializers)))
(define-method op:destroy ((obj container))
(dolist (x (contents obj))
(op:destroy x))
(call-next-method))
;;;; interface Repository : Container
(define-ir-class Repository (CORBA:Repository Container)
:def_kind :dk_repository
:slots ((idmap :initform (make-hash-table :test #'equal)
:reader idmap)
(primitives-cache
:initform nil
:accessor primitives-cache )))
;;; Method to simplify computation of absolute_name
(define-method absolute_name ((obj Repository))
"")
(define-method containing_repository ((r Repository))
r)
(defmethod subject-id ((r repository))
"")
;;; Contained lookup_id (in RepositoryId search_id);
(define-method lookup_id ((rep repository) id)
(gethash id (idmap rep)))
;;; TypeCode get_canonical_typecode(in TypeCode tc);
(define-method get_canonical_typecode ((container Repository) tc)
(flet ((reconstruct ()
(map-typecode (lambda (tc) (op:get_canonical_typecode container tc))
tc)))
(handler-case
(let ((id (op:id tc)))
(let ((obj (op:lookup_id container id)))
(if obj
(op:type obj)
(reconstruct))))
(CORBA:TYPECODE/BADKIND () (reconstruct)))))
;;; PrimitiveDef get_primitive (in PrimitiveKind kind);
(define-method get_primitive ((container Repository) kind)
(with-accessors ((cache primitives-cache)) container
(unless cache
(setf cache
(loop for (kind tc)
in '((:pk_null CORBA:tc_null)
(:pk_void CORBA:tc_void)
(:pk_short CORBA:tc_short)
(:pk_long CORBA:tc_long)
(:pk_ushort CORBA:tc_ushort)
(:pk_ulong CORBA:tc_ulong)
(:pk_float CORBA:tc_float)
(:pk_double CORBA:tc_double)
(:pk_boolean CORBA:tc_boolean)
(:pk_char CORBA:tc_char)
(:pk_octet CORBA:tc_octet)
(:pk_any CORBA:tc_any)
(:pk_typecode CORBA:tc_TypeCode)
;;(:pk_Principal CORBA:tc_Principal)
(:pk_string CORBA:tc_string)
(:pk_objref CORBA:tc_object)
(:pk_longlong CORBA:tc_longlong)
(:pk_ulonglong CORBA:tc_ulonglong)
(:pk_longdouble CORBA:tc_longdouble)
(:pk_wchar CORBA:tc_wchar)
(:pk_wstring CORBA:tc_wstring)
(:pk_value_base corba:tc_valuebase))
collect (make-instance 'primitive-def :kind kind
:type (symbol-value tc)))))
(find kind cache :key #'op:kind)))
;;; StringDef create_string (in unsigned long bound);
(define-method create_string ((container Repository) bound)
(make-instance 'string-def
:bound bound))
;;; WstringDef create_wstring (in unsigned long bound);
(define-method create_wstring ((container Repository) bound)
(make-instance 'wstring-def
:bound bound))
;;; SequenceDef create_sequence
;;; (in unsigned long bound,in IDLType element_type);
(define-method create_sequence ((container Repository) bound element-type)
(check-type bound integer)
(check-type element-type corba:idltype)
(make-instance 'sequence-def
:bound bound
:element_type_def element-type))
;;; ArrayDef create_array
;;; (in unsigned long length,in IDLType element_type);
(define-method create_array ((container Repository) length element_type)
(make-instance 'array-def
:length length
:element_type_def element_type))
;;; FixedDef create_fixed
;;; (in unsigned short digits,in short scale);
(define-method create_fixed ((container Repository) digits scale)
(make-instance 'fixed-def
:digits digits
:scale scale))
(define-method op:destroy ((obj repository))
(raise-system-exception 'omg.org/corba:bad_inv_order
2 :completed_yes))
;;;; ModuleDef
(define-ir-class module-def (CORBA:ModuleDef container contained)
:def_kind :dk_module)
(defmethod describe-contained ((module module-def))
(CORBA:ModuleDescription
:name (op:name module)
:id (op:id module)
:defined_in (subject-id (op:defined_in module))
:version (op:version module)))
;;;; interface ConstantDef : Contained
;;; readonly attribute TypeCode type;
;;; attribute IDLType type_def;
;;; attribute any value;
(define-ir-class constant-def (CORBA:ConstantDef contained)
:def_kind :dk_constant
:attributes ((type_def)
(value)))
(define-method type ((obj constant-def))
(op:type (op:type_def obj)))
(defmethod describe-contained ((def constant-def))
(CORBA:ConstantDescription
:name (op:name def)
:id (subject-id def)
:defined_in (subject-id (op:defined_in def))
:version (op:version def)
:type (op:type def)
:value (op:value def) ))
;;;; InterfaceDef
(define-ir-class interface-def (CORBA:InterfaceDef container contained idltype)
:def_kind :dk_interface
:attributes ((base_interfaces)))
(defmethod idltype-tc ((idef interface-def))
(create-interface-tc (subject-id idef) (op:name idef)))
(define-method is_a ((def interface-def) interface-id)
(or
(equal (subject-id def) interface-id)
(equal interface-id (symbol-ifr-id 'corba:object))
(some (lambda (b) (equal interface-id (op:id b)))
(op:base_interfaces def))))
(define-method describe_interface ((def interface-def))
(CORBA:InterfaceDef/FullInterfaceDescription
:name (op:name def)
:id (subject-id def)
:defined_in (subject-id (op:defined_in def))
:version (op:version def)
:operations (map 'list #'operation-description
(op:contents def :dk_operation nil))
:attributes (map 'list #'describe-contained
(op:contents def :dk_attribute nil))
:base_interfaces (map 'list #'subject-id (op:base_interfaces def))
:type (op:type def) ))
(defmethod describe-contained ((def interface-def))
(CORBA:InterfaceDescription
:name (op:name def)
:id (subject-id def)
:defined_in (subject-id (op:defined_in def))
:version (op:version def)
:base_interfaces (map 'list #'subject-id (op:base_interfaces def))))
(define-method contents ((obj interface-def) limit-type exclude-inherit)
(if exclude-inherit
(call-next-method)
(append (call-next-method)
(loop for x in (coerce (op:base_interfaces obj) 'list)
append (op:contents x limit-type nil)))))
(defun check-unique-name (container name &key (minor 3))
(when (op:lookup_name container name 1 :dk_all nil)
(raise-system-exception 'CORBA:bad_param minor)))
(define-method (setf op:base_interfaces) :before (value (self interface-def))
(loop for obj in (contents self) do
(loop for base in value do
(check-unique-name base (op:name obj) :minor 5))))
;;; AttributeDef create_attribute
(define-method create_attribute ((self interface-def)
id name version type mode)
(check-type id string) ; RepositoryId
(check-type name string) ; Identifier
(check-type version string) ; VersionSpec
(check-type type IDLType)
(check-type mode CORBA:AttributeMode)
(check-unique-name self name)
(addto self (make-instance 'attribute-def
:id id :name name :version version
:type_def type :mode mode)))
;;; OperationDef create_operation
(define-method create_operation ((self interface-def)
id name version
result mode params exceptions contexts)
(check-type id string) ; RepositoryId
(check-type name string) ; Identifier
(check-type version string) ; VersionSpec
(check-type result IDLType)
(check-type mode CORBA:OperationMode)
(check-type params CORBA:ParDescriptionSeq)
(check-type exceptions CORBA:ExceptionDefSeq)
(check-type contexts CORBA:ContextIdSeq)
(check-unique-name self name)
(addto self (make-instance 'operation-def
:id id :name name :version version
:result_def result :mode mode
:params params :exceptions exceptions
:contexts contexts)))
;;;; AttributeDef
(define-ir-class attribute-def (CORBA:AttributeDef contained)
:def_kind :dk_attribute
:attributes ((type_def)
(mode)))
(define-method type ((adef attribute-def))
(op:type (op:type_def adef)))
(defmethod describe-contained ((adef attribute-def))
(CORBA:AttributeDescription
;; Identifier name
:name (op:name adef)
;; RepositoryId id
:id (op:id adef)
;; RepositoryId defined_in
:defined_in (subject-id (op:defined_in adef))
;; VersionSpec version
:version (op:version adef)
;; TypeCode type
:type (op:type adef)
;; AttributeMode mode
:mode (op:mode adef)))
;;;; OperationDef
(define-ir-class operation-def (CORBA:OperationDef contained)
:def_kind :dk_operation
:attributes ((result :readonly :virtual result)
(result_def)
(params nil)
(mode ':op_normal)
(contexts nil)
(exceptions nil)))
(defun validate-operation-def (mode result params exceptions)
(when (eq mode :op_oneway)
(unless (and (eq :tk_void (op:kind (op:type result)))
(zerop (length exceptions))
(every (lambda (p)
(eq :param_in (op:mode p)))
params))
(raise-system-exception 'CORBA:bad_param 31 :completed_yes))))
(defun validate-operation-def-change (def &key
(mode (op:mode def))
(result (op:result_def def))
(params (slot-value def 'params))
(exceptions (op:exceptions def)))
(validate-operation-def mode result params exceptions))
(defmethod initialize-instance :before ((def operation-def)
&key result_def mode params exceptions)
(validate-operation-def mode result_def params exceptions))
(defmethod (setf op:result_def) :before (new (def operation-def))
(validate-operation-def-change def :result new))
(defmethod (setf op:mode) :before (new (def operation-def))
(validate-operation-def-change def :mode new))
(defmethod (setf op:params) :before (new (def operation-def))
(validate-operation-def-change def :params new))
(defmethod (setf op:exceptions) :before (new (def operation-def))
(validate-operation-def-change def :exceptions new))
(defmethod result ((opdef operation-def))
(op:type (slot-value opdef 'result_def)))
(defmethod op:params :before ((opdef operation-def) &key)
(doseq (pd (slot-value opdef 'params))
(setf (op:type pd) (op:type (op:type_def pd)))))
(defmethod opdef-inparam-typecodes ((opdef operation-def))
(loop for param in (op:params opdef)
unless (eq (op:mode param) :param_out)
collect (op:type param)))
#+unused-defuns
(defmethod opdef-outparam-typecodes ((opdef operation-def))
(let ((real-params
(loop for param in (op:params opdef)
unless (eq (op:mode param) :param_in)
collect (op:type param)))
(result (op:result opdef)))
(if (eq :tk_void (typecode-kind result))
real-params
(cons result real-params))))
(defun operation-description (opdef)
;; struct OperationDescription
(CORBA:OperationDescription
;; Identifier name;
:name (op:name opdef)
;; RepositoryId id;
:id (op:id opdef)
;; RepositoryId defined_in;
:defined_in (op:id (op:defined_in opdef))
;; VersionSpec version;
:version (op:version opdef)
;; TypeCode result;
:result (op:result opdef)
;; OperationMode mode;
:mode (op:mode opdef)
;; ContextIdSeq contexts;
:contexts (op:contexts opdef)
;; ParDescriptionSeq parameters;
:parameters (op:params opdef)
;; ExcDescriptionSeq exceptions;
:exceptions (map 'list
'describe-contained (op:exceptions opdef))))
(defmethod describe-contained ((obj operation-def))
(operation-description obj))
;;;; TypedefDef
(define-ir-class typedef-def (CORBA:TypedefDef contained idltype)
:def_kind :dk_typedef)
(defmethod describe-contained ((obj typedef-def))
(CORBA:TypeDescription
;; Identifier name
:name (op:name obj)
;; RepositoryId id
:id (op:id obj)
;; RepositoryId defined_in
:defined_in (subject-id (op:defined_in obj))
;; VersionSpec version
:version (op:version obj)
;; TypeCode type
:type (op:type obj)))
;;;; interface AliasDef : TypedefDef
;; attribute IDLType original_type_def;
(define-ir-class alias-def (corba:AliasDef typedef-def)
:def_kind :dk_alias
:attributes ((original_type_def)))
(defmethod idltype-tc ((def alias-def))
(create-alias-tc (op:id def) (op:name def)
(op:type (op:original_type_def def))))
(define-method op:destroy ((obj alias-def))
(let ((orig (op:original_type_def obj)))
(when (and (typep orig 'CORBA:IDLtype)
(typep orig 'CORBA:Contained))
(op:destroy orig)))
(call-next-method))
;;;; interface StructDef : TypedefDef
;; attribute StructMemberSeq members;
;; struct StructMember {
;; Identifier name;
;; TypeCode type;
;; IDLType type_def;
(define-ir-class struct-def (corba:StructDef typedef-def container)
:def_kind :dk_struct
:attributes ((members)))
(defmethod op:members :before ((obj struct-def) &rest x)
(declare (ignore x))
(doseq (m (slot-value obj 'members))
(setf (op:type m) (op:type (op:type_def m)))))
(defmethod idltype-tc ((def struct-def))
(create-struct-tc (op:id def) (op:name def) (simple-struct-members (op:members def))))
;;;; interface UnionDef : TypedefDef
;;; readonly attribute TypeCode discriminator_type;
;;; attribute IDLType discriminator_type_def;
;;; attribute UnionMemberSeq members;
;;; struct UnionMember {
;;; Identifier name;
;;; any label;
;;; TypeCode type;
;;; IDLType type_def;
;;; typedef sequence <UnionMember> UnionMemberSeq;
(define-ir-class union-def (CORBA:UnionDef typedef-def container)
:def_kind :dk_union
:attributes ((discriminator_type_def)
(members)))
(define-method discriminator_type ((obj union-def))
(op:type (op:discriminator_type_def obj)))
(defmethod op:members :before ((self union-def) &rest args)
(declare (ignore args))
(doseq (member (slot-value self 'members))
(setf (op:type member) (op:type (op:type_def member)))))
(defmethod idltype-tc ((obj union-def))
;; FIXME: should be simpler to use op:create_union_tc
(flet ((default-label-p (label)
(and (not (symbolp label))
(eql :tk_octet (op:kind (any-typecode label)))
(= 0 (any-value label)))))
(create-union-tc (op:id obj) (op:name obj)
(op:discriminator_type obj)
(map 'list (lambda (m)
(list (if (default-label-p (op:label m))
'default
(op:label m))
(op:name m)
(op:type m)))
(op:members obj)))))
;;;; interface EnumDef : TypedefDef
;;; attribute EnumMemberSeq members;
(define-ir-class enum-def (corba:EnumDef typedef-def)
:def_kind :dk_enum
:attributes ((members)))
(defmethod idltype-tc ((obj enum-def))
(create-enum-tc (op:id obj) (op:name obj) (op:members obj)))
;;;; interface ExceptionDef : Contained, Container
;;; readonly attribute TypeCode type;
;;; attribute StructMemberSeq members;
(define-ir-class exception-def (corba:ExceptionDef contained container
irtypecode-mixin)
:def_kind :dk_exception
:attributes ((members)))
(defmethod op:members :before ((obj exception-def) &rest x)
(declare (ignore x))
(doseq (m (slot-value obj 'members))
(setf (op:type m) (op:type (op:type_def m)))))
(defmethod idltype-tc ((obj exception-def))
(create-exception-tc (op:id obj) (op:name obj)
(simple-struct-members (op:members obj))))
(defmethod describe-contained ((obj exception-def))
(CORBA:ExceptionDescription
;; Identifier name;
:name (op:name obj)
;; RepositoryId id;
:id (op:id obj)
;; RepositoryId defined_in;
:defined_in (subject-id (op:defined_in obj))
;; VersionSpec version;
:version (op:version obj)
;; TypeCode type;
:type (op:type obj)))
;;;; moveto restrictions - for IDL-types union, struct, execption
(defmethod moveto :before ((c union-def) (object contained) new-name new-version)