Add toJson method for the protocol.
ClosedPublic

Authored by knauss on May 7 2018, 12:05 PM.

Details

Summary

To be able to send json as debug protocol, so we can better search and
parse this on akonadiconsole.

Test Plan

build

Diff Detail

Repository
R165 Akonadi
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
knauss created this revision.May 7 2018, 12:05 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptMay 7 2018, 12:05 PM
Restricted Application added a subscriber: KDE PIM. · View Herald Transcript
knauss requested review of this revision.May 7 2018, 12:05 PM
dvratil requested changes to this revision.May 13 2018, 10:15 AM

Looks good, thanks a lot! Just resolve the Relation serialization and I think we are good to go.

src/private/protocolgen/cppgenerator.cpp
649

Just add toJSON() to the Relation class.

This revision now requires changes to proceed.May 13 2018, 10:15 AM
knauss updated this revision to Diff 34512.May 20 2018, 11:17 AM

add toJson for Relations

make sure seek is only called when lists are not empty.

dvratil requested changes to this revision.May 20 2018, 12:21 PM

Use !foo.isEmpty() instead of foo.size() > 0 please

src/private/protocolgen/cppgenerator.cpp
631

qAsConst(serializeProperties) to prevent detaching the container

src/private/scope.cpp
329
const auto chain = hridChain();
for (const auto &hrid : chain) {
  ..
}

to prevent detaching the returned container.

332

Use the chain variable from above comment here

This revision now requires changes to proceed.May 20 2018, 12:21 PM
knauss marked 4 inline comments as done.May 20 2018, 5:00 PM
knauss added inline comments.
src/private/protocolgen/cppgenerator.cpp
631

this needs also be done at all other usages of serializeProperties , as they only read data this is not an issue, right?

knauss updated this revision to Diff 34541.May 20 2018, 5:01 PM
knauss marked an inline comment as done.

use iEmpty and qAsConst

dvratil added inline comments.May 21 2018, 7:30 AM
src/private/protocolgen/cppgenerator.cpp
631

This only needs to be done when using a non-const Qt container in a range-based for loop, because it calls non-const begin() and end(), causing the container to detach if it is (or could be) shared

knauss added inline comments.May 21 2018, 8:53 AM
src/private/scope.cpp
329

my compiler is unhappy with the const auto chain = hridChain(); line in the switch:

/home/neon/kdepim/src/kde/pim/akonadi/src/private/scope.cpp: In member function 'QTextStream& Akonadi::Scope::toJson(QTextStream&) const':                                                                                                    
/home/neon/kdepim/src/kde/pim/akonadi/src/private/scope.cpp:339:5: error: jump to case label [-fpermissive]
/home/neon/kdepim/src/kde/pim/akonadi/src/private/scope.cpp:329:21: note:   crosses initialization of 'const QVector<Akonadi::Scope::HRID>& chain'
/home/neon/kdepim/src/kde/pim/akonadi/src/private/scope.cpp:317:12: warning: enumeration value 'Invalid' not handled in switch [-Wswitch]
anthonyfieroni added inline comments.
src/private/protocol.cpp
203–205

You can make a helper macro like this

#define case_label(x)    case Command::x: stream << #x; break

swtich (mType)
{
    case_label(Invalid);
    case_label(Hello);
    ...
}

#undef case_label
src/private/scope.cpp
329

That's normal, you should use curly braces around a case when you want to declare a variable inside

case x : { int a = 5; } break;
knauss updated this revision to Diff 34577.May 21 2018, 12:46 PM

use case_label and fix issue in scope.

knauss marked 3 inline comments as done.May 21 2018, 12:54 PM
knauss added inline comments.
src/private/protocolgen/cppgenerator.cpp
520

used without qAsConst

598

used serializeProperties too without qAsConst

dvratil accepted this revision.May 21 2018, 6:17 PM
This revision is now accepted and ready to land.May 21 2018, 6:17 PM
This revision was automatically updated to reflect the committed changes.