]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
More refactoring: moved some C-style methods to C++ static member functions,
authorKinkie <kinkie@squid-cache.org>
Mon, 30 Jun 2008 09:45:54 +0000 (11:45 +0200)
committerKinkie <kinkie@squid-cache.org>
Mon, 30 Jun 2008 09:45:54 +0000 (11:45 +0200)
gotten rid of findAction

src/CacheManager.h
src/cache_manager.cc

index 12a3bdc27e52b136d145dfc34ef47cbda59492a7..807842356079e37ffb4390e2f227217e1cbf08fa 100644 (file)
@@ -110,6 +110,16 @@ protected:
 private:
     static CacheManager* instance;
 
+    //commands need to be static to be able to be referenced as C-style
+    //functions. Binding to nonstatic members can be done at runtime
+    //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 ShutdownCommand(StoreEntry *unused);
+    static void ReconfigureCommand(StoreEntry *sentry);
+    static void MenuCommand(StoreEntry *sentry);
+    static void OfflineToggleCommand(StoreEntry *sentry);
+
 
 };
 
index 4284bd4adc518657b20b3783f1fa7a05ec369871..2f4cce6e0ce7f7b68b076d9bfa7b533477776ddd 100644 (file)
 #define MGR_PASSWD_SZ 128
 
 
-static CacheManagerAction *cachemgrFindAction(const char *action);
 static void cachemgrStateFree(cachemgrStateData * mgr);
-static OBJH cachemgrShutdown;
-static OBJH cachemgrReconfigure;
-static OBJH cachemgrMenu;
-static OBJH cachemgrOfflineToggle;
 
 /// \ingroup CacheManagerInternal
 CacheManagerAction *ActionTable = NULL;
 
 CacheManager::CacheManager()
 {
-    registerAction("menu", "This Cachemanager Menu", cachemgrMenu, 0, 1);
+    registerAction("menu", "This Cachemanager Menu", MenuCommand, 0, 1);
     registerAction("shutdown",
                    "Shut Down the Squid Process",
-                   cachemgrShutdown, 1, 1);
+                   ShutdownCommand, 1, 1);
     registerAction("reconfigure",
                      "Reconfigure the Squid Process",
-                     cachemgrReconfigure, 1, 1);
+                     ReconfigureCommand, 1, 1);
     registerAction("offline_toggle",
                    "Toggle offline_mode setting",
-                   cachemgrOfflineToggle, 1, 1);
+                   OfflineToggleCommand, 1, 1);
 }
 
 void
@@ -100,15 +95,13 @@ CacheManager::registerAction(char const * action, char const * desc, OBJH * hand
     debugs(16, 3, "CacheManager::registerAction: registered " <<  action);
 }
 
+/// \ingroup CacheManagerInternal
+//TODO: revert those two functions and turn ActionTable into a 
+//      private data member.
+//      In order to do so ActionTable must be extended to allow using
+//      function objects rather than C-style functions
 CacheManagerAction *
 CacheManager::findAction(char const * action)
-{
-    return cachemgrFindAction(action);
-}
-
-/// \ingroup CacheManagerInternal
-static CacheManagerAction *
-cachemgrFindAction(const char *action)
 {
     CacheManagerAction *a;
 
@@ -144,7 +137,7 @@ CacheManager::ParseUrl(const char *url)
         xstrncpy(request, "menu", MAX_URL);
 #endif
 
-    } else if ((a = cachemgrFindAction(request)) == NULL) {
+    } else if ((a = findAction(request)) == NULL) {
         debugs(16, 1, "CacheManager::ParseUrl: action '" << request << "' not found");
         return NULL;
     } else {
@@ -211,7 +204,7 @@ int
 CacheManager::CheckPassword(cachemgrStateData * mgr)
 {
     char *pwd = PasswdGet(Config.passwd_list, mgr->action);
-    CacheManagerAction *a = cachemgrFindAction(mgr->action);
+    CacheManagerAction *a = findAction(mgr->action);
     assert(a != NULL);
 
     if (pwd == NULL)
@@ -314,7 +307,7 @@ CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry)
            fd_table[fd].ipaddr << " requesting '" << 
            mgr->action << "'" );
     /* retrieve object requested */
-    a = cachemgrFindAction(mgr->action);
+    a = findAction(mgr->action);
     assert(a != NULL);
 
     entry->buffer();
@@ -343,16 +336,16 @@ CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry)
 }
 
 /// \ingroup CacheManagerInternal
-static void
-cachemgrShutdown(StoreEntry * entryunused)
+void
+CacheManager::ShutdownCommand(StoreEntry *unused)
 {
     debugs(16, 0, "Shutdown by command.");
     shut_down(0);
 }
 
 /// \ingroup CacheManagerInternal
-static void
-cachemgrReconfigure(StoreEntry * sentry)
+void
+CacheManager::ReconfigureCommand(StoreEntry * sentry)
 {
     debug(16, 0) ("Reconfigure by command.\n");
     storeAppendPrintf(sentry, "Reconfiguring Squid Process ....");
@@ -360,8 +353,8 @@ cachemgrReconfigure(StoreEntry * sentry)
 }
 
 /// \ingroup CacheManagerInternal
-static void
-cachemgrOfflineToggle(StoreEntry * sentry)
+void
+CacheManager::OfflineToggleCommand(StoreEntry * sentry)
 {
     Config.onoff.offline = !Config.onoff.offline;
     debugs(16, 0, "offline_mode now " << (Config.onoff.offline ? "ON" : "OFF") << ".");
@@ -391,8 +384,8 @@ CacheManager::ActionProtection(const CacheManagerAction * at)
 }
 
 /// \ingroup CacheManagerInternal
-static void
-cachemgrMenu(StoreEntry * sentry)
+void
+CacheManager::MenuCommand(StoreEntry * sentry)
 {
     CacheManagerAction *a;