]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp
Merge remote-tracking branch 'github/master'
[stg.git] / projects / stargazer / plugins / store / postgresql / postgresql_store_services.cpp
index 825f798261410fec3da02be913c53cdc630adaf0..2b99fcee71bb5857d46ff42bc5623ec802775c79 100644 (file)
  *
  */
 
+#include "postgresql_store.h"
+
+#include "stg/service_conf.h"
+#include "stg/common.h"
+
 #include <string>
 #include <vector>
 #include <sstream>
 
 #include <libpq-fe.h>
 
-#include "postgresql_store.h"
-#include "stg/locker.h"
-
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetServicesList(std::vector<std::string> * servicesList) const
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -68,9 +70,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK)
     PQclear(result);
     printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): '%s'\n", strError.c_str());
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }
 
@@ -93,9 +95,9 @@ return 0;
 }
 
 //-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveService(const SERVICE_CONF & sc) const
+int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -123,9 +125,9 @@ if (EscapeString(ename))
     {
     printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to escape name'\n");
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }
 
@@ -133,9 +135,9 @@ if (EscapeString(ecomment))
     {
     printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to escape comment'\n");
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }
 
@@ -172,10 +174,10 @@ return 0;
 }
 
 //-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreService(SERVICE_CONF * sc,
-                                   const std::string & name) const
+int POSTGRESQL_STORE::RestoreService(STG::ServiceConf * sc,
+                                     const std::string & name) const
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -202,9 +204,9 @@ if (EscapeString(ename))
     {
     printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to escape name'\n");
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }
 
@@ -233,9 +235,9 @@ if (tuples != 1)
     printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples);
     PQclear(result);
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }
 
@@ -262,7 +264,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -289,9 +291,9 @@ if (EscapeString(ename))
     {
     printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to escape name'\n");
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }
 
@@ -329,7 +331,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -356,9 +358,9 @@ if (EscapeString(ename))
     {
     printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to escape name'\n");
     if (RollbackTransaction())
-       {
-       printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to rollback transaction'\n");
-       }
+        {
+        printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to rollback transaction'\n");
+        }
     return -1;
     }