Antares Simulator
Power System Simulator
fswalker.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #ifndef __ANTARES_FS_WALKER_FS_WALKER_H__
22 #define __ANTARES_FS_WALKER_FS_WALKER_H__
23 
24 #include <memory>
25 
26 #include <yuni/yuni.h>
27 #include <yuni/core/bind.h>
28 #include <yuni/core/noncopyable.h>
29 #include <yuni/core/string.h>
30 #include <yuni/thread/thread.h>
31 
32 #include "job.h"
33 #include "statistics.h"
34 
35 namespace FSWalker
36 {
37 enum Flow
38 {
39  flContinue,
40  flAbort,
41  flSkip
42 };
43 
45 using OnDirectoryEvent = Flow (*)(const YString& path, bool empty, void* user);
47 using OnFileEvent = void (*)(const YString& filename,
48  const YString& parent,
49  int64_t modified,
50  uint64_t size,
51  void* user);
53 using DispatchJobEvent = std::function<void(IJob::Ptr job)>;
54 
56 {
57 public:
59  using Ptr = std::shared_ptr<IExtension>;
61  using Vector = std::vector<Ptr>;
62 
63 public:
68  {
69  }
70 
74  virtual ~IExtension()
75  {
76  }
77 
81  virtual const char* caption() const = 0;
82 
86  virtual int priority() const
87  {
88  return 0;
89  }
90 
94  virtual OnDirectoryEvent directoryEvent()
95  {
96  return nullptr;
97  }
98 
102  virtual OnFileEvent fileEvent()
103  {
104  return nullptr;
105  }
106 
110  virtual void* userdataCreate(DispatchJobEvent&)
111  {
112  return nullptr;
113  }
114 
118  virtual void userdataDestroy(void* /*userdata*/)
119  {
120  }
121 
122 }; // class IExtension
123 
127 class Walker final: public Yuni::NonCopyable<Walker>
128 {
129 public:
130  Walker();
131  explicit Walker(const AnyString& logprefix);
132  ~Walker();
133 
134  void add(IExtension::Ptr extension);
135 
136  void directory(const AnyString& path);
137 
138  YString directory() const;
139 
140  void run();
141 
145  void retrieveStatistics(Statistics& out);
146 
147 private:
149  YString pDirectory;
151  Statistics pStats;
153  IExtension::Vector pExtensions;
155  YString pLogPrefix;
156 
157 }; // class Walker
158 
159 } // namespace FSWalker
160 
161 #endif // __ANTARES_FS_WALKER_FS_WALKER_H__
Definition: fswalker.h:56
virtual void * userdataCreate(DispatchJobEvent &)
Get the user data.
Definition: fswalker.h:110
IExtension()
Default constructor.
Definition: fswalker.h:67
virtual OnDirectoryEvent directoryEvent()
Provide a reentrant event for handling directories.
Definition: fswalker.h:94
virtual OnFileEvent fileEvent()
Provide a reentrant event for handling files.
Definition: fswalker.h:102
virtual ~IExtension()
Destructor.
Definition: fswalker.h:74
std::vector< Ptr > Vector
List.
Definition: fswalker.h:61
virtual void userdataDestroy(void *)
Destroy user data.
Definition: fswalker.h:118
std::shared_ptr< IExtension > Ptr
Most suitable smart pointer.
Definition: fswalker.h:59
virtual const char * caption() const =0
Human readable caption of the extension.
virtual int priority() const
Recommended priority for the extension.
Definition: fswalker.h:86
Yuni::Job::IJob::Ptr::Promote< IJob >::Ptr Ptr
The most suitable smart pointer for the class.
Definition: job.h:43
Definition: statistics.h:29
Definition: fswalker.h:128
void retrieveStatistics(Statistics &out)
Retrieve statistics for the last run.
Definition: fswalker.cpp:543