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

Go to the documentation of this file.
00001 #ifndef IPC_POLICY_H
00002 #define IPC_POLICY_H
00003 
00005 //      policy.h
00006 //
00007 //      header file for the IPC library
00008 //
00009 //      Sergei Kolos, September 2003
00010 //
00011 //      description:
00013 
00014 #include <string>
00015 
00016 #include <ipc/cache.h>
00017 #include <ipc/singleton.h>
00018 
00028 namespace ipc
00029 {    
00030     typedef CORBA::Object_ptr (*Fun1)(const std::string&);
00031     typedef CORBA::Object_ptr (*Fun3)(const std::string&,const std::string&,const std::string&);
00032         
00033     
00039     template <class T, template < class > class VP>
00040     struct use_cache
00041     {
00042         template <Fun1 fun>
00043         static
00044         typename T::_ptr_type resolve( const std::string & name )
00045         {
00046             CORBA::Object_var obj = IPCSingleton<IPCCache>::instance()->find( name );
00047             typename T::_var_type result = VP<T>::validate( obj );
00048             if ( CORBA::is_nil( result ) )
00049             {
00050                 obj = fun( name );
00051                 result = VP<T>::validate( obj );
00052                 if ( !CORBA::is_nil( result ) )
00053                 {
00054                     IPCSingleton<IPCCache>::instance()->insert( name, result );
00055                 }
00056             }
00057             return T::_duplicate( result );
00058         }
00059         
00060         template <Fun3 fun>
00061         static
00062         typename T::_ptr_type resolve( const std::string & n1, const std::string & n2, const std::string & n3 )
00063         {
00064             CORBA::Object_var obj = IPCSingleton<IPCCache>::instance()->find( n1, n2, n3 );
00065             typename T::_var_type result = VP<T>::validate( obj );
00066             if ( CORBA::is_nil( result ) )
00067             {
00068                 obj = fun( n1, n2, n3 );
00069                 result = VP<T>::validate( obj );
00070                 if ( !CORBA::is_nil( result ) )
00071                 {
00072                     IPCSingleton<IPCCache>::instance()->insert( n1, n2, n3, result );
00073                 }
00074             }
00075             return T::_duplicate( result );
00076         }
00077     };
00078         
00084     template <class T, template < class > class VP>
00085     struct no_cache
00086     {
00087         template <Fun1 fun>
00088         static
00089         typename T::_ptr_type resolve( const std::string & name )
00090         {
00091             CORBA::Object_var obj = fun( name );
00092             return VP<T>::validate( obj );
00093         }
00094         
00095         template <Fun3 fun>
00096         static
00097         typename T::_ptr_type resolve( const std::string & n1, const std::string & n2, const std::string & n3 )
00098         {
00099             CORBA::Object_var obj = fun( n1, n2, n3 );
00100             return VP<T>::validate( obj );
00101         }
00102     };
00103     
00112     template <class T>
00113     struct unchecked_narrow
00114     {
00115         static
00116         typename T::_ptr_type 
00117         validate( CORBA::Object_ptr obj ) { return T::_unchecked_narrow(obj); }
00118     };
00119     
00128     template <class T>
00129     struct narrow
00130     {
00131         static
00132         typename T::_ptr_type 
00133         validate( CORBA::Object_ptr obj )
00134         {
00135             try {
00136                 return T::_narrow(obj);
00137             }
00138             catch(...) { return T::_nil(); }
00139         }
00140     };
00141     
00149     template <class T>
00150     struct non_existent
00151     {
00152         static
00153         typename T::_ptr_type 
00154         validate( CORBA::Object_ptr obj )
00155         {
00156             typename T::_var_type result = T::_nil();
00157             try {
00158                 result = T::_narrow(obj);
00159                 if ( CORBA::is_nil(result) || result -> _non_existent() )
00160                     return T::_nil(); 
00161             }
00162             catch(...) { return T::_nil(); }
00163             return T::_duplicate( result );
00164         }
00165     };
00166     
00173     struct single_thread
00174     {
00175         static bool     threaded( ) { return false; }
00176     };
00177 
00183     struct multi_thread
00184     {
00185         static bool     threaded( ) { return true; }
00186     };
00187 }
00188 
00189 #endif

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