/afs/cern.ch/user/k/kolos/working/online/ipc/ipc/partition.h

Go to the documentation of this file.
00001 #ifndef IPC_PARTITION_H
00002 #define IPC_PARTITION_H
00003 
00005 //      partition.h
00006 //
00007 //      header file for the IPC library
00008 //
00009 //      Sergei Kolos August 2003
00010 //
00011 //      description:
00012 //          This file contains declarations for the IPCPartition class
00013 //
00015 
00016 #include <string>
00017 #include <list>
00018 #include <map>
00019 
00020 #include <ipc/ipc.hh>
00021 #include <ipc/util.h>
00022 #include <ipc/policy.h>
00023 
00029 template <class T> class IPCNamedObjectOperations;
00030 
00036 class IPCPartition
00037 {
00038     template <class > friend class IPCNamedObjectOperations;
00039     friend class Partition_impl;
00040 
00041   public:
00042 
00045     IPCPartition ( ) throw ()
00046       : name_( ipc::partition::default_name )
00047     { ; }
00048 
00052     IPCPartition ( const char * name ) throw ()
00053       : name_( name == 0 ? ipc::partition::default_name : name )
00054     { ; }
00055 
00059     IPCPartition ( const std::string & name ) throw ()
00060       : name_( name )
00061     { ; }
00062 
00065     IPCPartition ( const IPCPartition & p ) throw ()
00066       : name_( p.name_ )
00067     { ; }
00068 
00071     IPCPartition &
00072     operator= ( const IPCPartition & p ) throw () {
00073         if ( this != &p )
00074             name_ = p.name_;
00075         return *this;
00076     }
00077 
00083     const std::string &
00084     name ( ) const throw()
00085     { return name_;}
00086 
00093     bool
00094     isValid ( ) const throw();
00095 
00102     void
00103     getTypes ( std::list< std::string > & list ) const throw (daq::ipc::InvalidPartition);
00104 
00111     ipc::partition_var getImplementation() const throw(daq::ipc::InvalidPartition);
00112 
00122     template < class T >
00123     void
00124     getObjects ( std::map< std::string , typename T::_var_type > & map ) const throw ( daq::ipc::InvalidPartition )
00125     { getObjects<T, ipc::use_cache, ipc::non_existent >( map ); }
00126 
00135     template <class T>
00136     bool
00137     isObjectValid ( const std::string & object_name ) const throw ( daq::ipc::InvalidPartition )
00138     { return isObjectValid<T,ipc::use_cache,ipc::non_existent >( object_name ); }
00139 
00152     template < class T >
00153     typename T::_ptr_type
00154     lookup ( const std::string & object_name ) const
00155                 throw ( daq::ipc::InvalidPartition,
00156                         daq::ipc::ObjectNotFound,
00157                         daq::ipc::InvalidObjectName )
00158     { return lookup<T, ipc::use_cache, ipc::narrow >( object_name ); }
00159 
00178     template < class T, template < class , template < class > class > class RP, template < class > class VP >
00179     void
00180     getObjects ( std::map< std::string, typename T::_var_type > & map,
00181                  const std::string & type_name = ipc::util::getTypeName<T>() ) const throw ( daq::ipc::InvalidPartition )
00182     {
00183         CosNaming::BindingList_var      bl;
00184 
00185         ipc::util::list( name_, type_name, bl );
00186 
00187         if ( bl.operator->() == 0 )
00188             return;
00189 
00190         for ( unsigned int i = 0; i < bl->length(); i++ )
00191         {
00192             std::string object_name = (const char *)bl[i].binding_name[0].id;
00193             
00194             try
00195             {
00196                 map[ object_name ] = lookup<T,RP,VP>( object_name, type_name );
00197             }
00198             catch( ... )
00199             {
00200             }
00201         }
00202     }
00203 
00224     template < class T, template < class , template < class > class > class RP, template < class > class VP >
00225     bool
00226     isObjectValid (     const std::string & object_name,
00227                         const std::string & type_name = ipc::util::getTypeName<T>() ) const
00228                         throw ( daq::ipc::InvalidPartition,
00229                                 daq::ipc::InvalidObjectName )
00230     {
00231         try
00232         {
00233             typename T::_var_type obj = lookup< T, RP, VP >( object_name, type_name );
00234             return true;
00235         }
00236         catch(daq::ipc::ObjectNotFound)
00237         {
00238             return false;
00239         }
00240     }
00241 
00265     template < class T, template < class , template < class > class > class RP, template < class > class VP >
00266     typename T::_ptr_type
00267     lookup (    const std::string & object_name,
00268                 const std::string & type_name = ipc::util::getTypeName<T>() ) const
00269                         throw ( daq::ipc::InvalidPartition,
00270                                 daq::ipc::ObjectNotFound,
00271                                 daq::ipc::InvalidObjectName )
00272     { 
00273         typename T::_ptr_type object = RP<T, VP>::template resolve<ipc::util::resolve>( name_ , object_name, type_name );
00274         if ( CORBA::is_nil(object) ) {
00275             throw daq::ipc::ObjectNotFound( ERS_HERE, name_, type_name, object_name );
00276         }
00277         return object;
00278     }
00279 
00285     static void
00286     getPartitions ( std::list< IPCPartition > & list ) throw();
00287 
00298     template <template < class , template < class > class > class RP>
00299     static void
00300     getPartitions ( std::list< IPCPartition > & list, short = 0 ) throw ()
00301     {
00302         CosNaming::BindingList_var      bl;
00303 
00304         ipc::util::list ( ipc::partition::default_name, "", bl );
00305 
00306         if ( bl.operator->() == 0 )
00307             return;
00308 
00309         for ( unsigned int i = 0; i < bl->length(); i++ ) {
00310             if ( bl[i].binding_type == CosNaming::ncontext )
00311                 continue;
00312 
00313             try {
00314                 std::string name = (const char *)bl[i].binding_name[0].id;
00315                 ipc::partition_var ip = RP< ipc::partition,
00316                                             ipc::non_existent >::template resolve<ipc::util::resolvePartition>( name );
00317                 if ( !CORBA::is_nil(ip) ) {
00318                     list.push_back( IPCPartition( name ) );
00319                 }
00320             }
00321             catch( daq::ipc::InvalidPartition & ex )
00322             {
00323             }
00324         }
00325     }
00326 
00327   private:
00328     void
00329     publish  (  const std::string & object_name,
00330                 const std::string & type_name,
00331                 const ipc::servant_ptr obj )
00332                         const throw ( daq::ipc::InvalidPartition, daq::ipc::InvalidObjectName );
00333 
00334     void
00335     withdraw (  const std::string & object_name,
00336                 const std::string & type_name )
00337                         const throw ( daq::ipc::InvalidPartition, daq::ipc::ObjectNotFound, daq::ipc::InvalidObjectName );
00338 
00339   private:
00340     std::string name_;
00341 };
00342 
00343 #endif // IPC_PARTITION_H

Generated on Tue Aug 8 17:08:21 2006 for IPC User API by  doxygen 1.4.7