-
Notifications
You must be signed in to change notification settings - Fork 4
/
winner.h
147 lines (127 loc) · 3.07 KB
/
winner.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Winner.h
*
* Statistics of the winner of the race job
*
* @author Aljar Meesters <[email protected]>
* @copyright Copernica BV 2015
*/
/**
* include guard
*/
#pragma once
/**
* dependencies
*/
#include <phpcpp.h>
#include "json/object.h"
/**
* class definition
*/
class Winner : public Php::Base
{
private:
/**
* json that holds the information
* @var JSON::Object
*/
JSON::Object _json;
public:
/**
* Constructor
* @param json
*/
Winner(const JSON::Object &json) : _json(json) {}
/**
* input that was send to the winner
* @return Php::Value
*/
Php::Value input() const
{
// Unserialize the result
auto completeObject = std::string(_json.c_str("stdin"));
// look for the \n\n separator
auto separator = completeObject.find("\n\n");
// should exist
if (separator == std::string::npos) throw std::runtime_error("missing separator between serialized data and input data");
// we now know where the rest of the data starts
auto data = completeObject.data() + separator + 2;
// Decode the data
return Php::call("base64_decode" , Php::Value(data));
// unserialize the first part of the stdin
// return unserialized(Php::call("unserialize", Php::call("base64_decode", Php::Value(rest.data()))));
}
/**
* output that was send to stdout by winner
* @return Php::Value
*/
Php::Value output() const
{
// Unserialize the result
return Php::call("unserialize", Php::call("base64_decode", _json.c_str("stdout")));
}
/**
* error that was send to stderr by winner
* @return Php::Value
*/
Php::Value error() const
{
return Php::call("unserialize", Php::call("base64_decode", _json.c_str("stderr")));
}
/**
* name of sever on which the winning job ran
* @return Php::Value
*/
Php::Value server() const
{
return _json.c_str("server");
}
/**
* Process id of the winner
* @return Php::Value
*/
Php::Value pid() const
{
return _json.integer("pid");
}
/**
* Signal if the winner was killed
* @return Php::Value
*/
Php::Value signal() const
{
return _json.integer("signal");
}
/**
* Exit code with which the winner exited
* @return Php::Value
*/
Php::Value exit() const
{
return _json.integer("exit");
}
/**
* Starting time of the winner
* @return Php::Value
*/
Php::Value started() const
{
return _json.decimal("started");
}
/**
* Finishing time of the winner
* @return Php::Value
*/
Php::Value finished() const
{
return _json.decimal("finished");
}
/**
* Runtime of the winner
* @return Php::Value
*/
Php::Value runtime() const
{
return _json.decimal("runtime");
}
};