summaryrefslogtreecommitdiffstats
path: root/common/resourceaccess.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-05 15:22:10 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-05 15:22:10 +0200
commitb4df9eb5f1f4a0ac2b1272fc34d4b8aad473008b (patch)
tree9abf529061432031afefd6a8bfa821a9779f763d /common/resourceaccess.cpp
parentf9379318d801df204cc50385c5eca1f28e91755e (diff)
downloadsink-b4df9eb5f1f4a0ac2b1272fc34d4b8aad473008b.tar.gz
sink-b4df9eb5f1f4a0ac2b1272fc34d4b8aad473008b.zip
Prepare for making the resource status available
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r--common/resourceaccess.cpp49
1 files changed, 31 insertions, 18 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index d3bd85f..95b4a7e 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -230,6 +230,7 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket()
230ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType) 230ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType)
231 : ResourceAccessInterface(), d(new Private(resourceType, resourceInstanceIdentifier, this)) 231 : ResourceAccessInterface(), d(new Private(resourceType, resourceInstanceIdentifier, this))
232{ 232{
233 mResourceStatus = Sink::ApplicationDomain::OfflineStatus;
233 Trace() << "Starting access"; 234 Trace() << "Starting access";
234} 235}
235 236
@@ -513,6 +514,22 @@ void ResourceAccess::readResourceMessage()
513 } 514 }
514} 515}
515 516
517static Sink::Notification getNotification(const Sink::Commands::Notification *buffer)
518{
519 Sink::Notification n;
520 if (buffer->identifier()) {
521 // Don't use fromRawData, the buffer is gone once we invoke emit notification
522 n.id = BufferUtils::extractBufferCopy(buffer->identifier());
523 }
524 if (buffer->message()) {
525 // Don't use fromRawData, the buffer is gone once we invoke emit notification
526 n.message = BufferUtils::extractBufferCopy(buffer->message());
527 }
528 n.type = buffer->type();
529 n.code = buffer->code();
530 return n;
531}
532
516bool ResourceAccess::processMessageBuffer() 533bool ResourceAccess::processMessageBuffer()
517{ 534{
518 static const int headerSize = Commands::headerSize(); 535 static const int headerSize = Commands::headerSize();
@@ -535,7 +552,7 @@ bool ResourceAccess::processMessageBuffer()
535 auto buffer = Commands::GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize); 552 auto buffer = Commands::GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize);
536 Trace() << QString("Revision updated to: %1").arg(buffer->revision()); 553 Trace() << QString("Revision updated to: %1").arg(buffer->revision());
537 Notification n; 554 Notification n;
538 n.type = Sink::Commands::NotificationType::NotificationType_RevisionUpdate; 555 n.type = Sink::Notification::RevisionUpdate;
539 emit notification(n); 556 emit notification(n);
540 emit revisionChanged(buffer->revision()); 557 emit revisionChanged(buffer->revision());
541 558
@@ -553,30 +570,26 @@ bool ResourceAccess::processMessageBuffer()
553 case Commands::NotificationCommand: { 570 case Commands::NotificationCommand: {
554 auto buffer = Commands::GetNotification(d->partialMessageBuffer.constData() + headerSize); 571 auto buffer = Commands::GetNotification(d->partialMessageBuffer.constData() + headerSize);
555 switch (buffer->type()) { 572 switch (buffer->type()) {
556 case Sink::Commands::NotificationType::NotificationType_Shutdown: 573 case Sink::Notification::Shutdown:
557 Log() << "Received shutdown notification."; 574 Log() << "Received shutdown notification.";
558 close(); 575 close();
559 break; 576 break;
560 case Sink::Commands::NotificationType::NotificationType_Inspection: { 577 case Sink::Notification::Inspection: {
561 Trace() << "Received inspection notification."; 578 Trace() << "Received inspection notification.";
562 Notification n; 579 auto n = getNotification(buffer);
563 if (buffer->identifier()) {
564 // Don't use fromRawData, the buffer is gone once we invoke emit notification
565 n.id = BufferUtils::extractBufferCopy(buffer->identifier());
566 }
567 if (buffer->message()) {
568 // Don't use fromRawData, the buffer is gone once we invoke emit notification
569 n.message = BufferUtils::extractBufferCopy(buffer->message());
570 }
571 n.type = buffer->type();
572 n.code = buffer->code();
573 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first 580 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first
574 queuedInvoke([=]() { emit notification(n); }, this); 581 queuedInvoke([=]() { emit notification(n); }, this);
575 } break; 582 } break;
576 case Sink::Commands::NotificationType::NotificationType_Status: 583 case Sink::Notification::Status:
577 case Sink::Commands::NotificationType::NotificationType_Warning: 584 mResourceStatus = buffer->code();
578 case Sink::Commands::NotificationType::NotificationType_Progress: 585 [[clang::fallthrough]];
579 case Sink::Commands::NotificationType::NotificationType_RevisionUpdate: 586 case Sink::Notification::Warning:
587 [[clang::fallthrough]];
588 case Sink::Notification::Progress: {
589 auto n = getNotification(buffer);
590 emit notification(n);
591 } break;
592 case Sink::Notification::RevisionUpdate:
580 default: 593 default:
581 Warning() << "Received unknown notification: " << buffer->type(); 594 Warning() << "Received unknown notification: " << buffer->type();
582 break; 595 break;