-
Notifications
You must be signed in to change notification settings - Fork 1
/
Download.h
55 lines (36 loc) · 1.16 KB
/
Download.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
//
// Created by warnelso on 6/8/16.
//
#ifndef PXESIM_DOWNLOAD_H
#define PXESIM_DOWNLOAD_H
#include <exception>
#include <cstdint>
#include <string>
#include <vector>
#include <iostream>
#include "constants.h"
typedef std::string Filename;
typedef std::vector<uint8_t> Data;
struct block_does_not_fit : public std::exception {
const char *what() const throw() {
return "Block does not belong to this download";
}
};
class Download {
public:
Download() : _blocks_completed(0), _total_size(0) { }
~Download() { }
void total_size(uint32_t total_size) { _total_size = total_size; }
void filename(const Filename &filename) { _filename = filename; }
const Filename &filename() const { return _filename; }
virtual void add_data(const Data &data, uint16_t block_number) { };
virtual const uint8_t *data() const { return nullptr; }
virtual uint32_t size() const { return 0; }
virtual void finalize() { }
bool complete() const { return (uint32_t) _blocks_completed * BLOCK_SIZE >= _total_size; }
protected:
uint32_t _total_size;
uint16_t _blocks_completed;
Filename _filename;
};
#endif //PXESIM_DOWNLOAD_H