build: trial version target
builds now app and trail target, lib_gui added, istrail function
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#include "QtIDECommunicationController.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
QtIDECommunicationController::QtIDECommunicationController(QObject* parent, StorageAccess* storageAccess)
|
||||
: IDECommunicationController(storageAccess)
|
||||
, m_tcpWrapper(parent)
|
||||
{
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
|
||||
m_tcpWrapper.setReadCallback(std::bind(&QtIDECommunicationController::handleIncomingMessage, this, std::placeholders::_1));
|
||||
m_tcpWrapper.setServerPort(appSettings->getCoatiPort());
|
||||
m_tcpWrapper.setClientPort(appSettings->getPluginPort());
|
||||
m_tcpWrapper.startListening();
|
||||
}
|
||||
|
||||
QtIDECommunicationController::~QtIDECommunicationController()
|
||||
{}
|
||||
|
||||
void QtIDECommunicationController::sendMessage(const std::string& message) const
|
||||
{
|
||||
m_tcpWrapper.sendMessage(message);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef QT_IDE_COMMUNICATION_CONTROLLER
|
||||
#define QT_IDE_COMMUNICATION_CONTROLLER
|
||||
|
||||
#include <qobject.h>
|
||||
|
||||
#include "QtTcpWrapper.h"
|
||||
|
||||
#include "component/controller/IDECommunicationController.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
class StorageAccess;
|
||||
|
||||
class QtIDECommunicationController
|
||||
: public IDECommunicationController
|
||||
{
|
||||
public:
|
||||
QtIDECommunicationController(QObject* parent, StorageAccess* storageAccess);
|
||||
~QtIDECommunicationController();
|
||||
|
||||
private:
|
||||
virtual void sendMessage(const std::string& message) const;
|
||||
|
||||
QtTcpWrapper m_tcpWrapper;
|
||||
};
|
||||
|
||||
#endif // QT_IDE_COMMUNICATION_CONTROLLER
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "QtNetworkFactory.h"
|
||||
|
||||
#include "QtIDECommunicationController.h"
|
||||
|
||||
QtNetworkFactory::QtNetworkFactory()
|
||||
{
|
||||
}
|
||||
|
||||
QtNetworkFactory::~QtNetworkFactory()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<IDECommunicationController> QtNetworkFactory::createIDECommunicationController(StorageAccess* storageAccess) const
|
||||
{
|
||||
return std::make_shared<QtIDECommunicationController>(nullptr, storageAccess);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef QT_NETWORK_FACTORY_H
|
||||
#define QT_NETWORK_FACTORY_H
|
||||
|
||||
#include "component/controller/NetworkFactory.h"
|
||||
|
||||
class QtNetworkFactory : public NetworkFactory
|
||||
{
|
||||
public:
|
||||
QtNetworkFactory();
|
||||
virtual ~QtNetworkFactory();
|
||||
|
||||
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(StorageAccess* storageAccess) const;
|
||||
};
|
||||
|
||||
#endif // QT_NETWORK_FACTORY_H
|
||||
@@ -0,0 +1,99 @@
|
||||
#include "QtTcpWrapper.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
QtTcpWrapper::QtTcpWrapper(QObject* parent, const std::string& ip, const quint16 serverPort, const quint16 clientPort)
|
||||
: QObject(parent)
|
||||
, m_serverPort(serverPort)
|
||||
, m_clientPort(clientPort)
|
||||
, m_ip(ip)
|
||||
{
|
||||
}
|
||||
|
||||
void QtTcpWrapper::startListening()
|
||||
{
|
||||
QHostAddress address(m_ip.c_str());
|
||||
|
||||
m_tcpServer = new QTcpServer(this);
|
||||
|
||||
connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
|
||||
|
||||
if (!m_tcpServer->listen(QHostAddress::LocalHost, m_serverPort))
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "TCP server failed to start with error: \"" + m_tcpServer->errorString().toStdString() + "\". Unable to listen for IDE plugin messages.");
|
||||
}
|
||||
}
|
||||
|
||||
QtTcpWrapper::~QtTcpWrapper()
|
||||
{
|
||||
if (m_tcpServer != NULL)
|
||||
{
|
||||
if (m_tcpServer->isListening())
|
||||
{
|
||||
m_tcpServer->close();
|
||||
}
|
||||
|
||||
delete m_tcpServer;
|
||||
}
|
||||
}
|
||||
|
||||
void QtTcpWrapper::sendMessage(const std::string& message) const
|
||||
{
|
||||
QByteArray data;
|
||||
data.append(message.c_str());
|
||||
|
||||
QTcpSocket socket;
|
||||
socket.connectToHost(QHostAddress::LocalHost, 6666);
|
||||
|
||||
if (socket.waitForConnected())
|
||||
{
|
||||
socket.write(data);
|
||||
socket.flush();
|
||||
socket.waitForBytesWritten();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
void QtTcpWrapper::setReadCallback(const std::function<void(const std::string&)>& callback)
|
||||
{
|
||||
m_readCallback = callback;
|
||||
}
|
||||
|
||||
quint16 QtTcpWrapper::getServerPort() const
|
||||
{
|
||||
return m_serverPort;
|
||||
}
|
||||
|
||||
void QtTcpWrapper::setServerPort(const quint16 serverPort)
|
||||
{
|
||||
m_serverPort = serverPort;
|
||||
}
|
||||
|
||||
quint16 QtTcpWrapper::getClientPort() const
|
||||
{
|
||||
return m_clientPort;
|
||||
}
|
||||
|
||||
void QtTcpWrapper::setClientPort(const quint16 clientPort)
|
||||
{
|
||||
m_clientPort = clientPort;
|
||||
}
|
||||
|
||||
void QtTcpWrapper::acceptConnection()
|
||||
{
|
||||
m_tcpClient = m_tcpServer->nextPendingConnection();
|
||||
|
||||
connect(m_tcpClient, SIGNAL(readyRead()), this, SLOT(startRead()));
|
||||
}
|
||||
|
||||
void QtTcpWrapper::startRead()
|
||||
{
|
||||
char buffer[1024] = { 0 };
|
||||
m_tcpClient->read(buffer, m_tcpClient->bytesAvailable());
|
||||
m_tcpClient->close();
|
||||
|
||||
if (m_readCallback != NULL)
|
||||
{
|
||||
m_readCallback(buffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef QT_SOCKET_WRAPPER_H
|
||||
#define QT_SOCKET_WRAPPER_H
|
||||
|
||||
#include <functional>
|
||||
#include <qobject.h>
|
||||
#include <qudpsocket.h>
|
||||
|
||||
#include <qtcpserver.h>
|
||||
#include <qtcpsocket.h>
|
||||
|
||||
class QtTcpWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtTcpWrapper(QObject* parent, const std::string& ip = "127.0.0.1", const quint16 serverPort = 6667, const quint16 clientPort = 6666);
|
||||
~QtTcpWrapper();
|
||||
|
||||
void startListening();
|
||||
|
||||
void sendMessage(const std::string& message) const;
|
||||
|
||||
void setReadCallback(const std::function<void(const std::string&)>& callback);
|
||||
|
||||
quint16 getServerPort() const;
|
||||
void setServerPort(const quint16 serverPort);
|
||||
|
||||
quint16 getClientPort() const;
|
||||
void setClientPort(const quint16 clientPort);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void acceptConnection();
|
||||
void startRead();
|
||||
|
||||
private:
|
||||
quint16 m_serverPort;
|
||||
quint16 m_clientPort;
|
||||
std::string m_ip;
|
||||
|
||||
std::function<void(const std::string&)> m_readCallback;
|
||||
|
||||
QTcpServer* m_tcpServer;
|
||||
QTcpSocket* m_tcpClient;
|
||||
};
|
||||
|
||||
#endif // QT_SOCKET_WRAPPER_H
|
||||
Reference in New Issue
Block a user