3 #include "tao/Valuetype/AbstractBase.h"
4 #include "tao/Valuetype/ValueBase.h"
5 #include "tao/Valuetype/ValueFactory.h"
6 #include "tao/AnyTypeCode/Objref_TypeCode_Static.h"
8 #include "tao/ORB_Core.h"
9 #include "tao/Profile.h"
10 #include "tao/debug.h"
13 #if !defined (__ACE_INLINE__)
14 # include "tao/Valuetype/AbstractBase.inl"
15 #endif /* ! __ACE_INLINE__ */
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 CORBA::AbstractBase::AbstractBase ()
22 , is_collocated_ (false)
24 , equivalent_obj_ (CORBA::Object::_nil ())
28 CORBA::AbstractBase::AbstractBase (const CORBA::AbstractBase
&rhs
)
29 : is_objref_ (rhs
.is_objref_
)
31 , is_collocated_ (rhs
.is_collocated_
)
32 , servant_ (rhs
.servant_
)
33 , equivalent_obj_ (CORBA::Object::_nil ())
37 // Need to duplicate equivalent obj only if it's objref.
38 this->equivalent_obj_
=
39 CORBA::Object::_duplicate (rhs
.equivalent_obj_
.in ());
43 CORBA::AbstractBase::AbstractBase (TAO_Stub
* protocol_proxy
,
44 CORBA::Boolean collocated
,
45 TAO_Abstract_ServantBase
* servant
)
48 , is_collocated_ (collocated
)
50 , equivalent_obj_ (this->create_object (protocol_proxy
))
55 CORBA::AbstractBase::_add_ref ()
59 // This is required by the C++ Mapping 1.2.
62 CORBA::Object::_duplicate (this->equivalent_obj_
.in ());
67 CORBA::AbstractBase::_remove_ref ()
69 // This is required by the C++ Mapping 1.2.
72 CORBA::release (this->equivalent_obj_
.in ());
75 if (--this->refcount_
== 0)
77 // If this object is going to be deleted here then the reference to
78 // equivalent_obj_ that it owned is already released a few lines above.
79 this->equivalent_obj_
._retn ();
86 CORBA::AbstractBase::_tao_any_destructor (void *x
)
88 CORBA::AbstractBase_ptr tmp
= static_cast<CORBA::AbstractBase_ptr
> (x
);
89 ::CORBA::release (tmp
);
93 CORBA::AbstractBase::_to_object ()
95 if (!this->is_objref_
)
97 return CORBA::Object::_nil ();
100 return CORBA::Object::_duplicate (this->equivalent_obj_
.in ());
104 CORBA::AbstractBase::_to_value ()
106 if (this->is_objref_
)
111 CORBA::ValueBase
*retval
= this->_tao_to_value ();
113 if (retval
!= nullptr)
122 CORBA::AbstractBase::_is_a (const char *type_id
)
124 if (this->is_objref_
)
126 if (!CORBA::is_nil (this->equivalent_obj_
.in ()))
128 return this->equivalent_obj_
->_is_a (type_id
);
132 return (ACE_OS::strcmp (type_id
, "IDL:omg.org/CORBA/AbstractBase:1.0") == 0);
136 CORBA::AbstractBase::_interface_repository_id () const
138 return "IDL:omg.org/CORBA/AbstractBase:1.0";
142 CORBA::AbstractBase::_tao_obv_repository_id () const
144 return "IDL:omg.org/CORBA/AbstractBase:1.0";
148 operator<< (TAO_OutputCDR
&strm
, const CORBA::AbstractBase_ptr abs
)
150 CORBA::Boolean discriminator
= true;
152 // We marshal a null abstract interface ptr as a discriminator
153 // plus null object reference (see CORBA::Object::marshal()
154 // and operator << for CORBA::Object).
155 if (CORBA::is_nil (abs
))
157 // Marshal discriminator, then empty type hint.
158 strm
<< ACE_OutputCDR::from_boolean (discriminator
);
159 return strm
<< CORBA::Object::_nil ();
162 if (abs
->_is_objref ())
164 if (strm
<< ACE_OutputCDR::from_boolean (discriminator
))
166 TAO_Stub
*stubobj
= abs
->_stubobj ();
173 // STRING, a type ID hint
174 if ((strm
<< stubobj
->type_id
.in ()) == 0)
179 const TAO_MProfile
& mprofile
= stubobj
->base_profiles ();
181 CORBA::ULong
const profile_count
= mprofile
.profile_count ();
183 if ((strm
<< profile_count
) == 0)
188 // @@ The MProfile should be locked during this iteration, is there
189 // anyway to achieve that?
190 for (CORBA::ULong i
= 0; i
< profile_count
; ++i
)
192 const TAO_Profile
*p
= mprofile
.get_profile (i
);
194 if (p
->encode (strm
) == 0)
200 return strm
.good_bit ();
205 discriminator
= false;
207 if (strm
<< ACE_OutputCDR::from_boolean (discriminator
))
209 CORBA::ULong value_tag
= TAO_OBV_GIOP_Flags::Value_tag_base
210 | TAO_OBV_GIOP_Flags::Type_info_single
;
212 if ((strm
.write_ulong (value_tag
)) == 0)
217 if ((strm
<< abs
->_tao_obv_repository_id ()) == 0)
222 return abs
->_tao_marshal_v (strm
);
230 operator>> (TAO_InputCDR
&strm
, CORBA::AbstractBase_ptr
&abs
)
233 CORBA::Boolean discriminator
= false;
234 ACE_InputCDR::to_boolean
tb (discriminator
);
235 TAO_ORB_Core
*orb_core
= nullptr;
241 CORBA::ULong value_tag
;
243 if (!strm
.read_ulong (value_tag
))
248 if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag
))
250 // Ok, null reference unmarshaled.
254 if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag
))
256 TAOLIB_DEBUG ((LM_DEBUG
,
257 ACE_TEXT ("operator>> CORBA::AbstractBase ")
258 ACE_TEXT ("not value_tag\n")));
262 CORBA::String_var repo_id_stream
;
264 // It would be more efficient not to copy the string)
265 if (strm
.read_string (repo_id_stream
.inout ()) == 0)
270 orb_core
= strm
.orb_core ();
274 orb_core
= TAO_ORB_Core_instance ();
276 if (TAO_debug_level
> 0)
278 TAOLIB_DEBUG ((LM_WARNING
,
279 "TAO (%P|%t) WARNING: extracting "
280 "valuetype using default ORB_Core\n"));
284 CORBA::ValueFactory_var factory
=
285 orb_core
->orb ()->lookup_value_factory (repo_id_stream
.in ());
287 // We should throw an exception, if there were an appropriate one.
288 if (factory
.in() == 0)
290 TAOLIB_ERROR ((LM_ERROR
,
291 ACE_TEXT ("(%N:%l): The following unknown type was received: `%s'."),
292 repo_id_stream
.in ()));
296 abs
= factory
->create_for_unmarshal_abstract ();
298 return (abs
== 0 ? false : abs
->_tao_unmarshal_v (strm
));
302 CORBA::Object_var generic_objref
;
304 if (strm
>> generic_objref
.inout ())
306 if (CORBA::is_nil (generic_objref
.in ()))
311 TAO_Stub
*concrete_stubobj
= generic_objref
->_stubobj ();
313 bool const collocated
=
314 !CORBA::is_nil (concrete_stubobj
->servant_orb_var ().in ())
315 && concrete_stubobj
->optimize_collocation_objects ()
316 && generic_objref
->_is_collocated ();
319 CORBA::AbstractBase (
322 generic_objref
->_servant ()),
332 #if defined (GEN_OSTREAM_OPS)
335 operator<< (std::ostream
&strm
,
336 CORBA::AbstractBase_ptr _tao_objref
)
338 return CORBA::AbstractBase::_tao_stream (strm
, _tao_objref
);
341 #endif /* GEN_OSTREAM_OPS */
344 CORBA::AbstractBase::_tao_marshal_v (TAO_OutputCDR
&) const
350 CORBA::AbstractBase::_tao_unmarshal_v (TAO_InputCDR
&)
356 CORBA::AbstractBase::_tao_match_formal_type (ptrdiff_t ) const
361 #if defined (GEN_OSTREAM_OPS)
364 CORBA::AbstractBase::_tao_stream (std::ostream
&strm
,
365 const CORBA::AbstractBase_ptr _tao_objref
)
367 return _tao_objref
->_tao_stream_v (strm
);
371 CORBA::AbstractBase::_tao_stream_v (std::ostream
&strm
) const
373 return strm
<< "\"IDL:omg.org/CORBA/AbstractBase:1.0\"";
376 #endif /* GEN_OSTREAM_OPS */
379 CORBA::AbstractBase::_tao_to_value ()
385 CORBA::AbstractBase::create_object (TAO_Stub
*stub
)
389 stub
->_incr_refcnt ();
391 TAO_Stub_Auto_Ptr
safe_stub (stub
);
393 CORBA::Object_ptr obj
=
394 stub
->orb_core ()->create_object (stub
);
396 safe_stub
.release ();
401 return CORBA::Object::_nil ();
404 // ================== Typecode initializations ==================
410 char const tc_object_id
[] = "IDL:omg.org/CORBA/AbstractBase:1.0";
411 char const tc_object_name
[] = "AbstractBase";
413 TAO::Null_RefCount_Policy
>
414 tc_AbstractBase (CORBA::tk_abstract_interface
,
422 TypeCode_ptr
const _tc_AbstractBase
= &TAO::TypeCode::tc_AbstractBase
;
425 TAO_END_VERSIONED_NAMESPACE_DECL