|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2026 Popa Adrian Marius |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +#ifndef FBCPP_MAINTENANCE_MANAGER_H |
| 26 | +#define FBCPP_MAINTENANCE_MANAGER_H |
| 27 | + |
| 28 | +#include "ServiceManager.h" |
| 29 | +#include <cstdint> |
| 30 | +#include <optional> |
| 31 | +#include <string> |
| 32 | + |
| 33 | + |
| 34 | +/// |
| 35 | +/// fb-cpp namespace. |
| 36 | +/// |
| 37 | +namespace fbcpp |
| 38 | +{ |
| 39 | + /// |
| 40 | + /// Represents options used to run a database maintenance operation through the service manager. |
| 41 | + /// |
| 42 | + class MaintenanceOptions final |
| 43 | + { |
| 44 | + public: |
| 45 | + /// |
| 46 | + /// Returns the database path to be maintained. |
| 47 | + /// |
| 48 | + const std::string& getDatabase() const |
| 49 | + { |
| 50 | + return database; |
| 51 | + } |
| 52 | + |
| 53 | + /// |
| 54 | + /// Sets the database path to be maintained. |
| 55 | + /// |
| 56 | + MaintenanceOptions& setDatabase(const std::string& value) |
| 57 | + { |
| 58 | + database = value; |
| 59 | + return *this; |
| 60 | + } |
| 61 | + |
| 62 | + /// |
| 63 | + /// Returns the verbose output callback. |
| 64 | + /// |
| 65 | + const ServiceManager::VerboseOutput& getVerboseOutput() const |
| 66 | + { |
| 67 | + return verboseOutput; |
| 68 | + } |
| 69 | + |
| 70 | + /// |
| 71 | + /// Sets the verbose output callback. |
| 72 | + /// |
| 73 | + MaintenanceOptions& setVerboseOutput(ServiceManager::VerboseOutput value) |
| 74 | + { |
| 75 | + verboseOutput = std::move(value); |
| 76 | + return *this; |
| 77 | + } |
| 78 | + |
| 79 | + /// |
| 80 | + /// Returns the requested number of parallel workers. |
| 81 | + /// |
| 82 | + const std::optional<std::uint32_t>& getParallelWorkers() const |
| 83 | + { |
| 84 | + return parallelWorkers; |
| 85 | + } |
| 86 | + |
| 87 | + /// |
| 88 | + /// Sets the requested number of parallel workers. |
| 89 | + /// |
| 90 | + MaintenanceOptions& setParallelWorkers(std::uint32_t value) |
| 91 | + { |
| 92 | + parallelWorkers = value; |
| 93 | + return *this; |
| 94 | + } |
| 95 | + |
| 96 | + /// |
| 97 | + /// Returns whether database sweep is enabled. |
| 98 | + /// |
| 99 | + bool getSweep() const |
| 100 | + { |
| 101 | + return sweep; |
| 102 | + } |
| 103 | + |
| 104 | + /// |
| 105 | + /// Sets whether database sweep is enabled. |
| 106 | + /// |
| 107 | + MaintenanceOptions& setSweep(bool value) |
| 108 | + { |
| 109 | + sweep = value; |
| 110 | + return *this; |
| 111 | + } |
| 112 | + |
| 113 | + /// |
| 114 | + /// Returns whether database validation is enabled. |
| 115 | + /// |
| 116 | + bool getValidate() const |
| 117 | + { |
| 118 | + return validate; |
| 119 | + } |
| 120 | + |
| 121 | + /// |
| 122 | + /// Sets whether database validation is enabled. |
| 123 | + /// |
| 124 | + MaintenanceOptions& setValidate(bool value) |
| 125 | + { |
| 126 | + validate = value; |
| 127 | + return *this; |
| 128 | + } |
| 129 | + |
| 130 | + /// |
| 131 | + /// Returns whether database mending is enabled. |
| 132 | + /// |
| 133 | + bool getMend() const |
| 134 | + { |
| 135 | + return mend; |
| 136 | + } |
| 137 | + |
| 138 | + /// |
| 139 | + /// Sets whether database mending is enabled. |
| 140 | + /// |
| 141 | + MaintenanceOptions& setMend(bool value) |
| 142 | + { |
| 143 | + mend = value; |
| 144 | + return *this; |
| 145 | + } |
| 146 | + |
| 147 | + /// |
| 148 | + /// Returns whether checksum verification is ignored. |
| 149 | + /// |
| 150 | + bool getIgnoreChecksum() const |
| 151 | + { |
| 152 | + return ignoreChecksum; |
| 153 | + } |
| 154 | + |
| 155 | + /// |
| 156 | + /// Sets whether checksum verification is ignored. |
| 157 | + /// |
| 158 | + MaintenanceOptions& setIgnoreChecksum(bool value) |
| 159 | + { |
| 160 | + ignoreChecksum = value; |
| 161 | + return *this; |
| 162 | + } |
| 163 | + |
| 164 | + /// |
| 165 | + /// Returns whether killing database shadows is enabled. |
| 166 | + /// |
| 167 | + bool getKillShadows() const |
| 168 | + { |
| 169 | + return killShadows; |
| 170 | + } |
| 171 | + |
| 172 | + /// |
| 173 | + /// Sets whether killing database shadows is enabled. |
| 174 | + /// |
| 175 | + MaintenanceOptions& setKillShadows(bool value) |
| 176 | + { |
| 177 | + killShadows = value; |
| 178 | + return *this; |
| 179 | + } |
| 180 | + |
| 181 | + /// |
| 182 | + /// Returns whether full validation is enabled. |
| 183 | + /// |
| 184 | + bool getFull() const |
| 185 | + { |
| 186 | + return full; |
| 187 | + } |
| 188 | + |
| 189 | + /// |
| 190 | + /// Sets whether full validation is enabled. |
| 191 | + /// |
| 192 | + MaintenanceOptions& setFull(bool value) |
| 193 | + { |
| 194 | + full = value; |
| 195 | + return *this; |
| 196 | + } |
| 197 | + |
| 198 | + /// |
| 199 | + /// Returns whether checking only metadata/structure is enabled. |
| 200 | + /// |
| 201 | + bool getCheckDb() const |
| 202 | + { |
| 203 | + return checkDb; |
| 204 | + } |
| 205 | + |
| 206 | + /// |
| 207 | + /// Sets whether checking only metadata/structure is enabled. |
| 208 | + /// |
| 209 | + MaintenanceOptions& setCheckDb(bool value) |
| 210 | + { |
| 211 | + checkDb = value; |
| 212 | + return *this; |
| 213 | + } |
| 214 | + |
| 215 | + /// |
| 216 | + /// Returns whether recreating ICU indexes is enabled. |
| 217 | + /// |
| 218 | + bool getIcu() const |
| 219 | + { |
| 220 | + return icu; |
| 221 | + } |
| 222 | + |
| 223 | + /// |
| 224 | + /// Sets whether recreating ICU indexes is enabled. |
| 225 | + /// |
| 226 | + MaintenanceOptions& setIcu(bool value) |
| 227 | + { |
| 228 | + icu = value; |
| 229 | + return *this; |
| 230 | + } |
| 231 | + |
| 232 | + /// |
| 233 | + /// Returns whether database upgrade is enabled. |
| 234 | + /// |
| 235 | + bool getUpgradeDb() const |
| 236 | + { |
| 237 | + return upgradeDb; |
| 238 | + } |
| 239 | + |
| 240 | + /// |
| 241 | + /// Sets whether database upgrade is enabled. |
| 242 | + /// |
| 243 | + MaintenanceOptions& setUpgradeDb(bool value) |
| 244 | + { |
| 245 | + upgradeDb = value; |
| 246 | + return *this; |
| 247 | + } |
| 248 | + |
| 249 | + private: |
| 250 | + std::string database; |
| 251 | + ServiceManager::VerboseOutput verboseOutput; |
| 252 | + std::optional<std::uint32_t> parallelWorkers; |
| 253 | + bool sweep = false; |
| 254 | + bool validate = false; |
| 255 | + bool mend = false; |
| 256 | + bool ignoreChecksum = false; |
| 257 | + bool killShadows = false; |
| 258 | + bool full = false; |
| 259 | + bool checkDb = false; |
| 260 | + bool icu = false; |
| 261 | + bool upgradeDb = false; |
| 262 | + }; |
| 263 | + |
| 264 | + /// |
| 265 | + /// Executes maintenance and repair operations through the Firebird service manager. |
| 266 | + /// |
| 267 | + class MaintenanceManager final : public ServiceManager |
| 268 | + { |
| 269 | + public: |
| 270 | + using ServiceManager::ServiceManager; |
| 271 | + |
| 272 | + public: |
| 273 | + /// |
| 274 | + /// Runs a maintenance or repair operation using the provided options. |
| 275 | + /// |
| 276 | + void execute(const MaintenanceOptions& options); |
| 277 | + }; |
| 278 | +} // namespace fbcpp |
| 279 | + |
| 280 | + |
| 281 | +#endif // FBCPP_MAINTENANCE_MANAGER_H |
0 commit comments