LCOV - code coverage report
Current view: top level - source/lib/sysdep - dir_watch.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 6 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2022 Wildfire Games.
       2             :  *
       3             :  * Permission is hereby granted, free of charge, to any person obtaining
       4             :  * a copy of this software and associated documentation files (the
       5             :  * "Software"), to deal in the Software without restriction, including
       6             :  * without limitation the rights to use, copy, modify, merge, publish,
       7             :  * distribute, sublicense, and/or sell copies of the Software, and to
       8             :  * permit persons to whom the Software is furnished to do so, subject to
       9             :  * the following conditions:
      10             :  *
      11             :  * The above copyright notice and this permission notice shall be included
      12             :  * in all copies or substantial portions of the Software.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      15             :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      16             :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      17             :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      18             :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      19             :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      20             :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      21             :  */
      22             : 
      23             : /*
      24             :  * portable directory change notification API.
      25             :  */
      26             : 
      27             : #ifndef INCLUDED_DIR_WATCH
      28             : #define INCLUDED_DIR_WATCH
      29             : 
      30             : #include "lib/os_path.h"
      31             : 
      32             : #include <vector>
      33             : #include <memory>
      34             : 
      35             : struct DirWatch;
      36             : typedef std::shared_ptr<DirWatch> PDirWatch;
      37             : 
      38             : /**
      39             :  * start watching a single directory for changes.
      40             :  *
      41             :  * @param path (must end in slash)
      42             :  * @param dirWatch opaque smart pointer to the watch state; used to
      43             :  * manage its lifetime (this is deemed more convenient than a
      44             :  * separate dir_watch_Remove interface).
      45             :  *
      46             :  * clients typically want to watch entire directory subtrees (e.g. a mod),
      47             :  * which is supported by Windows but not FAM. to reduce overhead, the
      48             :  * Windows backend always watches subtrees, but portable clients should
      49             :  * still add a watch for each subdirectory (the shared watch state is
      50             :  * reference-counted).
      51             :  * rationale: since the VFS has per-directory data structures, it is
      52             :  * convenient to store PDirWatch there instead of creating a second
      53             :  * tree structure here.
      54             :  **/
      55             : Status dir_watch_Add(const OsPath& path, PDirWatch& dirWatch);
      56             : 
      57           0 : class DirWatchNotification
      58             : {
      59             : public:
      60             :     enum EType
      61             :     {
      62             :         Created,
      63             :         Deleted,
      64             :         Changed
      65             :     };
      66             : 
      67           0 :     DirWatchNotification(const OsPath& pathname, EType type)
      68           0 :         : pathname(pathname), type(type)
      69             :     {
      70           0 :     }
      71             : 
      72           0 :     const OsPath& Pathname() const
      73             :     {
      74           0 :         return pathname;
      75             :     }
      76             : 
      77             :     EType Type() const
      78             :     {
      79             :         return type;
      80             :     }
      81             : 
      82             : private:
      83             :     OsPath pathname;
      84             :     EType type;
      85             : };
      86             : 
      87             : typedef std::vector<DirWatchNotification> DirWatchNotifications;
      88             : 
      89             : /**
      90             :  * return all pending directory watch notifications.
      91             :  *
      92             :  * @param notifications receives any pending notifications in unspecified order.
      93             :  * @return Status (INFO::OK doesn't imply notifications were returned)
      94             :  *
      95             :  * note: the run time of this function is independent of the number of
      96             :  * directory watches and number of files.
      97             :  *
      98             :  * rationale for a polling interface: users (e.g. the main game loop)
      99             :  * typically want to receive change notifications at a single point,
     100             :  * rather than deal with the complexity of asynchronous notifications.
     101             :  **/
     102             : Status dir_watch_Poll(DirWatchNotifications& notifications);
     103             : 
     104             : #endif  // #ifndef INCLUDED_DIR_WATCH

Generated by: LCOV version 1.13