From: Francesco Chemolli Date: Fri, 4 Jul 2008 19:51:21 +0000 (+0200) Subject: List of actions is now a first-class protected data member of the cachemgr. X-Git-Tag: SQUID_3_1_0_1~49^2~143^2~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=afea465edfdedd1a1d960ef5da577c19384e0306;p=thirdparty%2Fsquid.git List of actions is now a first-class protected data member of the cachemgr. MenuCommand constructor has been extended to be able to reach it easily. --- diff --git a/src/CacheManager.h b/src/CacheManager.h index 092d3ad57c..4ff2675e29 100644 --- a/src/CacheManager.h +++ b/src/CacheManager.h @@ -70,9 +70,6 @@ public: }; -class CacheManagerActionList : public Vector { -}; - /** \ingroup CacheManagerAPI * a CacheManager - the menu system for interacting with squid. @@ -100,11 +97,11 @@ public: void Start(int fd, HttpRequest * request, StoreEntry * entry); static CacheManager* GetInstance(); - const char *ActionProtection(const CacheManagerAction * at); //needs to be called from C + const char *ActionProtection(const CacheManagerAction * at); protected: - // command classes. They are private to the cachemanager because they - // may require access to local data sources, plus we avoid polluting + // command classes. They are private to the cachemanager, they + // may require access to local data, plus we avoid polluting // the namespace more than needed. class ShutdownAction : public CacheManagerAction { public: @@ -122,19 +119,23 @@ protected: OfflineToggleAction(); }; class MenuAction : public CacheManagerAction { + private: + //needs to reference the cachemgr in order to get to ActionsList + CacheManager *cmgr; public: virtual void run (StoreEntry *sentry); - MenuAction(); + MenuAction(CacheManager *); + }; -/// \ingroup CacheManagerInternal -typedef struct -{ - StoreEntry *entry; - char *action; - char *user_name; - char *passwd; -} cachemgrStateData; + /// \ingroup CacheManagerInternal + typedef struct + { + StoreEntry *entry; + char *action; + char *user_name; + char *passwd; + } cachemgrStateData; CacheManager(); @@ -143,6 +144,11 @@ typedef struct int CheckPassword(cachemgrStateData * mgr); char *PasswdGet(cachemgr_passwd *, const char *); + // \ingroup CacheManagerInternal + typedef Vector CacheManagerActionList; + CacheManagerActionList ActionsList; + + private: static CacheManager* instance; diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 8de91f2d68..4eed8ad3a6 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -52,18 +52,15 @@ -/// \ingroup CacheManagerInternal -CacheManagerActionList *ActionsList = NULL; - CacheManager::CacheManager() { - if (ActionsList != NULL) - delete(ActionsList); //TODO: Laaazy. Will be moved to class member - ActionsList = new CacheManagerActionList; + //if (ActionsList != NULL) + // delete(ActionsList); //TODO: Laaazy. Will be moved to class member + //ActionsList = new CacheManagerActionList; registerAction(new OfflineToggleAction); registerAction(new ShutdownAction); registerAction(new ReconfigureAction); - registerAction(new MenuAction); + registerAction(new MenuAction(this)); } void @@ -84,7 +81,7 @@ CacheManager::registerAction(CacheManagerAction *anAction) assert (strstr (" ", action) == NULL); - *ActionsList += anAction; + ActionsList += anAction; debugs(16, 3, "CacheManager::registerAction: registered " << action); } @@ -97,7 +94,7 @@ CacheManager::findAction(char const * action) CacheManagerActionList::iterator a; debugs(16, 5, "CacheManager::findAction: looking for action " << action); - for ( a = ActionsList->begin(); a != ActionsList->end(); a++) { + for ( a = ActionsList.begin(); a != ActionsList.end(); a++) { if (0 == strcmp((*a)->action, action)) { debugs(16, 6, " found"); return *a; @@ -387,13 +384,13 @@ CacheManager::MenuAction::run(StoreEntry * sentry) CacheManagerActionList::iterator a; debugs(16, 4, "CacheManager::MenuCommand invoked"); - for (a = ActionsList->begin(); a != ActionsList->end(); ++a) { + for (a = cmgr->ActionsList.begin(); a != cmgr->ActionsList.end(); ++a) { debugs(16, 5, " showing action " << (*a)->action); storeAppendPrintf(sentry, " %-22s\t%-32s\t%s\n", - (*a)->action, (*a)->desc, CacheManager::GetInstance()->ActionProtection(*a)); + (*a)->action, (*a)->desc, cmgr->ActionProtection(*a)); } } -CacheManager::MenuAction::MenuAction() : CacheManagerAction ("menu", "Cache Manager Menu", 1, 1) { } +CacheManager::MenuAction::MenuAction(CacheManager *aMgr) : CacheManagerAction ("menu", "Cache Manager Menu", 1, 1), cmgr(aMgr) { } /// \ingroup CacheManagerInternal char *