00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _SERVANTLOCATORS_H_
00034 #define _SERVANTLOCATORS_H_
00035
00036
00037
00038
00039 #include <map>
00040 #include <list>
00041
00042
00043 #include <tao/PortableServer/Servant_Base.h>
00044 #include <tao/PortableServer/ServantLocatorC.h>
00045 #include <osbid.h>
00046 #include <mutex.h>
00047
00048
00049 #include "exceptionS.h"
00050
00051
00052
00053 namespace OSB_CORBA {
00054
00055 using corba::common::OsbCorbaException;
00056
00058 class Locators : public virtual PortableServer::ServantLocator
00059 {
00060 public:
00062 typedef std::pair<unsigned long, unsigned long> Key;
00063
00064 public:
00066 static const std::string IFC;
00067
00074 static PortableServer::ObjectId_var keyToOid(
00075 const Key& key
00076 );
00077
00088 static Key makeKey(long k1, long k2 = 0);
00089
00099 template<typename T>
00100 static Key makeKey(const OSB_LIB::Id<T>& id)
00101 {
00102 return makeKey(id.id());
00103 }
00104
00114 template<typename T>
00115 static Key makeKey(const OSB_LIB::Id2<T>& id)
00116 {
00117 return makeKey(id.id1_, id.id2_);
00118 }
00119
00120 public:
00121
00122 explicit Locators(unsigned long maxSize = 10000);
00123
00124
00125 ~Locators();
00126
00127 private:
00129 Locators(const Locators&);
00131 Locators& operator=(const Locators&);
00132
00133 public:
00145 template<typename T>
00146 Key regServant(
00147 const OSB_LIB::Id2<T>& id,
00148 PortableServer::Servant servant
00149 )
00150 {
00151 Locators::Key key = Locators::makeKey(id.id1_, id.id2_);
00152 return registerServant(key, servant);
00153 }
00154
00166 template<typename T>
00167 Key regServant(
00168 const OSB_LIB::Id<T>& id,
00169 PortableServer::Servant servant
00170 )
00171 {
00172 Locators::Key key = Locators::makeKey(id.id());
00173 return registerServant(key, servant);
00174 }
00175
00188 Key regServant(
00189 PortableServer::Servant servant
00190 );
00191
00216 template<typename T>
00217 Key regServantInc(
00218 const OSB_LIB::Id<T>& id,
00219 PortableServer::Servant servant
00220 )
00221 {
00222 unsigned long c = increaseCounter();
00223 Locators::Key key = Locators::makeKey(id.id(), c);
00224 return registerServant(key, servant);
00225 }
00226
00239 Key regServantInc(
00240 PortableServer::Servant servant
00241 );
00242
00256 void unregServant(
00257 const Key& key,
00258 bool destroy
00259 );
00260
00273 PortableServer::Servant find(
00274 const Key& key,
00275 unsigned long oid
00276 );
00277
00279 PortableServer::Servant find(const Key& key);
00280
00282 template<typename T>
00283 PortableServer::Servant find(
00284 const OSB_LIB::Id<T>& id
00285 )
00286 {
00287 return find(makeKey(id));
00288 }
00289
00291 template<typename T>
00292 PortableServer::Servant find(
00293 const OSB_LIB::Id2<T>& id
00294 )
00295 {
00296 return find(makeKey(id));
00297 }
00298
00312 virtual PortableServer::Servant preinvoke(
00313 const PortableServer::ObjectId& oid,
00314 PortableServer::POA_ptr poa,
00315 const char* operation,
00316 void* & cookie
00317 ) throw (
00318 CORBA::SystemException, PortableServer::ForwardRequest
00319 );
00320
00322 virtual void postinvoke(
00323 const PortableServer::ObjectId& oid,
00324 PortableServer::POA_ptr poa,
00325 const char* operation,
00326 void* cookie,
00327 PortableServer::Servant servant
00328 ) throw (CORBA::SystemException);
00329
00330 private:
00344 Key registerServant(
00345 Key key,
00346 PortableServer::Servant servant
00347 );
00348
00350 unsigned long increaseCounter();
00351
00365 CORBA::Boolean isEqual(
00366 const Key& key,
00367 unsigned long oid
00368 );
00369
00378 Key oidToKey(
00379 const PortableServer::ObjectId& oid
00380 ) throw (OsbCorbaException);
00381
00382 private:
00384 typedef OSB_LIB::RwGuard RwGuard;
00386 RwGuard readlock();
00388 RwGuard writelock();
00389
00390 private:
00392 typedef std::list<Key> EvictorQueue;
00393
00395 typedef std::map<Key, PortableServer::Servant> ActiveObjectMap;
00396
00398 OSB_LIB::RwMutex mutex_;
00399
00401 unsigned long maxSize_;
00403 unsigned long count_;
00404
00405 bool inDtor_;
00407 EvictorQueue evictorQ_;
00409 ActiveObjectMap servantMap_;
00410 };
00411 }
00412 #endif // #ifndef _SERVANTLOCATORS_H_