X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/94ed11aed11d6eae5797205bd808efddd32778e7..2196a3a0cdc5384c082febb7f4aa5994cc7d80db:/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp index 42a19073..3bc9c749 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp @@ -27,21 +27,21 @@ * */ +#include "postgresql_store.h" + +#include "stg/common.h" +#include "stg/message.h" + #include #include #include #include -#include "stg/common.h" -#include "postgresql_store.h" -#include "stg/locker.h" -#include "stg/message.h" - //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const std::string & login) const +int POSTGRESQL_STORE::AddMessage(STG::Message * msg, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -69,9 +69,9 @@ if (EscapeString(elogin)) { printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -79,9 +79,9 @@ if (EscapeString(etext)) { printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to escape message text'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -119,9 +119,9 @@ if (tuples != 1) printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples); PQclear(result); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -141,10 +141,10 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::EditMessage(const STG_MSG & msg, +int POSTGRESQL_STORE::EditMessage(const STG::Message & msg, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -172,9 +172,9 @@ if (EscapeString(elogin)) { printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -182,9 +182,9 @@ if (EscapeString(etext)) { printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to escape message text'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -227,10 +227,10 @@ return 0; } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetMessage(uint64_t id, - STG_MSG * msg, - const std::string &) const + STG::Message * msg, + const std::string &) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -280,9 +280,9 @@ if (tuples != 1) printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples); PQclear(result); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -308,7 +308,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::DelMessage(uint64_t id, const std::string &) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -357,10 +357,10 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetMessageHdrs(std::vector * hdrsList, +int POSTGRESQL_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -387,9 +387,9 @@ if (EscapeString(elogin)) { printfd(__FILE__, "POSTGRESQL_STORE::GetMessageHdrs(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::GetMessageHdrs(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::GetMessageHdrs(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -421,7 +421,7 @@ int tuples = PQntuples(result); for (int i = 0; i < tuples; ++i) { std::stringstream tuple; - STG_MSG_HDR header; + STG::Message::Header header; tuple << PQgetvalue(result, i, 0) << " "; tuple << PQgetvalue(result, i, 1) << " "; tuple << PQgetvalue(result, i, 2) << " ";