Diff for /parser3/src/main/pa_stylesheet_manager.C between versions 1.3 and 1.10

version 1.3, 2001/11/05 10:42:59 version 1.10, 2002/01/16 10:28:35
Line 2 Line 2
         Parser: sql driver manager implementation.          Parser: sql driver manager implementation.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
   
         $Id$          $Id$
 */  */
Line 11 Line 11
   
 #include "pa_stylesheet_manager.h"  #include "pa_stylesheet_manager.h"
 #include "pa_stylesheet_connection.h"  #include "pa_stylesheet_connection.h"
 #include "ltdl.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 45  static void expire_connections(const Has Line 44  static void expire_connections(const Has
   
 // Stylesheet_manager  // Stylesheet_manager
   
 Stylesheet_manager::Stylesheet_manager(Pool& apool) : Pooled(apool),  Stylesheet_manager::Stylesheet_manager(Pool& apool) : Cache_manager(apool),
         connection_cache(apool),          connection_cache(apool),
         prev_expiration_pass_time(0) {          prev_expiration_pass_time(0) {
                   }
         status_providers->put(*NEW String(pool(), "stylesheet"), this);  
 }  
 Stylesheet_manager::~Stylesheet_manager() {  Stylesheet_manager::~Stylesheet_manager() {
         connection_cache.for_each(expire_connections,           connection_cache.for_each(expire_connections, 
                 reinterpret_cast<void *>((time_t)0/*=in past=expire all*/));                  reinterpret_cast<void *>(time(0)+1/*=in future=expire all*/));
 }  }
   
 Stylesheet_connection& Stylesheet_manager::get_connection(const String& request_file_spec) {  Stylesheet_connection_ptr Stylesheet_manager::get_connection(const String& request_file_spec) {
         Pool& pool=request_file_spec.pool(); // request pool                                                                                                 Pool& pool=request_file_spec.pool(); // request pool                                                                                       
   
         // first trying to get cached stylesheet          // first trying to get cached stylesheet
         Stylesheet_connection *result=get_connection_from_cache(request_file_spec);          Stylesheet_connection *connection=get_connection_from_cache(request_file_spec);
         if(!result) {          if(!connection) {
                 // then just construct it                  // then just construct it
   
                 // make global_file_spec C-string on global pool                  // make global_file_spec C-string on global pool
Line 71  Stylesheet_connection& Stylesheet_manage Line 68  Stylesheet_connection& Stylesheet_manage
                 // make global_file_spec string on global pool                  // make global_file_spec string on global pool
                 String& global_file_spec=*new(this->pool()) String(this->pool(), global_file_spec_cstr);                  String& global_file_spec=*new(this->pool()) String(this->pool(), global_file_spec_cstr);
   
                 result=new(this->pool()) Stylesheet_connection(this->pool(), global_file_spec);                  connection=new(this->pool()) Stylesheet_connection(this->pool(), global_file_spec);
         }          }
         // associate with services[request]  (deassociates at close)          // associate with services[request]  (deassociates at close)
         result->set_services(&pool);           connection->set_services(&pool); 
         // return it          // return autoclosing object for it
         return *result;          return connection;
 }  }
   
 void Stylesheet_manager::close_connection(const String& file_spec,   void Stylesheet_manager::close_connection(const String& file_spec, 
Line 92  void Stylesheet_manager::close_connectio Line 89  void Stylesheet_manager::close_connectio
 Stylesheet_connection *Stylesheet_manager::get_connection_from_cache(const String& file_spec) {   Stylesheet_connection *Stylesheet_manager::get_connection_from_cache(const String& file_spec) { 
         SYNCHRONIZED;          SYNCHRONIZED;
   
         maybe_expire_connection_cache();  
   
         if(Stack *connections=static_cast<Stack *>(connection_cache.get(file_spec)))          if(Stack *connections=static_cast<Stack *>(connection_cache.get(file_spec)))
                 while(connections->top_index()>=0) { // there are cached stylesheets to that 'file_spec'                  while(connections->top_index()>=0) { // there are cached stylesheets to that 'file_spec'
                         Stylesheet_connection *result=static_cast<Stylesheet_connection *>(connections->pop());                          Stylesheet_connection *result=static_cast<Stylesheet_connection *>(connections->pop());
Line 116  void Stylesheet_manager::put_connection_ Line 111  void Stylesheet_manager::put_connection_
         connections->push(&connection);          connections->push(&connection);
 }  }
   
 void Stylesheet_manager::maybe_expire_connection_cache() {  void Stylesheet_manager::maybe_expire_cache() {
         time_t now=time(0);          time_t now=time(0);
   
         if(prev_expiration_pass_time<now-CHECK_EXPIRED_CONNECTION_SECONDS) {          if(prev_expiration_pass_time<now-CHECK_EXPIRED_CONNECTION_SECONDS) {
Line 133  static void add_connection_to_status_cac Line 128  static void add_connection_to_status_cac
   
         if(connection.connected()) {          if(connection.connected()) {
                 Pool& pool=table.pool();                  Pool& pool=table.pool();
                 Array& row=*new(pool) Array(pool, 3);                  Array& row=*new(pool) Array(pool);
   
                   // file
                 row+=&connection.file_spec();                  row+=&connection.file_spec();
                   // time
                 time_t time_stamp=connection.get_time_used();                  time_t time_stamp=connection.get_time_used();
                 const char *unsafe_time_cstr=ctime(&time_stamp);                  const char *unsafe_time_cstr=ctime(&time_stamp);
                 int time_buf_size=strlen(unsafe_time_cstr);                  int time_buf_size=strlen(unsafe_time_cstr);
Line 152  static void add_connections_to_status_ca Line 149  static void add_connections_to_status_ca
         for(int countdown=stack.top_index(); countdown-->=0; )          for(int countdown=stack.top_index(); countdown-->=0; )
                 add_connection_to_status_cache_table(iter.next(), info);                  add_connection_to_status_cache_table(iter.next(), info);
 }  }
   
 Value& Stylesheet_manager::get_status(Pool& pool, const String *source) {  Value& Stylesheet_manager::get_status(Pool& pool, const String *source) {
         VHash& result=*new(pool) VHash(pool);          VHash& result=*new(pool) VHash(pool);
   
         // cache          // cache
         {          {
                 Array& columns=*new(pool) Array(pool, 3);                  Array& columns=*new(pool) Array(pool);
                 columns+=new(pool) String(pool, "file");                  columns+=new(pool) String(pool, "file");
                 columns+=new(pool) String(pool, "time");                  columns+=new(pool) String(pool, "time");
                 Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size());                  Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size());

Removed from v.1.3  
changed lines
  Added in v.1.10


E-mail: