--- parser3/src/include/pa_stylesheet_connection.h 2002/03/27 15:30:35 1.28 +++ parser3/src/include/pa_stylesheet_connection.h 2003/03/21 13:42:29 1.32.2.5.2.2 @@ -1,22 +1,23 @@ /** @file Parser: Stylesheet connection decl. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: pa_stylesheet_connection.h,v 1.28 2002/03/27 15:30:35 paf Exp $ */ #ifndef PA_STYLESHEET_CONNECTION_H #define PA_STYLESHEET_CONNECTION_H +static const char* IDENT_STYLESHEET_CONNECTION_H="$Date: 2003/03/21 13:42:29 $"; + #include "libxslt/xslt.h" #include "libxslt/xsltInternals.h" -#include "pa_pool.h" + #include "pa_stylesheet_manager.h" #include "pa_exception.h" #include "pa_common.h" +#include "pa_globals.h" // defines @@ -25,27 +26,26 @@ /** Connection with stylesheet: remembers time and can figure out that it needs recompilation */ -class Stylesheet_connection : public Pooled { +class Stylesheet_connection: public PA_Object { +private: - friend class Stylesheet_connection_ptr; + const String& ffile_spec; + xsltStylesheet *fstylesheet; + time_t time_used; + time_t prev_disk_time; public: - Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool), + Stylesheet_connection(const String& afile_spec): ffile_spec(afile_spec), prev_disk_time(0), - fservices_pool(0), fstylesheet(0), - time_used(0), used(0) { - } + time_used(0) {} const String& file_spec() { return ffile_spec; } - void set_services(Pool *aservices_pool) { - fservices_pool=aservices_pool; - } bool expired(time_t older_dies) { - return !used && time_usedclose_connection(ffile_spec, *this); + stylesheet_manager.close_connection(ffile_spec, *this); } private: @@ -77,17 +77,18 @@ private: } void load(time_t new_disk_time) { - Pool& pool=*fservices_pool; - + int saved=xmlDoValidityCheckingDefaultValue;// + xmlDoValidityCheckingDefaultValue=0;// xsltStylesheet *nstylesheet= - xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::UL_FILE_SPEC)); + xsltParseStylesheetFile(BAD_CAST ffile_spec->cstr(String::L_FILE_SPEC).get()); + xmlDoValidityCheckingDefaultValue = saved;// if(xmlHaveGenericErrors()) { GdomeException exc=0; - throw Exception(&ffile_spec, exc); + throw Exception(ffile_spec, exc); } if(!nstylesheet) throw Exception("file.missing", - &ffile_spec, + ffile_spec, "stylesheet failed to load"); xsltFreeStylesheet(fstylesheet); @@ -98,8 +99,8 @@ private: time_t get_disk_time() { size_t size; time_t atime, mtime, ctime; - String stamp_file_spec(ffile_spec); - stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; + const String& stamp_file_spec(new String(*ffile_spec)); + *stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; // {file_spec}.stamp modification time OR {file_spec} const String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; file_stat(stat_file_spec, @@ -109,65 +110,12 @@ private: return mtime; } -private: // connection usage methods - - void use() { + void touch() { time_used=time(0); // they started to use at this time - used++; } - void unuse() { - used--; - if(!used) - close(); - } - -private: // connection usage data - int used; - -private: - - const String& ffile_spec; - xsltStylesheet *fstylesheet; - time_t time_used; - time_t prev_disk_time; - -private: - - Pool *fservices_pool; - -private: - void *malloc(size_t size) { return fservices_pool->malloc(size); } - void *calloc(size_t size) { return fservices_pool->calloc(size); } }; -/// Auto-object used to track Stylesheet_connection usage -class Stylesheet_connection_ptr { - Stylesheet_connection *fconnection; -public: - explicit Stylesheet_connection_ptr(Stylesheet_connection *aconnection) : - fconnection(aconnection) { - fconnection->use(); - } - ~Stylesheet_connection_ptr() { - fconnection->unuse(); - } - Stylesheet_connection* operator->() { - return fconnection; - } - - // copying - Stylesheet_connection_ptr(const Stylesheet_connection_ptr& src) : fconnection(src.fconnection) { - fconnection->use(); - } - Stylesheet_connection_ptr& operator =(const Stylesheet_connection_ptr& src) { - // may do without this=src check - fconnection->unuse(); - fconnection=src.fconnection; - fconnection->use(); - - return *this; - } -}; +DECLARE_OBJECT_PTR(Stylesheet_connection); #endif