]> git.stg.codes - stg.git/commitdiff
Replace update user authorization loop with std::for_each
authorMaxim Mamontov <faust@gts.dp.ua>
Tue, 5 Apr 2011 09:38:24 +0000 (12:38 +0300)
committerMaxim Mamontov <faust@gts.dp.ua>
Tue, 5 Apr 2011 09:38:24 +0000 (12:38 +0300)
projects/stargazer/plugins/authorization/ao/ao.cpp
projects/stargazer/plugins/authorization/ao/ao.h

index 811807deb4b9dade998eb8306af8038ab201ba01..84e97a0d87a81ab149406e7b30f28dc14057bdcc 100644 (file)
@@ -24,9 +24,11 @@ $Date: 2010/03/04 12:29:06 $
 $Author: faust $
 */
 
 $Author: faust $
 */
 
-#include <stdio.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <signal.h>
+
+#include <csignal>
+#include <algorithm> // for_each
+#include <functional> // mem_fun_ref
 
 #include "ao.h"
 #include "user.h"
 
 #include "ao.h"
 #include "user.h"
@@ -61,7 +63,6 @@ AO_CREATOR aoc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ×
 template <typename varType>
 class IS_CONTAINS_USER: public binary_function<varType, USER_PTR, bool>
 {
 template <typename varType>
 class IS_CONTAINS_USER: public binary_function<varType, USER_PTR, bool>
 {
@@ -94,44 +95,23 @@ AUTH_AO::AUTH_AO()
 {
 }
 //-----------------------------------------------------------------------------
 {
 }
 //-----------------------------------------------------------------------------
-void AUTH_AO::SetUsers(USERS * u)
-{
-users = u;
-}
-//-----------------------------------------------------------------------------
-void AUTH_AO::SetSettings(const MODULE_SETTINGS & s)
-{
-settings = s;
-}
-//-----------------------------------------------------------------------------
-int AUTH_AO::ParseSettings()
-{
-return 0;
-}
-//-----------------------------------------------------------------------------
-const string & AUTH_AO::GetStrError() const
-{
-return errorStr;
-}
-//-----------------------------------------------------------------------------
 int AUTH_AO::Start()
 {
 GetUsers();
 
 int AUTH_AO::Start()
 {
 GetUsers();
 
-list<USER_PTR>::iterator users_iter;
-
-/*onAddUserNotifier.SetAuthorizator(this);
-onDelUserNotifier.SetAuthorizator(this);*/
 users->AddNotifierUserAdd(&onAddUserNotifier);
 users->AddNotifierUserDel(&onDelUserNotifier);
 
 users->AddNotifierUserAdd(&onAddUserNotifier);
 users->AddNotifierUserDel(&onDelUserNotifier);
 
-users_iter = usersList.begin();
-while (users_iter != usersList.end())
+/*list<USER_PTR>::iterator it = usersList.begin();
+while (it != usersList.end())
     {
     {
-    UpdateUserAuthorization(*users_iter);
-    ++users_iter;
-    }
+    UpdateUserAuthorization(*it);
+    ++it;
+    }*/
+std::for_each(usersList.begin(), usersList.end(), std::bind1st(std::mem_fun(&AUTH_AO::UpdateUserAuthorization), this));
+
 isRunning = true;
 isRunning = true;
+
 return 0;
 }
 //-----------------------------------------------------------------------------
 return 0;
 }
 //-----------------------------------------------------------------------------
index 4c0c344a15ac07dba2a2e91e91eebbe42ee5e16b..f6c9f8a18aa479d60662716a9ae7628414dd65d0 100644 (file)
@@ -78,7 +78,7 @@ public:
     AUTH_AO();
     virtual ~AUTH_AO(){};
 
     AUTH_AO();
     virtual ~AUTH_AO(){};
 
-    void                SetUsers(USERS * u);
+    void                SetUsers(USERS * u) { users = u; }
     void                SetTariffs(TARIFFS *) {}
     void                SetAdmins(ADMINS *) {}
     void                SetTraffcounter(TRAFFCOUNTER *) {}
     void                SetTariffs(TARIFFS *) {}
     void                SetAdmins(ADMINS *) {}
     void                SetTraffcounter(TRAFFCOUNTER *) {}
@@ -89,9 +89,9 @@ public:
     int                 Stop();
     int                 Reload() { return 0; }
     bool                IsRunning();
     int                 Stop();
     int                 Reload() { return 0; }
     bool                IsRunning();
-    void                SetSettings(const MODULE_SETTINGS & s);
-    int                 ParseSettings();
-    const std::string & GetStrError() const;
+    void                SetSettings(const MODULE_SETTINGS &) {}
+    int                 ParseSettings() { return 0; }
+    const std::string & GetStrError() const { return errorStr; }
     const std::string   GetVersion() const;
     uint16_t            GetStartPosition() const;
     uint16_t            GetStopPosition() const;
     const std::string   GetVersion() const;
     uint16_t            GetStartPosition() const;
     uint16_t            GetStopPosition() const;
@@ -116,18 +116,11 @@ private:
     bool                isRunning;
     MODULE_SETTINGS     settings;
 
     bool                isRunning;
     MODULE_SETTINGS     settings;
 
-    /*
-    ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ Á×ÔÏÒÉÚÁÃÉÉ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
-    ÓÌÅÄÕÀÝÉÈ ÅÇÏ ÐÁÒÁÍÅÔÒÏ×:
-    - alwaysOnline
-    - ips
-    */
+    list<CHG_BEFORE_NOTIFIER<int> >      BeforeChgAONotifierList;
+    list<CHG_AFTER_NOTIFIER<int> >       AfterChgAONotifierList;
 
 
-    list<CHG_BEFORE_NOTIFIER<int> >         BeforeChgAONotifierList;
-    list<CHG_AFTER_NOTIFIER<int> >          AfterChgAONotifierList;
-
-    list<CHG_BEFORE_NOTIFIER<USER_IPS> >    BeforeChgIPNotifierList;
-    list<CHG_AFTER_NOTIFIER<USER_IPS> >     AfterChgIPNotifierList;
+    list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
+    list<CHG_AFTER_NOTIFIER<USER_IPS> >  AfterChgIPNotifierList;
 
     class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
     public:
 
     class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
     public: