Builds on windows again

This commit is contained in:
eelke 2017-11-26 13:07:21 +01:00
parent 33cf39b799
commit bebb3391c3
160 changed files with 138 additions and 117 deletions

76
pglab/ASyncDBConnection.h Normal file
View file

@ -0,0 +1,76 @@
#ifndef ASYNCDBCONNECTION_H
#define ASYNCDBCONNECTION_H
#include <QObject>
#include "Pgsql_Connection.h"
#include "Pgsql_Params.h"
#include "Pgsql_Result.h"
#include "Expected.h"
#include "ConnectionConfig.h"
#include <QElapsedTimer>
#include <mutex>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/io_service.hpp>
/** \brief Class that handles asynchronous execution of queries.
*
* Queries are passed to this class with a routine to call on completion
* when the result is on that routine is called.
*/
class ASyncDBConnection: public QObject {
Q_OBJECT
public:
enum class State {
NotConnected,
Connecting,
Connected, ///< connected and idle
QuerySend, ///< connected query send expecting result
CancelSend, ///< cancel send expecting result
Terminating ///< shutting down
};
using on_result_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>, qint64)>;
explicit ASyncDBConnection(boost::asio::io_service &ios);
~ASyncDBConnection();
State state() const;
void setupConnection(const ConnectionConfig &config);
void closeConnection();
/** Sends command to the server.
When the result is in on_result will be called directly within the thread.
If the command gives multiple results on_result will be called for each result.
*/
bool send(const std::string &command, on_result_callback on_result);
bool send(const std::string &command, Pgsql::Params params, on_result_callback on_result);
bool cancel();
signals:
void onStateChanged(ASyncDBConnection::State state);
void onNotice(Pgsql::ErrorDetails notice);
private:
Pgsql::Connection m_connection;
boost::asio::ip::tcp::socket m_asioSock;
ConnectionConfig m_config;
State m_state = State::NotConnected;
Pgsql::Canceller m_canceller;
QElapsedTimer m_timer;
void async_connect_handler(boost::system::error_code ec, std::size_t s);
void async_query_handler(boost::system::error_code ec, std::size_t s, on_result_callback on_result);
void doStateCallback(State state);
void processNotice(const PGresult *result);
};
Q_DECLARE_METATYPE(ASyncDBConnection::State);
Q_DECLARE_METATYPE(Pgsql::ErrorDetails);
#endif // ASYNCDBCONNECTION_H