Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / Active_Object_Map.cpp
blob29242635a7555bc712e422ecf863e69317d574fb
1 #include "tao/PortableServer/Active_Object_Map.h"
2 #include "tao/PortableServer/Active_Object_Map_Entry.h"
4 #if !defined (__ACE_INLINE__)
5 # include "tao/PortableServer/Active_Object_Map.inl"
6 #endif /* __ACE_INLINE__ */
8 #include "tao/SystemException.h"
10 #include <memory>
11 #include "ace/CORBA_macros.h"
12 #include "tao/debug.h"
13 #include "PortableServer_Functions.h"
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 /* static */
18 size_t TAO_Active_Object_Map::system_id_size_ = 0;
20 static void
21 hexstring (ACE_CString& hexstr, const char* s, size_t l)
23 char buf[3] = {0};
25 hexstr.fast_resize (2 + l * 2);
26 hexstr.append ("0x", 2);
27 while (--l)
29 ACE_OS::sprintf (buf, "%02x", (unsigned int)(unsigned char)*s);
30 hexstr.append (buf, 2);
31 ++s;
35 void
36 TAO_Active_Object_Map::set_system_id_size (
37 const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters)
39 if (TAO_Active_Object_Map::system_id_size_ == 0)
41 if (creation_parameters.allow_reactivation_of_system_ids_)
43 switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
45 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
46 case TAO_LINEAR:
47 TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
48 break;
49 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
51 case TAO_DYNAMIC_HASH:
52 default:
53 TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
54 break;
57 size_t hint_size = 0;
59 if (creation_parameters.use_active_hint_in_ids_)
60 hint_size = ACE_Active_Map_Manager_Key::size ();
62 TAO_Active_Object_Map::system_id_size_ += hint_size;
64 else
66 switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
68 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
69 case TAO_LINEAR:
70 TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
71 break;
73 case TAO_DYNAMIC_HASH:
74 TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
75 break;
76 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
78 case TAO_ACTIVE_DEMUX:
79 default:
80 TAO_Active_Object_Map::system_id_size_ =
81 ACE_Active_Map_Manager_Key::size ();
82 break;
88 TAO_Active_Object_Map::TAO_Active_Object_Map (
89 int user_id_policy,
90 int unique_id_policy,
91 int persistent_id_policy,
92 const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &
93 creation_parameters)
94 : using_active_maps_ (false)
96 TAO_Active_Object_Map::set_system_id_size (creation_parameters);
98 TAO_Id_Uniqueness_Strategy *id_uniqueness_strategy = 0;
100 if (unique_id_policy)
102 ACE_NEW_THROW_EX (id_uniqueness_strategy,
103 TAO_Unique_Id_Strategy,
104 CORBA::NO_MEMORY ());
106 else
108 #if !defined (CORBA_E_MICRO)
109 ACE_NEW_THROW_EX (id_uniqueness_strategy,
110 TAO_Multiple_Id_Strategy,
111 CORBA::NO_MEMORY ());
112 #else
113 TAOLIB_ERROR ((LM_ERROR,
114 "Multiple Id Strategy not supported with CORBA/e\n"));
115 #endif
118 // Give ownership to the unique pointer.
119 std::unique_ptr<TAO_Id_Uniqueness_Strategy> new_id_uniqueness_strategy (id_uniqueness_strategy);
121 TAO_Lifespan_Strategy *lifespan_strategy = 0;
123 if (persistent_id_policy)
125 #if !defined (CORBA_E_MICRO)
126 ACE_NEW_THROW_EX (lifespan_strategy,
127 TAO_Persistent_Strategy,
128 CORBA::NO_MEMORY ());
129 #else
130 ACE_UNUSED_ARG (persistent_id_policy);
131 TAOLIB_ERROR ((LM_ERROR,
132 "Persistent Id Strategy not supported with CORBA/e\n"));
133 #endif
135 else
137 ACE_NEW_THROW_EX (lifespan_strategy,
138 TAO_Transient_Strategy,
139 CORBA::NO_MEMORY ());
142 // Give ownership to the unique pointer.
143 std::unique_ptr<TAO_Lifespan_Strategy> new_lifespan_strategy (lifespan_strategy);
145 TAO_Id_Assignment_Strategy *id_assignment_strategy = 0;
147 if (user_id_policy)
149 #if !defined (CORBA_E_MICRO)
150 ACE_NEW_THROW_EX (id_assignment_strategy,
151 TAO_User_Id_Strategy,
152 CORBA::NO_MEMORY ());
153 #else
154 TAOLIB_ERROR ((LM_ERROR,
155 "User Id Assignment not supported with CORBA/e\n"));
156 #endif
158 else if (unique_id_policy)
160 ACE_NEW_THROW_EX (id_assignment_strategy,
161 TAO_System_Id_With_Unique_Id_Strategy,
162 CORBA::NO_MEMORY ());
164 else
166 #if !defined (CORBA_E_MICRO)
167 ACE_NEW_THROW_EX (id_assignment_strategy,
168 TAO_System_Id_With_Multiple_Id_Strategy,
169 CORBA::NO_MEMORY ());
170 #else
171 TAOLIB_ERROR ((LM_ERROR,
172 "System Id Assignment with multiple "
173 "not supported with CORBA/e\n"));
174 #endif
177 // Give ownership to the unique pointer.
178 std::unique_ptr<TAO_Id_Assignment_Strategy> new_id_assignment_strategy (id_assignment_strategy);
180 TAO_Id_Hint_Strategy *id_hint_strategy = 0;
181 if ((user_id_policy
182 || creation_parameters.allow_reactivation_of_system_ids_)
183 && creation_parameters.use_active_hint_in_ids_)
185 this->using_active_maps_ = true;
187 ACE_NEW_THROW_EX (id_hint_strategy,
188 TAO_Active_Hint_Strategy (
189 creation_parameters.active_object_map_size_),
190 CORBA::NO_MEMORY ());
192 else
194 ACE_NEW_THROW_EX (id_hint_strategy,
195 TAO_No_Hint_Strategy,
196 CORBA::NO_MEMORY ());
199 // Give ownership to the unique pointer.
200 std::unique_ptr<TAO_Id_Hint_Strategy> new_id_hint_strategy (id_hint_strategy);
202 servant_map *sm = 0;
203 if (unique_id_policy)
205 switch (creation_parameters.reverse_object_lookup_strategy_for_unique_id_policy_)
207 case TAO_LINEAR:
208 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
209 ACE_NEW_THROW_EX (sm,
210 servant_linear_map (
211 creation_parameters.active_object_map_size_),
212 CORBA::NO_MEMORY ());
213 break;
214 #else
215 TAOLIB_ERROR ((LM_ERROR,
216 "linear option for "
217 "-ORBUniqueidPolicyReverseDemuxStrategy "
218 "not supported with minimum POA maps. "
219 "Ignoring option to use default...\n"));
220 /* FALL THROUGH */
221 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
223 case TAO_DYNAMIC_HASH:
224 default:
225 ACE_NEW_THROW_EX (sm,
226 servant_hash_map (
227 creation_parameters.active_object_map_size_),
228 CORBA::NO_MEMORY ());
229 break;
233 // Give ownership to the unique pointer.
234 std::unique_ptr<servant_map> new_servant_map (sm);
236 user_id_map *uim = 0;
237 if (user_id_policy
238 || creation_parameters.allow_reactivation_of_system_ids_)
240 switch (creation_parameters.object_lookup_strategy_for_user_id_policy_)
242 case TAO_LINEAR:
243 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
244 ACE_NEW_THROW_EX (uim,
245 user_id_linear_map (
246 creation_parameters.active_object_map_size_),
247 CORBA::NO_MEMORY ());
248 break;
249 #else
250 TAOLIB_ERROR ((LM_ERROR,
251 "linear option for -ORBUseridPolicyDemuxStrategy "
252 "not supported with minimum POA maps. "
253 "Ignoring option to use default...\n"));
254 /* FALL THROUGH */
255 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
257 case TAO_DYNAMIC_HASH:
258 default:
259 ACE_NEW_THROW_EX (uim,
260 user_id_hash_map (creation_parameters.active_object_map_size_),
261 CORBA::NO_MEMORY ());
262 break;
265 else
267 switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
269 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
270 case TAO_LINEAR:
271 ACE_NEW_THROW_EX (uim,
272 user_id_linear_map (creation_parameters.active_object_map_size_),
273 CORBA::NO_MEMORY ());
274 break;
276 case TAO_DYNAMIC_HASH:
277 ACE_NEW_THROW_EX (uim,
278 user_id_hash_map (creation_parameters.active_object_map_size_),
279 CORBA::NO_MEMORY ());
280 break;
281 #else
282 case TAO_LINEAR:
283 case TAO_DYNAMIC_HASH:
284 TAOLIB_ERROR ((LM_ERROR,
285 "linear and dynamic options for -ORBSystemidPolicyDemuxStrategy "
286 "are not supported with minimum POA maps. "
287 "Ignoring option to use default...\n"));
288 /* FALL THROUGH */
289 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
291 case TAO_ACTIVE_DEMUX:
292 default:
294 this->using_active_maps_ = true;
296 ACE_NEW_THROW_EX (uim,
297 user_id_active_map (creation_parameters.active_object_map_size_),
298 CORBA::NO_MEMORY ());
299 break;
303 // Give ownership to the unique pointer.
304 std::unique_ptr<user_id_map> new_user_id_map (uim);
306 id_uniqueness_strategy->set_active_object_map (this);
307 lifespan_strategy->set_active_object_map (this);
308 id_assignment_strategy->set_active_object_map (this);
310 // Finally everything is fine. Make sure to take ownership away
311 // from the unique pointer.
312 this->id_uniqueness_strategy_ = std::move(new_id_uniqueness_strategy);
313 this->lifespan_strategy_ = std::move(new_lifespan_strategy);
314 this->id_assignment_strategy_ = std::move(new_id_assignment_strategy);
315 this->id_hint_strategy_ = std::move(new_id_hint_strategy);
316 this->servant_map_ = std::move(new_servant_map);
317 this->user_id_map_ = std::move(new_user_id_map);
319 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
320 ACE_NEW (this->monitor_,
321 ACE::Monitor_Control::Size_Monitor);
322 #endif /* TAO_HAS_MONITOR_POINTS==1 */
325 TAO_Active_Object_Map::~TAO_Active_Object_Map ()
327 user_id_map::iterator iterator = this->user_id_map_->begin ();
328 user_id_map::iterator end = this->user_id_map_->end ();
330 for (;
331 iterator != end;
332 ++iterator)
334 user_id_map::value_type map_entry = *iterator;
335 delete map_entry.second ();
338 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
339 this->monitor_->remove_from_registry ();
340 this->monitor_->remove_ref ();
341 #endif /* TAO_HAS_MONITOR_POINTS==1 */
344 bool
345 TAO_Active_Object_Map::is_user_id_in_map (
346 const PortableServer::ObjectId &user_id,
347 CORBA::Short priority,
348 bool &priorities_match,
349 bool &deactivated)
351 TAO_Active_Object_Map_Entry *entry = 0;
352 bool result = false;
353 int const find_result = this->user_id_map_->find (user_id, entry);
355 if (find_result == 0)
357 if (entry->servant_ == 0)
359 if (entry->priority_ != priority)
361 priorities_match = false;
364 else
366 result = true;
368 if (entry->deactivated_)
370 deactivated = true;
375 return result;
378 ////////////////////////////////////////////////////////////////////////////////
380 void
381 TAO_Id_Uniqueness_Strategy::set_active_object_map (
382 TAO_Active_Object_Map *active_object_map)
384 this->active_object_map_ = active_object_map;
388 TAO_Unique_Id_Strategy::is_servant_in_map (PortableServer::Servant servant,
389 bool &deactivated)
391 TAO_Active_Object_Map_Entry *entry = 0;
392 int result = this->active_object_map_->servant_map_->find (servant,
393 entry);
394 if (result == 0)
396 result = 1;
398 if (entry->deactivated_)
400 deactivated = true;
403 else
405 result = 0;
408 return result;
412 TAO_Unique_Id_Strategy::bind_using_user_id (
413 PortableServer::Servant servant,
414 const PortableServer::ObjectId &user_id,
415 CORBA::Short priority,
416 TAO_Active_Object_Map_Entry *&entry)
418 int result =
419 this->active_object_map_->user_id_map_->find (user_id, entry);
421 if (result == 0)
423 if (servant != 0)
425 entry->servant_ = servant;
427 result =
428 this->active_object_map_->servant_map_->bind (entry->servant_,
429 entry);
431 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
432 if (result == 0)
434 this->active_object_map_->monitor_->receive (
435 this->active_object_map_->servant_map_->current_size ());
437 #endif /* TAO_HAS_MONITOR_POINTS==1 */
440 else
442 ACE_NEW_RETURN (entry,
443 TAO_Active_Object_Map_Entry,
444 -1);
445 entry->user_id_ = user_id;
446 entry->servant_ = servant;
447 entry->priority_ = priority;
449 result = this->active_object_map_->id_hint_strategy_->bind (*entry);
451 if (result == 0)
453 result =
454 this->active_object_map_->user_id_map_->bind (entry->user_id_,
455 entry);
456 if (result == 0)
458 if (servant != 0)
460 result =
461 this->active_object_map_->servant_map_->bind (
462 entry->servant_,
463 entry);
466 if (result != 0)
468 this->active_object_map_->user_id_map_->unbind (
469 entry->user_id_);
470 this->active_object_map_->id_hint_strategy_->unbind (
471 *entry);
472 delete entry;
474 else
476 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
477 this->active_object_map_->monitor_->receive (
478 this->active_object_map_->servant_map_->current_size ());
479 #endif /* TAO_HAS_MONITOR_POINTS==1 */
482 else
484 this->active_object_map_->id_hint_strategy_->unbind (*entry);
485 delete entry;
488 else
490 delete entry;
494 #if (TAO_HAS_MINIMUM_CORBA == 0)
495 if (result == 0 && TAO_debug_level > 7)
497 CORBA::String_var idstr (PortableServer::ObjectId_to_string (user_id));
498 CORBA::String_var repository_id (
499 servant ? servant->_repository_id () : 0);
500 ACE_CString hex_idstr;
501 hexstring (hex_idstr, idstr.in (), user_id.length ());
503 TAOLIB_DEBUG ((LM_DEBUG,
504 "TAO (%P|%t) - TAO_Unique_Id_Strategy::"
505 "bind_using_user_id: type=%C, id=%C\n",
506 repository_id.in (),
507 hex_idstr.c_str()));
509 #endif
511 return result;
515 TAO_Unique_Id_Strategy::unbind_using_user_id (
516 const PortableServer::ObjectId &user_id)
518 TAO_Active_Object_Map_Entry *entry = 0;
519 int result = this->active_object_map_->user_id_map_->unbind (user_id,
520 entry);
521 if (result == 0)
523 if (TAO_debug_level > 7)
525 CORBA::String_var idstr (
526 PortableServer::ObjectId_to_string (entry->user_id_));
527 ACE_CString hex_idstr;
528 hexstring (hex_idstr, idstr.in (), entry->user_id_.length ());
530 TAOLIB_DEBUG ((LM_DEBUG,
531 "TAO (%P|%t) - TAO_Unique_Id_Strategy::unbind_using_user_id: id=%C\n",
532 hex_idstr.c_str()));
535 if (entry->servant_ != 0)
537 result =
538 this->active_object_map_->servant_map_->unbind (entry->servant_);
541 if (result == 0)
543 result =
544 this->active_object_map_->id_hint_strategy_->unbind (*entry);
546 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
547 this->active_object_map_->monitor_->receive (
548 this->active_object_map_->servant_map_->current_size ());
549 #endif /* TAO_HAS_MONITOR_POINTS==1 */
552 if (result == 0)
554 delete entry;
558 return result;
562 TAO_Unique_Id_Strategy::find_user_id_using_servant (
563 PortableServer::Servant servant,
564 PortableServer::ObjectId_out user_id)
566 TAO_Active_Object_Map_Entry *entry = 0;
567 int result = this->active_object_map_->servant_map_->find (servant, entry);
569 if (result == 0)
571 if (entry->deactivated_)
573 result = -1;
575 else
577 ACE_NEW_RETURN (user_id,
578 PortableServer::ObjectId (entry->user_id_),
579 -1);
583 return result;
587 TAO_Unique_Id_Strategy::find_system_id_using_servant (
588 PortableServer::Servant servant,
589 PortableServer::ObjectId_out system_id,
590 CORBA::Short &priority)
592 TAO_Active_Object_Map_Entry *entry = 0;
593 int result = this->active_object_map_->servant_map_->find (servant,
594 entry);
595 if (result == 0)
597 if (entry->deactivated_)
599 result = -1;
601 else
603 result =
604 this->active_object_map_->id_hint_strategy_->system_id (
605 system_id,
606 *entry);
607 if (result == 0)
609 priority = entry->priority_;
614 return result;
617 CORBA::Boolean
618 TAO_Unique_Id_Strategy::remaining_activations (
619 PortableServer::Servant servant)
621 ACE_UNUSED_ARG (servant);
623 // Since servant are always unique here, return false.
624 return 0;
627 ////////////////////////////////////////////////////////////////////////////////
629 #if !defined (CORBA_E_MICRO)
631 TAO_Multiple_Id_Strategy::is_servant_in_map (PortableServer::Servant, bool &)
633 return -1;
637 TAO_Multiple_Id_Strategy::bind_using_user_id (
638 PortableServer::Servant servant,
639 const PortableServer::ObjectId &user_id,
640 CORBA::Short priority,
641 TAO_Active_Object_Map_Entry *&entry)
643 int result =
644 this->active_object_map_->user_id_map_->find (user_id, entry);
646 if (result == 0)
648 if (servant != 0)
650 entry->servant_ = servant;
653 else
655 ACE_NEW_RETURN (entry,
656 TAO_Active_Object_Map_Entry,
657 -1);
658 entry->user_id_ = user_id;
659 entry->servant_ = servant;
660 entry->priority_ = priority;
662 result =
663 this->active_object_map_->id_hint_strategy_->bind (*entry);
665 if (result == 0)
667 result =
668 this->active_object_map_->user_id_map_->bind (entry->user_id_,
669 entry);
670 if (result != 0)
672 this->active_object_map_->id_hint_strategy_->unbind (*entry);
673 delete entry;
675 else
677 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
678 this->active_object_map_->monitor_->receive (
679 this->active_object_map_->user_id_map_->current_size ());
680 #endif /* TAO_HAS_MONITOR_POINTS==1 */
683 else
685 delete entry;
689 #if (TAO_HAS_MINIMUM_CORBA == 0)
690 if (result == 0 && TAO_debug_level > 7)
692 CORBA::String_var idstr (PortableServer::ObjectId_to_string (user_id));
693 CORBA::String_var repository_id (
694 servant ? servant->_repository_id () : 0);
695 ACE_CString hex_idstr;
696 hexstring (hex_idstr, idstr.in (), user_id.length ());
698 TAOLIB_DEBUG ((LM_DEBUG,
699 "TAO (%P|%t) - TAO_Multiple_Id_Strategy::"
700 "bind_using_user_id: type=%C, id=%C\n",
701 repository_id.in (),
702 hex_idstr.c_str()
705 #endif
707 return result;
711 TAO_Multiple_Id_Strategy::unbind_using_user_id (
712 const PortableServer::ObjectId &user_id)
714 TAO_Active_Object_Map_Entry *entry = 0;
715 int result = this->active_object_map_->user_id_map_->unbind (user_id,
716 entry);
717 if (result == 0)
719 if (TAO_debug_level > 7)
721 CORBA::String_var idstr (
722 PortableServer::ObjectId_to_string (entry->user_id_));
723 ACE_CString hex_idstr;
724 hexstring (hex_idstr, idstr.in (), entry->user_id_.length ());
726 TAOLIB_DEBUG ((LM_DEBUG,
727 "TAO (%P|%t) - TAO_Multiple_Id_Strategy::unbind_using_user_id: id=%C\n",
728 hex_idstr.c_str()));
731 result = this->active_object_map_->id_hint_strategy_->unbind (*entry);
733 if (result == 0)
735 delete entry;
738 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
739 this->active_object_map_->monitor_->receive (
740 this->active_object_map_->user_id_map_->current_size ());
741 #endif /* TAO_HAS_MONITOR_POINTS==1 */
744 return result;
748 TAO_Multiple_Id_Strategy::find_user_id_using_servant (
749 PortableServer::Servant,
750 PortableServer::ObjectId_out)
752 return -1;
756 TAO_Multiple_Id_Strategy::find_system_id_using_servant (
757 PortableServer::Servant,
758 PortableServer::ObjectId_out,
759 CORBA::Short &)
761 return -1;
764 CORBA::Boolean
765 TAO_Multiple_Id_Strategy::remaining_activations (
766 PortableServer::Servant servant)
768 TAO_Active_Object_Map::user_id_map::iterator end =
769 this->active_object_map_->user_id_map_->end ();
771 for (TAO_Active_Object_Map::user_id_map::iterator iter =
772 this->active_object_map_->user_id_map_->begin ();
773 iter != end;
774 ++iter)
776 TAO_Active_Object_Map::user_id_map::value_type map_pair = *iter;
777 TAO_Active_Object_Map_Entry *entry = map_pair.second ();
779 if (entry->servant_ == servant)
781 return 1;
785 return 0;
787 #endif
789 void
790 TAO_Lifespan_Strategy::set_active_object_map (
791 TAO_Active_Object_Map *active_object_map)
793 this->active_object_map_ = active_object_map;
797 TAO_Transient_Strategy::find_servant_using_system_id_and_user_id (
798 const PortableServer::ObjectId &system_id,
799 const PortableServer::ObjectId &user_id,
800 PortableServer::Servant &servant,
801 TAO_Active_Object_Map_Entry *&entry)
803 int result = this->active_object_map_->id_hint_strategy_->find (system_id,
804 entry);
805 if (result == 0)
807 if (entry->deactivated_)
809 result = -1;
811 else if (entry->servant_ == 0)
813 result = -1;
815 else
817 servant = entry->servant_;
820 else
822 result = this->active_object_map_->user_id_map_->find (user_id,
823 entry);
824 if (result == 0)
826 if (entry->deactivated_)
828 result = -1;
830 else if (entry->servant_ == 0)
832 result = -1;
834 else
836 servant = entry->servant_;
841 if (result == -1)
843 entry = 0;
846 return result;
849 ////////////////////////////////////////////////////////////////////////////////
851 #if !defined (CORBA_E_MICRO)
853 TAO_Persistent_Strategy::find_servant_using_system_id_and_user_id (
854 const PortableServer::ObjectId &system_id,
855 const PortableServer::ObjectId &user_id,
856 PortableServer::Servant &servant,
857 TAO_Active_Object_Map_Entry *&entry)
859 int result =
860 this->active_object_map_->id_hint_strategy_->find (system_id,
861 entry);
862 if (result == 0 && user_id == entry->user_id_)
864 if (entry->deactivated_)
866 result = -1;
868 else if (entry->servant_ == 0)
870 result = -1;
872 else
874 servant = entry->servant_;
877 else
879 result =
880 this->active_object_map_->user_id_map_->find (user_id, entry);
882 if (result == 0)
884 if (entry->deactivated_)
886 result = -1;
888 else if (entry->servant_ == 0)
890 result = -1;
892 else
894 servant = entry->servant_;
899 if (result == -1)
901 entry = 0;
904 return result;
906 #endif
908 void
909 TAO_Id_Assignment_Strategy::set_active_object_map (
910 TAO_Active_Object_Map *active_object_map)
912 this->active_object_map_ = active_object_map;
915 #if !defined (CORBA_E_MICRO)
917 TAO_User_Id_Strategy::bind_using_system_id (PortableServer::Servant,
918 CORBA::Short,
919 TAO_Active_Object_Map_Entry *&)
921 return -1;
923 #endif
926 TAO_System_Id_With_Unique_Id_Strategy::bind_using_system_id (
927 PortableServer::Servant servant,
928 CORBA::Short priority,
929 TAO_Active_Object_Map_Entry *&entry)
931 ACE_NEW_RETURN (entry,
932 TAO_Active_Object_Map_Entry,
933 -1);
935 int result =
936 this->active_object_map_->user_id_map_->bind_create_key (entry,
937 entry->user_id_);
938 if (result == 0)
940 entry->servant_ = servant;
941 entry->priority_ = priority;
943 result = this->active_object_map_->id_hint_strategy_->bind (*entry);
945 if (result == 0)
947 if (servant != 0)
949 result =
950 this->active_object_map_->servant_map_->bind (entry->servant_,
951 entry);
954 if (result != 0)
956 this->active_object_map_->user_id_map_->unbind (entry->user_id_);
957 this->active_object_map_->id_hint_strategy_->unbind (*entry);
958 delete entry;
960 else
962 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
963 this->active_object_map_->monitor_->receive (
964 this->active_object_map_->servant_map_->current_size ());
965 #endif /* TAO_HAS_MONITOR_POINTS==1 */
968 else
970 this->active_object_map_->user_id_map_->unbind (entry->user_id_);
971 delete entry;
974 else
976 delete entry;
979 #if (TAO_HAS_MINIMUM_CORBA == 0)
980 if (result == 0 && TAO_debug_level > 7)
982 CORBA::String_var idstr (
983 PortableServer::ObjectId_to_string (entry->user_id_));
984 CORBA::String_var repository_id (
985 servant ? servant->_repository_id () : 0);
986 ACE_CString hex_idstr;
987 hexstring (hex_idstr, idstr.in (), entry->user_id_.length ());
989 TAOLIB_DEBUG ((LM_DEBUG,
990 "TAO (%P|%t) - TAO_System_Id_With_Unique_Id_Strategy::"
991 "bind_using_system_id: type=%C, id=%C\n",
992 repository_id.in (),
993 hex_idstr.c_str()
996 #endif
998 return result;
1001 #if !defined (CORBA_E_MICRO)
1003 TAO_System_Id_With_Multiple_Id_Strategy::bind_using_system_id (
1004 PortableServer::Servant servant,
1005 CORBA::Short priority,
1006 TAO_Active_Object_Map_Entry *&entry)
1008 ACE_NEW_RETURN (entry,
1009 TAO_Active_Object_Map_Entry,
1010 -1);
1011 int result =
1012 this->active_object_map_->user_id_map_->bind_create_key (entry,
1013 entry->user_id_);
1014 if (result == 0)
1016 entry->servant_ = servant;
1017 entry->priority_ = priority;
1019 result = this->active_object_map_->id_hint_strategy_->bind (*entry);
1021 if (result != 0)
1023 this->active_object_map_->user_id_map_->unbind (entry->user_id_);
1024 delete entry;
1027 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
1028 this->active_object_map_->monitor_->receive (
1029 this->active_object_map_->user_id_map_->current_size ());
1030 #endif /* TAO_HAS_MONITOR_POINTS==1 */
1032 else
1034 delete entry;
1037 #if (TAO_HAS_MINIMUM_CORBA == 0)
1038 if (result == 0 && TAO_debug_level > 7)
1040 CORBA::String_var idstr (
1041 PortableServer::ObjectId_to_string (entry->user_id_));
1042 CORBA::String_var repository_id (
1043 servant ? servant->_repository_id () : 0);
1044 ACE_CString hex_idstr;
1045 hexstring (hex_idstr, idstr.in (), entry->user_id_.length ());
1047 TAOLIB_DEBUG ((LM_DEBUG,
1048 "TAO (%P|%t) - TAO_System_Id_With_Multiple_Id_Strategy::"
1049 "bind_using_system_id: type=%C, id=%C\n",
1050 repository_id.in (),
1051 hex_idstr.c_str()
1054 #endif
1056 return result;
1058 #endif
1060 ////////////////////////////////////////////////////////////////////////////////
1062 TAO_Active_Hint_Strategy::TAO_Active_Hint_Strategy (CORBA::ULong map_size)
1063 : system_id_map_ (map_size)
1068 TAO_Active_Hint_Strategy::recover_key (
1069 const PortableServer::ObjectId &system_id,
1070 PortableServer::ObjectId &user_id)
1072 return this->system_id_map_.recover_key (system_id, user_id);
1076 TAO_Active_Hint_Strategy::bind (TAO_Active_Object_Map_Entry &entry)
1078 entry.system_id_ = entry.user_id_;
1080 return this->system_id_map_.bind_modify_key (&entry,
1081 entry.system_id_);
1085 TAO_Active_Hint_Strategy::unbind (TAO_Active_Object_Map_Entry &entry)
1087 return this->system_id_map_.unbind (entry.system_id_);
1091 TAO_Active_Hint_Strategy::find (const PortableServer::ObjectId &system_id,
1092 TAO_Active_Object_Map_Entry *&entry)
1094 return this->system_id_map_.find (system_id,
1095 entry);
1098 size_t
1099 TAO_Active_Hint_Strategy::hint_size ()
1101 return ACE_Active_Map_Manager_Key::size ();
1105 TAO_Active_Hint_Strategy::system_id (PortableServer::ObjectId_out system_id,
1106 TAO_Active_Object_Map_Entry &entry)
1108 ACE_NEW_RETURN (system_id,
1109 PortableServer::ObjectId (entry.system_id_),
1110 -1);
1111 return 0;
1114 ////////////////////////////////////////////////////////////////////////////////
1117 TAO_No_Hint_Strategy::recover_key (const PortableServer::ObjectId &system_id,
1118 PortableServer::ObjectId &user_id)
1120 // Smartly copy all the data; <user_id does not own the data>.
1121 user_id.replace (system_id.maximum (),
1122 system_id.length (),
1123 const_cast<CORBA::Octet *> (system_id.get_buffer ()),
1126 return 0;
1130 TAO_No_Hint_Strategy::bind (TAO_Active_Object_Map_Entry &)
1132 return 0;
1136 TAO_No_Hint_Strategy::unbind (TAO_Active_Object_Map_Entry &)
1138 return 0;
1142 TAO_No_Hint_Strategy::find (const PortableServer::ObjectId &,
1143 TAO_Active_Object_Map_Entry *&)
1145 return -1;
1148 size_t
1149 TAO_No_Hint_Strategy::hint_size ()
1151 return 0;
1155 TAO_No_Hint_Strategy::system_id (PortableServer::ObjectId_out system_id,
1156 TAO_Active_Object_Map_Entry &entry)
1158 ACE_NEW_RETURN (system_id,
1159 PortableServer::ObjectId (entry.user_id_),
1160 -1);
1161 return 0;
1164 TAO_END_VERSIONED_NAMESPACE_DECL