Skip to content

Commit 86ea33d

Browse files
committed
Cost
1 parent cad7879 commit 86ea33d

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

include/fastotv/commands_info/machine_info.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class MachineInfo : public common::serializer::JsonSerializer<MachineInfo> {
2929
typedef JsonSerializer<MachineInfo> base_class;
3030
typedef double cpu_load_t;
3131
typedef double gpu_load_t;
32+
typedef double cost_t;
33+
3234
MachineInfo();
3335
MachineInfo(cpu_load_t cpu_load,
3436
gpu_load_t gpu_load,
@@ -42,7 +44,8 @@ class MachineInfo : public common::serializer::JsonSerializer<MachineInfo> {
4244
time_t uptime,
4345
fastotv::timestamp_t timestamp,
4446
size_t net_total_bytes_recv,
45-
size_t net_total_bytes_send);
47+
size_t net_total_bytes_send,
48+
cost_t cost);
4649

4750
cpu_load_t GetCpuLoad() const;
4851
gpu_load_t GetGpuLoad() const;
@@ -59,6 +62,7 @@ class MachineInfo : public common::serializer::JsonSerializer<MachineInfo> {
5962

6063
size_t GetNetTotalBytesRecv() const;
6164
size_t GetNetTotalBytesSend() const;
65+
cost_t GetCost() const;
6266

6367
bool Equals(const MachineInfo& mach) const;
6468

@@ -80,6 +84,7 @@ class MachineInfo : public common::serializer::JsonSerializer<MachineInfo> {
8084
time_t uptime_;
8185
size_t net_total_bytes_recv_;
8286
size_t net_total_bytes_send_;
87+
cost_t cost_;
8388
};
8489

8590
inline bool operator==(const MachineInfo& left, const MachineInfo& right) {

src/commands_info/machine_info.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#define TOTAL_BYTES_IN_FIELD "total_bytes_in"
3333
#define TOTAL_BYTES_OUT_FIELD "total_bytes_out"
34+
#define COST_FIELD "cost"
3435

3536
namespace fastotv {
3637
namespace commands_info {
@@ -49,7 +50,8 @@ MachineInfo::MachineInfo()
4950
current_ts_(0),
5051
uptime_(0),
5152
net_total_bytes_recv_(0),
52-
net_total_bytes_send_(0) {}
53+
net_total_bytes_send_(0),
54+
cost_(0) {}
5355

5456
MachineInfo::MachineInfo(cpu_load_t cpu_load,
5557
gpu_load_t gpu_load,
@@ -63,7 +65,8 @@ MachineInfo::MachineInfo(cpu_load_t cpu_load,
6365
time_t uptime,
6466
fastotv::timestamp_t timestamp,
6567
size_t net_total_bytes_recv,
66-
size_t net_total_bytes_send)
68+
size_t net_total_bytes_send,
69+
cost_t cost)
6770
: base_class(),
6871
cpu_load_(cpu_load),
6972
gpu_load_(gpu_load),
@@ -77,7 +80,8 @@ MachineInfo::MachineInfo(cpu_load_t cpu_load,
7780
current_ts_(timestamp),
7881
uptime_(uptime),
7982
net_total_bytes_recv_(net_total_bytes_recv),
80-
net_total_bytes_send_(net_total_bytes_send) {}
83+
net_total_bytes_send_(net_total_bytes_send),
84+
cost_(cost) {}
8185

8286
common::Error MachineInfo::SerializeFields(json_object* out) const {
8387
ignore_result(SetDoubleField(out, CPU_FIELD, cpu_load_));
@@ -93,6 +97,7 @@ common::Error MachineInfo::SerializeFields(json_object* out) const {
9397
ignore_result(SetInt64Field(out, TIMESTAMP_FIELD, current_ts_));
9498
ignore_result(SetUInt64Field(out, TOTAL_BYTES_IN_FIELD, net_total_bytes_recv_));
9599
ignore_result(SetUInt64Field(out, TOTAL_BYTES_OUT_FIELD, net_total_bytes_send_));
100+
ignore_result(SetDoubleField(out, COST_FIELD, cost_));
96101
return common::Error();
97102
}
98103

@@ -136,9 +141,12 @@ common::Error MachineInfo::DoDeSerialize(json_object* serialized) {
136141
uint64_t net_total_bytes_send = 0;
137142
ignore_result(GetUint64Field(serialized, TOTAL_BYTES_OUT_FIELD, &net_total_bytes_send));
138143

144+
cost_t cost = 0;
145+
ignore_result(GetDoubleField(serialized, COST_FIELD, &cost));
146+
139147
*this =
140148
MachineInfo(cpu_load, gpu_load, load_average, ram_bytes_total, ram_bytes_free, hdd_bytes_total, hdd_bytes_free,
141-
net_bytes_recv, net_bytes_send, uptime, current_ts, net_total_bytes_recv, net_total_bytes_send);
149+
net_bytes_recv, net_bytes_send, uptime, current_ts, net_total_bytes_recv, net_total_bytes_send, cost);
142150
return common::Error();
143151
}
144152

@@ -194,13 +202,18 @@ size_t MachineInfo::GetNetTotalBytesSend() const {
194202
return net_total_bytes_send_;
195203
}
196204

205+
MachineInfo::cost_t MachineInfo::GetCost() const {
206+
return cost_;
207+
}
208+
197209
bool MachineInfo::Equals(const MachineInfo& mach) const {
198210
return mach.cpu_load_ == cpu_load_ && mach.gpu_load_ == gpu_load_ && mach.load_average_ == load_average_ &&
199211
mach.ram_bytes_total_ == ram_bytes_total_ && mach.ram_bytes_free_ == ram_bytes_free_ &&
200212
mach.hdd_bytes_total_ == hdd_bytes_total_ && mach.hdd_bytes_free_ == hdd_bytes_free_ &&
201213
mach.net_bytes_recv_ == net_bytes_recv_ && mach.net_bytes_send_ == net_bytes_send_ &&
202214
mach.uptime_ == uptime_ && mach.current_ts_ == current_ts_ &&
203-
mach.net_total_bytes_recv_ == net_total_bytes_recv_ && mach.net_total_bytes_send_ == net_total_bytes_send_;
215+
mach.net_total_bytes_recv_ == net_total_bytes_recv_ && mach.net_total_bytes_send_ == net_total_bytes_send_ &&
216+
mach.cost_ == cost_;
204217
}
205218

206219
} // namespace commands_info

0 commit comments

Comments
 (0)