]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Command object classes are now members of the CacheManager class.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 4 Jul 2008 17:22:13 +0000 (19:22 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 4 Jul 2008 17:22:13 +0000 (19:22 +0200)
Converted offline_toggle command.

src/CacheManager.h
src/cache_manager.cc

index c829232a17dcb9a381fd471f2a9a309842cbc3f1..8839239c44cbb113981eb1fb431edf0b984ab883 100644 (file)
@@ -69,18 +69,6 @@ public:
      CacheManagerActionLegacy(char const *anAction, char const *aDesc, unsigned int isPwReq, unsigned int isAtomic, OBJH *aHandler);
 };
 
-class CacheManagerShutdownAction : public CacheManagerAction {
-public:
-     virtual void run (StoreEntry *sentry);
-     CacheManagerShutdownAction();
-};
-
-class CacheManagerReconfigureAction : public CacheManagerAction {
-public:
-     virtual void run (StoreEntry *sentry);
-     CacheManagerReconfigureAction();
-};
-
 
 class CacheManagerActionList : public Vector<CacheManagerAction *> {
 };
@@ -130,6 +118,26 @@ protected:
     int CheckPassword(cachemgrStateData * mgr);
     char *PasswdGet(cachemgr_passwd *, const char *);
 
+    // command classes. They are private to the cachemanager because they
+    // may require access to local data sources, plus we avoid polluting
+    // the namespace more than needed.
+    class CacheManagerShutdownAction : public CacheManagerAction {
+    public:
+         virtual void run (StoreEntry *sentry);
+         CacheManagerShutdownAction();
+    };
+    class CacheManagerReconfigureAction : public CacheManagerAction {
+    public:
+         virtual void run (StoreEntry *sentry);
+         CacheManagerReconfigureAction();
+    };
+    class CacheManagerOfflineToggleAction : public CacheManagerAction {
+    public:
+         virtual void run (StoreEntry *sentry);
+         CacheManagerOfflineToggleAction();
+    };
+
+
 private:
     static CacheManager* instance;
 
@@ -138,7 +146,6 @@ private:
     //via the singleton, but it's syntactic hackery
     //TODO: fix so that ActionTable uses a Command pattern and thus
     //      function calls are properly object-wrapped
-    static void ReconfigureCommand(StoreEntry *sentry);
     static void MenuCommand(StoreEntry *sentry);
     static void OfflineToggleCommand(StoreEntry *sentry);
 
index 73e8c89422833c810d59f77a1b030b4133d62412..03fc82f3725636904b030d885ab920a648cde6f2 100644 (file)
@@ -61,9 +61,8 @@ CacheManager::CacheManager()
          delete(ActionsList); //TODO: Laaazy. Will be moved to class member
     ActionsList = new CacheManagerActionList;
     registerAction("menu", "This Cachemanager Menu", MenuCommand, 0, 1);
-    registerAction("offline_toggle",
-                   "Toggle offline_mode setting",
-                   OfflineToggleCommand, 1, 1);
+    //registerAction("offline_toggle", "Toggle offline_mode setting", OfflineToggleCommand, 1, 1);
+    registerAction(new CacheManagerOfflineToggleAction);
     registerAction(new CacheManagerShutdownAction);
     registerAction(new CacheManagerReconfigureAction);
 }
@@ -335,25 +334,25 @@ CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry)
     StateFree(mgr);
 }
 
-void CacheManagerShutdownAction::run(StoreEntry *sentry)
+void CacheManager::CacheManagerShutdownAction::run(StoreEntry *sentry)
 {
     debugs(16, 0, "Shutdown by command.");
     shut_down(0);
 }
-CacheManagerShutdownAction::CacheManagerShutdownAction() : CacheManagerAction("shutdown","Shut Down the Squid Process", 1, 1) { }
+CacheManager::CacheManagerShutdownAction::CacheManagerShutdownAction() : CacheManagerAction("shutdown","Shut Down the Squid Process", 1, 1) { }
 
 void
-CacheManagerReconfigureAction::run(StoreEntry * sentry)
+CacheManager::CacheManagerReconfigureAction::run(StoreEntry * sentry)
 {
     debug(16, 0) ("Reconfigure by command.\n");
     storeAppendPrintf(sentry, "Reconfiguring Squid Process ....");
     reconfigure(SIGHUP);
 }
-CacheManagerReconfigureAction::CacheManagerReconfigureAction() : CacheManagerAction("reconfigure","Reconfigure Squid", 1, 1) { }
+CacheManager::CacheManagerReconfigureAction::CacheManagerReconfigureAction() : CacheManagerAction("reconfigure","Reconfigure Squid", 1, 1) { }
 
 /// \ingroup CacheManagerInternal
 void
-CacheManager::OfflineToggleCommand(StoreEntry * sentry)
+CacheManager::CacheManagerOfflineToggleAction::run(StoreEntry * sentry)
 {
     Config.onoff.offline = !Config.onoff.offline;
     debugs(16, 0, "offline_mode now " << (Config.onoff.offline ? "ON" : "OFF") << ".");
@@ -361,6 +360,7 @@ CacheManager::OfflineToggleCommand(StoreEntry * sentry)
     storeAppendPrintf(sentry, "offline_mode is now %s\n",
                       Config.onoff.offline ? "ON" : "OFF");
 }
+CacheManager::CacheManagerOfflineToggleAction::CacheManagerOfflineToggleAction() : CacheManagerAction ("offline_toggle", "Toggle offline_mode setting", 1, 1) { }
 
 /// \ingroup CacheManagerInternal
 const char *