2014-07-30 19:20:55 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 ownCloud, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
|
|
|
#include <condition_variable>
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class __declspec(dllexport) RemotePathChecker {
|
|
|
|
public:
|
|
|
|
enum FileState {
|
|
|
|
// Order synced with OCOverlay
|
|
|
|
StateError = 0, StateErrorSWM,
|
|
|
|
StateOk, StateOkSWM,
|
|
|
|
StateSync, StateSyncSWM,
|
|
|
|
StateWarning, StateWarningSWM,
|
|
|
|
StateNone
|
|
|
|
};
|
2014-10-14 18:05:48 +04:00
|
|
|
RemotePathChecker();
|
|
|
|
~RemotePathChecker();
|
2014-08-05 21:23:40 +04:00
|
|
|
std::vector<std::wstring> WatchedDirectories();
|
2014-08-04 17:40:08 +04:00
|
|
|
bool IsMonitoredPath(const wchar_t* filePath, int* state);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
private:
|
2014-10-14 18:05:48 +04:00
|
|
|
FileState _StrToFileState(const std::wstring &str);
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
2014-10-15 17:57:15 +04:00
|
|
|
std::thread _thread;
|
2014-10-14 18:05:48 +04:00
|
|
|
void workerThreadLoop();
|
2014-07-30 19:20:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|