Object.rb

Martin Corino, 06/20/2016 06:49 pm

Download (5.39 KB)

 
1
#--------------------------------------------------------------------
2
# Object.rb - Common CORBA Object definitions
3
#
4
# Author: Martin Corino
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the R2CORBA LICENSE which is
8
# included with this program.
9
#
10
# Copyright (c) Remedy IT Expertise BV
11
# Chamber of commerce Rotterdam nr.276339, The Netherlands
12
#--------------------------------------------------------------------
13
module R2CORBA
14
  module CORBA
15

    
16
    def CORBA.is_nil(obj)
17
      if obj.nil?
18
        return true
19
      elsif obj.is_a?(R2CORBA::CORBA::Object) || obj.respond_to?(:_is_nil?)
20
        return obj._is_nil?()
21
      end
22
      false
23
    end
24

    
25
    module Object
26
      @@wrapper_klass = Class.new do
27
        include CORBA::Object
28
        def initialize(nobj)
29
          @objref_ = nobj
30
        end
31
        def _free_ref
32
          self._release
33
        end
34
        attr_reader :objref_
35
        def self.name
36
          'CORBA::Object'
37
        end
38
      end
39

    
40
      def self._wrap_native(nobj)
41
        raise ArgumentError, 'Expected org.omg.CORBA.Object' unless nobj.nil? || nobj.is_a?(Native::Object)
42
        (nobj.nil? || (nobj.respond_to?(:_is_nil) && nobj._is_nil)) ? nil : @@wrapper_klass.new(nobj)
43
      end
44

    
45
      def self._narrow(obj)
46
        raise CORBA::BAD_PARAM.new('not an object reference', 0, CORBA::COMPLETED_NO) unless obj.nil? || obj.is_a?(CORBA::Object) || obj.is_a?(Native::Object)
47
        obj = self._wrap_native(obj) if obj.is_a?(Native::Object)
48
        obj
49
      end
50

    
51
      def self._tc
52
        CORBA._tc_Object
53
      end
54

    
55
      #-------------------  4.3 "Object Reference Operations"
56

    
57
      def ==(other)
58
        self.class == other.class && self.objref_.eql?(other.objref_)
59
      end
60

    
61
      def hash
62
        self.objref_.hash
63
      end
64

    
65
      def dup
66
        self
67
      end
68

    
69
      def clone
70
        self
71
      end
72

    
73
      #ret InterfaceDef
74
      def _get_interface()
75
        raise ::CORBA::NO_IMPLEMENT
76
      end
77

    
78
      #ret boolean
79
      def _is_nil?()
80
        self.objref_.nil? || (self.objref_.respond_to?(:_is_nil) && self.objref_._is_nil)
81
      end
82

    
83
      #ret ::CORBA::Object
84
      def _duplicate()
85
        return nil if self._is_nil?()
86
        begin
87
          self._wrap_native(self.objref_._duplicate)
88
        rescue ::NativeException
89
          CORBA::Exception.native2r($!)
90
        end
91
      end
92

    
93
      # ret void
94
      def _release()
95
        self.objref_._release unless self.objref_.nil?
96
        @objref_ = nil
97
      end
98

    
99
      # ::String logical_type_id
100
      # ret boolean
101
      def _is_a?(logical_type_id)
102
        return false if self._is_nil?()
103
        begin
104
          self.objref_._is_a(logical_type_id)
105
        rescue ::NativeException
106
          CORBA::Exception.native2r($!)
107
        end
108
      end
109

    
110
      # ret boolean
111
      def _non_existent?()
112
        raise CORBA::INV_OBJREF.new if self._is_nil?()
113
        begin
114
          self.objref_._non_existent
115
        rescue ::NativeException
116
          CORBA::Exception.native2r($!)
117
        end
118
      end
119

    
120
      # ::CORBA::Object other_object
121
      # ret boolean
122
      def _is_equivalent?(other_object)
123
        raise CORBA::INV_OBJREF.new if self._is_nil?()
124
        begin
125
          self.objref_._is_equivalent(other_object)
126
        rescue ::NativeException
127
          CORBA::Exception.native2r($!)
128
        end
129
      end
130

    
131
      # Integer(ulong) maximum
132
      # ret unsigned long
133
      def _hash(maximum)
134
        raise CORBA::INV_OBJREF.new if self._is_nil?()
135
        begin
136
          self.objref_._hash(maximum)
137
        rescue ::NativeException
138
          CORBA::Exception.native2r($!)
139
        end
140
      end
141

    
142
      # ret ::String
143
      def _repository_id()
144
        raise CORBA::INV_OBJREF.new if self._is_nil?()
145
        ## if this object ref has already been narrowed
146
        return self._interface_repository_id if self.respond_to?(:_interface_repository_id)
147
        ## ask the remote side
148
        begin
149
          self.objref_._repository_id()
150
        rescue ::NativeException
151
          CORBA::Exception.native2r($!)
152
        end
153
      end
154

    
155
      #def PolicyType policy_type
156
      # ret Policy
157
      def _get_policy(policy_type)
158
        raise ::CORBA::NO_IMPLEMENT
159
      end
160

    
161
      #PolicyList policies
162
      #SetOverrideType set_add
163
      #ret ::CORBA::Object
164
      def _set_policy_overrides(policies, set_add )
165
        raise ::CORBA::NO_IMPLEMENT
166
      end
167

    
168
      #int[] types
169
      #ret PolicyList
170
      def _get_policy_overrides(types)
171
        raise ::CORBA::NO_IMPLEMENT
172
      end
173

    
174
      #PolicyList inconsistent_policies
175
      #ret bool
176
      def _validate_connection(inconsistent_policies)
177
        raise ::CORBA::NO_IMPLEMENT
178
      end
179

    
180
      #ret ::CORBA::Object
181
      def _get_component()
182
        raise CORBA::INV_OBJREF.new if self._is_nil?()
183
        begin
184
          CORBA::Object._wrap_native(self.objref_._get_component())
185
        rescue ::NativeException
186
          CORBA::Exception.native2r($!)
187
        end
188
      end
189

    
190
      # ret CORBA::ORB
191
      def _get_orb()
192
        raise CORBA::INV_OBJREF.new if self._is_nil?()
193
        begin
194
          CORBA::ORB._wrap_native(self.objref_._get_orb)
195
        rescue ::NativeException
196
          CORBA::Exception.native2r($!)
197
        end
198
      end
199

    
200
      def _request(operation)
201
        raise CORBA::INV_OBJREF.new if self._is_nil?()
202
        begin
203
          self.objref_._request(operation.to_s)
204
        rescue ::NativeException
205
          CORBA::Exception.native2r($!)
206
        end
207
      end
208

    
209
    end # Object
210
  end # CORBA
211
end # R2CORBA
212