From: Alex Rousskov Date: Tue, 17 Mar 2009 15:24:36 +0000 (-0600) Subject: Simplified registration. We will no longer support implicit registration using X-Git-Tag: SQUID_3_2_0_1~1111^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7901db21e7c9063b04c41fdd3d1f4e856e4dea23;p=thirdparty%2Fsquid.git Simplified registration. We will no longer support implicit registration using static initialization because that not-referenced-by-Squid code gets removed when building the squid executable from convenience libraries. Support de-registration as long as it is done in the order opposite of registration. --- diff --git a/src/esi/Parser.cc b/src/esi/Parser.cc index 51546759cf..1b656071b1 100644 --- a/src/esi/Parser.cc +++ b/src/esi/Parser.cc @@ -54,3 +54,14 @@ ESIParser::NewParser(ESIParserClient *aClient) return (Parser->newParser)(aClient); } + +ESIParser::Register::Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser) { + this->next = ESIParser::Parsers; + ESIParser::Parsers = this; +} + +ESIParser::Register::~Register() { + // TODO: support random-order deregistration + assert(ESIParser::Parsers == this); + ESIParser::Parsers = next; +} diff --git a/src/esi/Parser.h b/src/esi/Parser.h index e6bbfb1962..13ac18d4f3 100644 --- a/src/esi/Parser.h +++ b/src/esi/Parser.h @@ -52,6 +52,7 @@ public: class ESIParser : public RefCountable { public: + class Register; typedef RefCount Pointer; static void registerParser(const char *name, Pointer (*new_func)(ESIParserClient *aClient)); @@ -70,8 +71,6 @@ public: protected: ESIParser() {}; - class Register; - private: static Register *Parser; static Register *Parsers; @@ -83,26 +82,21 @@ class ESIParser::Register { public: - Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser) { - this->next = ESIParser::Parsers; - ESIParser::Parsers = this; - } + Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)); + ~Register(); const char *name; ESIParser::Pointer (*newParser)(ESIParserClient *aClient); Register * next; }; -#define RegisterESIParser(name, ThisClass) \ - ESIParser::Register ThisClass::thisParser(name, &NewParser); \ +#define EsiParserDefinition(ThisClass) \ ESIParser::Pointer ThisClass::NewParser(ESIParserClient *aClient) \ { \ return new ThisClass (aClient); \ } -#define ESI_PARSER_TYPE \ - static ESIParser::Pointer NewParser(ESIParserClient *aClient); \ - static ESIParser::Register thisParser - +#define EsiParserDeclaration \ + static ESIParser::Pointer NewParser(ESIParserClient *aClient) #endif /* SQUID_ESIPARSER_H */