Loading...
Searching...
No Matches
FileWatch.hpp
1#pragma once
2#include <score/tools/ThreadPool.hpp>
3
4#include <ossia/detail/flat_map.hpp>
5
6#include <boost/container/small_vector.hpp>
7
8#include <QString>
9
10#include <score_lib_base_export.h>
11
12#include <functional>
13
14namespace score
15{
16using comparable_function = std::shared_ptr<std::function<void()>>;
17class SCORE_LIB_BASE_EXPORT FileWatch : public QObject
18{
19public:
20 FileWatch() noexcept;
21 ~FileWatch();
22
23 static FileWatch& instance();
24
25 void add(QString path, comparable_function cb);
26 void remove(QString path, comparable_function cb);
27 void timerEvent(QTimerEvent* ev);
28
29private:
30 class Worker;
31 Worker* m_worker{};
32 std::mutex m_mtx;
33 struct watch
34 {
35 int64_t mtime{};
36 boost::container::small_vector<comparable_function, 1> functions;
37 };
38
39 using map_type = ossia::flat_map<QString, watch>;
40 map_type m_map;
41 QThread* m_thread{};
42 int m_count = 0;
43 int m_timer = -1;
44};
45}
Definition FileWatch.hpp:18
Base toolkit upon which the software is built.
Definition Application.cpp:90