--- parser3/src/main/pa_stylesheet_manager.C 2001/10/22 16:44:42 1.1 +++ parser3/src/main/pa_stylesheet_manager.C 2001/11/05 11:46:29 1.4 @@ -2,9 +2,9 @@ Parser: sql driver manager implementation. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_stylesheet_manager.C,v 1.1 2001/10/22 16:44:42 parser Exp $ + $Id: pa_stylesheet_manager.C,v 1.4 2001/11/05 11:46:29 paf Exp $ */ #include "pa_config_includes.h" #ifdef XML @@ -16,6 +16,8 @@ #include "pa_common.h" #include "pa_threads.h" #include "pa_stack.h" +#include "pa_vhash.h" +#include "pa_vtable.h" // globals @@ -43,9 +45,11 @@ static void expire_connections(const Has // Stylesheet_manager -Stylesheet_manager::Stylesheet_manager(Pool& pool) : Pooled(pool), - connection_cache(pool), +Stylesheet_manager::Stylesheet_manager(Pool& apool) : Pooled(apool), + connection_cache(apool), prev_expiration_pass_time(0) { + + status_providers->put(*NEW String(pool(), "stylesheet"), this); } Stylesheet_manager::~Stylesheet_manager() { connection_cache.for_each(expire_connections, @@ -122,4 +126,51 @@ void Stylesheet_manager::maybe_expire_co 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); + + if(connection.connected()) { + Pool& pool=table.pool(); + Array& row=*new(pool) Array(pool); + + // file + row+=&connection.file_spec(); + // time + time_t time_stamp=connection.get_time_used(); + const char *unsafe_time_cstr=ctime(&time_stamp); + int time_buf_size=strlen(unsafe_time_cstr); + char *safe_time_buf=(char *)pool.malloc(time_buf_size); + memcpy(safe_time_buf, unsafe_time_cstr, time_buf_size); + row+=new(pool) String(pool, safe_time_buf, time_buf_size); + + 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); +} + +Value& Stylesheet_manager::get_status(Pool& pool, const String *source) { + VHash& result=*new(pool) VHash(pool); + + // cache + { + Array& columns=*new(pool) Array(pool); + columns+=new(pool) String(pool, "file"); + columns+=new(pool) String(pool, "time"); + Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size()); + + 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)); + } + + return result; +} + #endif