forked from edman007/chiton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.hpp
69 lines (62 loc) · 2.31 KB
/
export.hpp
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
#ifndef __EXPORT_HPP__
#define __EXPORT_HPP__
/**************************************************************************
*
* This file is part of Chiton.
*
* Chiton is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiton is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiton. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright 2020 Ed Martin <[email protected]>
*
**************************************************************************
*/
#include "chiton_config.hpp"
#include "database.hpp"
#include "file_manager.hpp"
#include <thread>
#include <atomic>
#include <mutex>
/*
* This checks for tasks to export and exports them
*/
class Export {
public:
Export(Database &db, Config &cfg, FileManager &fm);
~Export(void);
bool check_for_jobs(void);//checks for any pending export jobs and executes them, returns true if a job is in progress
bool rm_export(int export_id);//deletes export with this ID, cancles it if in progress, thread safe
private:
Database &db;
Config &cfg;
FileManager &g_fm;
//details of current job:
std::atomic<long> id;
long starttime;
long endtime;
long camera;
std::string path;
long progress;
Config* camera_cfg;
long reserved_bytes;
std::thread runner;
std::atomic<bool> export_in_progress;//set to true when the runner is active
std::atomic<bool> force_exit;//will cause the runner to exis ASAP when true
std::mutex lock;//lock to check on the runner
bool start_job(void);//kicks off a thread to perform the export
void run_job(void);//main loop for exporting
bool update_progress();//sets the current progress
void reserve_space(FileManager &fm, long size);//reserve size bytes of drive space
bool split_export(long seg_id);//split the export so that a new export is created starting with this segment
};
#endif