diff options
-rw-r--r-- | mthemedaemon/main.cpp | 9 | ||||
-rw-r--r-- | mthemedaemon/mthemedaemonserver.cpp | 8 | ||||
-rw-r--r-- | mthemedaemon/mthemedaemonserver.h | 8 | ||||
-rw-r--r-- | src/corelib/theme/mremotethemedaemon.cpp | 5 | ||||
-rw-r--r-- | src/corelib/theme/mremotethemedaemon.h | 11 | ||||
-rw-r--r-- | tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp | 15 | ||||
-rw-r--r-- | tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h | 2 |
7 files changed, 49 insertions, 9 deletions
diff --git a/mthemedaemon/main.cpp b/mthemedaemon/main.cpp index b58cd2c5..9ee5c9d5 100644 --- a/mthemedaemon/main.cpp +++ b/mthemedaemon/main.cpp @@ -41,7 +41,14 @@ int main(int argc, char **argv) QApplication app(argc, argv); - MThemeDaemonServer server; + // Apply custom server address, if the "-address" has been passed as argument + QString serverAddress; + const int index = app.arguments().indexOf("-address"); + if ((index >= 0) && (index + 1 < app.arguments().count())) { + serverAddress = app.arguments().at(index + 1); + } + + MThemeDaemonServer server(serverAddress); #ifdef CLOSE_ON_ENTER KeyPressWaiter keyWaiter; diff --git a/mthemedaemon/mthemedaemonserver.cpp b/mthemedaemon/mthemedaemonserver.cpp index 9f0fcd1e..f7dd4a2c 100644 --- a/mthemedaemon/mthemedaemonserver.cpp +++ b/mthemedaemon/mthemedaemonserver.cpp @@ -31,7 +31,7 @@ using namespace M::MThemeDaemonProtocol; const int THEME_CHANGE_TIMEOUT = 3000; -MThemeDaemonServer::MThemeDaemonServer() : +MThemeDaemonServer::MThemeDaemonServer(const QString &serverAddress) : currentTheme("/meegotouch/theme/name"), currentLocale("/meegotouch/i18n/language"), defaultTheme(M_THEME_DEFAULT), @@ -68,9 +68,11 @@ MThemeDaemonServer::MThemeDaemonServer() : // start socket server for client registeration // first remove the old one, if there's such - QLocalServer::removeServer(M::MThemeDaemonProtocol::ServerAddress); + const QString address = serverAddress.isEmpty() ? M::MThemeDaemonProtocol::ServerAddress : serverAddress; + + QLocalServer::removeServer(address); connect(&server, SIGNAL(newConnection()), SLOT(clientConnected())); - if (!server.listen(M::MThemeDaemonProtocol::ServerAddress)) { + if (!server.listen(address)) { mWarning("MThemeDaemonServer") << "Failed to start socket server."; } diff --git a/mthemedaemon/mthemedaemonserver.h b/mthemedaemon/mthemedaemonserver.h index 5ded210f..9346825a 100644 --- a/mthemedaemon/mthemedaemonserver.h +++ b/mthemedaemon/mthemedaemonserver.h @@ -37,7 +37,13 @@ class MThemeDaemonServer : public QObject { Q_OBJECT public: - MThemeDaemonServer(); + /** + * @param serverAddress Address that is used for the local connection + * between the clients and the server. If an empty + * string is passed, M::MThemeDaemonProtocol::ServerAddress + * is used per default. + */ + MThemeDaemonServer(const QString &serverAddress = QString()); virtual ~MThemeDaemonServer(); private slots: diff --git a/src/corelib/theme/mremotethemedaemon.cpp b/src/corelib/theme/mremotethemedaemon.cpp index 3f38e4e6..f1309373 100644 --- a/src/corelib/theme/mremotethemedaemon.cpp +++ b/src/corelib/theme/mremotethemedaemon.cpp @@ -37,7 +37,7 @@ using namespace M::MThemeDaemonProtocol; -MRemoteThemeDaemon::MRemoteThemeDaemon(const QString &applicationName, int timeout) : +MRemoteThemeDaemon::MRemoteThemeDaemon(const QString &applicationName, int timeout, const QString &serverAddress) : d_ptr(new MRemoteThemeDaemonPrivate) { Q_D(MRemoteThemeDaemon); @@ -48,7 +48,8 @@ MRemoteThemeDaemon::MRemoteThemeDaemon(const QString &applicationName, int timeo QObject::connect(&d->socket, SIGNAL(readyRead()), this, SLOT(connectionDataAvailable())); // this blocking behavior could be removed - if (d->waitForServer(M::MThemeDaemonProtocol::ServerAddress, timeout)) { + const QString address = serverAddress.isEmpty() ? M::MThemeDaemonProtocol::ServerAddress : serverAddress; + if (d->waitForServer(address, timeout)) { d->stream.setDevice(&d->socket); registerApplicationName(applicationName); } else { diff --git a/src/corelib/theme/mremotethemedaemon.h b/src/corelib/theme/mremotethemedaemon.h index b40eeaf9..8288e365 100644 --- a/src/corelib/theme/mremotethemedaemon.h +++ b/src/corelib/theme/mremotethemedaemon.h @@ -29,7 +29,16 @@ class MRemoteThemeDaemon : public IMThemeDaemon { Q_OBJECT public: - MRemoteThemeDaemon(const QString &applicationName, int timeout); + /** + * @param applicationName Name of the application that uses the daemon. + * @param timeout Timeout in milliseconds, until connecting + * to the server will be canceled. + * @param serverAddress Address that is used for the local connection + * between the client and the server. If an empty + * string is passed, M::MThemeDaemonProtocol::ServerAddress + * is used per default. + */ + MRemoteThemeDaemon(const QString &applicationName, int timeout, const QString &serverAddress = QString()); virtual ~MRemoteThemeDaemon(); bool connected() const; diff --git a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp index 2d64394a..369627b2 100644 --- a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp +++ b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp @@ -41,7 +41,16 @@ void Ut_MRemoteThemeDaemon::initTestCase() QCoreApplication::processEvents(); } - m_themeDaemon = new MRemoteThemeDaemon(appName, 5000); + const QString serverAddress = "m.mtestthemedaemon"; + + m_process = new QProcess(); + QStringList arguments; + arguments.append("-address"); + arguments.append(serverAddress); + m_process->start("mthemedaemon", arguments); + QVERIFY(m_process->waitForStarted()); + + m_themeDaemon = new MRemoteThemeDaemon(appName, 5000, serverAddress); } void Ut_MRemoteThemeDaemon::cleanupTestCase() @@ -49,6 +58,10 @@ void Ut_MRemoteThemeDaemon::cleanupTestCase() delete m_themeDaemon; m_themeDaemon = 0; + m_process->close(); + delete m_process; + m_process = 0; + delete m_app; m_app = 0; } diff --git a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h index 000eff33..2ca5fe86 100644 --- a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h +++ b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h @@ -24,6 +24,7 @@ class MApplication; class MRemoteThemeDaemon; +class QProcess; class Ut_MRemoteThemeDaemon : public QObject { @@ -43,6 +44,7 @@ private slots: private: MApplication *m_app; + QProcess *m_process; MRemoteThemeDaemon *m_themeDaemon; }; #endif |