Added the thread safe TSQueue and using it in mainwindow to replace the adhoc queue implementation.
This commit is contained in:
parent
c551d982c6
commit
83064ab86b
10 changed files with 253 additions and 27 deletions
61
asyncdbconnection.cpp
Normal file
61
asyncdbconnection.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include "asyncdbconnection.h"
|
||||
|
||||
ASyncDBConnection::ASyncDBConnection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASyncDBConnection::setupConnection(const std::string &connstring)
|
||||
{}
|
||||
|
||||
void ASyncDBConnection::closeConnection()
|
||||
{}
|
||||
|
||||
void ASyncDBConnection::setStateCallback(on_state_callback state_callback)
|
||||
{}
|
||||
|
||||
|
||||
void ASyncDBConnection::Thread::run()
|
||||
{
|
||||
while (!terminateRequested) {
|
||||
|
||||
// make or recover connection
|
||||
if (makeConnection()) {
|
||||
// send commands and receive results
|
||||
communicate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// close connection
|
||||
}
|
||||
|
||||
bool ASyncDBConnection::Thread::makeConnection()
|
||||
{
|
||||
while (!terminateRequested) {
|
||||
|
||||
// start connecting
|
||||
|
||||
// poll till complete or failed (we can get an abort command)
|
||||
|
||||
// if connected return true
|
||||
// else retry (unless we get a command to stop then return false)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ASyncDBConnection::Thread::communicate()
|
||||
{
|
||||
while (!terminateRequested) {
|
||||
// wait for something to do:
|
||||
// - command to send to server
|
||||
// - wait for results and (notifies can also come in)
|
||||
// - pass each result on to the completion routine
|
||||
// - notify comming in from the server
|
||||
// - pass to notify callback
|
||||
// - connection raises an error
|
||||
// - return
|
||||
// - stop signal
|
||||
// - return
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue