]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
List of actions is now a first-class protected data member of the cachemgr.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 4 Jul 2008 19:51:21 +0000 (21:51 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 4 Jul 2008 19:51:21 +0000 (21:51 +0200)
MenuCommand constructor has been extended to be able to reach it easily.

src/CacheManager.h
src/cache_manager.cc

index 092d3ad57cf682bd9392900647fcd496b4c902f5..4ff2675e29af0de718f0fc98bb75bdac8e184aa1 100644 (file)
@@ -70,9 +70,6 @@ public:
 };
 
 
-class CacheManagerActionList : public Vector<CacheManagerAction *> {
-};
-
 /**
  \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<CacheManagerAction *> CacheManagerActionList;
+    CacheManagerActionList ActionsList;
+
+
 private:
     static CacheManager* instance;
 
index 8de91f2d681903af32d5ef8e3b4fa00e288d911d..4eed8ad3a6d4c4e094d1bc923ee65922866bd5c6 100644 (file)
 
 
 
-/// \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 *