diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-02 14:29:52 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-02 14:29:52 +0100 |
commit | 2fb350cb0a5749ecdccf29c1b4e643f7c8fd1201 (patch) | |
tree | 06fd600f4f4c1346405748fe78a286f365456bc2 /client/resourceaccess.cpp | |
parent | 5b235416ef818950a72e8ab7ac6f3803dbea4e82 (diff) | |
download | sink-2fb350cb0a5749ecdccf29c1b4e643f7c8fd1201.tar.gz sink-2fb350cb0a5749ecdccf29c1b4e643f7c8fd1201.zip |
prefix messages with the resource name
handy when multiple resources are connected
Diffstat (limited to 'client/resourceaccess.cpp')
-rw-r--r-- | client/resourceaccess.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/client/resourceaccess.cpp b/client/resourceaccess.cpp index 1b6fd08..702671e 100644 --- a/client/resourceaccess.cpp +++ b/client/resourceaccess.cpp | |||
@@ -20,7 +20,7 @@ ResourceAccess::ResourceAccess(const QString &resourceName, QObject *parent) | |||
20 | connect(m_tryOpenTimer, &QTimer::timeout, | 20 | connect(m_tryOpenTimer, &QTimer::timeout, |
21 | this, &ResourceAccess::open); | 21 | this, &ResourceAccess::open); |
22 | 22 | ||
23 | Console::main()->log(QString("Starting access to %1").arg(resourceName)); | 23 | log("Starting access"); |
24 | connect(m_socket, &QLocalSocket::connected, | 24 | connect(m_socket, &QLocalSocket::connected, |
25 | this, &ResourceAccess::connected); | 25 | this, &ResourceAccess::connected); |
26 | connect(m_socket, &QLocalSocket::disconnected, | 26 | connect(m_socket, &QLocalSocket::disconnected, |
@@ -50,26 +50,26 @@ bool ResourceAccess::isReady() const | |||
50 | void ResourceAccess::open() | 50 | void ResourceAccess::open() |
51 | { | 51 | { |
52 | if (m_socket->isValid()) { | 52 | if (m_socket->isValid()) { |
53 | Console::main()->log("Socket valid, so aborting the open"); | 53 | log("Socket valid, so aborting the open"); |
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | 56 | ||
57 | m_socket->setServerName(m_resourceName); | 57 | m_socket->setServerName(m_resourceName); |
58 | Console::main()->log(QString("Opening: %1").arg(m_socket->serverName())); | 58 | log(QString("Opening %1").arg(m_socket->serverName())); |
59 | //FIXME: race between starting the exec and opening the socket? | 59 | //FIXME: race between starting the exec and opening the socket? |
60 | m_socket->open(); | 60 | m_socket->open(); |
61 | } | 61 | } |
62 | 62 | ||
63 | void ResourceAccess::close() | 63 | void ResourceAccess::close() |
64 | { | 64 | { |
65 | Console::main()->log(QString("Closing: %1").arg(m_socket->fullServerName())); | 65 | log(QString("Closing %1").arg(m_socket->fullServerName())); |
66 | m_socket->close(); | 66 | m_socket->close(); |
67 | } | 67 | } |
68 | 68 | ||
69 | void ResourceAccess::connected() | 69 | void ResourceAccess::connected() |
70 | { | 70 | { |
71 | m_startingProcess = false; | 71 | m_startingProcess = false; |
72 | Console::main()->log(QString("Connected: %1").arg(m_socket->fullServerName())); | 72 | log(QString("Connected: ").arg(m_socket->fullServerName())); |
73 | 73 | ||
74 | { | 74 | { |
75 | flatbuffers::FlatBufferBuilder fbb; | 75 | flatbuffers::FlatBufferBuilder fbb; |
@@ -89,14 +89,16 @@ void ResourceAccess::connected() | |||
89 | void ResourceAccess::disconnected() | 89 | void ResourceAccess::disconnected() |
90 | { | 90 | { |
91 | m_socket->close(); | 91 | m_socket->close(); |
92 | Console::main()->log(QString("Disconnected: %1").arg(m_socket->fullServerName())); | 92 | log(QString("Disconnected from %1").arg(m_socket->fullServerName())); |
93 | emit ready(false); | 93 | emit ready(false); |
94 | open(); | 94 | open(); |
95 | } | 95 | } |
96 | 96 | ||
97 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | 97 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) |
98 | { | 98 | { |
99 | Console::main()->log(QString("Could not connect to %1 due to error %2").arg(m_socket->serverName()).arg(error)); | 99 | log(QString("Could not connect to %1 due to error %2") |
100 | .arg(m_resourceName) | ||
101 | .arg(m_socket->serverName()).arg(error)); | ||
100 | if (m_startingProcess) { | 102 | if (m_startingProcess) { |
101 | if (!m_tryOpenTimer->isActive()) { | 103 | if (!m_tryOpenTimer->isActive()) { |
102 | m_tryOpenTimer->start(); | 104 | m_tryOpenTimer->start(); |
@@ -105,7 +107,7 @@ void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | |||
105 | } | 107 | } |
106 | 108 | ||
107 | m_startingProcess = true; | 109 | m_startingProcess = true; |
108 | Console::main()->log(QString("Attempting to start resource...")); | 110 | log(QString("Attempting to start resource ") + m_resourceName); |
109 | QStringList args; | 111 | QStringList args; |
110 | args << m_resourceName; | 112 | args << m_resourceName; |
111 | if (QProcess::startDetached("akonadinext_resource", args)) { | 113 | if (QProcess::startDetached("akonadinext_resource", args)) { |
@@ -142,7 +144,7 @@ bool ResourceAccess::processMessageBuffer() | |||
142 | switch (commandId) { | 144 | switch (commandId) { |
143 | case Commands::RevisionUpdateCommand: { | 145 | case Commands::RevisionUpdateCommand: { |
144 | auto buffer = Akonadi::GetRevisionUpdate(m_partialMessageBuffer.constData() + headerSize); | 146 | auto buffer = Akonadi::GetRevisionUpdate(m_partialMessageBuffer.constData() + headerSize); |
145 | Console::main()->log(QString(" Revision updated to: %1").arg(buffer->revision())); | 147 | log(QString("Revision updated to: %1").arg(buffer->revision())); |
146 | emit revisionChanged(buffer->revision()); | 148 | emit revisionChanged(buffer->revision()); |
147 | break; | 149 | break; |
148 | } | 150 | } |
@@ -153,3 +155,8 @@ bool ResourceAccess::processMessageBuffer() | |||
153 | m_partialMessageBuffer.remove(0, headerSize + size); | 155 | m_partialMessageBuffer.remove(0, headerSize + size); |
154 | return m_partialMessageBuffer.size() >= headerSize; | 156 | return m_partialMessageBuffer.size() >= headerSize; |
155 | } | 157 | } |
158 | |||
159 | void ResourceAccess::log(const QString &message) | ||
160 | { | ||
161 | Console::main()->log(m_resourceName + ": " + message); | ||
162 | } | ||