aboutsummaryrefslogtreecommitdiff
path: root/oop2eindopdr/DownloadManager.h
blob: c98ae670f375e5c2155b9ef45f8c20e4e90c680e (plain)
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
#pragma once

#include <string>
#include <thread>
#include <vector>

class DownloadManager {
private:
	const unsigned max_files = 50;

	std::vector<std::thread*> download_queue = {};
	std::vector<std::fstream*> file_queue = {};

	/**
	 * @brief open file in DownloadManager (THREAD-ONLY)
	 * 
	 * this function opens a file, but blocks until a slot is available, so
	 * should only be used in threads
	 */
	std::fstream* open_file(std::string filename);
	/**
	 * @brief close file in DownloadManager (THREAD-ONLY)
	 *
	 * this function closes a file and removes it's pointer from the file_queue
	 * vector
	 */
	void close_file(std::fstream* file_ptr);

public:
	DownloadManager();
	virtual ~DownloadManager();

	/** @brief downlaod `url` to `file` and close `file` when done */
	virtual std::thread* wget(std::string url, std::string filename);
};