File indexing completed on 2024-05-19 04:38:45

0001 /****************************************************************************
0002 **
0003 ** Copyright (C) 2016 The Qt Company Ltd.
0004 ** Contact: https://www.qt.io/licensing/
0005 **
0006 ** This file is part of Qt Creator.
0007 **
0008 ** Commercial License Usage
0009 ** Licensees holding valid commercial Qt licenses may use this file in
0010 ** accordance with the commercial license agreement provided with the
0011 ** Software or, alternatively, in accordance with the terms contained in
0012 ** a written agreement between you and The Qt Company. For licensing terms
0013 ** and conditions see https://www.qt.io/terms-conditions. For further
0014 ** information use the contact form at https://www.qt.io/contact-us.
0015 **
0016 ** GNU General Public License Usage
0017 ** Alternatively, this file may be used under the terms of the GNU
0018 ** General Public License version 3 as published by the Free Software
0019 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
0020 ** included in the packaging of this file. Please review the following
0021 ** information to ensure the GNU General Public License requirements will
0022 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
0023 **
0024 ****************************************************************************/
0025 
0026 #include <qtlockedfile.h>
0027 
0028 #include <QLocalServer>
0029 #include <QLocalSocket>
0030 #include <QDir>
0031 
0032 namespace SharedTools {
0033 
0034 class QtLocalPeer : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     explicit QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
0040     bool isClient();
0041     bool sendMessage(const QString &message, int timeout, bool block);
0042     QString applicationId() const
0043         { return id; }
0044     static QString appSessionId(const QString &appId);
0045 
0046 Q_SIGNALS:
0047     void messageReceived(const QString &message, QObject *socket);
0048 
0049 protected Q_SLOTS:
0050     void receiveConnection();
0051 
0052 protected:
0053     QString id;
0054     QString socketName;
0055     QLocalServer* server;
0056     QtLockedFile lockFile;
0057 };
0058 
0059 } // namespace SharedTools