2014-07-30 19:20:55 +04:00
|
|
|
/**
|
2016-07-26 17:53:11 +03:00
|
|
|
* Copyright (c) 2014 ownCloud GmbH. All rights reserved.
|
2014-07-30 19:20:55 +04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; version 2.1 of the License
|
|
|
|
*
|
|
|
|
* This library 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 Lesser General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PATHCHECKER_H
|
|
|
|
#define PATHCHECKER_H
|
|
|
|
|
|
|
|
#include <string>
|
2014-08-05 21:23:40 +04:00
|
|
|
#include <vector>
|
2014-10-14 18:05:48 +04:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <queue>
|
|
|
|
#include <thread>
|
2017-01-09 18:28:26 +03:00
|
|
|
#include <memory>
|
2014-10-14 18:05:48 +04:00
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
|
|
|
#include <condition_variable>
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-05-18 00:32:42 +03:00
|
|
|
class RemotePathChecker {
|
2014-07-30 19:20:55 +04:00
|
|
|
public:
|
2017-01-05 19:28:28 +03:00
|
|
|
enum FileState {
|
2020-08-18 20:11:08 +03:00
|
|
|
// Order synced with NCOverlay
|
2017-01-05 19:28:28 +03:00
|
|
|
StateError = 0,
|
|
|
|
StateOk, StateOkSWM,
|
|
|
|
StateSync,
|
|
|
|
StateWarning,
|
|
|
|
StateNone
|
|
|
|
};
|
|
|
|
RemotePathChecker();
|
2014-10-14 18:05:48 +04:00
|
|
|
~RemotePathChecker();
|
2017-01-09 18:28:26 +03:00
|
|
|
std::shared_ptr<const std::vector<std::wstring>> WatchedDirectories() const;
|
2017-01-05 19:28:28 +03:00
|
|
|
bool IsMonitoredPath(const wchar_t* filePath, int* state);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
private:
|
2017-01-05 19:28:28 +03:00
|
|
|
FileState _StrToFileState(const std::wstring &str);
|
2014-10-14 18:05:48 +04:00
|
|
|
std::mutex _mutex;
|
|
|
|
std::atomic<bool> _stop;
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2014-10-14 18:05:48 +04:00
|
|
|
// Everything here is protected by the _mutex
|
|
|
|
|
|
|
|
/** The list of paths we need to query. The main thread fill this, and the worker thread
|
|
|
|
* send that to the socket. */
|
|
|
|
std::queue<std::wstring> _pending;
|
|
|
|
|
|
|
|
std::unordered_map<std::wstring, FileState> _cache;
|
2020-08-18 20:11:08 +03:00
|
|
|
// The vector is const since it will be accessed from multiple threads through NCOverlay::IsMemberOf.
|
2017-01-09 18:28:26 +03:00
|
|
|
// Each modification needs to be made onto a copy and then atomically replaced in the shared_ptr.
|
|
|
|
std::shared_ptr<const std::vector<std::wstring>> _watchedDirectories;
|
2014-10-15 17:13:04 +04:00
|
|
|
bool _connected;
|
2014-10-14 18:05:48 +04:00
|
|
|
|
|
|
|
|
|
|
|
// The main thread notifies when there are new items in _pending
|
|
|
|
//std::condition_variable _newQueries;
|
|
|
|
HANDLE _newQueries;
|
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
std::thread _thread;
|
2014-10-14 18:05:48 +04:00
|
|
|
void workerThreadLoop();
|
2014-07-30 19:20:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|