-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_command.h
105 lines (89 loc) · 2.79 KB
/
server_command.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef SERVER_COMMAND_H
#define SERVER_COMMAND_H
#include <string>
#include <cpprest/json.h>
namespace CommandTypes
{
enum CommandTypes {
NOOP,
START_RECORDING,
STOP_RECORDING,
COMPLETE,
STREAM,
UNKNOWN
};
}
/**
* @brief parameters for a "START_RECORDING" command
*/
struct RecordingParameters {
int session_id; ///< session ID of recording session device is joining
size_t duration; ///< length of recording session in seconds
int target_fps; ///< target frames per second
bool fragment_hourly; ///< fragment video files at the top of the hour
bool apply_filter; ///< apply filtering when encoding video
std::string file_prefix; ///< user specified filename prefix
};
/**
* @brief basic command from the server
*
* this is used for basic commands that don't have any parameters
*/
class ServerCommand {
public:
/**
* @brief get the type of command this is
* @return command type of CommandTypes::CommandTypes enum
*/
CommandTypes::CommandTypes command(){return command_;}
/**
* @brief create a new ServerCommand from the json payload in the server
* response
* @param command_payload JSON payload sent in response to a status update
*/
ServerCommand(web::json::value command_payload);
/**
* @brief explicitly create a ServerCommand of a specific command type
* @param cmd command type
*/
ServerCommand(CommandTypes::CommandTypes cmd);
/**
* @brief default constructor -- creates a "NO OP" command
*/
ServerCommand();
private:
/// command type (what action the server wants us to take)
CommandTypes::CommandTypes command_;
};
/**
* @brief special case command for a START_RECORDING command since it also
* includes parameters
*/
class RecordCommand: public ServerCommand {
public:
/**
* @brief get parameters for this RecordCommand
* @return RecordingParameters struct containing recording session parameters
*/
RecordingParameters parameters(){return parameters_;}
/**
* @brief createa RecordCommand from JSON payload
*/
RecordCommand(web::json::value command_payload);
private:
/// recording session parameters from server
RecordingParameters parameters_;
/**
* @brief extract parameters from JSON payload
* @param payload JSON body from server response
* @return RecordingParameters struct with information extracted from JSON
*/
RecordingParameters parseRecordingParameters(web::json::value payload);
};
/**
* @brief determine command type by examining JSON
* @param payload JSON body from server response
* @return which command type is specified by the response
*/
CommandTypes::CommandTypes getCommand(web::json::value payload);
#endif //SERVER_COMMAND_H