refactor: ProtocolTypes EDataReceived => enum class ProtocolTypes::TransferState
This commit is contained in:
@ -521,12 +521,12 @@ void ServerProxy::setClipboard()
|
||||
ClipboardID id;
|
||||
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();
|
||||
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()));
|
||||
|
||||
// forward
|
||||
|
||||
@ -63,36 +63,38 @@ ClipboardChunk *ClipboardChunk::end(ClipboardID id, uint32_t sequence)
|
||||
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;
|
||||
std::string data;
|
||||
|
||||
if (!ProtocolUtil::readf(stream, kMsgDClipboard + 4, &id, &sequence, &mark, &data)) {
|
||||
return kError;
|
||||
return Error;
|
||||
}
|
||||
|
||||
if (mark == kDataStart) {
|
||||
s_expectedSize = deskflow::string::stringToSizeType(data);
|
||||
LOG((CLOG_DEBUG "start receiving clipboard data"));
|
||||
dataCached.clear();
|
||||
return kStart;
|
||||
return Started;
|
||||
} else if (mark == kDataChunk) {
|
||||
dataCached.append(data);
|
||||
return kNotFinish;
|
||||
return InProgress;
|
||||
} else if (mark == kDataEnd) {
|
||||
// validate
|
||||
if (id >= kClipboardEnd) {
|
||||
return kError;
|
||||
return Error;
|
||||
} else if (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"));
|
||||
return kError;
|
||||
return Error;
|
||||
}
|
||||
|
||||
void ClipboardChunk::send(deskflow::IStream *stream, void *data)
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "common/Common.h"
|
||||
#include "deskflow/Chunk.h"
|
||||
#include "deskflow/ClipboardTypes.h"
|
||||
#include "deskflow/ProtocolTypes.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -27,7 +28,8 @@ public:
|
||||
static ClipboardChunk *data(ClipboardID id, uint32_t sequence, const std::string &data);
|
||||
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);
|
||||
|
||||
|
||||
@ -210,12 +210,12 @@ enum EDataTransfer
|
||||
*
|
||||
* @since Protocol version 1.5
|
||||
*/
|
||||
enum EDataReceived
|
||||
enum class TransferState : uint8_t
|
||||
{
|
||||
kStart, ///< Reception started
|
||||
kNotFinish, ///< Reception in progress
|
||||
kFinish, ///< Reception completed successfully
|
||||
kError ///< Reception failed with error
|
||||
Started, ///< Reception started
|
||||
InProgress, ///< Reception in progress
|
||||
Finished, ///< Reception completed successfully
|
||||
Error ///< Reception failed with error
|
||||
};
|
||||
|
||||
/** @} */ // end of protocol_enums group
|
||||
|
||||
@ -50,10 +50,10 @@ bool ClientProxy1_6::recvClipboard()
|
||||
ClipboardID id;
|
||||
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();
|
||||
LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size));
|
||||
} else if (r == kFinish) {
|
||||
} else if (r == TransferState::Finished) {
|
||||
LOG(
|
||||
(CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seq,
|
||||
dataCached.size())
|
||||
|
||||
Reference in New Issue
Block a user