RemoteSync.cpp   RemoteSync.cpp 
skipping to change at line 26 skipping to change at line 26
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "RemoteSync.hpp" #include "RemoteSync.hpp"
#include "RemoteSyncDialog.hpp" #include "RemoteSyncDialog.hpp"
#include "SyncServer.hpp" #include "SyncServer.hpp"
#include "SyncClient.hpp" #include "SyncClient.hpp"
#include "CLIProcessor.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include <QApplication>
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
Q_LOGGING_CATEGORY(remoteSync,"stel.plugin.remoteSync")
//! This method is the one called automatically by the StelModuleMgr just a fter loading the dynamic library //! This method is the one called automatically by the StelModuleMgr just a fter loading the dynamic library
StelModule* RemoteSyncStelPluginInterface::getStelModule() const StelModule* RemoteSyncStelPluginInterface::getStelModule() const
{ {
return new RemoteSync(); return new RemoteSync();
} }
StelPluginInfo RemoteSyncStelPluginInterface::getPluginInfo() const StelPluginInfo RemoteSyncStelPluginInterface::getPluginInfo() const
{ {
// Allow to load the resources when used as a static plugin // Allow to load the resources when used as a static plugin
Q_INIT_RESOURCE(RemoteSync); Q_INIT_RESOURCE(RemoteSync);
StelPluginInfo info; StelPluginInfo info;
info.id = "RemoteSync"; info.id = "RemoteSync";
info.displayedName = N_("Remote Sync"); info.displayedName = N_("Remote Sync");
info.authors = "Florian Schaukowitsch and Georg Zotti"; info.authors = "Florian Schaukowitsch and Georg Zotti";
info.contact = "http://homepage.univie.ac.at/Georg.Zotti"; info.contact = "http://homepage.univie.ac.at/Georg.Zotti";
info.description = N_("<p>Provides state synchronization for multipl info.description = N_("Provides state synchronization for multiple S
e Stellarium instances running in a network.</p> " tellarium instances running in a network. See manual for detailed descripti
"<p>This can be used, for example, to create m on.");
ulti-screen/panorama setups using multiple physical PCs.</p>"
"<p>See manual for detailed description.</p>"
"<p>This plugin was developed during ESA SoCiS
2015.</p>");
info.version = REMOTESYNC_VERSION; info.version = REMOTESYNC_VERSION;
return info; return info;
} }
RemoteSync::RemoteSync() : state(IDLE), server(NULL), client(NULL) RemoteSync::RemoteSync()
: clientServerPort(20180)
, serverPort(20180)
, connectionLostBehavior(ClientBehavior::RECONNECT)
, quitBehavior(ClientBehavior::NONE)
, state(IDLE)
, server(Q_NULLPTR)
, client(Q_NULLPTR)
{ {
setObjectName("RemoteSync"); setObjectName("RemoteSync");
configDialog = new RemoteSyncDialog(); configDialog = new RemoteSyncDialog();
conf = StelApp::getInstance().getSettings(); conf = StelApp::getInstance().getSettings();
reconnectTimer.setSingleShot(true);
connect(&reconnectTimer, SIGNAL(timeout()), this, SLOT(connectToServ
er()));
} }
RemoteSync::~RemoteSync() RemoteSync::~RemoteSync()
{ {
delete configDialog; delete configDialog;
} }
bool RemoteSync::configureGui(bool show) bool RemoteSync::configureGui(bool show)
{ {
if (show) if (show)
skipping to change at line 85 skipping to change at line 96
return true; return true;
} }
void RemoteSync::init() void RemoteSync::init()
{ {
if (!conf->childGroups().contains("RemoteSync")) if (!conf->childGroups().contains("RemoteSync"))
restoreDefaultSettings(); restoreDefaultSettings();
loadSettings(); loadSettings();
qDebug()<<"[RemoteSync] Plugin initialized"; qCDebug(remoteSync)<<"Plugin initialized";
// TODO create actions/buttons, if required //parse command line args
QStringList args = StelApp::getCommandlineArguments();;
QString syncMode = CLIProcessor::argsGetOptionWithArg(args,"","--syn
cMode","").toString();
QString syncHost = CLIProcessor::argsGetOptionWithArg(args,"","--syn
cHost","").toString();
int syncPort = CLIProcessor::argsGetOptionWithArg(args,"","--syncPor
t",0).toInt();
if(syncMode=="server")
{
if(syncPort!=0)
setServerPort(syncPort);
qCDebug(remoteSync)<<"Starting server from command line";
startServer();
}
else if(syncMode=="client")
{
if(!syncHost.isEmpty())
setClientServerHost(syncHost);
if(syncPort!=0)
setClientServerPort(syncPort);
qCDebug(remoteSync)<<"Connecting to server from command line
";
connectToServer();
}
} }
void RemoteSync::update(double deltaTime) void RemoteSync::update(double deltaTime)
{ {
Q_UNUSED(deltaTime); Q_UNUSED(deltaTime);
if(server) if(server)
{ {
//pass update on to server, client does not need this //pass update on to server, client does not need this
server->update(); server->update();
} }
skipping to change at line 136 skipping to change at line 168
void RemoteSync::setServerPort(const int port) void RemoteSync::setServerPort(const int port)
{ {
if(port!= serverPort) if(port!= serverPort)
{ {
serverPort = port; serverPort = port;
emit serverPortChanged(port); emit serverPortChanged(port);
} }
} }
void RemoteSync::setClientSyncOptions(SyncClient::SyncOptions options)
{
if(options!=syncOptions)
{
syncOptions = options;
emit clientSyncOptionsChanged(options);
}
}
void RemoteSync::setStelPropFilter(const QStringList &stelPropFilter)
{
if(stelPropFilter!=this->stelPropFilter)
{
this->stelPropFilter = stelPropFilter;
emit stelPropFilterChanged(stelPropFilter);
}
}
void RemoteSync::setConnectionLostBehavior(const ClientBehavior bh)
{
if(connectionLostBehavior!=bh)
{
connectionLostBehavior = bh;
emit connectionLostBehaviorChanged(bh);
}
}
void RemoteSync::setQuitBehavior(const ClientBehavior bh)
{
if(quitBehavior!=bh)
{
quitBehavior = bh;
emit quitBehaviorChanged(bh);
}
}
void RemoteSync::startServer() void RemoteSync::startServer()
{ {
if(state == IDLE) if(state == IDLE)
{ {
server = new SyncServer(this); server = new SyncServer(this);
if(server->start(serverPort)) if(server->start(serverPort))
setState(SERVER); setState(SERVER);
else else
{ {
setError(server->errorString()); setError(server->errorString());
delete server; delete server;
server = Q_NULLPTR;
} }
} }
else else
qWarning()<<"[RemoteSync] startServer: invalid state"; qCWarning(remoteSync)<<"startServer: invalid state";
} }
void RemoteSync::stopServer() void RemoteSync::stopServer()
{ {
if(state == SERVER) if(state == SERVER)
{ {
connect(server, SIGNAL(serverStopped()), server, SLOT(delete Later()));
server->stop(); server->stop();
delete server; server = Q_NULLPTR;
server = NULL;
setState(IDLE); setState(IDLE);
} }
else else
qWarning()<<"[RemoteSync] stopServer: invalid state"; qCWarning(remoteSync)<<"stopServer: invalid state";
} }
void RemoteSync::connectToServer() void RemoteSync::connectToServer()
{ {
if(state == IDLE) if(state == IDLE || state == CLIENT_WAIT_RECONNECT)
{ {
client = new SyncClient(this); client = new SyncClient(syncOptions, stelPropFilter, this);
connect(client, SIGNAL(connectionError()), this, SLOT(client
ConnectionFailed()));
connect(client, SIGNAL(connected()), this, SLOT(clientConnec ted())); connect(client, SIGNAL(connected()), this, SLOT(clientConnec ted()));
connect(client, SIGNAL(disconnected()), this, SLOT(clientDis connect(client, SIGNAL(disconnected(bool)), this, SLOT(clien
connected())); tDisconnected(bool)));
client->connectToServer(clientServerHost,clientServerPort);
setState(CLIENT_CONNECTING); setState(CLIENT_CONNECTING);
client->connectToServer(clientServerHost,clientServerPort);
} }
else else
qWarning()<<"[RemoteSync] connectToServer: invalid state"; qCWarning(remoteSync)<<"connectToServer: invalid state";
} }
void RemoteSync::clientConnected() void RemoteSync::clientConnected()
{ {
Q_ASSERT(state == CLIENT_CONNECTING);
setState(CLIENT); setState(CLIENT);
} }
void RemoteSync::clientDisconnected() void RemoteSync::clientDisconnected(bool clean)
{ {
setState(IDLE); QString errStr = client->errorString();
client->deleteLater(); client->deleteLater();
client = Q_NULLPTR;
if(!clean)
{
setError(errStr);
}
setState(applyClientBehavior(clean ? quitBehavior : connectionLostBe
havior));
} }
void RemoteSync::clientConnectionFailed() RemoteSync::SyncState RemoteSync::applyClientBehavior(ClientBehavior bh)
{ {
setState(IDLE); if(state!=CLIENT_CLOSING) //when client closes we do nothing
setError(client->errorString()); {
client->deleteLater(); switch (bh) {
case RECONNECT:
reconnectTimer.start();
return CLIENT_WAIT_RECONNECT;
case QUIT:
StelApp::getInstance().quit();
break;
default:
break;
}
}
return IDLE;
} }
void RemoteSync::disconnectFromServer() void RemoteSync::disconnectFromServer()
{ {
if(state == CLIENT) if(state == CLIENT)
{ {
setState(CLIENT_CLOSING);
client->disconnectFromServer(); client->disconnectFromServer();
} }
else if(state == CLIENT_WAIT_RECONNECT)
{
reconnectTimer.stop();
setState(IDLE);
}
else else
qWarning()<<"[RemoteSync] disconnectFromServer: invalid stat e"; qCWarning(remoteSync)<<"disconnectFromServer: invalid state" <<state;
} }
void RemoteSync::restoreDefaultSettings() void RemoteSync::restoreDefaultSettings()
{ {
Q_ASSERT(conf); Q_ASSERT(conf);
// Remove the old values... // Remove the old values...
conf->remove("RemoteSync"); conf->remove("RemoteSync");
// ...load the default values... // ...load the default values...
loadSettings(); loadSettings();
// ...and then save them. // ...and then save them.
saveSettings(); saveSettings();
} }
void RemoteSync::loadSettings() void RemoteSync::loadSettings()
{ {
conf->beginGroup("RemoteSync"); conf->beginGroup("RemoteSync");
setClientServerHost(conf->value("clientServerHost","127.0.0.1").toSt ring()); setClientServerHost(conf->value("clientServerHost","127.0.0.1").toSt ring());
setClientServerPort(conf->value("clientServerPort",20180).toInt()); setClientServerPort(conf->value("clientServerPort",20180).toInt());
setServerPort(conf->value("serverPort",20180).toInt()); setServerPort(conf->value("serverPort",20180).toInt());
setClientSyncOptions(SyncClient::SyncOptions(conf->value("clientSync
Options", SyncClient::ALL).toInt()));
setStelPropFilter(unpackStringList(conf->value("stelPropFilter").toS
tring()));
setConnectionLostBehavior(static_cast<ClientBehavior>(conf->value("c
onnectionLostBehavior",1).toInt()));
setQuitBehavior(static_cast<ClientBehavior>(conf->value("quitBehavio
r").toInt()));
reconnectTimer.setInterval(conf->value("clientReconnectInterval", 50
00).toInt());
conf->endGroup(); conf->endGroup();
} }
void RemoteSync::saveSettings() void RemoteSync::saveSettings()
{ {
conf->beginGroup("RemoteSync"); conf->beginGroup("RemoteSync");
conf->setValue("clientServerHost",clientServerHost); conf->setValue("clientServerHost",clientServerHost);
conf->setValue("clientServerPort",clientServerPort); conf->setValue("clientServerPort",clientServerPort);
conf->setValue("serverPort",serverPort); conf->setValue("serverPort",serverPort);
conf->setValue("clientSyncOptions",static_cast<int>(syncOptions));
conf->setValue("stelPropFilter", packStringList(stelPropFilter));
conf->setValue("connectionLostBehavior", connectionLostBehavior);
conf->setValue("quitBehavior", quitBehavior);
conf->setValue("clientReconnectInterval", reconnectTimer.interval())
;
conf->endGroup(); conf->endGroup();
} }
QString RemoteSync::packStringList(const QStringList props)
{
return props.join("|");
}
QStringList RemoteSync::unpackStringList(const QString packedProps)
{
return packedProps.split("|");
}
void RemoteSync::setState(RemoteSync::SyncState state) void RemoteSync::setState(RemoteSync::SyncState state)
{ {
if(state != this->state) if(state != this->state)
{ {
this->state = state; this->state = state;
qDebug()<<"[RemoteSync] New state:"<<state; qCDebug(remoteSync)<<"New state:"<<state;
emit stateChanged(state); emit stateChanged(state);
} }
} }
void RemoteSync::setError(const QString &errorString) void RemoteSync::setError(const QString &errorString)
{ {
this->errorString = errorString; this->errorString = errorString;
emit errorOccurred(errorString); emit errorOccurred(errorString);
} }
skipping to change at line 269 skipping to change at line 384
break; break;
case RemoteSync::SERVER: case RemoteSync::SERVER:
deb<<"SERVER"; deb<<"SERVER";
break; break;
case RemoteSync::CLIENT: case RemoteSync::CLIENT:
deb<<"CLIENT"; deb<<"CLIENT";
break; break;
case RemoteSync::CLIENT_CONNECTING: case RemoteSync::CLIENT_CONNECTING:
deb<<"CLIENT_CONNECTING"; deb<<"CLIENT_CONNECTING";
break; break;
case RemoteSync::CLIENT_WAIT_RECONNECT:
deb<<"CLIENT_WAIT_RECONNECT";
break;
default: default:
deb<<"RemoteSync::SyncState(" <<int(state)<<')'; deb<<"RemoteSync::SyncState(" <<int(state)<<')';
break; break;
} }
return deb; return deb;
} }
 End of changes. 33 change blocks. 
30 lines changed or deleted 158 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/