--- parser3/src/main/pa_stylesheet_manager.C 2003/03/20 08:11:15 1.16.2.7.2.2 +++ parser3/src/main/pa_stylesheet_manager.C 2004/02/11 15:33:16 1.26 @@ -1,16 +1,15 @@ /** @file Parser: sql driver manager implementation. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #include "pa_config_includes.h" #ifdef XML -static const char* IDENT_STYLESHEET_MANAGER_C="$Date: 2003/03/20 08:11:15 $"; +static const char * const IDENT_STYLESHEET_MANAGER_C="$Date: 2004/02/11 15:33:16 $"; #include "pa_stylesheet_manager.h" -#include "pa_stylesheet_connection.h" #include "pa_exception.h" #include "pa_common.h" #include "pa_threads.h" @@ -20,11 +19,10 @@ static const char* IDENT_STYLESHEET_MANA // globals -Stylesheet_manager stylesheet_manager; +Stylesheet_manager* stylesheet_manager=0; // consts -const time_t SECOND=1; const time_t EXPIRE_UNUSED_CONNECTION_SECONDS=5*60; const time_t CHECK_EXPIRED_CONNECTION_SECONDS=EXPIRE_UNUSED_CONNECTION_SECONDS*2; @@ -35,61 +33,64 @@ static void expire_connection(Stylesheet connection.disconnect(); } static void expire_connections( - Stylesheet_manager::connection_cache_type::key_type /*key*/, - Stylesheet_manager::connection_cache_type::value_type stack, - time_t older_dies) { - for(int i=0; i<=stack->top_index(); i++) + Stylesheet_manager::connection_cache_type::key_type /*key*/, + Stylesheet_manager::connection_cache_type::value_type stack, + time_t older_dies) { + for(size_t i=0; itop_index(); i++) expire_connection(*stack->get(i), older_dies); } -// Stylesheet_manager +// Stylesheet_connection methods -Stylesheet_manager::Stylesheet_manager(): prev_expiration_pass_time(0) { +void Stylesheet_connection::close() { + stylesheet_manager->close_connection(ffile_spec, *this); +} - cache_managers.put(String* (new String("stylesheet")), this); +// Stylesheet_manager methods + +Stylesheet_manager::Stylesheet_manager(): prev_expiration_pass_time(0) { } 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)+(time_t)10/*=in future=expire all*/); } -Stylesheet_connectionPtr Stylesheet_manager::get_connection(const String& file_spec) { - Stylesheet_connectionPtr result=get_connection_from_cache(file_spec); +Stylesheet_connection_ptr Stylesheet_manager::get_connection(String::Body file_spec) { + Stylesheet_connection* result=get_connection_from_cache(file_spec); if(!result) - result=Stylesheet_connectionPtr(new Stylesheet_connection(file_spec)); - return result; + result=new Stylesheet_connection(file_spec); + return Stylesheet_connection_ptr(result); } -void Stylesheet_manager::close_connection(const String& file_spec, - Stylesheet_connection& connection) { - put_connection_to_cache(file_spec, Stylesheet_connectionPtr(&connection)); +void Stylesheet_manager::close_connection(String::Body file_spec, Stylesheet_connection& connection) { + put_connection_to_cache(file_spec, connection); } // stylesheet cache /// @todo get rid of memory spending Stack [zeros deep inside got accumulated] -Stylesheet_connectionPtr Stylesheet_manager::get_connection_from_cache(const String& file_spec) { +Stylesheet_connection* Stylesheet_manager::get_connection_from_cache(String::Body file_spec) { SYNCHRONIZED; 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' - Stylesheet_connectionPtr result=connections->pop(); + while(!connections->is_empty()) { // there are cached stylesheets to that 'file_spec' + Stylesheet_connection* result=connections->pop(); if(result->connected()) // not expired? return result; } - return Stylesheet_connectionPtr(0); + return 0; } -void Stylesheet_manager::put_connection_to_cache(const String& file_spec, - Stylesheet_connectionPtr connection) { +void Stylesheet_manager::put_connection_to_cache(String::Body file_spec, + Stylesheet_connection& connection) { SYNCHRONIZED; connection_cache_type::value_type connections=connection_cache.get(file_spec); 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); } - connections->push(connection); + connections->push(&connection); } void Stylesheet_manager::maybe_expire_cache() { @@ -101,46 +102,41 @@ void Stylesheet_manager::maybe_expire_ca prev_expiration_pass_time=now; } } -/* -static void add_connection_to_status_cache_table(Array::Item *value, void *info) { - Stylesheet_connection& connection=*static_cast(value); - Table& table=*static_cast(info); +static void add_connection_to_status_cache_table(Stylesheet_connection& connection, Table* table) { if(connection.connected()) { - =table.pool(); - Array& row=*new Array(); + ArrayString& row=*new ArrayString; // file - row+=&connection.file_spec(); + row+=new String(connection.file_spec(), String::L_AS_IS); // time - time_t time_stamp=connection.get_time_used(); - row+=new String(pool.copy(ctime(&time_stamp))); + time_t time_used=connection.get_time_used(); + row+=new String(pa_strdup(ctime(&time_used))); - table+=&row; + *table+=&row; } } -static void add_connections_to_status_cache_table(const Hash::Key& key, Hash::Val *value, void *info) { - Stack& stack=*static_cast(value); - Array_iter iter(stack); - for(int countdown=stack.top_index(); countdown-->=0; ) - add_connection_to_status_cache_table(iter.next(), info); +static void add_connections_to_status_cache_table( + Stylesheet_manager::connection_cache_type::key_type /*key*/, + Stylesheet_manager::connection_cache_type::value_type stack, Table* table) +{ + for(Array_iterator i(*stack); i.has_next(); ) + add_connection_to_status_cache_table(*i.next(), table); } -*/ -ValuePtr Stylesheet_manager::get_statusconst String* source) { - VHashPtr result(new VHash); -/* + +Value* Stylesheet_manager::get_status() { + VHash* result=new VHash; // cache { - Array& columns=*new Array(); + ArrayString& columns=*new ArrayString; columns+=new String("file"); columns+=new String("time"); - Table& table=*new Table(0, &columns, connection_cache.size()); + Table& table=*new Table(&columns, connection_cache.count()); connection_cache.for_each(add_connections_to_status_cache_table, &table); - result.hash(source).put(*new String("cache"), new VTable(&table)); + result->get_hash()->put(*new String("cache"), new VTable(&table)); } -*/ return result; }