23 using namespace folly;
27 MultiFilePoller::MultiFilePoller(std::chrono::milliseconds pollInterval)
28 : poller_(pollInterval) {}
40 throw std::runtime_error(
"Run out of callback ID.");
50 const std::vector<std::string>& paths,
52 VLOG(4) <<
"registerFiles({" <<
join(
", ", paths) <<
"}, cb=" << &cb <<
")";
54 throw std::invalid_argument(
"Argument paths must be non-empty.");
60 for (
const auto& path : paths) {
64 cbPaths.push_back(key);
73 std::vector<std::string> pathsToErase;
78 throw std::out_of_range(
79 to<std::string>(
"Callback ", cbId.
id_,
" not found"));
83 for (
const auto& path : pos->second.files_) {
86 std::remove(callbackIds.begin(), callbackIds.end(), cbId.
id_));
88 if (callbackIds.empty()) {
90 pathsToErase.emplace_back(path);
96 for (
const auto& path : pathsToErase) {
102 VLOG(4) <<
"onFileUpdated(" << triggeredPath <<
").";
106 std::unordered_map<std::string, std::string> filePathsToFileContents;
114 for (
const auto& cbId : callbacks->second) {
117 for (
const auto& path : cbEnt->second.files_) {
118 if (filePathsToFileContents.find(path) == filePathsToFileContents.end()) {
121 filePathsToFileContents.emplace(path,
std::move(data));
123 VLOG(4) <<
"Failed to read file " << path.get();
127 cbEnt->second.cb_(filePathsToFileContents);
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
std::unordered_map< std::string, std::vector< size_t > > pathsToCallbackIds_
constexpr detail::Map< Move > move
void onFileUpdated(const std::string &triggeredPath)
—— Concurrent Priority Queue Implementation ——
void addFileToTrack(const std::string &fileName, Cob yCob, Cob nCob=nullptr, Condition condition=fileTouchedCondInternal)
std::vector< std::reference_wrapper< const std::string >> StringReferences
size_t getNextCallbackId()
wangle::FilePoller poller_
void removeFileToTrack(const std::string &fileName)
std::unordered_map< size_t, CallbackDetail > idsToCallbacks_
void cancelCallback(const CallbackId &cbId)
folly::SharedMutex rwlock_
CallbackId registerFile(std::string path, Callback cb)
static constexpr uint64_t data[1]
CallbackId registerFiles(const std::vector< std::string > &paths, Callback cb)