MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / readNote

Method readNote

cmdtools/cmdlinetool.cpp:620–667  ·  view source on GitHub ↗

Read a note via the command line and extract the text contents.

Source from the content-addressed store, hash-verified

618// Read a note via the command line and extract the text
619// contents.
620int CmdLineTool::readNote(StartupConfig config) {
621 bool useCrossMemory = true;
622
623 // Look to see if another NixNote is running. If so, then we
624 // expect a response. Otherwise, we do it ourself.
625 global.sharedMemory->unlock();
626 global.sharedMemory->detach();
627 if (!global.sharedMemory->attach()) {
628 useCrossMemory = false;
629 }
630 if (useCrossMemory) {
631 NUuid uuid;
632 config.extractText->returnUuid = uuid.create();
633 CrossMemoryMapper sharedMemory(config.extractText->returnUuid);
634 if (!sharedMemory.allocate(500*1024))
635 return 16;
636 sharedMemory.clearMemory();
637 global.sharedMemory->write("READ_NOTE:" + config.extractText->wrap());
638 int maxWait = 5;
639 bool expectResponse = true;
640 int cnt = 0;
641 while (expectResponse && cnt<maxWait) {
642 QByteArray data = sharedMemory.read();
643 if (!data.startsWith('\0')) {
644 expectResponse = false;
645 config.extractText->unwrap(data);
646 } else {
647 sleep(1);
648 }
649 cnt++;
650 }
651 if (!expectResponse)
652 std::cout << config.extractText->text.toStdString() << endl;
653 else
654 std::cout << tr("No response received from NixNote.").toStdString();
655 } else {
656 global.db = new DatabaseConnection("nixnote"); // Startup the database
657 NoteTable noteTable(global.db);
658 Note n;
659 QString text;
660 if (noteTable.get(n,config.extractText->lid,false,false))
661 text = config.extractText->stripTags(n.content);
662 else
663 text = tr("Note not found.");
664 std::cout << text.toStdString() << endl;
665 }
666 return 0;
667}
668
669
670

Callers 1

runMethod · 0.45

Calls 12

detachMethod · 0.80
attachMethod · 0.80
allocateMethod · 0.80
clearMemoryMethod · 0.80
stripTagsMethod · 0.80
unlockMethod · 0.45
createMethod · 0.45
writeMethod · 0.45
wrapMethod · 0.45
readMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected