diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 4dfa5e12..29e76ab1 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -212,6 +212,7 @@ #define GUI_SECURE_CONFIG_FILENAME "gui_secure_conf.bin" #define GUI_CONFIG_FILENAME "gui_settings.json" #define GUI_INTERNAL_CONFIG2 "gui_internal_config.json" +#define GUI_IPC_MESSAGE_CHANNEL_NAME CURRENCY_NAME_BASE "_message_que" diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 083c2afd..1fbec761 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -740,6 +740,69 @@ void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, c } } + + +bool MainWindow::init_ipc_server() +{ + +#define GUI_IPC_BUFFER_SIZE 4000 + try { + //Create a message queue. + std::shared_ptr pmq = new boost::interprocess::message_queue(create_only //only create + , GUI_IPC_MESSAGE_CHANNEL_NAME //name + , 100 //max message number + , GUI_IPC_BUFFER_SIZE //max message size + ); + + m_ipc_worker = std::thread([this, pmq]() + { + //m_ipc_worker; + try + { + unsigned int priority = 0; + boost::interprocess::message_queue::size_type recvd_size = 0; + + while (m_gui_deinitialize_done_1 == false) + { + std::string buff(GUI_IPC_BUFFER_SIZE, ' '); + bool data_received = pmq->timed_receive(buff.data(), GUI_IPC_BUFFER_SIZE, recvd_size, priority, boost::posix_time::ptime(microsec_clock::universal_time()) + boost::posix_time::milliseconds(300)); + if (data_received && recvd_size != 0) + { + //todo process token + } + } + message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + } + catch (const std::exception& ex) + { + boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + LOG_ERROR("Failed to receive IPC que: " << ex.what()); + } + + catch (...) + { + boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + LOG_ERROR("Failed to receive IPC que: unknown exception"); + } + }); + } + catch(const std::exception& ex) + { + boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + LOG_ERROR("Failed to initialize IPC que: " << ex.what()); + return false; + } + + catch (...) + { + boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + LOG_ERROR("Failed to initialize IPC que: unknown exception"); + return false; + } + return true; +} + + bool MainWindow::init_backend(int argc, char* argv[]) { TRY_ENTRY(); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 57fcf129..5470602d 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -6,10 +6,12 @@ #include #include +#include #include "wallet/view_iface.h" #include "serialization/keyvalue_helper_structs.h" + #ifndef Q_MOC_RUN #include "wallet/wallets_manager.h" #include "currency_core/offers_services_helpers.h"