/*************************************************************************** miniCashConnect Copyright © 2022 christoph holzheuer c.holzheuer@sourceworx.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /** * @brief MCSender::MCSender */ MCSender::MCSender() { } /** * @brief MCSender::~MCSender */ MCSender::~MCSender() { if( isOpen() ) close(); } void MCSender::setupConnection( const QString& host, int port ) { //qDebug() << "\n\nMCSender::setupConnection(): " << host << " : " << port; _port = port; _host = host; } /** * @brief MCSender::initConnection * @param parent * @param host * @param port * @return */ void MCSender::onCreateConnection() { if( isOpen() ) onDiscardConnection(); //qDebug() << "MCSender::onCreateConnection()"; connectToHost( _host, _port, QIODevice::WriteOnly ); if( waitForConnected( miniCash::senderTimeout ) ) { emit connectionChanged( miniCash::Connected ); return; // allet jut } emit errorOccurred( error() ); } /** * @brief MCSender::onDiscardConnection */ void MCSender::onDiscardConnection() { // qDebug() << "MCSender::onDiscardConnection()"; flush(); if( isOpen() ) close(); emit connectionChanged( miniCash::UnConnected ); } /** * @brief MCSender::writeTransaction * @param transaction */ void MCSender::onSendTransaction( const QString& transaction ) { if( !isOpen() ) { emit connectionChanged( miniCash::UnConnected ); //qDebug( "---QTCPClient: Not connected"); return; } QDataStream socketStream( this ); socketStream.setVersion(QDataStream::Qt_5_15); QByteArray byteArray = transaction.toUtf8(); socketStream << byteArray; }