File indexing completed on 2025-01-05 04:47:00

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QSharedPointer>
0011 
0012 #include "entities.h"
0013 #include "exception.h"
0014 
0015 namespace Akonadi
0016 {
0017 namespace Protocol
0018 {
0019 class PartMetaData;
0020 class Command;
0021 using CommandPtr = QSharedPointer<Command>;
0022 }
0023 
0024 namespace Server
0025 {
0026 AKONADI_EXCEPTION_MAKE_INSTANCE(PartStreamerException);
0027 
0028 class PimItem;
0029 class Part;
0030 class Connection;
0031 
0032 class PartStreamer
0033 {
0034 public:
0035     explicit PartStreamer(Connection *connection, const PimItem &pimItem);
0036     ~PartStreamer();
0037 
0038     /**
0039      * @throws PartStreamException
0040      */
0041     void stream(bool checkExists, const QByteArray &partName, qint64 &partSize, bool *changed = nullptr);
0042 
0043     /**
0044      * @throws PartStreamerException
0045      */
0046     void streamAttribute(bool checkExists, const QByteArray &partName, const QByteArray &value, bool *changed = nullptr);
0047 
0048 private:
0049     void streamPayload(Part &part, const QByteArray &partName);
0050     void streamPayloadToFile(Part &part, const Protocol::PartMetaData &metaPart);
0051     void streamPayloadData(Part &part, const Protocol::PartMetaData &metaPart);
0052     void streamForeignPayload(Part &part, const Protocol::PartMetaData &metaPart);
0053 
0054     Protocol::PartMetaData requestPartMetaData(const QByteArray &partName);
0055     void preparePart(bool checkExists, const QByteArray &partName, Part &part);
0056 
0057     Connection *mConnection;
0058     PimItem mItem;
0059     bool mCheckChanged;
0060     bool mDataChanged;
0061 };
0062 
0063 } // namespace Server
0064 } // namespace Akonadi