RemotePathChecker.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright (c) 2014 ownCloud GmbH. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; version 2.1 of the License
  7. *
  8. * This library is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  11. * details.
  12. */
  13. #ifndef PATHCHECKER_H
  14. #define PATHCHECKER_H
  15. #include <string>
  16. #include <vector>
  17. #include <unordered_map>
  18. #include <queue>
  19. #include <thread>
  20. #include <mutex>
  21. #include <atomic>
  22. #include <condition_variable>
  23. #pragma once
  24. class __declspec(dllexport) RemotePathChecker {
  25. public:
  26. enum FileState {
  27. // Order synced with OCOverlay
  28. StateError = 0,
  29. StateOk, StateOkSWM,
  30. StateSync,
  31. StateWarning,
  32. StateNone
  33. };
  34. RemotePathChecker();
  35. ~RemotePathChecker();
  36. std::vector<std::wstring> WatchedDirectories();
  37. bool IsMonitoredPath(const wchar_t* filePath, int* state);
  38. private:
  39. FileState _StrToFileState(const std::wstring &str);
  40. std::mutex _mutex;
  41. std::atomic<bool> _stop;
  42. // Everything here is protected by the _mutex
  43. /** The list of paths we need to query. The main thread fill this, and the worker thread
  44. * send that to the socket. */
  45. std::queue<std::wstring> _pending;
  46. std::unordered_map<std::wstring, FileState> _cache;
  47. std::unordered_map<std::wstring, FileState> _oldCache;
  48. std::vector<std::wstring> _watchedDirectories;
  49. bool _connected;
  50. // The main thread notifies when there are new items in _pending
  51. //std::condition_variable _newQueries;
  52. HANDLE _newQueries;
  53. std::thread _thread;
  54. void workerThreadLoop();
  55. };
  56. #endif