summaryrefslogtreecommitdiffstats
path: root/common/genericresource.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-02 14:00:37 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-02 14:00:37 +0100
commitf4381b746da350f44168674da69bd6ad6876de19 (patch)
tree916c2ff3c9e0022beb3bd92c92ceeb3fe4ba84bb /common/genericresource.cpp
parent2e98a7f6eb11a071a8ac232bcbb37abea85f6f06 (diff)
downloadsink-f4381b746da350f44168674da69bd6ad6876de19.tar.gz
sink-f4381b746da350f44168674da69bd6ad6876de19.zip
Writeback of unread flag changes
Diffstat (limited to 'common/genericresource.cpp')
-rw-r--r--common/genericresource.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/common/genericresource.cpp b/common/genericresource.cpp
index a9eab36..29cd8b1 100644
--- a/common/genericresource.cpp
+++ b/common/genericresource.cpp
@@ -312,12 +312,14 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c
312 QVariant expectedValue; 312 QVariant expectedValue;
313 s >> expectedValue; 313 s >> expectedValue;
314 inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue).then<void>([=]() { 314 inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue).then<void>([=]() {
315 Log() << "Inspection was successful: " << inspectionType << inspectionId << entityId;
315 Sink::Notification n; 316 Sink::Notification n;
316 n.type = Sink::Commands::NotificationType_Inspection; 317 n.type = Sink::Commands::NotificationType_Inspection;
317 n.id = inspectionId; 318 n.id = inspectionId;
318 n.code = Sink::Commands::NotificationCode_Success; 319 n.code = Sink::Commands::NotificationCode_Success;
319 emit notify(n); 320 emit notify(n);
320 }, [=](int code, const QString &message) { 321 }, [=](int code, const QString &message) {
322 Log() << "Inspection failed: "<< inspectionType << inspectionId << entityId << message;
321 Sink::Notification n; 323 Sink::Notification n;
322 n.type = Sink::Commands::NotificationType_Inspection; 324 n.type = Sink::Commands::NotificationType_Inspection;
323 n.message = message; 325 n.message = message;
@@ -555,38 +557,39 @@ void GenericResource::deleteEntity(const QByteArray &sinkId, qint64 revision, co
555 557
556void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) 558void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction)
557{ 559{
558 Index index("rid.mapping." + bufferType, transaction); 560 Index("rid.mapping." + bufferType, transaction).add(remoteId, localId);;
559 Index localIndex("localid.mapping." + bufferType, transaction); 561 Index("localid.mapping." + bufferType, transaction).add(localId, remoteId);
560 index.add(remoteId, localId);
561 localIndex.add(localId, remoteId);
562} 562}
563 563
564void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) 564void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction)
565{ 565{
566 Index index("rid.mapping." + bufferType, transaction); 566 Index("rid.mapping." + bufferType, transaction).remove(remoteId, localId);
567 Index localIndex("localid.mapping." + bufferType, transaction); 567 Index("localid.mapping." + bufferType, transaction).remove(localId, remoteId);
568 index.remove(remoteId, localId); 568}
569 localIndex.remove(localId, remoteId); 569
570void GenericResource::updateRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction)
571{
572 const auto oldRemoteId = Index("localid.mapping." + bufferType, transaction).lookup(localId);
573 removeRemoteId(bufferType, localId, oldRemoteId, transaction);
574 recordRemoteId(bufferType, localId, remoteId, transaction);
570} 575}
571 576
572QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) 577QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Sink::Storage::Transaction &transaction)
573{ 578{
574 //Lookup local id for remote id, or insert a new pair otherwise 579 //Lookup local id for remote id, or insert a new pair otherwise
575 Index index("rid.mapping." + bufferType, transaction); 580 Index index("rid.mapping." + bufferType, transaction);
576 Index localIndex("localid.mapping." + bufferType, transaction);
577 QByteArray sinkId = index.lookup(remoteId); 581 QByteArray sinkId = index.lookup(remoteId);
578 if (sinkId.isEmpty()) { 582 if (sinkId.isEmpty()) {
579 sinkId = QUuid::createUuid().toString().toUtf8(); 583 sinkId = QUuid::createUuid().toString().toUtf8();
580 index.add(remoteId, sinkId); 584 index.add(remoteId, sinkId);
581 localIndex.add(sinkId, remoteId); 585 Index("localid.mapping." + bufferType, transaction).add(sinkId, remoteId);
582 } 586 }
583 return sinkId; 587 return sinkId;
584} 588}
585 589
586QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction) 590QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction)
587{ 591{
588 Index index("localid.mapping." + bufferType, transaction); 592 QByteArray remoteId = Index("localid.mapping." + bufferType, transaction).lookup(localId);
589 QByteArray remoteId = index.lookup(localId);
590 if (remoteId.isEmpty()) { 593 if (remoteId.isEmpty()) {
591 Warning() << "Couldn't find the remote id for " << localId; 594 Warning() << "Couldn't find the remote id for " << localId;
592 return QByteArray(); 595 return QByteArray();