Tcp Server is up
This commit is contained in:
parent
d4f6ff208e
commit
8a087afdc6
|
@ -534,6 +534,8 @@ set(HEADERS
|
|||
|
||||
networkremote/networkremote.h
|
||||
networkremote/tcpserver.h
|
||||
networkremote/remoteclient.cpp
|
||||
networkremote/remoteclient.h
|
||||
|
||||
)
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@
|
|||
|
||||
#include "radios/radioservices.h"
|
||||
#include "radios/radiobackend.h"
|
||||
#include "networkremote/networkremote.h"
|
||||
|
||||
using std::make_shared;
|
||||
using namespace std::chrono_literals;
|
||||
|
@ -201,8 +202,13 @@ class ApplicationImpl {
|
|||
moodbar_loader_([app]() { return new MoodbarLoader(app); }),
|
||||
moodbar_controller_([app]() { return new MoodbarController(app); }),
|
||||
#endif
|
||||
lastfm_import_([app]() { return new LastFMImport(app->network()); })
|
||||
{}
|
||||
lastfm_import_([app]() { return new LastFMImport(app->network()); }),
|
||||
network_remote_([app]() {
|
||||
NetworkRemote *remote = new NetworkRemote(app);
|
||||
app->MoveToNewThread(remote);
|
||||
return remote;
|
||||
})
|
||||
{}
|
||||
|
||||
Lazy<TagReaderClient> tag_reader_client_;
|
||||
Lazy<Database> database_;
|
||||
|
@ -228,6 +234,7 @@ class ApplicationImpl {
|
|||
Lazy<MoodbarController> moodbar_controller_;
|
||||
#endif
|
||||
Lazy<LastFMImport> lastfm_import_;
|
||||
Lazy<NetworkRemote> network_remote_;
|
||||
|
||||
};
|
||||
|
||||
|
@ -237,6 +244,7 @@ Application::Application(QObject *parent)
|
|||
device_finders()->Init();
|
||||
collection()->Init();
|
||||
tag_reader_client();
|
||||
network_remote()->Init();
|
||||
|
||||
QObject::connect(&*database(), &Database::Error, this, &Application::ErrorAdded);
|
||||
|
||||
|
@ -286,7 +294,8 @@ void Application::Exit() {
|
|||
<< &*device_manager()
|
||||
#endif
|
||||
<< &*internet_services()
|
||||
<< &*radio_services()->radio_backend();
|
||||
<< &*radio_services()->radio_backend()
|
||||
<< &*network_remote();
|
||||
|
||||
QObject::connect(&*tag_reader_client(), &TagReaderClient::ExitFinished, this, &Application::ExitReceived);
|
||||
tag_reader_client()->ExitAsync();
|
||||
|
@ -355,7 +364,9 @@ SharedPtr<InternetServices> Application::internet_services() const { return p_->
|
|||
SharedPtr<RadioServices> Application::radio_services() const { return p_->radio_services_.ptr(); }
|
||||
SharedPtr<AudioScrobbler> Application::scrobbler() const { return p_->scrobbler_.ptr(); }
|
||||
SharedPtr<LastFMImport> Application::lastfm_import() const { return p_->lastfm_import_.ptr(); }
|
||||
SharedPtr<NetworkRemote> Application::network_remote() const { return p_->network_remote_.ptr();}
|
||||
#ifdef HAVE_MOODBAR
|
||||
SharedPtr<MoodbarController> Application::moodbar_controller() const { return p_->moodbar_controller_.ptr(); }
|
||||
SharedPtr<MoodbarLoader> Application::moodbar_loader() const { return p_->moodbar_loader_.ptr(); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,7 @@ class RadioServices;
|
|||
class MoodbarController;
|
||||
class MoodbarLoader;
|
||||
#endif
|
||||
class NetworkRemote;
|
||||
|
||||
class Application : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -106,6 +107,7 @@ class Application : public QObject {
|
|||
#endif
|
||||
|
||||
SharedPtr<LastFMImport> lastfm_import() const;
|
||||
SharedPtr<NetworkRemote> network_remote() const;
|
||||
|
||||
void Exit();
|
||||
|
||||
|
|
|
@ -1,7 +1,58 @@
|
|||
#include "networkremote.h"
|
||||
|
||||
NetworkRemote::NetworkRemote(QObject *parent)
|
||||
: QObject{parent}
|
||||
#include <QSettings>
|
||||
#include <QThread>
|
||||
|
||||
#include "networkremote/networkremote.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
class TcpServer;
|
||||
|
||||
const char *NetworkRemote::kSettingsGroup = "Remote";
|
||||
|
||||
NetworkRemote::NetworkRemote(Application* app, QObject *parent)
|
||||
: QObject(parent),
|
||||
app_(app),
|
||||
original_thread_(nullptr)
|
||||
{
|
||||
setObjectName("Network Remote");
|
||||
original_thread_ = thread();
|
||||
}
|
||||
|
||||
NetworkRemote::~NetworkRemote()
|
||||
{
|
||||
}
|
||||
|
||||
void NetworkRemote::Init()
|
||||
{
|
||||
LoadSettings();
|
||||
if (use_remote_){
|
||||
server_->StartServer(ipAddr_,remote_port_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NetworkRemote::LoadSettings()
|
||||
{
|
||||
QSettings s;
|
||||
s.beginGroup(NetworkRemote::kSettingsGroup);
|
||||
use_remote_ = s.value("useRemote").toBool();
|
||||
local_only_ = s.value("localOnly").toBool();
|
||||
remote_port_ = s.value("remotePort").toInt();
|
||||
ipAddr_.setAddress(s.value("ipAddress").toString());
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
void NetworkRemote::start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetworkRemote::stop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetworkRemote::newConnection()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -2,15 +2,40 @@
|
|||
#define NETWORKREMOTE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpServer>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
#include "tcpserver.h"
|
||||
|
||||
class Application;
|
||||
class QThread;
|
||||
|
||||
class NetworkRemote : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NetworkRemote(QObject *parent = nullptr);
|
||||
static const char* kSettingsGroup;
|
||||
explicit NetworkRemote(Application* app, QObject *parent = nullptr);
|
||||
~NetworkRemote() override;
|
||||
void Init();
|
||||
void LoadSettings();
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
void stop();
|
||||
void newConnection();
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
static NetworkRemote *sInstance;
|
||||
bool use_remote_;
|
||||
bool local_only_;
|
||||
int remote_port_;
|
||||
QHostAddress ipAddr_;
|
||||
TcpServer *server_ = new TcpServer();
|
||||
QThread *original_thread_;
|
||||
};
|
||||
|
||||
#endif // NETWORKREMOTE_H
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include "remoteclient.h"
|
||||
|
||||
RemoteClient::RemoteClient(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef REMOTECLIENT_H
|
||||
#define REMOTECLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class RemoteClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RemoteClient(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // REMOTECLIENT_H
|
|
@ -1,34 +1,38 @@
|
|||
#include "tcpserver.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
TcpServer::TcpServer(QObject *parent)
|
||||
: QTcpServer{parent}
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
server_ = new QTcpServer(this);
|
||||
connect(server_, SIGNAL(newConnection()),this,SLOT(newConnection()));
|
||||
}
|
||||
|
||||
TcpServer::~TcpServer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TcpServer::SetupServer()
|
||||
void TcpServer::StartServer(QHostAddress ipAddr, int port)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
ok = server_->listen(ipAddr, port);
|
||||
if (ok){
|
||||
qLog(Debug) << "Server Started";
|
||||
}
|
||||
}
|
||||
|
||||
void TcpServer::StartServer()
|
||||
void TcpServer::NewConnection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TcpServer::AcceptConnections()
|
||||
{
|
||||
|
||||
//QTcpSocket *socket = server_->nextPendingConnection();
|
||||
socket_ = server_->nextPendingConnection();
|
||||
qLog(Debug) << "New Socket";
|
||||
qLog(Debug) << socket_->currentReadChannel();
|
||||
}
|
||||
|
||||
void TcpServer::StopServer()
|
||||
{
|
||||
|
||||
server_->close();
|
||||
}
|
||||
|
||||
void TcpServer::CreateRemoteClient()
|
||||
|
@ -36,3 +40,8 @@ void TcpServer::CreateRemoteClient()
|
|||
|
||||
}
|
||||
|
||||
bool TcpServer::ServerUp()
|
||||
{
|
||||
return server_->isListening();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef TCPSERVER_H
|
||||
#define TCPSERVER_H
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include <QObject>
|
||||
#include <QHostAddress>
|
||||
#include <QNetworkInterface>
|
||||
#include <QTcpServer>
|
||||
#include <QTcpSocket>
|
||||
|
||||
class TcpServer : public QTcpServer
|
||||
class TcpServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -15,20 +16,20 @@ public:
|
|||
explicit TcpServer(QObject *parent = nullptr);
|
||||
~TcpServer();
|
||||
|
||||
signals:
|
||||
bool ServerUp();
|
||||
|
||||
public slots:
|
||||
void SetupServer();
|
||||
void StartServer();
|
||||
void AcceptConnections();
|
||||
void NewConnection();
|
||||
void StartServer(QHostAddress ipAddr, int port);
|
||||
void StopServer();
|
||||
void CreateRemoteClient();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
SharedPtr<QTcpServer> server_;
|
||||
bool use_remote_;
|
||||
bool use_local_only_;
|
||||
qint16 port_;
|
||||
QTcpServer *server_;
|
||||
QTcpSocket *socket_;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "core/iconloader.h"
|
||||
#include "qpushbutton.h"
|
||||
#include "settings/settingsdialog.h"
|
||||
#include "networkremotesettingspage.h"
|
||||
#include "settings/networkremotesettingspage.h"
|
||||
#include "ui_networkremotesettingspage.h"
|
||||
|
||||
const char *NetworkRemoteSettingsPage::kSettingsGroup = "Remote";
|
||||
|
@ -30,6 +30,7 @@ void NetworkRemoteSettingsPage::Load()
|
|||
ui_->portSelected->setRange(5050, 65535);
|
||||
ui_->ip_address->setText("0.0.0.0");
|
||||
|
||||
|
||||
s.beginGroup(NetworkRemoteSettingsPage::kSettingsGroup);
|
||||
if (s.contains("useRemote")){
|
||||
ui_->useRemoteClient->setChecked(s.value("useRemote", false).toBool());
|
||||
|
@ -49,6 +50,7 @@ void NetworkRemoteSettingsPage::Load()
|
|||
s.setValue("useRemote", false);
|
||||
s.setValue("localOnly",false);
|
||||
s.setValue("remotePort",5050);
|
||||
s.setValue("ipAddress","0.0.0.0");
|
||||
}
|
||||
s.endGroup();
|
||||
DisplayIP();
|
||||
|
@ -62,25 +64,26 @@ void NetworkRemoteSettingsPage::Save()
|
|||
s.setValue("useRemote",ui_->useRemoteClient->isChecked());
|
||||
s.setValue("localOnly",ui_->localConnectionsOnly->isChecked());
|
||||
s.setValue("remotePort",int(ui_->portSelected->value()));
|
||||
s.setValue("ipAddress",ipAddr_);
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
void NetworkRemoteSettingsPage::DisplayIP()
|
||||
{
|
||||
qLog(Debug) << "Display IP Code";
|
||||
QString ipAddresses;
|
||||
bool found = false;
|
||||
QList<QHostAddress> hostList = QNetworkInterface::allAddresses();
|
||||
|
||||
for (const QHostAddress &address : hostList)
|
||||
{
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address.isLoopback() == false){
|
||||
if (!ipAddresses.isEmpty()){
|
||||
ipAddresses.append(", ");
|
||||
}
|
||||
ipAddresses = ipAddresses.append(address.toString());
|
||||
}
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address.isLoopback() == false && !found){
|
||||
// NOTE: this code currently only takes the first ip address it finds
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
qInfo("Warning: The code only pickst the first IPv4 address");
|
||||
found = true;
|
||||
ipAddr_ = address.toString();
|
||||
}
|
||||
}
|
||||
ui_->ip_address->setText(ipAddresses);
|
||||
ui_->ip_address->setText(ipAddr_);
|
||||
}
|
||||
|
||||
void NetworkRemoteSettingsPage::RemoteButtonClicked()
|
||||
|
|
|
@ -26,6 +26,7 @@ private:
|
|||
Ui_NetworkRemoteSettingsPage *ui_;
|
||||
QSettings s;
|
||||
void DisplayIP();
|
||||
QString ipAddr_;
|
||||
|
||||
private slots:
|
||||
void RemoteButtonClicked();
|
||||
|
|
Loading…
Reference in New Issue