Skip to content

Commit

Permalink
REFAC(ipc): extract getRuntimeDir() for Socket and OverlayPipe
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocastoldi committed Nov 16, 2022
1 parent e088f6c commit e55e979
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 39 deletions.
5 changes: 5 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ set(MUMBLE_SOURCES
"GlobalShortcutButtons.ui"
"GlobalShortcutTarget.ui"
"GlobalShortcutTypes.h"
"IPCUtils.h"
"JSONSerialization.cpp"
"JSONSerialization.h"
"LCD.cpp"
Expand Down Expand Up @@ -655,6 +656,9 @@ else()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
find_library(LIB_RT rt)
target_link_libraries(mumble_client_object_lib PUBLIC ${LIB_RT})
target_sources(mumble_client_object_lib PRIVATE "IPCUtils_linux.cpp")
else()
target_sources(mumble_client_object_lib PRIVATE "IPCUtils_unix.cpp")
endif()

target_link_libraries(mumble_client_object_lib PUBLIC X11::Xext)
Expand All @@ -672,6 +676,7 @@ else()
"AppNap.mm"
"GlobalShortcut_macx.h"
"GlobalShortcut_macx.mm"
"IPCUtils_macx.cpp"
"Log_macx.mm"
"os_macx.mm"
)
Expand Down
20 changes: 20 additions & 0 deletions src/mumble/IPCUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021-2022 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#ifndef MUMBLE_MUMBLE_IPCUTILS_H_
#define MUMBLE_MUMBLE_IPCUTILS_H_

#include <QtCore/QDir>

namespace Mumble {

/**
* @returns The path where Mumble sets up MumbleOverlayPipe and MumbleSocket
*/
QDir getRuntimeDir(void);

}; // namespace Mumble

#endif // MUMBLE_MUMBLE_IPCUTILS_H_
27 changes: 27 additions & 0 deletions src/mumble/IPCUtils_linux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2021-2022 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "IPCUtils.h"

#include <unistd.h>
#include <QtCore/QDir>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QString>

namespace Mumble {
QDir getRuntimeDir(void) {
QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR"));
QString mumbleRuntimePath;
if (!xdgRuntimePath.isNull()) {
mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/");
} else {
mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/");
}
QDir mumbleRuntimeDir = QDir(mumbleRuntimePath);
mumbleRuntimeDir.mkpath(".");
return mumbleRuntimeDir;
}

}; // namespace Mumble
20 changes: 20 additions & 0 deletions src/mumble/IPCUtils_macx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021-2022 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "IPCUtils.h"

#include <unistd.h>
//#include <QtCore/QStandardPaths>
#include <QtCore/QDir>

namespace Mumble {
QDir getRuntimeDir(void) {
// QString runtimePath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); // defaults to "~/Library/Application Support"
// QDir mumbleRuntimeDir = QDir(runtimePath);
QDir mumbleRuntimeDir = QDir::home();
return mumbleRuntimeDir;
}

}; // namespace Mumble
17 changes: 17 additions & 0 deletions src/mumble/IPCUtils_unix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2021-2022 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "IPCUtils.h"

#include <QtCore/QDir>
#include <QtCore/QString>

namespace Mumble {
QDir getRuntimeDir(void) {
QDir mumbleRuntimeDir = QDir::home();
return mumbleRuntimeDir;
}

}; // namespace Mumble
11 changes: 2 additions & 9 deletions src/mumble/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Channel.h"
#include "ClientUser.h"
#include "Database.h"
#include "IPCUtils.h"
#include "MainWindow.h"
#include "OverlayClient.h"
#include "OverlayText.h"
Expand Down Expand Up @@ -243,15 +244,7 @@ void Overlay::createPipe() {
pipepath = QLatin1String("MumbleOverlayPipe");
#else
{
QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR"));
QString mumbleRuntimePath;
if (!xdgRuntimePath.isNull()) {
mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/");
} else {
mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/");
}
QDir mumbleRuntimeDir = QDir(mumbleRuntimePath);
mumbleRuntimeDir.mkpath(".");
QDir mumbleRuntimeDir = Mumble::getRuntimeDir();
pipepath = mumbleRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe"));
}

Expand Down
22 changes: 3 additions & 19 deletions src/mumble/SocketRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Channel.h"
#include "ClientUser.h"
#include "IPCUtils.h"
#include "MainWindow.h"
#include "ServerHandler.h"
#include "Global.h"
Expand Down Expand Up @@ -235,15 +236,7 @@ SocketRPC::SocketRPC(const QString &basename, QObject *p) : QObject(p) {
pipepath = basename;
#else
{
QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR"));
QString mumbleRuntimePath;
if (!xdgRuntimePath.isNull()) {
mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/");
} else {
mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/");
}
QDir mumbleRuntimeDir = QDir(mumbleRuntimePath);
mumbleRuntimeDir.mkpath(".");
QDir mumbleRuntimeDir = Mumble::getRuntimeDir();
pipepath = mumbleRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket"));
}

Expand Down Expand Up @@ -281,15 +274,7 @@ bool SocketRPC::send(const QString &basename, const QString &request, const QMap
pipepath = basename;
#else
{
QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR"));
QString mumbleRuntimePath;
if (!xdgRuntimePath.isNull()) {
mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/");
} else {
mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/");
}
QDir mumbleRuntimeDir = QDir(mumbleRuntimePath);
mumbleRuntimeDir.mkpath(".");
QDir mumbleRuntimeDir = Mumble::getRuntimeDir();
pipepath = mumbleRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket"));
}
#endif
Expand Down Expand Up @@ -329,4 +314,3 @@ bool SocketRPC::send(const QString &basename, const QString &request, const QMap

return QVariant(succ.text()).toBool();
}

14 changes: 3 additions & 11 deletions src/tests/OverlayTest/OverlayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

#include "../../overlay/overlay.h"

#include "IPCUtils.h"
#include "SharedMemory.h"
#include "Timer.h"

#ifdef Q_OS_WIN
# include "win.h"
#else
# include <unistd.h>
# include <unistd.h>
#endif

#include <QtCore>
Expand All @@ -26,7 +27,6 @@
#include <QMainWindow>
#include <QApplication>


class OverlayWidget : public QWidget {
Q_OBJECT

Expand Down Expand Up @@ -101,15 +101,7 @@ void OverlayWidget::paintEvent(QPaintEvent *) {
#ifdef Q_OS_WIN
qlsSocket->connectToServer(QLatin1String("MumbleOverlayPipe"));
#else
QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR"));
QString mumbleRuntimePath;
if (!xdgRuntimePath.isNull()) {
mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/");
} else {
mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/");
}
QDir mumbleRuntimeDir = QDir(mumbleRuntimePath);
mumbleRuntimeDir.mkpath(".");
QDir mumbleRuntimeDir = Mumble::getRuntimeDir();
QString pipepath = mumbleRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe"));
qWarning() << "connectToServer(" << pipepath << ")";
qlsSocket->connectToServer(pipepath);
Expand Down

0 comments on commit e55e979

Please sign in to comment.