diff options
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r-- | common/resourceaccess.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index feffcf4..249dd55 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -69,10 +69,11 @@ public: | |||
69 | class ResourceAccess::Private | 69 | class ResourceAccess::Private |
70 | { | 70 | { |
71 | public: | 71 | public: |
72 | Private(const QByteArray &name, ResourceAccess *ra); | 72 | Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *ra); |
73 | KAsync::Job<void> tryToConnect(); | 73 | KAsync::Job<void> tryToConnect(); |
74 | KAsync::Job<void> initializeSocket(); | 74 | KAsync::Job<void> initializeSocket(); |
75 | QByteArray resourceName; | 75 | QByteArray resourceName; |
76 | QByteArray resourceInstanceIdentifier; | ||
76 | QSharedPointer<QLocalSocket> socket; | 77 | QSharedPointer<QLocalSocket> socket; |
77 | QByteArray partialMessageBuffer; | 78 | QByteArray partialMessageBuffer; |
78 | flatbuffers::FlatBufferBuilder fbb; | 79 | flatbuffers::FlatBufferBuilder fbb; |
@@ -82,8 +83,9 @@ public: | |||
82 | uint messageId; | 83 | uint messageId; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | ResourceAccess::Private::Private(const QByteArray &name, ResourceAccess *q) | 86 | ResourceAccess::Private::Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *q) |
86 | : resourceName(name), | 87 | : resourceName(name), |
88 | resourceInstanceIdentifier(instanceIdentifier), | ||
87 | messageId(0) | 89 | messageId(0) |
88 | { | 90 | { |
89 | } | 91 | } |
@@ -118,7 +120,7 @@ KAsync::Job<void> ResourceAccess::Private::tryToConnect() | |||
118 | [this](KAsync::Future<void> &future) { | 120 | [this](KAsync::Future<void> &future) { |
119 | Trace() << "Loop"; | 121 | Trace() << "Loop"; |
120 | KAsync::wait(50) | 122 | KAsync::wait(50) |
121 | .then(connectToServer(resourceName)) | 123 | .then(connectToServer(resourceInstanceIdentifier)) |
122 | .then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { | 124 | .then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { |
123 | Q_ASSERT(s); | 125 | Q_ASSERT(s); |
124 | socket = s; | 126 | socket = s; |
@@ -134,7 +136,7 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
134 | { | 136 | { |
135 | return KAsync::start<void>([this](KAsync::Future<void> &future) { | 137 | return KAsync::start<void>([this](KAsync::Future<void> &future) { |
136 | Trace() << "Trying to connect"; | 138 | Trace() << "Trying to connect"; |
137 | connectToServer(resourceName).then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { | 139 | connectToServer(resourceInstanceIdentifier).then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { |
138 | Trace() << "Connected to resource, without having to start it."; | 140 | Trace() << "Connected to resource, without having to start it."; |
139 | Q_ASSERT(s); | 141 | Q_ASSERT(s); |
140 | socket = s; | 142 | socket = s; |
@@ -144,7 +146,7 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
144 | Trace() << "Failed to connect, starting resource"; | 146 | Trace() << "Failed to connect, starting resource"; |
145 | //We failed to connect, so let's start the resource | 147 | //We failed to connect, so let's start the resource |
146 | QStringList args; | 148 | QStringList args; |
147 | args << resourceName; | 149 | args << resourceInstanceIdentifier; |
148 | qint64 pid = 0; | 150 | qint64 pid = 0; |
149 | if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) { | 151 | if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) { |
150 | Trace() << "Started resource " << pid; | 152 | Trace() << "Started resource " << pid; |
@@ -159,9 +161,16 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
159 | }); | 161 | }); |
160 | } | 162 | } |
161 | 163 | ||
162 | ResourceAccess::ResourceAccess(const QByteArray &resourceName, QObject *parent) | 164 | static QByteArray getResourceName(const QByteArray &instanceIdentifier) |
165 | { | ||
166 | auto split = instanceIdentifier.split('.'); | ||
167 | split.removeLast(); | ||
168 | return split.join('.'); | ||
169 | } | ||
170 | |||
171 | ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, QObject *parent) | ||
163 | : QObject(parent), | 172 | : QObject(parent), |
164 | d(new Private(resourceName, this)) | 173 | d(new Private(getResourceName(resourceInstanceIdentifier), resourceInstanceIdentifier, this)) |
165 | { | 174 | { |
166 | log("Starting access"); | 175 | log("Starting access"); |
167 | } | 176 | } |
@@ -316,7 +325,7 @@ void ResourceAccess::disconnected() | |||
316 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | 325 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) |
317 | { | 326 | { |
318 | if (error == QLocalSocket::PeerClosedError) { | 327 | if (error == QLocalSocket::PeerClosedError) { |
319 | Log(d->resourceName) << "The resource closed the connection."; | 328 | Log(d->resourceInstanceIdentifier) << "The resource closed the connection."; |
320 | } else { | 329 | } else { |
321 | Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); | 330 | Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); |
322 | } | 331 | } |
@@ -379,7 +388,7 @@ bool ResourceAccess::processMessageBuffer() | |||
379 | auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize); | 388 | auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize); |
380 | switch (buffer->type()) { | 389 | switch (buffer->type()) { |
381 | case Akonadi2::NotificationType::NotificationType_Shutdown: | 390 | case Akonadi2::NotificationType::NotificationType_Shutdown: |
382 | Log(d->resourceName) << "Received shutdown notification."; | 391 | Log(d->resourceInstanceIdentifier) << "Received shutdown notification."; |
383 | close(); | 392 | close(); |
384 | break; | 393 | break; |
385 | default: | 394 | default: |
@@ -406,7 +415,7 @@ void ResourceAccess::callCallbacks(int id) | |||
406 | 415 | ||
407 | void ResourceAccess::log(const QString &message) | 416 | void ResourceAccess::log(const QString &message) |
408 | { | 417 | { |
409 | Log(d->resourceName) << this << message; | 418 | Log(d->resourceInstanceIdentifier) << this << message; |
410 | } | 419 | } |
411 | 420 | ||
412 | } | 421 | } |