--- parser3/src/include/pa_stylesheet_connection.h 2001/09/15 11:48:41 1.2 +++ parser3/src/include/pa_stylesheet_connection.h 2023/09/26 20:49:07 1.49 @@ -1,118 +1,121 @@ /** @file - Parser: stylesheet fstylesheet decl. + Parser: Stylesheet connection decl. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_stylesheet_connection.h,v 1.2 2001/09/15 11:48:41 parser Exp $ + Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_STYLESHEET_CONNECTION_H #define PA_STYLESHEET_CONNECTION_H -#include "pa_config_includes.h" -#include "pa_pool.h" -#include "pa_xslt_stylesheet_manager.h" -#include "pa_exception.h" -#include "pa_common.h" +#define IDENT_PA_STYLESHEET_CONNECTION_H "$Id: pa_stylesheet_connection.h,v 1.49 2023/09/26 20:49:07 moko Exp $" -#include +#include "libxslt/xslt.h" +#include "libxslt/xsltInternals.h" -// defines -#define STYLESHEET_FILENAME_STAMP_SUFFIX ".stamp" +#include "pa_xml_exception.h" +#include "pa_common.h" +#include "pa_globals.h" +#include "pa_xml_io.h" + +// defines -/** Connection with stylesheet: +/** Connection with stylesheet: remembers time and can figure out that it needs recompilation */ -class Stylesheet_connection : public Pooled { +class Stylesheet_connection: public PA_Object { -public: + friend class Stylesheet_connection_ptr; - Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool), - ftransformer(new XalanTransformer), +private: + String::Body ffile_spec; + xsltStylesheet *fstylesheet; + HashStringBool* dependencies; + time_t time_used; + time_t prev_disk_time; + +public: + + Stylesheet_connection(String::Body afile_spec): ffile_spec(afile_spec), + fstylesheet(0), + dependencies(0), time_used(0), prev_disk_time(0), - fservices_pool(0) { - } - - const String& file_spec() { return ffile_spec; } + used(0) + {} - void set_services(Pool *aservices_pool) { - time_used=time(0); // they started to use at this time - fservices_pool=aservices_pool; - } - bool expired(time_t older_dies) { - return time_usedclose_connection(ffile_spec, *this); + bool uncachable() { + return !dependencies /*means they were external*/; } - void disconnect() { - /*ignore error*/ftransformer->destroyStylesheet(fstylesheet); fstylesheet=0; + bool expired(time_t older_dies) { + return uncachable() || (!used && time_usedprev_disk_time?now_disk_time:0; } - void load(time_t new_disk_time) { - Pool& pool=*fservices_pool; + void load(time_t new_disk_time); + time_t get_disk_time(); - int error=ftransformer->compileStylesheet(ffile_spec.cstr(String::UL_FILE_SPEC), fstylesheet); - if(error) - PTHROW(0, 0, - &ffile_spec, - ftransformer->getLastError()); - - prev_disk_time=new_disk_time; - } - - 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; - // {file_spec}.stamp modification time OR {file_spec} mtime - if(!file_stat(file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec, - size, - atime, mtime, ctime, - false/*no exceptions on global pool, please*/)) - mtime=0; // no file=no time - return mtime; - } +private: // connection usage methods -private: + int used; - const String& ffile_spec; - XalanCompiledStylesheet *fstylesheet; - time_t time_used; - time_t prev_disk_time; + void use() { + time_used=time(0); // they started to use at this time + used++; + } -private: + void unuse() { + used--; + if(!used) + close(); + } - XalanTransformer *ftransformer; +}; - Pool *fservices_pool; +/// Auto-object used to track Stylesheet_connection usage +class Stylesheet_connection_ptr { + Stylesheet_connection *fconnection; +public: + Stylesheet_connection_ptr(Stylesheet_connection *aconnection) : fconnection(aconnection) { + fconnection->use(); + } + ~Stylesheet_connection_ptr() { + fconnection->unuse(); + } + Stylesheet_connection* operator->() { + return fconnection; + } }; #endif