Diff for /parser3/src/main/pa_stylesheet_manager.C between versions 1.16.2.7 and 1.18

version 1.16.2.7, 2003/03/06 16:15:25 version 1.18, 2003/09/25 09:15:03
Line 10 Line 10
 static const char* IDENT_STYLESHEET_MANAGER_C="$Date$";  static const char* IDENT_STYLESHEET_MANAGER_C="$Date$";
   
 #include "pa_stylesheet_manager.h"  #include "pa_stylesheet_manager.h"
 #include "pa_stylesheet_connection.h"  
 #include "pa_exception.h"  #include "pa_exception.h"
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_threads.h"  #include "pa_threads.h"
Line 35  static void expire_connection(Stylesheet Line 34  static void expire_connection(Stylesheet
                 connection.disconnect();                  connection.disconnect();
 }  }
 static void expire_connections(  static void expire_connections(
                                                            Stylesheet_manager::connection_cache_type::key_type /*key*/,                                  Stylesheet_manager::connection_cache_type::key_type /*key*/, 
                                                            Stylesheet_manager::connection_cache_type::value_type stack,                                  Stylesheet_manager::connection_cache_type::value_type stack, 
                                                            time_t older_dies) {                                 time_t older_dies) {
         for(int i=0; i<=stack->top_index(); i++)          for(size_t i=0; i<stack->top(); i++)
                 expire_connection(*stack->get(i), older_dies);                  expire_connection(*stack->get(i), older_dies);
 }  }
   
 // Stylesheet_manager  // Stylesheet_connection methods
   
   void Stylesheet_connection::close() {
           stylesheet_manager.close_connection(ffile_spec, *this);
   }
   
   // Stylesheet_manager methods
   
 Stylesheet_manager::Stylesheet_manager(): prev_expiration_pass_time(0) {  Stylesheet_manager::Stylesheet_manager(): prev_expiration_pass_time(0) {
   
         cache_managers.put(StringPtr(new String("stylesheet")), this);          cache_managers.put(String::Body("stylesheet"), this);
 }  }
   
 Stylesheet_manager::~Stylesheet_manager() {  Stylesheet_manager::~Stylesheet_manager() {
         connection_cache.for_each(expire_connections, time(0)+SECOND/*=in future=expire all*/);          connection_cache.for_each(expire_connections, time(0)+SECOND/*=in future=expire all*/);
 }  }
   
 Stylesheet_connectionPtr Stylesheet_manager::get_connection(StringPtr file_spec) {  Stylesheet_connection_ptr Stylesheet_manager::get_connection(const String& file_spec) {
         Stylesheet_connectionPtr result=get_connection_from_cache(file_spec);          Stylesheet_connection* result=get_connection_from_cache(file_spec);
         if(!result)          if(!result)
                 result=Stylesheet_connectionPtr(new Stylesheet_connection(file_spec));                  result=new Stylesheet_connection(file_spec);
         return result;          return Stylesheet_connection_ptr(result);
 }  }
   
 void Stylesheet_manager::close_connection(StringPtr file_spec,   void Stylesheet_manager::close_connection(const String& file_spec, 
                                                                                   Stylesheet_connection& connection) {                                                                                    Stylesheet_connection& connection) {
         put_connection_to_cache(file_spec, Stylesheet_connectionPtr(&connection));          put_connection_to_cache(file_spec, connection);
 }  }
   
 // stylesheet cache  // stylesheet cache
 /// @todo get rid of memory spending Stack [zeros deep inside got accumulated]  /// @todo get rid of memory spending Stack [zeros deep inside got accumulated]
 Stylesheet_connectionPtr Stylesheet_manager::get_connection_from_cache(StringPtr file_spec) {   Stylesheet_connection* Stylesheet_manager::get_connection_from_cache(const String& file_spec) { 
         SYNCHRONIZED;          SYNCHRONIZED;
   
         if(connection_cache_type::value_type connections=connection_cache.get(file_spec))          if(connection_cache_type::value_type connections=connection_cache.get(file_spec))
                 while(connections->top_index()>=0) { // there are cached stylesheets to that 'file_spec'                  while(!connections->is_empty()) { // there are cached stylesheets to that 'file_spec'
                         Stylesheet_connectionPtr result=connections->pop();                          Stylesheet_connection* result=connections->pop();
                         if(result->connected()) // not expired?                          if(result->connected()) // not expired?
                                 return result;                                  return result;
                 }                  }
   
         return Stylesheet_connectionPtr(0);          return 0;
 }  }
   
 void Stylesheet_manager::put_connection_to_cache(StringPtr file_spec,   void Stylesheet_manager::put_connection_to_cache(const String& file_spec, 
                                                                                                  Stylesheet_connectionPtr connection) {                                                    Stylesheet_connection& connection) { 
         SYNCHRONIZED;          SYNCHRONIZED;
   
         connection_cache_type::value_type connections=connection_cache.get(file_spec);          connection_cache_type::value_type connections=connection_cache.get(file_spec);
         if(!connections) { // there are no cached stylesheets to that 'file_spec' yet?          if(!connections) { // there are no cached stylesheets to that 'file_spec' yet?
                 connections=connection_cache_type::value_type(new connection_cache_type::value_type::element_type);                  connections=new connection_cache_value_type;
                 connection_cache.put(file_spec, connections);                  connection_cache.put(file_spec, connections);
         }                 }       
         connections->push(connection);          connections->push(&connection);
 }  }
   
 void Stylesheet_manager::maybe_expire_cache() {  void Stylesheet_manager::maybe_expire_cache() {
Line 107  static void add_connection_to_status_cac Line 112  static void add_connection_to_status_cac
         Table& table=*static_cast<Table *>(info);          Table& table=*static_cast<Table *>(info);
   
         if(connection.connected()) {          if(connection.connected()) {
                 Pool& pool=table.pool();                  =table.pool();
                 Array& row=*new(pool) Array(pool);                  Array& row=*new Array();
   
                 // file                  // file
                 row+=&connection.file_spec();                  row+=&connection.file_spec();
                 // time                  // time
                 time_t time_stamp=connection.get_time_used();                  time_t time_stamp=connection.get_time_used();
                 row+=new(pool) String(pool, pool.copy(ctime(&time_stamp)));                  row+=new String(pool.copy(ctime(&time_stamp)));
   
                 table+=&row;                  table+=&row;
         }          }
Line 126  static void add_connections_to_status_ca Line 131  static void add_connections_to_status_ca
                 add_connection_to_status_cache_table(iter.next(), info);                  add_connection_to_status_cache_table(iter.next(), info);
 }  }
 */  */
 ValuePtr Stylesheet_manager::get_status(Pool& pool, StringPtr source) {  Value* Stylesheet_manager::get_status() {
         VHashPtr result(new VHash);          VHash* result=new VHash;
 /*  /*
         // cache          // cache
         {          {
                 Array& columns=*new(pool) Array(pool);                  Array& columns=*new Array();
                 columns+=new(pool) String(pool, "file");                  columns+=new String("file");
                 columns+=new(pool) String(pool, "time");                  columns+=new String("time");
                 Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size());                  Table& table=*new Table(0, &columns, connection_cache.length());
   
                 connection_cache.for_each(add_connections_to_status_cache_table, &table);                  connection_cache.for_each(add_connections_to_status_cache_table, &table);
   
                 result.hash(source).put(*new(pool) String(pool, "cache"), new(pool) VTable(pool, &table));                  result.hash(source).put(*new String("cache"), new VTable(&table));
         }          }
 */  */
         return result;          return result;

Removed from v.1.16.2.7  
changed lines
  Added in v.1.18


E-mail: