Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/CuteIPCInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CuteIPCInterface : public QObject
bool connectToServer(const QHostAddress& host, quint16 port);

void disconnectFromServer();

bool isConnected();
bool remoteConnect(const char* signal, QObject* object, const char* method);
bool remoteSlotConnect(QObject* localObject, const char* signal, const char* remoteSlot);

Expand Down Expand Up @@ -52,6 +52,10 @@ class CuteIPCInterface : public QObject

QString lastError() const;

signals:
void disconnected();


protected:
CuteIPCInterfacePrivate* const d_ptr;
CuteIPCInterface(CuteIPCInterfacePrivate& dd, QObject* parent);
Expand Down
9 changes: 9 additions & 0 deletions src/CuteIPCInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ bool CuteIPCInterfacePrivate::sendSynchronousRequest(const QByteArray& request,

QEventLoop loop;
QObject::connect(&connection, SIGNAL(callFinished()), &loop, SLOT(quit()));

QObject::connect(&connection, SIGNAL(socketDisconnected()), q_ptr, SIGNAL(disconnected()));
QObject::connect(&connection, SIGNAL(socketDisconnected()), &loop, SLOT(quit()));
connection.sendCallRequest(request);
loop.exec();
Expand Down Expand Up @@ -296,6 +298,7 @@ CuteIPCInterface::CuteIPCInterface(QObject* parent)
Q_D(CuteIPCInterface);
d->q_ptr = this;

connect(d->m_worker, SIGNAL(disconnected()), SIGNAL(disconnected()));
connect(d->m_worker, SIGNAL(setLastError(QString)), SLOT(_q_setLastError(QString)));
connect(d->m_worker, SIGNAL(invokeRemoteSignal(QString, CuteIPCMessage::Arguments)),
SLOT(_q_invokeRemoteSignal(QString, CuteIPCMessage::Arguments)));
Expand Down Expand Up @@ -325,6 +328,12 @@ CuteIPCInterface::CuteIPCInterface(CuteIPCInterfacePrivate& dd, QObject* parent)
}


bool CuteIPCInterface::isConnected() {
Q_D(CuteIPCInterface);
d->q_ptr = this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q_ptr is set in CuteIPCInterface constructor (CuteIPCInterface.cpp:299). Why duplicate it here?

return d->m_worker->isConnected();
}

/*!
Destroyes the object.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/CuteIPCInterfaceConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CuteIPCInterfaceConnection::CuteIPCInterfaceConnection(QLocalSocket* socket, QOb
m_socket(socket),
m_nextBlockSize(0)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary new line at the beginning of method

connect(socket, SIGNAL(disconnected()), SIGNAL(socketDisconnected()));
connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)), SLOT(errorOccured(QLocalSocket::LocalSocketError)));
connect(socket, SIGNAL(readyRead()), SLOT(readyRead()));
Expand All @@ -31,6 +32,9 @@ CuteIPCInterfaceConnection::CuteIPCInterfaceConnection(QTcpSocket* socket, QObje
connect(socket, SIGNAL(readyRead()), SLOT(readyRead()));
}

bool CuteIPCInterfaceConnection::isConnected() {
return m_socket && m_socket->isOpen();
}

void CuteIPCInterfaceConnection::sendCallRequest(const QByteArray& request)
{
Expand Down
1 change: 1 addition & 0 deletions src/CuteIPCInterfaceConnection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CuteIPCInterfaceConnection : public QObject
void sendCallRequest(const QByteArray& request);
void setReturnedObject(QGenericReturnArgument returnedObject);
bool lastCallSuccessful() const;
bool isConnected();

signals:
void callFinished();
Expand Down
7 changes: 7 additions & 0 deletions src/CuteIPCInterfaceWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void CuteIPCInterfaceWorker::connectToServer(const QString& name, void* successf

QLocalSocket* socket = new QLocalSocket;
socket->connectToServer(name);

bool connected = socket->waitForConnected(5000);
if (!connected)
{
Expand All @@ -42,6 +43,7 @@ void CuteIPCInterfaceWorker::connectToServer(const QString& name, void* successf
this, SIGNAL(invokeRemoteSignal(QString, CuteIPCMessage::Arguments)));
connect(m_connection, SIGNAL(errorOccured(QString)), this, SIGNAL(setLastError(QString)));

connect(m_connection, SIGNAL(socketDisconnected()), SIGNAL(disconnected()));
connect(m_connection, SIGNAL(socketDisconnected()), m_connection, SLOT(deleteLater()));
connect(m_connection, SIGNAL(socketDisconnected()), socket, SLOT(deleteLater()));

Expand Down Expand Up @@ -88,6 +90,7 @@ void CuteIPCInterfaceWorker::connectToTcpServer(const QHostAddress& host, const
this, SIGNAL(invokeRemoteSignal(QString, CuteIPCMessage::Arguments)));
connect(m_connection, SIGNAL(errorOccured(QString)), this, SIGNAL(setLastError(QString)));

connect(m_connection, SIGNAL(socketDisconnected()), SIGNAL(disconnected()));
connect(m_connection, SIGNAL(socketDisconnected()), m_connection, SLOT(deleteLater()));
connect(m_connection, SIGNAL(socketDisconnected()), socket, SLOT(deleteLater()));

Expand Down Expand Up @@ -131,6 +134,10 @@ void CuteIPCInterfaceWorker::disconnectFromServer()
}


bool CuteIPCInterfaceWorker::isConnected() {
return m_connection->isConnected();
}

void CuteIPCInterfaceWorker::sendCallRequest(const QByteArray& request)
{
if (!m_connection)
Expand Down
2 changes: 2 additions & 0 deletions src/CuteIPCInterfaceWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class CuteIPCInterfaceWorker : public QObject
explicit CuteIPCInterfaceWorker(QObject* parent = 0);
~CuteIPCInterfaceWorker();

bool isConnected();
signals:
void setLastError(const QString& error);
void disconnected();

// slot finish signals
void connectToServerFinished();
Expand Down