Big cleanup
This commit is contained in:
parent
d3080a08bb
commit
8b671090a0
55 changed files with 214 additions and 3967 deletions
|
|
@ -41,26 +41,16 @@ namespace {
|
|||
class ASyncDBConnectionThread {
|
||||
public:
|
||||
using t_CommandQueue = std::queue<Command>;
|
||||
// struct {
|
||||
// std::mutex m_mutex;
|
||||
// on_state_callback m_func;
|
||||
// } m_stateCallback;
|
||||
// struct {
|
||||
// std::mutex m_mutex;
|
||||
// on_notice_callback m_func;
|
||||
// } m_noticeCallback;
|
||||
|
||||
struct t_Command {
|
||||
std::mutex m_mutex;
|
||||
t_CommandQueue m_queue;
|
||||
//std::condition_variable m_newEvent;
|
||||
Win32Event m_newEvent;
|
||||
t_Command()
|
||||
: m_newEvent(Win32Event::Reset::Auto, Win32Event::Initial::Clear)
|
||||
{}
|
||||
} m_commandQueue;
|
||||
|
||||
// std::string m_initString;
|
||||
ConnectionConfig m_config;
|
||||
ASyncDBConnection::State m_state = ASyncDBConnection::State::NotConnected;
|
||||
|
||||
|
|
@ -274,20 +264,7 @@ void ASyncDBConnectionThread::doStateCallback(ASyncDBConnection::State state)
|
|||
|
||||
void ASyncDBConnectionThread::waitForAndSendCommand()
|
||||
{
|
||||
#if false
|
||||
using namespace std::chrono_literals;
|
||||
// lock the data
|
||||
std::unique_lock<std::mutex> lk(m_commandQueue.m_mutex);
|
||||
if (m_commandQueue.m_queue.empty()) {
|
||||
// no data wait till there is data
|
||||
m_commandQueue.m_newEvent.wait_for(lk, 1000ms);
|
||||
// can we use the predicate to reimplement the stop function???, []{return ready;});
|
||||
|
||||
}
|
||||
doNewCommand();
|
||||
|
||||
#else
|
||||
WaitHandleList whl;
|
||||
WaitHandleList whl;
|
||||
auto wait_result_new_command = whl.add(m_commandQueue.m_newEvent);
|
||||
auto wait_result_stop = whl.add(m_stopEvent);
|
||||
|
||||
|
|
@ -301,9 +278,8 @@ void ASyncDBConnectionThread::waitForAndSendCommand()
|
|||
if (res == wait_result_new_command) {
|
||||
doNewCommand();
|
||||
}
|
||||
if (res == wait_result_stop)
|
||||
return;
|
||||
#endif
|
||||
// Note if it was stop we can just return and function
|
||||
// above will stop looping because terminateRequested has been set too by stop
|
||||
}
|
||||
|
||||
void ASyncDBConnectionThread::doNewCommand()
|
||||
|
|
@ -365,30 +341,6 @@ bool ASyncDBConnectionThread::consumeResultInput()
|
|||
|
||||
void ASyncDBConnectionThread::waitForResult()
|
||||
{
|
||||
#if false
|
||||
int sock = m_connection.socket();
|
||||
|
||||
fd_set readfds;
|
||||
timeval timeout;
|
||||
bool finished = false;
|
||||
while (!finished && !terminateRequested) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(sock, &readfds);
|
||||
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
int select_result = select(sock + 1, &readfds, nullptr, nullptr, &timeout);
|
||||
if (select_result > 0) {
|
||||
if (FD_ISSET(sock, &readfds)) {
|
||||
if (consumeResultInput()) {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
SOCKET sock = static_cast<SOCKET>(m_connection.socket());
|
||||
Win32Event socket_event(Win32Event::Reset::Manual, Win32Event::Initial::Clear);
|
||||
|
||||
|
|
@ -426,18 +378,10 @@ void ASyncDBConnectionThread::waitForResult()
|
|||
finished = true;
|
||||
}
|
||||
} // end while
|
||||
// When last result received, remove command from queue
|
||||
#endif
|
||||
}
|
||||
|
||||
void ASyncDBConnectionThread::processNotice(const PGresult *result)
|
||||
{
|
||||
// Pgsql::Result res(result);
|
||||
// std::lock_guard<std::mutex> lg(m_noticeCallback.m_mutex);
|
||||
// if (m_noticeCallback.m_func) {
|
||||
// Pgsql::ErrorDetails details = Pgsql::ErrorDetails::createErrorDetailsFromPGresult(result);
|
||||
// m_noticeCallback.m_func(details);
|
||||
// }
|
||||
Pgsql::ErrorDetails details = Pgsql::ErrorDetails::createErrorDetailsFromPGresult(result);
|
||||
Q_EMIT asyncConnObject->onNotice(details);
|
||||
}
|
||||
|
|
@ -486,13 +430,10 @@ void ASyncDBConnection::doStateCallback(State state)
|
|||
|
||||
void ASyncDBConnection::closeConnection()
|
||||
{
|
||||
// doStateCallback(State::NotConnected);
|
||||
// TODO also send cancel???
|
||||
m_threadData->stop();
|
||||
if (m_thread.joinable()) {
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ASyncDBConnection::send(const std::string &command, on_result_callback on_result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue