-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandinterpreter.h
More file actions
28 lines (24 loc) · 1.04 KB
/
Copy pathcommandinterpreter.h
File metadata and controls
28 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef COMMANDINTERPRETER_H
#define COMMANDINTERPRETER_H
#include <string>
#include "connection.h"
enum class Command {Echo, File, Unknown};
class CommandInterpreter
{
Connection& socket;
unsigned maxPackageSize = 1024;
u_int8_t clientId = 1;
size_t getFileSize(std::fstream& file);
FileInitPackage fillInitPackage(size_t fileSize, const std::string& fileName);
std::string transferFile(const std::string& fileName);
std::string echo(const std::string& cmd);
Command decode(const std::string& cmd);
Header fillHeader(ServerCommand command, size_t size, bool confirm);
void sendMarker(unsigned chunkId, size_t chunksCount);
void sendFilePart(Buffer& buff, std::fstream& file, unsigned chunkId, unsigned fullChunkSize, unsigned chunkSize);
bool resendMissingParts(Buffer& buff, std::fstream& file, unsigned chunkId, unsigned fullChunkSize, unsigned chunkSize);
public:
CommandInterpreter(Connection& socket, int id);
std::string Interpret(const std::string& command);
};
#endif // COMMANDINTERPRETER_H