refactor: ProtocolTypes EDataReceived => enum class ProtocolTypes::TransferState

This commit is contained in:
sithlord48 2025-07-03 14:06:56 -04:00 committed by Nick Bolton
parent 0ea2576032
commit bc9f47c957
5 changed files with 23 additions and 19 deletions

View file

@ -521,12 +521,12 @@ void ServerProxy::setClipboard()
ClipboardID id; ClipboardID id;
uint32_t seq; uint32_t seq;
int r = ClipboardChunk::assemble(m_stream, dataCached, id, seq); auto r = ClipboardChunk::assemble(m_stream, dataCached, id, seq);
if (r == kStart) { if (r == TransferState::Started) {
size_t size = ClipboardChunk::getExpectedSize(); size_t size = ClipboardChunk::getExpectedSize();
LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size)); LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size));
} else if (r == kFinish) { } else if (r == TransferState::Finished) {
LOG((CLOG_DEBUG "received clipboard %d size=%d", id, dataCached.size())); LOG((CLOG_DEBUG "received clipboard %d size=%d", id, dataCached.size()));
// forward // forward

View file

@ -63,36 +63,38 @@ ClipboardChunk *ClipboardChunk::end(ClipboardID id, uint32_t sequence)
return end; return end;
} }
int ClipboardChunk::assemble(deskflow::IStream *stream, std::string &dataCached, ClipboardID &id, uint32_t &sequence) TransferState
ClipboardChunk::assemble(deskflow::IStream *stream, std::string &dataCached, ClipboardID &id, uint32_t &sequence)
{ {
using enum TransferState;
uint8_t mark; uint8_t mark;
std::string data; std::string data;
if (!ProtocolUtil::readf(stream, kMsgDClipboard + 4, &id, &sequence, &mark, &data)) { if (!ProtocolUtil::readf(stream, kMsgDClipboard + 4, &id, &sequence, &mark, &data)) {
return kError; return Error;
} }
if (mark == kDataStart) { if (mark == kDataStart) {
s_expectedSize = deskflow::string::stringToSizeType(data); s_expectedSize = deskflow::string::stringToSizeType(data);
LOG((CLOG_DEBUG "start receiving clipboard data")); LOG((CLOG_DEBUG "start receiving clipboard data"));
dataCached.clear(); dataCached.clear();
return kStart; return Started;
} else if (mark == kDataChunk) { } else if (mark == kDataChunk) {
dataCached.append(data); dataCached.append(data);
return kNotFinish; return InProgress;
} else if (mark == kDataEnd) { } else if (mark == kDataEnd) {
// validate // validate
if (id >= kClipboardEnd) { if (id >= kClipboardEnd) {
return kError; return Error;
} else if (s_expectedSize != dataCached.size()) { } else if (s_expectedSize != dataCached.size()) {
LOG((CLOG_ERR "corrupted clipboard data, expected size=%d actual size=%d", s_expectedSize, dataCached.size())); LOG((CLOG_ERR "corrupted clipboard data, expected size=%d actual size=%d", s_expectedSize, dataCached.size()));
return kError; return Error;
} }
return kFinish; return Finished;
} }
LOG((CLOG_ERR "clipboard transmission failed: unknown error")); LOG((CLOG_ERR "clipboard transmission failed: unknown error"));
return kError; return Error;
} }
void ClipboardChunk::send(deskflow::IStream *stream, void *data) void ClipboardChunk::send(deskflow::IStream *stream, void *data)

View file

@ -9,6 +9,7 @@
#include "common/Common.h" #include "common/Common.h"
#include "deskflow/Chunk.h" #include "deskflow/Chunk.h"
#include "deskflow/ClipboardTypes.h" #include "deskflow/ClipboardTypes.h"
#include "deskflow/ProtocolTypes.h"
#include <string> #include <string>
@ -27,7 +28,8 @@ public:
static ClipboardChunk *data(ClipboardID id, uint32_t sequence, const std::string &data); static ClipboardChunk *data(ClipboardID id, uint32_t sequence, const std::string &data);
static ClipboardChunk *end(ClipboardID id, uint32_t sequence); static ClipboardChunk *end(ClipboardID id, uint32_t sequence);
static int assemble(deskflow::IStream *stream, std::string &dataCached, ClipboardID &id, uint32_t &sequence); static TransferState
assemble(deskflow::IStream *stream, std::string &dataCached, ClipboardID &id, uint32_t &sequence);
static void send(deskflow::IStream *stream, void *data); static void send(deskflow::IStream *stream, void *data);

View file

@ -210,12 +210,12 @@ enum EDataTransfer
* *
* @since Protocol version 1.5 * @since Protocol version 1.5
*/ */
enum EDataReceived enum class TransferState : uint8_t
{ {
kStart, ///< Reception started Started, ///< Reception started
kNotFinish, ///< Reception in progress InProgress, ///< Reception in progress
kFinish, ///< Reception completed successfully Finished, ///< Reception completed successfully
kError ///< Reception failed with error Error ///< Reception failed with error
}; };
/** @} */ // end of protocol_enums group /** @} */ // end of protocol_enums group

View file

@ -50,10 +50,10 @@ bool ClientProxy1_6::recvClipboard()
ClipboardID id; ClipboardID id;
uint32_t seq; uint32_t seq;
if (int r = ClipboardChunk::assemble(getStream(), dataCached, id, seq); r == kStart) { if (auto r = ClipboardChunk::assemble(getStream(), dataCached, id, seq); r == TransferState::Started) {
size_t size = ClipboardChunk::getExpectedSize(); size_t size = ClipboardChunk::getExpectedSize();
LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size)); LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size));
} else if (r == kFinish) { } else if (r == TransferState::Finished) {
LOG( LOG(
(CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seq, (CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seq,
dataCached.size()) dataCached.size())