root/software/photo_compress_archiver/PhotoCompressArchiver.hh @ 2243e528
| b216a5b0 | David Sorber | #ifndef PHOTOCOMPRESSARCHIVER_H
|
||
#define PHOTOCOMPRESSARCHIVER_H
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
| 3eeb1485 | David Sorber | #include <deque>
|
||
| b216a5b0 | David Sorber | #include <mutex>
|
||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
// Alias the boost fs namespace to keep the code readable
|
||||
namespace bfs = boost::filesystem;
|
||||
| 328d0fa5 | David Sorber | const std::string BOLD("\033[1m");
|
||
const std::string ENDC("\033[0m");
|
||||
const std::string RED("\033[31m");
|
||||
const std::string YELLOW("\033[33m");
|
||||
const std::string PURPLE("\033[35m");
|
||||
const std::string version("v0.1.0");
|
||||
| b216a5b0 | David Sorber | const boost::regex JPEG_REGEX("^.+\\.(jpg)|(jpeg)$", boost::regex::icase);
|
||
| 328d0fa5 | David Sorber | const boost::regex PJG_REGEX("^.+\\.pjg$", boost::regex::icase);
|
||
| b216a5b0 | David Sorber | |||
| 3eeb1485 | David Sorber | struct work_unit_t {
|
||
std::vector<const char*> exec_argv;
|
||||
std::vector<std::string*> output_filenames;
|
||||
};
|
||||
typedef struct work_unit_t WorkUnit;
|
||||
| b216a5b0 | David Sorber | class PhotoCompressArchiver
|
||
{
|
||||
public:
|
||||
| 328d0fa5 | David Sorber | PhotoCompressArchiver(
|
||
const std::string& path,
|
||||
uint32_t num_cores,
|
||||
bool decompress,
|
||||
| e0b7f8b9 | David Sorber | bool keep_orig,
|
||
boost::regex& filter_regex);
|
||||
| b216a5b0 | David Sorber | |||
~PhotoCompressArchiver();
|
||||
/**
|
||||
* Start processing
|
||||
*/
|
||||
int execute();
|
||||
/**
|
||||
* Recursively find input files based on passed regex
|
||||
*/
|
||||
void find_files(
|
||||
const bfs::path& dir_path,
|
||||
const boost::regex& file_regex);
|
||||
/**
|
||||
* Fork and wait
|
||||
*/
|
||||
| 3eeb1485 | David Sorber | void fork_worker(uint32_t tid);
|
||
| f8e600bc | David Sorber | |||
/**
|
||||
* Calculate the return the "global" percent done as determined by the
|
||||
* m_files_processed and m_num_input_files instance variables.
|
||||
*/
|
||||
double get_global_percent_done();
|
||||
| b216a5b0 | David Sorber | |||
private:
|
||||
| f8e600bc | David Sorber | const bfs::path m_path; // top level path where to look for input files
|
||
| b216a5b0 | David Sorber | uint32_t m_num_cores; // number of cores on the machine
|
||
| 328d0fa5 | David Sorber | bool m_decompress; // decompress files instead of compress them
|
||
bool m_keep_orig; // keep; don't delete original files
|
||||
| b216a5b0 | David Sorber | std::mutex m_output_mutex; // output mutex
|
||
| f8e600bc | David Sorber | std::atomic<uint32_t> m_files_processed; // number of input files processed
|
||
uint32_t m_num_input_files; // total number of input files found
|
||||
std::atomic<uint64_t> m_total_uncompressed_size;// total uncompressed size of all images
|
||||
std::atomic<uint64_t> m_total_compressed_size; // total compressed size of all images
|
||||
| b216a5b0 | David Sorber | |||
| f8e600bc | David Sorber | std::vector<bfs::path> m_file_list; // input file list (either images or compressed images)
|
||
| b216a5b0 | David Sorber | |||
| f8e600bc | David Sorber | std::thread* p_finder_thread; // file finder thread
|
||
std::vector<std::thread*> m_worker_threads; // worker threads
|
||||
| e0b7f8b9 | David Sorber | |||
| 3eeb1485 | David Sorber | std::deque<WorkUnit*> m_work_unit_queue;
|
||
std::mutex m_work_unit_mtx;
|
||||
std::condition_variable m_work_unit_cv;
|
||||
| e0b7f8b9 | David Sorber | bool m_filter_empty; // is the filter regex empty
|
||
boost::regex& m_filter_regex; // filter regular expression
|
||||
| b216a5b0 | David Sorber | };
|
||
#endif // PHOTOCOMPRESSARCHIVER_H
|