diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
commit | bdb01c2c068df326f5a8328ed1492ab1bea388c5 (patch) | |
tree | 25c2ee1b29bc481b6914c244ed9ca194b1415d16 /common/listener.cpp | |
parent | 17e7ee40c9185c0505883853345fd6024c675b1a (diff) | |
download | sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.tar.gz sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.zip |
Renamed Akonadi2 to Sink
(except for documentation).
Diffstat (limited to 'common/listener.cpp')
-rw-r--r-- | common/listener.cpp | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/common/listener.cpp b/common/listener.cpp index fa08472..13ebbbb 100644 --- a/common/listener.cpp +++ b/common/listener.cpp | |||
@@ -42,7 +42,7 @@ | |||
42 | Listener::Listener(const QByteArray &resourceInstanceIdentifier, QObject *parent) | 42 | Listener::Listener(const QByteArray &resourceInstanceIdentifier, QObject *parent) |
43 | : QObject(parent), | 43 | : QObject(parent), |
44 | m_server(new QLocalServer(this)), | 44 | m_server(new QLocalServer(this)), |
45 | m_resourceName(Akonadi2::resourceName(resourceInstanceIdentifier)), | 45 | m_resourceName(Sink::resourceName(resourceInstanceIdentifier)), |
46 | m_resourceInstanceIdentifier(resourceInstanceIdentifier), | 46 | m_resourceInstanceIdentifier(resourceInstanceIdentifier), |
47 | m_resource(0), | 47 | m_resource(0), |
48 | m_clientBufferProcessesTimer(new QTimer(this)), | 48 | m_clientBufferProcessesTimer(new QTimer(this)), |
@@ -209,20 +209,20 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c | |||
209 | { | 209 | { |
210 | bool success = true; | 210 | bool success = true; |
211 | switch (commandId) { | 211 | switch (commandId) { |
212 | case Akonadi2::Commands::HandshakeCommand: { | 212 | case Sink::Commands::HandshakeCommand: { |
213 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); | 213 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); |
214 | if (Akonadi2::Commands::VerifyHandshakeBuffer(verifier)) { | 214 | if (Sink::Commands::VerifyHandshakeBuffer(verifier)) { |
215 | auto buffer = Akonadi2::Commands::GetHandshake(commandBuffer.constData()); | 215 | auto buffer = Sink::Commands::GetHandshake(commandBuffer.constData()); |
216 | client.name = buffer->name()->c_str(); | 216 | client.name = buffer->name()->c_str(); |
217 | } else { | 217 | } else { |
218 | Warning() << "received invalid command"; | 218 | Warning() << "received invalid command"; |
219 | } | 219 | } |
220 | break; | 220 | break; |
221 | } | 221 | } |
222 | case Akonadi2::Commands::SynchronizeCommand: { | 222 | case Sink::Commands::SynchronizeCommand: { |
223 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); | 223 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); |
224 | if (Akonadi2::Commands::VerifySynchronizeBuffer(verifier)) { | 224 | if (Sink::Commands::VerifySynchronizeBuffer(verifier)) { |
225 | auto buffer = Akonadi2::Commands::GetSynchronize(commandBuffer.constData()); | 225 | auto buffer = Sink::Commands::GetSynchronize(commandBuffer.constData()); |
226 | Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); | 226 | Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); |
227 | auto timer = QSharedPointer<QTime>::create(); | 227 | auto timer = QSharedPointer<QTime>::create(); |
228 | timer->start(); | 228 | timer->start(); |
@@ -243,28 +243,28 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c | |||
243 | } | 243 | } |
244 | break; | 244 | break; |
245 | } | 245 | } |
246 | case Akonadi2::Commands::InspectionCommand: | 246 | case Sink::Commands::InspectionCommand: |
247 | case Akonadi2::Commands::FetchEntityCommand: | 247 | case Sink::Commands::FetchEntityCommand: |
248 | case Akonadi2::Commands::DeleteEntityCommand: | 248 | case Sink::Commands::DeleteEntityCommand: |
249 | case Akonadi2::Commands::ModifyEntityCommand: | 249 | case Sink::Commands::ModifyEntityCommand: |
250 | case Akonadi2::Commands::CreateEntityCommand: | 250 | case Sink::Commands::CreateEntityCommand: |
251 | Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; | 251 | Log() << "\tCommand id " << messageId << " of type \"" << Sink::Commands::name(commandId) << "\" from " << client.name; |
252 | loadResource()->processCommand(commandId, commandBuffer); | 252 | loadResource()->processCommand(commandId, commandBuffer); |
253 | break; | 253 | break; |
254 | case Akonadi2::Commands::ShutdownCommand: | 254 | case Sink::Commands::ShutdownCommand: |
255 | Log() << QString("\tReceived shutdown command from %1").arg(client.name); | 255 | Log() << QString("\tReceived shutdown command from %1").arg(client.name); |
256 | //Immediately reject new connections | 256 | //Immediately reject new connections |
257 | m_server->close(); | 257 | m_server->close(); |
258 | QTimer::singleShot(0, this, &Listener::quit); | 258 | QTimer::singleShot(0, this, &Listener::quit); |
259 | break; | 259 | break; |
260 | case Akonadi2::Commands::PingCommand: | 260 | case Sink::Commands::PingCommand: |
261 | Log() << QString("\tReceived ping command from %1").arg(client.name); | 261 | Log() << QString("\tReceived ping command from %1").arg(client.name); |
262 | break; | 262 | break; |
263 | case Akonadi2::Commands::RevisionReplayedCommand: { | 263 | case Sink::Commands::RevisionReplayedCommand: { |
264 | Log() << QString("\tReceived revision replayed command from %1").arg(client.name); | 264 | Log() << QString("\tReceived revision replayed command from %1").arg(client.name); |
265 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); | 265 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); |
266 | if (Akonadi2::Commands::VerifyRevisionReplayedBuffer(verifier)) { | 266 | if (Sink::Commands::VerifyRevisionReplayedBuffer(verifier)) { |
267 | auto buffer = Akonadi2::Commands::GetRevisionReplayed(commandBuffer.constData()); | 267 | auto buffer = Sink::Commands::GetRevisionReplayed(commandBuffer.constData()); |
268 | client.currentRevision = buffer->revision(); | 268 | client.currentRevision = buffer->revision(); |
269 | } else { | 269 | } else { |
270 | Warning() << "received invalid command"; | 270 | Warning() << "received invalid command"; |
@@ -273,7 +273,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c | |||
273 | } | 273 | } |
274 | break; | 274 | break; |
275 | default: | 275 | default: |
276 | if (commandId > Akonadi2::Commands::CustomCommand) { | 276 | if (commandId > Sink::Commands::CustomCommand) { |
277 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; | 277 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; |
278 | loadResource()->processCommand(commandId, commandBuffer); | 278 | loadResource()->processCommand(commandId, commandBuffer); |
279 | } else { | 279 | } else { |
@@ -303,11 +303,11 @@ qint64 Listener::lowerBoundRevision() | |||
303 | void Listener::quit() | 303 | void Listener::quit() |
304 | { | 304 | { |
305 | //Broadcast shutdown notifications to open clients, so they don't try to restart the resource | 305 | //Broadcast shutdown notifications to open clients, so they don't try to restart the resource |
306 | auto command = Akonadi2::Commands::CreateNotification(m_fbb, Akonadi2::Commands::NotificationType::NotificationType_Shutdown); | 306 | auto command = Sink::Commands::CreateNotification(m_fbb, Sink::Commands::NotificationType::NotificationType_Shutdown); |
307 | Akonadi2::Commands::FinishNotificationBuffer(m_fbb, command); | 307 | Sink::Commands::FinishNotificationBuffer(m_fbb, command); |
308 | for (Client &client : m_connections) { | 308 | for (Client &client : m_connections) { |
309 | if (client.socket && client.socket->isOpen()) { | 309 | if (client.socket && client.socket->isOpen()) { |
310 | Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); | 310 | Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::NotificationCommand, m_fbb); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | m_fbb.Clear(); | 313 | m_fbb.Clear(); |
@@ -318,7 +318,7 @@ void Listener::quit() | |||
318 | 318 | ||
319 | bool Listener::processClientBuffer(Client &client) | 319 | bool Listener::processClientBuffer(Client &client) |
320 | { | 320 | { |
321 | static const int headerSize = Akonadi2::Commands::headerSize(); | 321 | static const int headerSize = Sink::Commands::headerSize(); |
322 | if (client.commandBuffer.size() < headerSize) { | 322 | if (client.commandBuffer.size() < headerSize) { |
323 | return false; | 323 | return false; |
324 | } | 324 | } |
@@ -339,7 +339,7 @@ bool Listener::processClientBuffer(Client &client) | |||
339 | const QByteArray commandBuffer = client.commandBuffer.left(size); | 339 | const QByteArray commandBuffer = client.commandBuffer.left(size); |
340 | client.commandBuffer.remove(0, size); | 340 | client.commandBuffer.remove(0, size); |
341 | processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { | 341 | processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { |
342 | Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); | 342 | Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Sink::Commands::name(commandId))).arg(clientName); |
343 | if (socket) { | 343 | if (socket) { |
344 | sendCommandCompleted(socket.data(), messageId, success); | 344 | sendCommandCompleted(socket.data(), messageId, success); |
345 | } else { | 345 | } else { |
@@ -359,9 +359,9 @@ void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId, bool s | |||
359 | return; | 359 | return; |
360 | } | 360 | } |
361 | 361 | ||
362 | auto command = Akonadi2::Commands::CreateCommandCompletion(m_fbb, messageId, success); | 362 | auto command = Sink::Commands::CreateCommandCompletion(m_fbb, messageId, success); |
363 | Akonadi2::Commands::FinishCommandCompletionBuffer(m_fbb, command); | 363 | Sink::Commands::FinishCommandCompletionBuffer(m_fbb, command); |
364 | Akonadi2::Commands::write(socket, ++m_messageId, Akonadi2::Commands::CommandCompletionCommand, m_fbb); | 364 | Sink::Commands::write(socket, ++m_messageId, Sink::Commands::CommandCompletionCommand, m_fbb); |
365 | m_fbb.Clear(); | 365 | m_fbb.Clear(); |
366 | } | 366 | } |
367 | 367 | ||
@@ -372,8 +372,8 @@ void Listener::refreshRevision(qint64 revision) | |||
372 | 372 | ||
373 | void Listener::updateClientsWithRevision(qint64 revision) | 373 | void Listener::updateClientsWithRevision(qint64 revision) |
374 | { | 374 | { |
375 | auto command = Akonadi2::Commands::CreateRevisionUpdate(m_fbb, revision); | 375 | auto command = Sink::Commands::CreateRevisionUpdate(m_fbb, revision); |
376 | Akonadi2::Commands::FinishRevisionUpdateBuffer(m_fbb, command); | 376 | Sink::Commands::FinishRevisionUpdateBuffer(m_fbb, command); |
377 | 377 | ||
378 | for (const Client &client: m_connections) { | 378 | for (const Client &client: m_connections) { |
379 | if (!client.socket || !client.socket->isValid()) { | 379 | if (!client.socket || !client.socket->isValid()) { |
@@ -381,44 +381,44 @@ void Listener::updateClientsWithRevision(qint64 revision) | |||
381 | } | 381 | } |
382 | 382 | ||
383 | Trace() << "Sending revision update for " << client.name << revision; | 383 | Trace() << "Sending revision update for " << client.name << revision; |
384 | Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); | 384 | Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::RevisionUpdateCommand, m_fbb); |
385 | } | 385 | } |
386 | m_fbb.Clear(); | 386 | m_fbb.Clear(); |
387 | } | 387 | } |
388 | 388 | ||
389 | void Listener::notify(const Akonadi2::Notification ¬ification) | 389 | void Listener::notify(const Sink::Notification ¬ification) |
390 | { | 390 | { |
391 | auto messageString = m_fbb.CreateString(notification.message.toUtf8().constData(), notification.message.toUtf8().size()); | 391 | auto messageString = m_fbb.CreateString(notification.message.toUtf8().constData(), notification.message.toUtf8().size()); |
392 | auto idString = m_fbb.CreateString(notification.id.constData(), notification.id.size()); | 392 | auto idString = m_fbb.CreateString(notification.id.constData(), notification.id.size()); |
393 | Akonadi2::Commands::NotificationBuilder builder(m_fbb); | 393 | Sink::Commands::NotificationBuilder builder(m_fbb); |
394 | builder.add_type(static_cast<Akonadi2::Commands::NotificationType>(notification.type)); | 394 | builder.add_type(static_cast<Sink::Commands::NotificationType>(notification.type)); |
395 | builder.add_code(notification.code); | 395 | builder.add_code(notification.code); |
396 | builder.add_identifier(idString); | 396 | builder.add_identifier(idString); |
397 | builder.add_message(messageString); | 397 | builder.add_message(messageString); |
398 | auto command = builder.Finish(); | 398 | auto command = builder.Finish(); |
399 | Akonadi2::Commands::FinishNotificationBuffer(m_fbb, command); | 399 | Sink::Commands::FinishNotificationBuffer(m_fbb, command); |
400 | for (Client &client : m_connections) { | 400 | for (Client &client : m_connections) { |
401 | if (client.socket && client.socket->isOpen()) { | 401 | if (client.socket && client.socket->isOpen()) { |
402 | Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); | 402 | Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::NotificationCommand, m_fbb); |
403 | } | 403 | } |
404 | } | 404 | } |
405 | m_fbb.Clear(); | 405 | m_fbb.Clear(); |
406 | } | 406 | } |
407 | 407 | ||
408 | Akonadi2::Resource *Listener::loadResource() | 408 | Sink::Resource *Listener::loadResource() |
409 | { | 409 | { |
410 | if (!m_resource) { | 410 | if (!m_resource) { |
411 | if (Akonadi2::ResourceFactory *resourceFactory = Akonadi2::ResourceFactory::load(m_resourceName)) { | 411 | if (Sink::ResourceFactory *resourceFactory = Sink::ResourceFactory::load(m_resourceName)) { |
412 | m_resource = resourceFactory->createResource(m_resourceInstanceIdentifier); | 412 | m_resource = resourceFactory->createResource(m_resourceInstanceIdentifier); |
413 | Trace() << QString("Resource factory: %1").arg((qlonglong)resourceFactory); | 413 | Trace() << QString("Resource factory: %1").arg((qlonglong)resourceFactory); |
414 | Trace() << QString("\tResource: %1").arg((qlonglong)m_resource); | 414 | Trace() << QString("\tResource: %1").arg((qlonglong)m_resource); |
415 | connect(m_resource, &Akonadi2::Resource::revisionUpdated, | 415 | connect(m_resource, &Sink::Resource::revisionUpdated, |
416 | this, &Listener::refreshRevision); | 416 | this, &Listener::refreshRevision); |
417 | connect(m_resource, &Akonadi2::Resource::notify, | 417 | connect(m_resource, &Sink::Resource::notify, |
418 | this, &Listener::notify); | 418 | this, &Listener::notify); |
419 | } else { | 419 | } else { |
420 | ErrorMsg() << "Failed to load resource " << m_resourceName; | 420 | ErrorMsg() << "Failed to load resource " << m_resourceName; |
421 | m_resource = new Akonadi2::Resource; | 421 | m_resource = new Sink::Resource; |
422 | } | 422 | } |
423 | } | 423 | } |
424 | return m_resource; | 424 | return m_resource; |