Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
registry.inc.hxx
1/*
2** Copyright 2007-2024, 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_REGISTRY_H__
22#define __ANTARES_FS_WALKER_REGISTRY_H__
23
24#include <vector>
25
26#include <yuni/yuni.h>
27#include <yuni/core/noncopyable.h>
28
29namespace FSWalker
30{
31class EventsRegistry: private Yuni::NonCopyable<EventsRegistry>
32{
33public:
34 using OnDirectoryEventList = std::vector<OnDirectoryEvent>;
35 using OnFileEventList = std::vector<OnFileEvent>;
36 using IndexList = std::vector<uint>;
37 using UserDataList = std::vector<void*>;
38
39public:
41 {
42 }
43
45 void initialize(const IExtension::Vector& exts, DispatchJobEvent& queue);
46 void finalize();
47
48 struct
49 {
50 OnDirectoryEventList enter;
51 IndexList indexes;
52 UserDataList userdata;
53 } directory;
54
55 struct
56 {
57 OnFileEventList access;
58 IndexList indexes;
59 UserDataList userdata;
60 } file;
61
65 UserDataList uniqueUserdata;
66
67}; // class EventsRegistry
68
69inline EventsRegistry::~EventsRegistry()
70{
71 finalize();
72}
73
74void EventsRegistry::finalize()
75{
76 if (extensions.empty())
77 {
78 return;
79 }
80
81 for (uint i = 0; i != extensions.size(); ++i)
82 {
83 void* userdata = uniqueUserdata[i];
84 if (!userdata)
85 {
86 continue;
87 }
88 auto& extension = *(extensions[i]);
89
90 // release ressources
91 extension.userdataDestroy(userdata);
92 uniqueUserdata[i] = nullptr;
93 }
94
95 file.indexes.clear();
96 file.access.clear();
97 file.userdata.clear();
98
99 directory.indexes.clear();
100 directory.enter.clear();
101 directory.userdata.clear();
102
103 extensions.clear();
104}
105
106void EventsRegistry::initialize(const IExtension::Vector& exts, DispatchJobEvent& queue)
107{
108 // release all previously acquired ressources
109 finalize();
110 // Keeping a reference on each extension
111 extensions = exts;
112 uniqueUserdata.resize(extensions.size());
113
114 for (uint i = 0; i != extensions.size(); ++i)
115 {
116 auto& extension = *(extensions[i]);
117
118 // File access
119 auto access = extension.fileEvent();
120 // Directory access
121 auto directoryEnter = extension.directoryEvent();
122
123 if (!access && !directoryEnter)
124 {
125 uniqueUserdata[i] = nullptr;
126 continue;
127 }
128
129 void* userdata = extension.userdataCreate(queue);
130 uniqueUserdata[i] = userdata;
131
132 if (access)
133 {
134 file.indexes.push_back(i);
135 file.access.push_back(access);
136 file.userdata.push_back(userdata);
137 }
138
139 if (directoryEnter)
140 {
141 directory.indexes.push_back(i);
142 directory.enter.push_back(directoryEnter);
143 directory.userdata.push_back(userdata);
144 }
145
146 } // each extension
147}
148
149} // namespace FSWalker
150
151#endif // __ANTARES_FS_WALKER_REGISTRY_H__
Definition registry.inc.hxx:32
IExtension::Vector extensions
Extensions.
Definition registry.inc.hxx:63
UserDataList uniqueUserdata
Unique user data per extension.
Definition registry.inc.hxx:65
std::vector< Ptr > Vector
List.
Definition fswalker.h:61