00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef TAO_OBJECT_ADAPTER_H
00014 #define TAO_OBJECT_ADAPTER_H
00015
00016 #include "ace/pre.h"
00017
00018 #include "tao/PortableServer/portableserver_export.h"
00019
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif
00023
00024 #include "tao/PortableServer/Key_Adapters.h"
00025 #include "tao/PortableServer/poa_macros.h"
00026 #include "tao/PortableServer/Servant_Location.h"
00027 #include "tao/PortableServer/Default_Policy_Validator.h"
00028 #include "tao/PortableServer/POA_Policy_Set.h"
00029 #include "tao/PortableServer/POAManagerC.h"
00030
00031 #include "tao/Adapter.h"
00032 #include "tao/Adapter_Factory.h"
00033 #include "tao/Server_Strategy_Factory.h"
00034 #include "tao/LocalObject.h"
00035
00036 #include "ace/Reverse_Lock_T.h"
00037 #include "ace/Condition_Thread_Mutex.h"
00038 #include "ace/Map_T.h"
00039
00040 #include "tao/PortableServer/Servant_Location.h"
00041
00042 #if defined(_MSC_VER)
00043 #pragma warning(push)
00044 #pragma warning(disable:4250)
00045 #endif
00046
00047 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00048
00049 class TAO_Root_POA;
00050 class TAO_POA_Manager;
00051 class TAO_TSS_Resources;
00052 class TAO_Transport;
00053 class TAO_Servant_Dispatcher;
00054 class TAO_POAManager_Factory;
00055
00056 namespace TAO
00057 {
00058 namespace Portable_Server
00059 {
00060 class Non_Servant_Upcall;
00061 class Servant_Upcall;
00062 class POA_Current_Impl;
00063 class Temporary_Creation_Time;
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 class TAO_PortableServer_Export TAO_Object_Adapter
00075 : public TAO_Adapter
00076 {
00077 public:
00078
00079 friend class TAO_Root_POA;
00080
00081 typedef PortableServer::ObjectId poa_name;
00082 typedef PortableServer::ObjectId_var poa_name_var;
00083 typedef PortableServer::ObjectId_out poa_name_out;
00084
00085
00086 TAO_Object_Adapter (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters,
00087 TAO_ORB_Core &orb_core);
00088
00089
00090 ~TAO_Object_Adapter (void);
00091
00092 int dispatch_servant (const TAO::ObjectKey &key,
00093 TAO_ServerRequest &req,
00094 CORBA::Object_out forward_to
00095 );
00096
00097 int locate_servant (const TAO::ObjectKey &key
00098 );
00099
00100 TAO_SERVANT_LOCATION find_servant (const TAO::ObjectKey &key,
00101 PortableServer::Servant &servant
00102 );
00103
00104 int find_poa (const poa_name &system_name,
00105 CORBA::Boolean activate_it,
00106 CORBA::Boolean root,
00107 const TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time,
00108 TAO_Root_POA *&poa
00109 );
00110
00111 int bind_poa (const poa_name &folded_name,
00112 TAO_Root_POA *poa,
00113 poa_name_out system_name);
00114
00115 int unbind_poa (TAO_Root_POA *poa,
00116 const poa_name &folded_name,
00117 const poa_name &system_name);
00118
00119 int activate_poa (const poa_name &folded_name,
00120 TAO_Root_POA *&poa
00121 );
00122
00123 ACE_Lock &lock (void);
00124
00125 TAO_SYNCH_MUTEX &thread_lock (void);
00126
00127 ACE_Reverse_Lock<ACE_Lock> &reverse_lock (void);
00128
00129
00130 TAO_Root_POA *root_poa (void) const;
00131
00132
00133 TAO_ORB_Core &orb_core (void) const;
00134
00135
00136 void wait_for_non_servant_upcalls_to_complete (void);
00137
00138
00139 void wait_for_non_servant_upcalls_to_complete_no_throw (void);
00140
00141 static CORBA::ULong transient_poa_name_size (void);
00142
00143
00144 TAO_Policy_Validator &validator (void);
00145
00146 int enable_locking() const;
00147
00148
00149 TAO_POA_Policy_Set &default_poa_policies (void);
00150
00151
00152
00153
00154 void servant_dispatcher (TAO_Servant_Dispatcher *dispatcher);
00155
00156
00157 void init_default_policies (TAO_POA_Policy_Set &policies
00158 );
00159
00160
00161
00162 virtual void open (void);
00163 virtual void close (int wait_for_completion
00164 );
00165 virtual void check_close (int wait_for_completion
00166 );
00167 virtual int priority (void) const;
00168 virtual int dispatch (TAO::ObjectKey &key,
00169 TAO_ServerRequest &request,
00170 CORBA::Object_out forward_to
00171 );
00172 virtual const char *name (void) const;
00173 virtual CORBA::Object_ptr root (void);
00174 virtual CORBA::Object_ptr create_collocated_object (TAO_Stub *,
00175 const TAO_MProfile &);
00176
00177 virtual CORBA::Long initialize_collocated_object (TAO_Stub *);
00178
00179 protected:
00180
00181 int locate_servant_i (const TAO::ObjectKey &key
00182 );
00183
00184 TAO_SERVANT_LOCATION find_servant_i (const TAO::ObjectKey &key,
00185 PortableServer::Servant &servant
00186 );
00187
00188 void dispatch_servant_i (const TAO::ObjectKey &key,
00189 TAO_ServerRequest &req,
00190 void *context
00191 );
00192
00193 void locate_poa (const TAO::ObjectKey &key,
00194 PortableServer::ObjectId &id,
00195 TAO_Root_POA *&poa
00196 );
00197
00198 int find_transient_poa (const poa_name &system_name,
00199 CORBA::Boolean root,
00200 const TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time,
00201 TAO_Root_POA *&poa
00202 );
00203
00204 int find_persistent_poa (const poa_name &system_name,
00205 TAO_Root_POA *&poa
00206 );
00207
00208 int bind_transient_poa (TAO_Root_POA *poa,
00209 poa_name_out system_name);
00210
00211 int bind_persistent_poa (const poa_name &folded_name,
00212 TAO_Root_POA *poa,
00213 poa_name_out system_name);
00214
00215 int unbind_transient_poa (const poa_name &system_name);
00216
00217 int unbind_persistent_poa (const poa_name &folded_name,
00218 const poa_name &system_name);
00219
00220 static ACE_Lock *create_lock (int enable_locking,
00221 TAO_SYNCH_MUTEX &thread_lock);
00222
00223 virtual void do_dispatch (TAO_ServerRequest& req,
00224 TAO::Portable_Server::Servant_Upcall& upcall
00225 );
00226
00227 public:
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 class TAO_PortableServer_Export Hint_Strategy
00238 {
00239 public:
00240
00241 virtual ~Hint_Strategy (void);
00242
00243 virtual int find_persistent_poa (const poa_name &system_name,
00244 TAO_Root_POA *&poa
00245 ) = 0;
00246
00247 virtual int bind_persistent_poa (const poa_name &folded_name,
00248 TAO_Root_POA *poa,
00249 poa_name_out system_name) = 0;
00250
00251 virtual int unbind_persistent_poa (const poa_name &folded_name,
00252 const poa_name &system_name) = 0;
00253
00254 void object_adapter (TAO_Object_Adapter *oa);
00255
00256 protected:
00257
00258 TAO_Object_Adapter *object_adapter_;
00259 };
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 class TAO_PortableServer_Export Active_Hint_Strategy : public Hint_Strategy
00271 {
00272 public:
00273
00274 Active_Hint_Strategy (CORBA::ULong map_size);
00275
00276 virtual ~Active_Hint_Strategy (void);
00277
00278 virtual int find_persistent_poa (const poa_name &system_name,
00279 TAO_Root_POA *&poa
00280 );
00281
00282 virtual int bind_persistent_poa (const poa_name &folded_name,
00283 TAO_Root_POA *poa,
00284 poa_name_out system_name);
00285
00286 virtual int unbind_persistent_poa (const poa_name &folded_name,
00287 const poa_name &system_name);
00288
00289 protected:
00290
00291 typedef ACE_Active_Map_Manager_Adapter<
00292 poa_name,
00293 TAO_Root_POA *,
00294 TAO_Preserve_Original_Key_Adapter> persistent_poa_system_map;
00295
00296 persistent_poa_system_map persistent_poa_system_map_;
00297 };
00298
00299 friend class Active_Hint_Strategy;
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 class TAO_PortableServer_Export No_Hint_Strategy : public Hint_Strategy
00311 {
00312 public:
00313
00314 virtual ~No_Hint_Strategy (void);
00315
00316 virtual int find_persistent_poa (const poa_name &system_name,
00317 TAO_Root_POA *&poa
00318 );
00319
00320 virtual int bind_persistent_poa (const poa_name &folded_name,
00321 TAO_Root_POA *poa,
00322 poa_name_out system_name);
00323
00324 virtual int unbind_persistent_poa (const poa_name &folded_name,
00325 const poa_name &system_name);
00326
00327 };
00328
00329 friend class No_Hint_Strategy;
00330
00331 protected:
00332
00333 Hint_Strategy *hint_strategy_;
00334
00335
00336 typedef ACE_Map<
00337 poa_name,
00338 TAO_Root_POA *> transient_poa_map;
00339
00340 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00341
00342 typedef ACE_Hash_Map_Manager_Ex_Adapter<
00343 poa_name,
00344 TAO_Root_POA *,
00345 TAO_ObjectId_Hash,
00346 ACE_Equal_To<poa_name>,
00347 TAO_Incremental_Key_Generator> transient_poa_hash_map;
00348 #endif
00349
00350 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00351
00352 typedef ACE_Map_Manager_Adapter<
00353 poa_name,
00354 TAO_Root_POA *,
00355 TAO_Incremental_Key_Generator> transient_poa_linear_map;
00356 #endif
00357
00358
00359 typedef ACE_Active_Map_Manager_Adapter<
00360 poa_name,
00361 TAO_Root_POA *,
00362 TAO_Ignore_Original_Key_Adapter> transient_poa_active_map;
00363
00364
00365 typedef ACE_Map<
00366 poa_name,
00367 TAO_Root_POA *> persistent_poa_name_map;
00368
00369
00370 typedef ACE_Hash_Map_Manager_Ex_Adapter<
00371 poa_name,
00372 TAO_Root_POA *,
00373 TAO_ObjectId_Hash,
00374 ACE_Equal_To<PortableServer::ObjectId>,
00375 ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_hash_map;
00376
00377 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00378
00379 typedef ACE_Map_Manager_Adapter<
00380 poa_name,
00381 TAO_Root_POA *,
00382 ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_linear_map;
00383 #endif
00384
00385
00386 TAO_Servant_Dispatcher *servant_dispatcher_;
00387
00388
00389 persistent_poa_name_map *persistent_poa_name_map_;
00390
00391
00392 transient_poa_map *transient_poa_map_;
00393
00394 protected:
00395
00396 static CORBA::ULong transient_poa_name_size_;
00397
00398 static void set_transient_poa_name_size (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters);
00399
00400 TAO_ORB_Core &orb_core_;
00401
00402 int enable_locking_;
00403
00404 TAO_SYNCH_MUTEX thread_lock_;
00405
00406 ACE_Lock *lock_;
00407
00408 ACE_Reverse_Lock<ACE_Lock> reverse_lock_;
00409
00410 public:
00411
00412
00413
00414
00415
00416
00417 class poa_name_iterator
00418 {
00419 public:
00420
00421
00422 poa_name_iterator (int begin,
00423 CORBA::ULong size,
00424 const CORBA::Octet *folded_buffer);
00425
00426
00427 bool operator== (const poa_name_iterator &rhs) const;
00428 bool operator!= (const poa_name_iterator &rhs) const;
00429
00430
00431 ACE_CString operator* () const;
00432
00433
00434 poa_name_iterator &operator++ (void);
00435
00436 protected:
00437
00438 CORBA::ULong size_;
00439 CORBA::ULong position_;
00440 const CORBA::Octet *folded_buffer_;
00441 CORBA::ULong last_separator_;
00442 };
00443
00444
00445
00446
00447
00448
00449 class iteratable_poa_name
00450 {
00451 public:
00452
00453 typedef poa_name_iterator iterator;
00454
00455 iteratable_poa_name (const poa_name &folded_name);
00456
00457 iterator begin (void) const;
00458 iterator end (void) const;
00459
00460 protected:
00461
00462 const poa_name &folded_name_;
00463 };
00464
00465 friend class TAO::Portable_Server::Non_Servant_Upcall;
00466
00467 friend class TAO::Portable_Server::Servant_Upcall;
00468
00469 public:
00470
00471
00472
00473 TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress (void) const;
00474
00475 private:
00476
00477
00478 TAO_ServantBase *get_collocated_servant (const TAO_MProfile &mp);
00479
00480 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00481 static void release_poa_manager_factory (TAO_POAManager_Factory *factory);
00482 #endif
00483 private:
00484
00485
00486 TAO_SYNCH_CONDITION non_servant_upcall_condition_;
00487
00488
00489
00490 TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress_;
00491
00492
00493 unsigned int non_servant_upcall_nesting_level_;
00494
00495
00496 ACE_thread_t non_servant_upcall_thread_;
00497
00498
00499 TAO_Root_POA *root_;
00500
00501 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00502
00503 TAO_POAManager_Factory *poa_manager_factory_;
00504 #else
00505
00506 PortableServer::POAManager_var the_poa_manager_;
00507 #endif
00508
00509
00510
00511 TAO_POA_Default_Policy_Validator default_validator_;
00512
00513
00514
00515 TAO_POA_Policy_Set default_poa_policies_;
00516 };
00517
00518 TAO_END_VERSIONED_NAMESPACE_DECL
00519
00520 #if defined(_MSC_VER)
00521 #pragma warning(pop)
00522 #endif
00523
00524 #if defined (__ACE_INLINE__)
00525 # include "tao/PortableServer/Object_Adapter.inl"
00526 #endif
00527
00528 #include "ace/post.h"
00529
00530 #endif