|
|
| version 1.16.2.7.2.8, 2003/07/23 08:40:54 | version 1.38, 2026/04/25 13:38:46 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: sql driver manager implementation. | Parser: sql driver manager implementation. |
| Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| #include "pa_config_includes.h" | #include "pa_config_includes.h" |
| #ifdef XML | #ifdef XML |
| static const char* IDENT_STYLESHEET_MANAGER_C="$Date$"; | |
| #include "pa_stylesheet_manager.h" | #include "pa_stylesheet_manager.h" |
| #include "pa_exception.h" | #include "pa_exception.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| Line 17 static const char* IDENT_STYLESHEET_MANA | Line 15 static const char* IDENT_STYLESHEET_MANA |
| #include "pa_vhash.h" | #include "pa_vhash.h" |
| #include "pa_vtable.h" | #include "pa_vtable.h" |
| volatile const char * IDENT_PA_STYLESHEET_MANAGER_C="$Id$" IDENT_PA_STYLESHEET_MANAGER_H; | |
| // globals | // globals |
| Stylesheet_manager stylesheet_manager; | Stylesheet_manager* stylesheet_manager=0; |
| // consts | // consts |
| const time_t SECOND=1; | |
| const time_t EXPIRE_UNUSED_CONNECTION_SECONDS=5*60; | const time_t EXPIRE_UNUSED_CONNECTION_SECONDS=5*60; |
| const time_t CHECK_EXPIRED_CONNECTION_SECONDS=EXPIRE_UNUSED_CONNECTION_SECONDS*2; | const time_t CHECK_EXPIRED_CONNECTION_SECONDS=EXPIRE_UNUSED_CONNECTION_SECONDS*2; |
| Line 33 static void expire_connection(Stylesheet | Line 32 static void expire_connection(Stylesheet |
| if(connection.connected() && connection.expired(older_dies)) | if(connection.connected() && connection.expired(older_dies)) |
| 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::value_type stack, time_t older_dies) { |
| Stylesheet_manager::connection_cache_type::key_type /*key*/, | for(size_t i=0; i<stack->top_index(); i++) |
| Stylesheet_manager::connection_cache_type::value_type stack, | |
| time_t older_dies) { | |
| for(size_t i=0; i<stack->top(); i++) | |
| expire_connection(*stack->get(i), older_dies); | expire_connection(*stack->get(i), older_dies); |
| } | } |
| // Stylesheet_connection methods | // Stylesheet_connection methods |
| void Stylesheet_connection::close() { | void Stylesheet_connection::close() { |
| stylesheet_manager.close_connection(ffile_spec, *this); | stylesheet_manager->close_connection(ffile_spec, *this); |
| } | } |
| // Stylesheet_manager methods | // Stylesheet_manager methods |
| Stylesheet_manager::Stylesheet_manager(): prev_expiration_pass_time(0) { | Stylesheet_manager::Stylesheet_manager(): prev_expiration_pass_time(0) { |
| cache_managers.put(StringBody("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<time_t>(expire_connections, time(0)+(time_t)10/*=in future=expire all*/); |
| } | } |
| Stylesheet_connection_ptr Stylesheet_manager::get_connection(const String& file_spec) { | Stylesheet_connection* Stylesheet_manager::get_connection(String::Body file_spec) { |
| Stylesheet_connection* result=get_connection_from_cache(file_spec); | Stylesheet_connection* result=get_connection_from_cache(file_spec); |
| if(!result) | return result ? result : new Stylesheet_connection(file_spec); |
| result=new Stylesheet_connection(file_spec); | |
| return Stylesheet_connection_ptr(result); | |
| } | } |
| void Stylesheet_manager::close_connection(const String& file_spec, | void Stylesheet_manager::close_connection(String::Body file_spec, Stylesheet_connection& connection) { |
| Stylesheet_connection& connection) { | |
| put_connection_to_cache(file_spec, 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_connection* Stylesheet_manager::get_connection_from_cache(const String& file_spec) { | Stylesheet_connection* Stylesheet_manager::get_connection_from_cache(String::Body 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)) |
| Line 85 Stylesheet_connection* Stylesheet_manage | Line 76 Stylesheet_connection* Stylesheet_manage |
| return 0; | return 0; |
| } | } |
| void Stylesheet_manager::put_connection_to_cache(const String& file_spec, | void Stylesheet_manager::put_connection_to_cache(String::Body file_spec, Stylesheet_connection& 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); |
| Line 101 void Stylesheet_manager::maybe_expire_ca | Line 91 void Stylesheet_manager::maybe_expire_ca |
| 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) { |
| connection_cache.for_each(expire_connections, now-EXPIRE_UNUSED_CONNECTION_SECONDS); | connection_cache.for_each<time_t>(expire_connections, now-EXPIRE_UNUSED_CONNECTION_SECONDS); |
| prev_expiration_pass_time=now; | prev_expiration_pass_time=now; |
| } | } |
| } | } |
| /* | |
| static void add_connection_to_status_cache_table(Array::Item *value, void *info) { | |
| Stylesheet_connection& connection=*static_cast<Stylesheet_connection *>(value); | |
| Table& table=*static_cast<Table *>(info); | |
| static void add_connection_to_status_cache_table(Stylesheet_connection& connection, Table* table) { | |
| if(connection.connected()) { | if(connection.connected()) { |
| =table.pool(); | ArrayString& row=*new ArrayString; |
| Array& row=*new Array(); | |
| // file | // file |
| row+=&connection.file_spec(); | row+=new String(connection.file_spec(), String::L_AS_IS); |
| // time | // time |
| time_t time_stamp=connection.get_time_used(); | time_t time_used=connection.get_time_used(); |
| row+=new String(pool.copy(ctime(&time_stamp))); | 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) { | 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) { |
| Stack& stack=*static_cast<Stack *>(value); | for(Array_iterator<Stylesheet_connection*> i(*stack); i; ) |
| Array_iter iter(stack); | add_connection_to_status_cache_table(*i.next(), table); |
| for(int countdown=stack.top_index(); countdown-->=0; ) | |
| add_connection_to_status_cache_table(iter.next(), info); | |
| } | } |
| */ | |
| Value* Stylesheet_manager::get_status() { | Value* Stylesheet_manager::get_status() { |
| VHash* result=new VHash; | VHash* result=new VHash; |
| /* | |
| // cache | // cache |
| { | { |
| Array& columns=*new Array(); | ArrayString& columns=*new ArrayString; |
| columns+=new String("file"); | columns+=new String("file"); |
| columns+=new String("time"); | columns+=new String("time"); |
| Table& table=*new Table(0, &columns, connection_cache.length()); | Table& table=*new Table(&columns, connection_cache.count()); |
| connection_cache.for_each(add_connections_to_status_cache_table, &table); | connection_cache.for_each<Table*>(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; | return result; |
| } | } |