Adding in boost::asio support
main starts a thread that keep a global io_service object running and makes sure it is stopped when everything else is stopped.
This commit is contained in:
parent
a6755c20f2
commit
4beea05ba6
7 changed files with 50 additions and 9 deletions
9
BUILD
9
BUILD
|
|
@ -2,3 +2,12 @@
|
||||||
If it doesn't detect Qt CMAKE_PREFIX_PATH needs to be set
|
If it doesn't detect Qt CMAKE_PREFIX_PATH needs to be set
|
||||||
|
|
||||||
export CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake
|
export CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake
|
||||||
|
|
||||||
|
Dependencies:
|
||||||
|
- Botan-2
|
||||||
|
- libpq
|
||||||
|
- Qt5
|
||||||
|
- fmt (should we include this one in the project?
|
||||||
|
|
||||||
|
|
||||||
|
- jsoncpp (included)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.1.0)
|
||||||
project(pglaball)
|
project(pglaball)
|
||||||
|
|
||||||
set (CMAKE_PREFIX_PATH /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake)
|
set (CMAKE_PREFIX_PATH /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake)
|
||||||
|
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
|
|
@ -52,8 +53,11 @@ include_directories( ${Qt5Widgets_INCLUDE_DIRS} )
|
||||||
find_package(fmt 4.0 REQUIRED)
|
find_package(fmt 4.0 REQUIRED)
|
||||||
include_directories( ${fmt_INCLUDE_DIRS} )
|
include_directories( ${fmt_INCLUDE_DIRS} )
|
||||||
|
|
||||||
#find_package(Boost 1.62 REQUIRED) # COMPONENTS program_options REQUIRED )
|
#find_package(Libevent 2.0 REQUIRED)
|
||||||
#include_directories( ${Boost_INCLUDE_DIRS} )
|
#include_directories( ${Libevent_INCLUDE_DIRS} )
|
||||||
|
|
||||||
|
find_package(Boost 1.63 COMPONENTS system REQUIRED )
|
||||||
|
include_directories( ${Boost_INCLUDE_DIRS} )
|
||||||
|
|
||||||
add_library(core STATIC
|
add_library(core STATIC
|
||||||
core/BackupFormatModel.cpp
|
core/BackupFormatModel.cpp
|
||||||
|
|
@ -75,6 +79,7 @@ add_executable(pglab
|
||||||
pglab/DatabasesTableModel.cpp
|
pglab/DatabasesTableModel.cpp
|
||||||
pglab/DatabaseWindow.cpp
|
pglab/DatabaseWindow.cpp
|
||||||
pglab/ExplainTreeModelItem.cpp
|
pglab/ExplainTreeModelItem.cpp
|
||||||
|
pglab/GlobalIoService.cpp
|
||||||
pglab/jsoncpp.cpp
|
pglab/jsoncpp.cpp
|
||||||
pglab/main.cpp
|
pglab/main.cpp
|
||||||
pglab/MainWindow.cpp
|
pglab/MainWindow.cpp
|
||||||
|
|
|
||||||
7
pglab/GlobalIoService.cpp
Normal file
7
pglab/GlobalIoService.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "GlobalIoService.h"
|
||||||
|
|
||||||
|
std::shared_ptr<boost::asio::io_service> getGlobalAsioIoService()
|
||||||
|
{
|
||||||
|
static auto ios = std::make_shared<boost::asio::io_service>();
|
||||||
|
return ios;
|
||||||
|
}
|
||||||
6
pglab/GlobalIoService.h
Normal file
6
pglab/GlobalIoService.h
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
|
std::shared_ptr<boost::asio::io_service> getGlobalAsioIoService();
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
#define MASTERCONTROLLER_H
|
#define MASTERCONTROLLER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <future>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
class ConnectionConfig;
|
class ConnectionConfig;
|
||||||
class ConnectionList;
|
class ConnectionList;
|
||||||
class ConnectionListModel;
|
class ConnectionListModel;
|
||||||
|
|
@ -39,6 +41,7 @@ private:
|
||||||
ConnectionList *m_connectionList = nullptr;
|
ConnectionList *m_connectionList = nullptr;
|
||||||
ConnectionListModel *m_connectionListModel = nullptr;
|
ConnectionListModel *m_connectionListModel = nullptr;
|
||||||
ConnectionManagerWindow *m_connectionManagerWindow = nullptr;
|
ConnectionManagerWindow *m_connectionManagerWindow = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERCONTROLLER_H
|
#endif // MASTERCONTROLLER_H
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
#include "PgsqlDatabaseCatalogue.h"
|
#include "PgsqlDatabaseCatalogue.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
QueryParamListController::QueryParamListController(QTableView *tv,
|
QueryParamListController::QueryParamListController(QTableView *tv,
|
||||||
OpenDatabase *opendb, QWidget *parent)
|
OpenDatabase *opendb, QWidget *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
#endif
|
#endif
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "GlobalIoService.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
|
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
|
||||||
#ifdef _WIN32
|
#ifdef WIN32
|
||||||
WORD wVersionRequested = MAKEWORD(2, 2);
|
WORD wVersionRequested = MAKEWORD(2, 2);
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int err = WSAStartup(wVersionRequested, &wsaData);
|
int err = WSAStartup(wVersionRequested, &wsaData);
|
||||||
|
|
@ -20,16 +21,27 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
QCoreApplication::setOrganizationName("pglab");
|
QCoreApplication::setOrganizationName("pglab");
|
||||||
QCoreApplication::setOrganizationDomain("eelkeklein.nl");
|
QCoreApplication::setOrganizationDomain("eelkeklein.nl");
|
||||||
QCoreApplication::setApplicationName("pglab");
|
QCoreApplication::setApplicationName("pglab");
|
||||||
|
|
||||||
auto master_controller = std::make_unique<MasterController>();
|
std::thread asio_service_thread;
|
||||||
master_controller->init();
|
int result = -1;
|
||||||
int result = a.exec();
|
{
|
||||||
#ifdef _WIN32
|
auto ios = getGlobalAsioIoService();
|
||||||
|
boost::asio::io_service::work work(*ios); // Prevent service from running out of work so run doesn't return
|
||||||
|
asio_service_thread = std::thread([ios](){ ios->run(); });
|
||||||
|
|
||||||
|
// make sure the io_service is stopped before we wait on the future
|
||||||
|
auto master_controller = std::make_unique<MasterController>();
|
||||||
|
master_controller->init();
|
||||||
|
result = a.exec();
|
||||||
|
}
|
||||||
|
asio_service_thread.join();
|
||||||
|
#ifdef WIN32
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue