| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <map> |
| 24 |
#include <mutex> |
| 25 |
#include <sstream> |
| 26 |
#include <string> |
| 27 |
#include <iomanip> |
| 28 |
#include <vector> |
| 29 |
|
| 30 |
#include "Config.h" |
| 31 |
#include "ControlInterface.h" |
| 32 |
#include "DataModel/AccessoryConfig.h" |
| 33 |
#include "DataModel/DataModel.h" |
| 34 |
#include "DataModel/FeedbackConfig.h" |
| 35 |
#include "DataModel/LocoConfig.h" |
| 36 |
#include "DataModel/ObjectIdentifier.h" |
| 37 |
#include "Hardware/HardwareParams.h" |
| 38 |
#include "Hardware/LocoCache.h" |
| 39 |
#include "Logger/Logger.h" |
| 40 |
#include "Storage/StorageHandler.h" |
| 41 |
|
| 42 |
class Manager |
| 43 |
{ |
| 44 |
public: |
| 45 |
Manager() = delete; |
| 46 |
Manager(const Manager&) = delete; |
| 47 |
Manager& operator=(const Manager&) = delete; |
| 48 |
|
| 49 |
Manager(Config& config); |
| 50 |
~Manager(); |
| 51 |
|
| 52 |
|
| 53 |
inline BoosterState Booster() const |
| 54 |
{ |
| 55 |
return boosterState; |
| 56 |
} |
| 57 |
|
| 58 |
void Booster(const ControlType controlType, const BoosterState status); |
| 59 |
|
| 60 |
|
| 61 |
bool ControlSave(ControlID controlID, |
| 62 |
const HardwareType& hardwareType, |
| 63 |
const std::string& name, |
| 64 |
const std::string& arg1, |
| 65 |
const std::string& arg2, |
| 66 |
const std::string& arg3, |
| 67 |
const std::string& arg4, |
| 68 |
const std::string& arg5, |
| 69 |
std::string& result); |
| 70 |
|
| 71 |
bool ControlDelete(ControlID controlID); |
| 72 |
Hardware::HardwareParams* GetHardware(const ControlID controlID); |
| 73 |
unsigned int ControlsOfHardwareType(const HardwareType hardwareType); |
| 74 |
|
| 75 |
|
| 76 |
const std::string GetControlName(const ControlID controlID); |
| 77 |
|
| 78 |
const std::map<std::string,Hardware::HardwareParams*> ControlListByName() const; |
| 79 |
|
| 80 |
const std::map<ControlID,std::string> ControlListNames(const Hardware::Capabilities capability) const; |
| 81 |
|
| 82 |
inline const std::map<std::string,Protocol> LocoProtocolsOfControl(const ControlID controlID) const |
| 83 |
{ |
| 84 |
return ProtocolsOfControl(AddressTypeLoco, controlID); |
| 85 |
} |
| 86 |
|
| 87 |
inline const std::map<std::string,Protocol> AccessoryProtocolsOfControl(const ControlID controlID) const |
| 88 |
{ |
| 89 |
return ProtocolsOfControl(AddressTypeAccessory, controlID); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
std::string GetLocoList() const; |
| 94 |
|
| 95 |
DataModel::Loco* GetLoco(const LocoID locoID) const; |
| 96 |
|
| 97 |
DataModel::LocoConfig GetLocoOfConfigByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 98 |
|
| 99 |
DataModel::Loco* GetLocoByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 100 |
|
| 101 |
void LocoRemoveMatchKey(const LocoID locoId); |
| 102 |
|
| 103 |
void LocoReplaceMatchKey(const LocoID locoId, const std::string& newMatchKey); |
| 104 |
|
| 105 |
const std::map<std::string,DataModel::LocoConfig> GetUnmatchedLocosOfControl(const ControlID controlId, |
| 106 |
const std::string& matchKey) const; |
| 107 |
|
| 108 |
const std::map<std::string,LocoID> LocoBaseListFree() const; |
| 109 |
|
| 110 |
const std::map<std::string,DataModel::LocoConfig> LocoConfigByName() const; |
| 111 |
|
| 112 |
const std::map<std::string,LocoID> LocoIdsByName() const; |
| 113 |
|
| 114 |
inline void LocoSave(const DataModel::Loco* loco) const |
| 115 |
{ |
| 116 |
if (!storage) |
| 117 |
{ |
| 118 |
return; |
| 119 |
} |
| 120 |
Storage::TransactionGuard guard(storage); |
| 121 |
storage->Save(*loco); |
| 122 |
} |
| 123 |
|
| 124 |
bool LocoSave(LocoID locoID, |
| 125 |
const std::string& name, |
| 126 |
const ControlID controlID, |
| 127 |
const std::string& matchKey, |
| 128 |
const Protocol protocol, |
| 129 |
const Address address, |
| 130 |
const Address serverAddress, |
| 131 |
const Length length, |
| 132 |
const bool pushpull, |
| 133 |
const Speed maxSpeed, |
| 134 |
const Speed travelSpeed, |
| 135 |
const Speed reducedSpeed, |
| 136 |
const Speed creepingSpeed, |
| 137 |
const Propulsion propulsion, |
| 138 |
const TrainType type, |
| 139 |
const std::vector<DataModel::LocoFunctionEntry>& locoFunctions, |
| 140 |
std::string& result); |
| 141 |
|
| 142 |
bool LocoDelete(const LocoID locoID, |
| 143 |
std::string& result); |
| 144 |
|
| 145 |
inline bool LocoDelete(const LocoID locoId) |
| 146 |
{ |
| 147 |
std::string result; |
| 148 |
return LocoDelete(locoId, result); |
| 149 |
} |
| 150 |
|
| 151 |
bool LocoProtocolAddress(const LocoID locoID, ControlID& controlID, Protocol& protocol, Address& address) const; |
| 152 |
|
| 153 |
inline void LocoSpeed(const ControlType controlType, |
| 154 |
const ControlID controlID, |
| 155 |
const Protocol protocol, |
| 156 |
const Address address, |
| 157 |
const Speed speed) |
| 158 |
{ |
| 159 |
|
| 160 |
LocoBaseSpeed(controlType, GetLoco(controlID, protocol, address), speed); |
| 161 |
} |
| 162 |
|
| 163 |
inline bool LocoBaseSpeed(const ControlType controlType, |
| 164 |
const DataModel::ObjectIdentifier& locoBaseIdentifier, |
| 165 |
const Speed speed) |
| 166 |
{ |
| 167 |
|
| 168 |
return LocoBaseSpeed(controlType, GetLocoBase(locoBaseIdentifier), speed); |
| 169 |
} |
| 170 |
|
| 171 |
bool LocoBaseSpeed(const ControlType controlType, |
| 172 |
DataModel::LocoBase* loco, |
| 173 |
const Speed speed); |
| 174 |
|
| 175 |
Speed LocoSpeed(const LocoID locoID) const; |
| 176 |
|
| 177 |
inline void LocoOrientation(const ControlType controlType, |
| 178 |
const ControlID controlID, |
| 179 |
const Protocol protocol, |
| 180 |
const Address address, |
| 181 |
const Orientation orientation) |
| 182 |
{ |
| 183 |
|
| 184 |
LocoBaseOrientation(controlType, GetLoco(controlID, protocol, address), orientation); |
| 185 |
} |
| 186 |
|
| 187 |
inline void LocoBaseOrientation(const ControlType controlType, |
| 188 |
const DataModel::ObjectIdentifier& locoBaseIdentifier, |
| 189 |
const Orientation orientation) |
| 190 |
{ |
| 191 |
|
| 192 |
LocoBaseOrientation(controlType, GetLocoBase(locoBaseIdentifier), orientation); |
| 193 |
} |
| 194 |
|
| 195 |
void LocoBaseOrientation(const ControlType controlType, |
| 196 |
DataModel::LocoBase* loco, |
| 197 |
Orientation orientation); |
| 198 |
|
| 199 |
void LocoFunctionState(const ControlType controlType, |
| 200 |
const ControlID controlID, |
| 201 |
const Protocol protocol, |
| 202 |
const Address address, |
| 203 |
const DataModel::LocoFunctionNr function, |
| 204 |
const DataModel::LocoFunctionState on) |
| 205 |
{ |
| 206 |
|
| 207 |
LocoBaseFunctionState(controlType, GetLoco(controlID, protocol, address), function, on); |
| 208 |
} |
| 209 |
|
| 210 |
void LocoBaseFunctionState(const ControlType controlType, |
| 211 |
const DataModel::ObjectIdentifier& locoBaseIdentifier, |
| 212 |
const DataModel::LocoFunctionNr function, |
| 213 |
const DataModel::LocoFunctionState on); |
| 214 |
|
| 215 |
void LocoBaseFunctionState(const ControlType controlType, |
| 216 |
DataModel::LocoBase* loco, |
| 217 |
const DataModel::LocoFunctionNr function, |
| 218 |
const DataModel::LocoFunctionState on); |
| 219 |
|
| 220 |
|
| 221 |
DataModel::MultipleUnit* GetMultipleUnit(const MultipleUnitID multipleUnitId) const; |
| 222 |
|
| 223 |
DataModel::LocoConfig GetMultipleUnitOfConfigByMatchKey(const ControlID controlId, |
| 224 |
const std::string& matchKey) const; |
| 225 |
|
| 226 |
const std::map<std::string,DataModel::LocoConfig> MultipleUnitConfigByName() const; |
| 227 |
|
| 228 |
inline void MultipleUnitSave(const DataModel::MultipleUnit* multipleUnit) const |
| 229 |
{ |
| 230 |
if (!storage) |
| 231 |
{ |
| 232 |
return; |
| 233 |
} |
| 234 |
Storage::TransactionGuard guard(storage); |
| 235 |
storage->Save(*multipleUnit); |
| 236 |
} |
| 237 |
|
| 238 |
bool MultipleUnitSave(MultipleUnitID multipleUnitID, |
| 239 |
const std::string& name, |
| 240 |
const ControlID controlID, |
| 241 |
const std::string& matchKey, |
| 242 |
const Address address, |
| 243 |
const Address serverAddress, |
| 244 |
const Length length, |
| 245 |
const bool pushpull, |
| 246 |
const Speed maxSpeed, |
| 247 |
const Speed travelSpeed, |
| 248 |
const Speed reducedSpeed, |
| 249 |
const Speed creepingSpeed, |
| 250 |
const TrainType type, |
| 251 |
const std::vector<DataModel::LocoFunctionEntry>& locoFunctions, |
| 252 |
const std::vector<DataModel::Relation*>& slaves, |
| 253 |
std::string& result); |
| 254 |
|
| 255 |
bool MultipleUnitDelete(const MultipleUnitID multipleUnitID, |
| 256 |
std::string& result); |
| 257 |
|
| 258 |
inline bool MultipleUnitDelete(const MultipleUnitID multipleUnitId) |
| 259 |
{ |
| 260 |
std::string result; |
| 261 |
return MultipleUnitDelete(multipleUnitId, result); |
| 262 |
} |
| 263 |
|
| 264 |
bool MultipleUnitRelease(const MultipleUnitID multipleUnitID); |
| 265 |
|
| 266 |
|
| 267 |
inline DataModel::LocoBase* GetLocoBase(const DataModel::ObjectIdentifier& locoBaseIdentifier) const |
| 268 |
{ |
| 269 |
return locoBaseIdentifier.GetObjectType() == ObjectTypeLoco |
| 270 |
? static_cast<DataModel::LocoBase*>(GetLoco(locoBaseIdentifier.GetObjectID())) |
| 271 |
: static_cast<DataModel::LocoBase*>(GetMultipleUnit(locoBaseIdentifier.GetObjectID())); |
| 272 |
} |
| 273 |
|
| 274 |
const std::map<std::string,LocoID> LocoBaseIdsByName() const; |
| 275 |
|
| 276 |
const std::string& GetLocoBaseName(const DataModel::ObjectIdentifier& locoBaseIdentifier) const; |
| 277 |
|
| 278 |
|
| 279 |
inline DataModel::AccessoryBase* GetAccessoryBase(const DataModel::ObjectIdentifier& accessoryBaseIdentifier) const |
| 280 |
{ |
| 281 |
switch (accessoryBaseIdentifier.GetObjectType()) |
| 282 |
{ |
| 283 |
case ObjectTypeAccessory: |
| 284 |
return static_cast<DataModel::AccessoryBase*>(GetAccessory(accessoryBaseIdentifier.GetObjectID())); |
| 285 |
|
| 286 |
case ObjectTypeSwitch: |
| 287 |
return static_cast<DataModel::AccessoryBase*>(GetSwitch(accessoryBaseIdentifier.GetObjectID())); |
| 288 |
|
| 289 |
case ObjectTypeSignal: |
| 290 |
return static_cast<DataModel::AccessoryBase*>(GetSignal(accessoryBaseIdentifier.GetObjectID())); |
| 291 |
|
| 292 |
default: |
| 293 |
return nullptr; |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
void AccessoryBaseState(const ControlType controlType, |
| 298 |
const ControlID controlID, |
| 299 |
const Protocol protocol, |
| 300 |
const Address address, |
| 301 |
const DataModel::AccessoryState state); |
| 302 |
|
| 303 |
void AccessoryBaseState(const ControlType controlType, |
| 304 |
const DataModel::ObjectIdentifier& identifier, |
| 305 |
const DataModel::AccessoryState state); |
| 306 |
|
| 307 |
|
| 308 |
bool AccessoryState(const ControlType controlType, const AccessoryID accessoryID, const DataModel::AccessoryState state, const bool force = false); |
| 309 |
void AccessoryState(const ControlType controlType, const AccessoryID accessoryID, const DataModel::AccessoryState state, const bool inverted, const bool on); |
| 310 |
DataModel::Accessory* GetAccessory(const AccessoryID accessoryID) const; |
| 311 |
|
| 312 |
const std::map<std::string,DataModel::AccessoryConfig> GetUnmatchedAccessoriesOfControl(const ControlID controlId, |
| 313 |
const std::string& matchKey) const; |
| 314 |
|
| 315 |
const std::string& GetAccessoryName(const AccessoryID accessoryID) const; |
| 316 |
|
| 317 |
inline const std::map<AccessoryID,DataModel::Accessory*>& AccessoryList() const |
| 318 |
{ |
| 319 |
return accessories; |
| 320 |
} |
| 321 |
|
| 322 |
const std::map<std::string,DataModel::AccessoryConfig> AccessoryConfigByName() const; |
| 323 |
|
| 324 |
bool AccessorySave(AccessoryID accessoryID, |
| 325 |
const std::string& name, |
| 326 |
const DataModel::LayoutItem::LayoutPosition x, |
| 327 |
const DataModel::LayoutItem::LayoutPosition y, |
| 328 |
const DataModel::LayoutItem::LayoutPosition z, |
| 329 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 330 |
const ControlID controlID, |
| 331 |
const std::string& matchKey, |
| 332 |
const Protocol protocol, |
| 333 |
const Address address, |
| 334 |
const AddressPort port, |
| 335 |
const Address serverAddress, |
| 336 |
const DataModel::AccessoryType type, |
| 337 |
const DataModel::AccessoryPulseDuration duration, |
| 338 |
const bool inverted, |
| 339 |
std::string& result); |
| 340 |
|
| 341 |
bool AccessoryDelete(const AccessoryID accessoryID, |
| 342 |
std::string& result); |
| 343 |
|
| 344 |
bool AccessoryRelease(const AccessoryID accessoryID); |
| 345 |
|
| 346 |
DataModel::AccessoryConfig GetAccessoryOfConfigByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 347 |
|
| 348 |
DataModel::Accessory* GetAccessoryByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 349 |
|
| 350 |
void AccessoryRemoveMatchKey(const AccessoryID accessoryId); |
| 351 |
|
| 352 |
|
| 353 |
void FeedbackState(const ControlID controlID, const FeedbackPin pin, const DataModel::Feedback::FeedbackState state); |
| 354 |
void FeedbackState(const FeedbackID feedbackID, const DataModel::Feedback::FeedbackState state); |
| 355 |
void FeedbackPublishState(const DataModel::Feedback* feedback); |
| 356 |
DataModel::Feedback* GetFeedback(const FeedbackID feedbackID) const; |
| 357 |
DataModel::Feedback* GetFeedbackUnlocked(const FeedbackID feedbackID) const; |
| 358 |
const std::string& GetFeedbackName(const FeedbackID feedbackID) const; |
| 359 |
|
| 360 |
inline const std::map<FeedbackID,DataModel::Feedback*>& FeedbackList() const |
| 361 |
{ |
| 362 |
return feedbacks; |
| 363 |
} |
| 364 |
|
| 365 |
const std::map<std::string,DataModel::Feedback*> FeedbackListByName() const; |
| 366 |
const std::map<RouteID,std::string> RoutesOfTrack(const TrackID trackID) const; |
| 367 |
const std::map<std::string,FeedbackID> FeedbacksOfTrack(const TrackID trackID) const; |
| 368 |
|
| 369 |
const std::map<std::string,DataModel::FeedbackConfig> FeedbackConfigByName() const; |
| 370 |
|
| 371 |
bool FeedbackSave(FeedbackID feedbackID, |
| 372 |
const std::string& name, |
| 373 |
const DataModel::LayoutItem::Visible visible, |
| 374 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 375 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 376 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 377 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 378 |
const ControlID controlID, |
| 379 |
const std::string& matchKey, |
| 380 |
const FeedbackPin pin, |
| 381 |
const bool inverted, |
| 382 |
const DataModel::FeedbackType feedbackType, |
| 383 |
const RouteID routeId, |
| 384 |
std::string& result); |
| 385 |
|
| 386 |
bool FeedbackDelete(const FeedbackID feedbackID, |
| 387 |
std::string& result); |
| 388 |
|
| 389 |
inline bool FeedbackExists(const FeedbackID feedbackID) const |
| 390 |
{ |
| 391 |
return feedbacks.count(feedbackID) == 1; |
| 392 |
} |
| 393 |
|
| 394 |
DataModel::FeedbackConfig GetFeedbackOfConfigByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 395 |
|
| 396 |
DataModel::Feedback* GetFeedbackByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 397 |
|
| 398 |
void FeedbackRemoveMatchKey(const FeedbackID feedbackId); |
| 399 |
|
| 400 |
void FeedbackReplaceMatchKey(const FeedbackID feedbackId, const std::string& newMatchKey); |
| 401 |
|
| 402 |
const std::map<std::string,DataModel::FeedbackConfig> GetUnmatchedFeedbacksOfControl(const ControlID controlId, |
| 403 |
const std::string& matchKey) const; |
| 404 |
|
| 405 |
|
| 406 |
DataModel::Track* GetTrack(const TrackID trackID) const; |
| 407 |
const std::string& GetTrackName(const TrackID trackID) const; |
| 408 |
|
| 409 |
inline const std::map<TrackID,DataModel::Track*>& TrackList() const |
| 410 |
{ |
| 411 |
return tracks; |
| 412 |
} |
| 413 |
|
| 414 |
const std::map<std::string,DataModel::Track*> TrackListByName() const; |
| 415 |
|
| 416 |
const std::map<std::string,DataModel::Track*> TrackListMasterByName() const; |
| 417 |
|
| 418 |
const std::map<std::string,TrackID> TrackListIdByName(const TrackID excludeTrackID = TrackNone) const; |
| 419 |
|
| 420 |
inline void TrackSave(const DataModel::Track* track) const |
| 421 |
{ |
| 422 |
if (!storage) |
| 423 |
{ |
| 424 |
return; |
| 425 |
} |
| 426 |
Storage::TransactionGuard guard(storage); |
| 427 |
storage->Save(*track); |
| 428 |
} |
| 429 |
|
| 430 |
bool TrackSave(const TrackID trackID, |
| 431 |
const std::string& name, |
| 432 |
const bool showName, |
| 433 |
const std::string& displayName, |
| 434 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 435 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 436 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 437 |
const DataModel::LayoutItem::LayoutItemSize width, |
| 438 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 439 |
const DataModel::TrackType trackType, |
| 440 |
const TrackID main, |
| 441 |
const std::vector<DataModel::Relation*>& newFeedbacks, |
| 442 |
const std::vector<DataModel::Relation*>& newSignals, |
| 443 |
const DataModel::SelectRouteApproach selectRouteApproach, |
| 444 |
const bool allowLocoTurn, |
| 445 |
const bool releaseWhenFree, |
| 446 |
std::string& result); |
| 447 |
|
| 448 |
bool TrackDelete(const TrackID trackID, |
| 449 |
std::string& result); |
| 450 |
|
| 451 |
|
| 452 |
bool SwitchState(const ControlType controlType, const SwitchID switchID, const DataModel::AccessoryState state, const bool force = false); |
| 453 |
DataModel::Switch* GetSwitch(const SwitchID switchID) const; |
| 454 |
const std::string& GetSwitchName(const SwitchID switchID) const; |
| 455 |
|
| 456 |
inline const std::map<SwitchID,DataModel::Switch*>& SwitchList() const |
| 457 |
{ |
| 458 |
return switches; |
| 459 |
} |
| 460 |
|
| 461 |
const std::map<std::string,DataModel::AccessoryConfig> SwitchConfigByName() const; |
| 462 |
|
| 463 |
bool SwitchSave(SwitchID switchID, |
| 464 |
const std::string& name, |
| 465 |
const DataModel::LayoutItem::LayoutPosition x, |
| 466 |
const DataModel::LayoutItem::LayoutPosition y, |
| 467 |
const DataModel::LayoutItem::LayoutPosition z, |
| 468 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 469 |
const ControlID controlID, |
| 470 |
const std::string& matchKey, |
| 471 |
const Protocol protocol, |
| 472 |
const Address address, |
| 473 |
const Address serverAddress, |
| 474 |
const DataModel::AccessoryType type, |
| 475 |
const DataModel::AccessoryPulseDuration duration, |
| 476 |
const bool inverted, |
| 477 |
std::string& result); |
| 478 |
|
| 479 |
bool SwitchDelete(const SwitchID switchID, |
| 480 |
std::string& result); |
| 481 |
|
| 482 |
bool SwitchRelease(const SwitchID switchID); |
| 483 |
|
| 484 |
DataModel::Switch* GetSwitchByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 485 |
void SwitchRemoveMatchKey(const SwitchID switchId); |
| 486 |
|
| 487 |
|
| 488 |
bool RouteExecute(Logger::Logger* logger, const DataModel::ObjectIdentifier& locoBaseIdentifier, const RouteID routeID); |
| 489 |
|
| 490 |
void RouteExecuteAsync(Logger::Logger* logger, const RouteID routeID); |
| 491 |
|
| 492 |
std::string GetRouteList() const; |
| 493 |
|
| 494 |
DataModel::Route* GetRoute(const RouteID routeID) const; |
| 495 |
|
| 496 |
const std::string& GetRouteName(const RouteID routeID) const; |
| 497 |
|
| 498 |
inline const std::map<RouteID,DataModel::Route*>& RouteList() const |
| 499 |
{ |
| 500 |
return routes; |
| 501 |
} |
| 502 |
|
| 503 |
const std::map<std::string,DataModel::Route*> RouteListByName() const; |
| 504 |
|
| 505 |
inline void RouteSave(const DataModel::Route* route) const |
| 506 |
{ |
| 507 |
if (!storage) |
| 508 |
{ |
| 509 |
return; |
| 510 |
} |
| 511 |
Storage::TransactionGuard guard(storage); |
| 512 |
storage->Save(*route); |
| 513 |
} |
| 514 |
|
| 515 |
bool RouteSave(RouteID routeID, |
| 516 |
const std::string& name, |
| 517 |
const Delay delay, |
| 518 |
const DataModel::Route::PushpullType pushpull, |
| 519 |
const Propulsion propulsion, |
| 520 |
const TrainType trainType, |
| 521 |
const Length minTrainLength, |
| 522 |
const Length maxTrainLength, |
| 523 |
const std::vector<DataModel::Relation*>& relationsAtLock, |
| 524 |
const std::vector<DataModel::Relation*>& relationsAtUnlock, |
| 525 |
const DataModel::LayoutItem::Visible visible, |
| 526 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 527 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 528 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 529 |
const Automode automode, |
| 530 |
const TrackID fromTrack, |
| 531 |
const Orientation fromOrientation, |
| 532 |
const TrackID toTrack, |
| 533 |
const Orientation toOrientation, |
| 534 |
const DataModel::Route::Speed speed, |
| 535 |
const FeedbackID feedbackIdReduced, |
| 536 |
const Delay reducedDelay, |
| 537 |
const FeedbackID feedbackIdCreep, |
| 538 |
const Delay creepDelay, |
| 539 |
const FeedbackID feedbackIdStop, |
| 540 |
const Delay stopDelay, |
| 541 |
const FeedbackID feedbackIdOver, |
| 542 |
const Pause waitAfterRelease, |
| 543 |
const RouteID followUpRoute, |
| 544 |
std::string& result); |
| 545 |
|
| 546 |
bool RouteDelete(const RouteID routeID, |
| 547 |
std::string& result); |
| 548 |
|
| 549 |
DataModel::Route* GetFirstRouteFromOrToTrack(const TrackID trackID) const; |
| 550 |
|
| 551 |
inline bool HasRouteFromOrToTrack(const TrackID trackID) const |
| 552 |
{ |
| 553 |
return (GetFirstRouteFromOrToTrack(trackID) != nullptr); |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
DataModel::Layer* GetLayer(const LayerID layerID) const; |
| 558 |
const std::map<std::string,LayerID> LayerListByName() const; |
| 559 |
const std::map<std::string,LayerID> LayerListByNameWithFeedback() const; |
| 560 |
bool LayerSave(const LayerID layerID, const std::string&name, std::string& result); |
| 561 |
|
| 562 |
bool LayerDelete(const LayerID layerID, |
| 563 |
std::string& result); |
| 564 |
|
| 565 |
|
| 566 |
bool SignalState(const ControlType controlType, const SignalID signalID, const DataModel::AccessoryState state, const bool force = false); |
| 567 |
bool SignalState(const ControlType controlType, DataModel::Signal* signal, const DataModel::AccessoryState state, const bool force = false); |
| 568 |
DataModel::Signal* GetSignal(const SignalID signalID) const; |
| 569 |
const std::string& GetSignalName(const SignalID signalID) const; |
| 570 |
|
| 571 |
inline const std::map<SignalID,DataModel::Signal*>& SignalList() const |
| 572 |
{ |
| 573 |
return signals; |
| 574 |
} |
| 575 |
|
| 576 |
const std::map<std::string,DataModel::Signal*> SignalListByName() const; |
| 577 |
const std::map<std::string,DataModel::AccessoryConfig> SignalConfigByName() const; |
| 578 |
|
| 579 |
bool SignalSave(SignalID signalID, |
| 580 |
const std::string& name, |
| 581 |
const DataModel::LayoutItem::LayoutPosition x, |
| 582 |
const DataModel::LayoutItem::LayoutPosition y, |
| 583 |
const DataModel::LayoutItem::LayoutPosition z, |
| 584 |
const DataModel::LayoutItem::LayoutItemSize height, |
| 585 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 586 |
const ControlID controlID, |
| 587 |
const std::string& matchKey, |
| 588 |
const Protocol protocol, |
| 589 |
const Address address, |
| 590 |
const Address serverAddress, |
| 591 |
const DataModel::AccessoryType type, |
| 592 |
const std::map<DataModel::AccessoryState,DataModel::AddressOffset>& offsets, |
| 593 |
const DataModel::AccessoryPulseDuration duration, |
| 594 |
const bool inverted, |
| 595 |
std::string& result); |
| 596 |
|
| 597 |
bool SignalDelete(const SignalID signalID, |
| 598 |
std::string& result); |
| 599 |
|
| 600 |
void SignalPublishState(const ControlType controlType, const DataModel::Signal* signal); |
| 601 |
|
| 602 |
DataModel::Signal* GetSignalByMatchKey(const ControlID controlId, const std::string& matchKey) const; |
| 603 |
void SignalRemoveMatchKey(const SignalID signalId); |
| 604 |
|
| 605 |
bool SignalRelease(const SignalID signalID); |
| 606 |
|
| 607 |
|
| 608 |
DataModel::Cluster* GetCluster(const ClusterID clusterID) const; |
| 609 |
const std::map<std::string,DataModel::Cluster*> ClusterListByName() const; |
| 610 |
|
| 611 |
bool ClusterSave(ClusterID clusterID, |
| 612 |
const std::string& name, |
| 613 |
const std::vector<DataModel::Relation*>& newTracks, |
| 614 |
std::string& result); |
| 615 |
|
| 616 |
bool ClusterDelete(const ClusterID clusterID); |
| 617 |
|
| 618 |
|
| 619 |
DataModel::Text* GetText(const TextID textID) const; |
| 620 |
|
| 621 |
inline const std::map<TextID,DataModel::Text*>& TextList() const |
| 622 |
{ |
| 623 |
return texts; |
| 624 |
} |
| 625 |
|
| 626 |
const std::map<std::string,DataModel::Text*> TextListByName() const; |
| 627 |
|
| 628 |
bool TextSave(TextID textID, |
| 629 |
const std::string& name, |
| 630 |
const DataModel::LayoutItem::LayoutPosition x, |
| 631 |
const DataModel::LayoutItem::LayoutPosition y, |
| 632 |
const DataModel::LayoutItem::LayoutPosition z, |
| 633 |
const DataModel::LayoutItem::LayoutItemSize width, |
| 634 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 635 |
std::string& result); |
| 636 |
|
| 637 |
bool TextDelete(const TextID textID, |
| 638 |
std::string& result); |
| 639 |
|
| •640 |
|
| 641 |
DataModel::Counter* GetCounter(const CounterID counterID) const; |
| 642 |
|
| 643 |
bool Count(const CounterID counterID, const DataModel::CounterType type); |
| 644 |
|
| 645 |
inline const std::map<TextID,DataModel::Counter*>& CounterList() const |
| 646 |
{ |
| 647 |
return counters; |
| 648 |
} |
| 649 |
|
| 650 |
const std::map<std::string,DataModel::Counter*> CounterListByName() const; |
| 651 |
|
| 652 |
bool CounterSave(CounterID counterID, |
| 653 |
const std::string& name, |
| 654 |
const int max, |
| 655 |
const int min, |
| 656 |
const DataModel::LayoutItem::LayoutPosition x, |
| 657 |
const DataModel::LayoutItem::LayoutPosition y, |
| 658 |
const DataModel::LayoutItem::LayoutPosition z, |
| 659 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 660 |
std::string& result); |
| 661 |
|
| 662 |
bool CounterDelete(const CounterID counterID, |
| 663 |
std::string& result); |
| 664 |
|
| 665 |
|
| 666 |
bool LocoBaseIntoTrack(Logger::Logger* logger, const DataModel::ObjectIdentifier& locoBaseIdentifier, const TrackID trackID); |
| 667 |
bool LocoRelease(const LocoID locoID); |
| 668 |
bool TrackRelease(const TrackID trackID); |
| 669 |
bool LocoBaseReleaseOnTrack(const TrackID trackID); |
| 670 |
|
| 671 |
bool TrackStartLocoBase(const TrackID trackID); |
| 672 |
|
| 673 |
bool TrackStopLocoBase(const TrackID trackID); |
| 674 |
void TrackBlock(const TrackID trackID, const bool blocked); |
| 675 |
void TrackSetLocoOrientation(const TrackID trackID, const Orientation orientation); |
| 676 |
void TrackPublishState(const DataModel::Track* track); |
| 677 |
bool RouteRelease(const RouteID routeID); |
| 678 |
|
| 679 |
bool LocoDestinationReached(const DataModel::LocoBase* loco, |
| 680 |
const DataModel::Route* route, |
| 681 |
const DataModel::Track* track); |
| 682 |
|
| 683 |
bool LocoBaseStart(const DataModel::ObjectIdentifier& locoBaseIdentifier); |
| 684 |
bool LocoBaseStartAll(); |
| 685 |
|
| 686 |
bool LocoBaseStop(const DataModel::ObjectIdentifier& locoBaseIdentifier); |
| 687 |
bool LocoBaseStopAll(); |
| 688 |
void LocoBaseStopAllImmediately(const ControlType controlType); |
| 689 |
|
| 690 |
bool LocoBaseAddTimeTable(const DataModel::ObjectIdentifier& locoBaseIdentifier, |
| 691 |
const RouteID routeID, |
| 692 |
const bool automode); |
| 693 |
|
| 694 |
std::string GetCs2Lokomotive() const; |
| 695 |
static std::string GetCs2Magnetartikel(const DataModel::AccessoryBase* base); |
| 696 |
std::string GetCs2Magnetartikel() const; |
| 697 |
std::string GetCs2GBS() const; |
| 698 |
std::string GetCs2GBS(const signed char gbs) const; |
| 699 |
|
| 700 |
inline DataModel::ObjectIdentifier GetLocoBaseIdentifierOfTrack(const TrackID trackId) |
| 701 |
{ |
| 702 |
const DataModel::Track* track = GetTrack(trackId); |
| 703 |
return (track ? track->GetLocoBase() : DataModel::ObjectIdentifier()); |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
inline StartupInitLocos GetStartupInitLocos() const |
| 708 |
{ |
| 709 |
return startupInitLocos; |
| 710 |
} |
| 711 |
|
| 712 |
inline DataModel::AccessoryPulseDuration GetDefaultAccessoryDuration() const |
| 713 |
{ |
| 714 |
return defaultAccessoryDuration; |
| 715 |
} |
| 716 |
|
| 717 |
inline bool GetAutoAddFeedback() const |
| 718 |
{ |
| 719 |
return autoAddFeedback; |
| 720 |
} |
| 721 |
|
| 722 |
inline bool GetStopOnFeedbackInFreeTrack() const |
| 723 |
{ |
| 724 |
return stopOnFeedbackInFreeTrack; |
| 725 |
} |
| 726 |
|
| 727 |
inline bool GetExecuteAccessory() const |
| 728 |
{ |
| 729 |
return executeAccessory; |
| 730 |
} |
| 731 |
|
| 732 |
inline DataModel::SelectRouteApproach GetSelectRouteApproach() const |
| 733 |
{ |
| 734 |
return selectRouteApproach; |
| 735 |
} |
| 736 |
|
| 737 |
inline DataModel::Loco::NrOfTracksToReserve GetNrOfTracksToReserve() const |
| 738 |
{ |
| 739 |
return nrOfTracksToReserve; |
| 740 |
} |
| 741 |
|
| 742 |
bool SettingsSave(const Languages::Language language, |
| 743 |
const StartupInitLocos startupInitLocos, |
| 744 |
const DataModel::AccessoryPulseDuration duration, |
| 745 |
const bool autoAddFeedback, |
| 746 |
const bool stopOnFeedbackInFreeTrack, |
| 747 |
const bool executeAccessoryAlways, |
| 748 |
const DataModel::SelectRouteApproach selectRouteApproach, |
| 749 |
const DataModel::Loco::NrOfTracksToReserve nrOfTracksToReserve, |
| 750 |
const Logger::Logger::Level logLevel |
| 751 |
); |
| 752 |
|
| 753 |
ControlID GetPossibleControlForLoco() const; |
| 754 |
ControlID GetPossibleControlForAccessory() const; |
| 755 |
ControlID GetPossibleControlForFeedback() const; |
| 756 |
|
| 757 |
void ProgramRead(const ControlID controlID, const ProgramMode mode, const Address address, const CvNumber cv); |
| 758 |
void ProgramWrite(const ControlID controlID, const ProgramMode mode, const Address address, const CvNumber cv, const CvValue value); |
| 759 |
void ProgramValue(const CvNumber cv, const CvValue value); |
| 760 |
|
| 761 |
inline static void ProgramDccValueStatic(Manager* manager, const CvNumber cv, const CvValue value) |
| 762 |
{ |
| 763 |
manager->ProgramValue(cv, value); |
| 764 |
} |
| 765 |
|
| 766 |
bool CanHandle(const Hardware::Capabilities capability) const; |
| 767 |
bool CanHandle(const ControlID controlId, const Hardware::Capabilities capability) const; |
| 768 |
Hardware::Capabilities GetCapabilities(const ControlID controlID) const; |
| 769 |
|
| 770 |
bool LayoutItemRotate(const DataModel::ObjectIdentifier& identifier, |
| 771 |
std::string& result); |
| 772 |
|
| 773 |
bool LayoutItemNewPosition(const DataModel::ObjectIdentifier& identifier, |
| 774 |
const DataModel::LayoutItem::LayoutItemSize posX, |
| 775 |
const DataModel::LayoutItem::LayoutItemSize posY, |
| 776 |
std::string& result); |
| 777 |
|
| 778 |
inline bool IsServerEnabled() const |
| 779 |
{ |
| 780 |
return serverEnabled; |
| 781 |
} |
| 782 |
|
| 783 |
DataModel::ObjectIdentifier GetIdentifierOfServerLocoAddress(const Address serverAddress) const; |
| 784 |
DataModel::ObjectIdentifier GetIdentifierOfServerAccessoryAddress(const Address serverAddress) const; |
| 785 |
|
| 786 |
private: |
| 787 |
bool ControlIsOfHardwareType(const ControlID controlID, const HardwareType hardwareType); |
| 788 |
|
| 789 |
ControlInterface* GetControl(const ControlID controlID) const; |
| 790 |
|
| 791 |
DataModel::Loco* GetLoco(const ControlID controlID, |
| 792 |
const Protocol protocol, |
| 793 |
const Address address) const; |
| 794 |
|
| 795 |
DataModel::Accessory* GetAccessory(const ControlID controlID, |
| 796 |
const Protocol protocol, |
| 797 |
const Address address, |
| 798 |
const AddressPort port) const; |
| 799 |
|
| 800 |
DataModel::Switch* GetSwitch(const ControlID controlID, const Protocol protocol, const Address address) const; |
| 801 |
|
| 802 |
DataModel::Feedback* GetFeedback(const ControlID controlID, const FeedbackPin pin) const; |
| 803 |
|
| 804 |
DataModel::Signal* GetSignal(const ControlID controlID, const Protocol protocol, const Address address) const; |
| 805 |
|
| 806 |
void AccessoryState(const ControlType controlType, DataModel::Accessory* accessory, const DataModel::AccessoryState state, const bool force); |
| 807 |
|
| 808 |
void SwitchState(const ControlType controlType, DataModel::Switch* mySwitch, const DataModel::AccessoryState state, const bool force); |
| 809 |
|
| 810 |
static inline void FeedbackState(DataModel::Feedback* feedback, const DataModel::Feedback::FeedbackState state) |
| 811 |
{ |
| 812 |
feedback->SetState(state); |
| 813 |
} |
| 814 |
|
| 815 |
bool AccessoryPosition(const AccessoryID accessoryID, |
| 816 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 817 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 818 |
std::string& result); |
| 819 |
|
| 820 |
bool FeedbackPosition(const FeedbackID feedbackID, |
| 821 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 822 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 823 |
std::string& result); |
| 824 |
|
| 825 |
bool RoutePosition(const RouteID routeID, |
| 826 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 827 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 828 |
std::string& result); |
| 829 |
|
| 830 |
bool SignalPosition(const SignalID signalID, |
| 831 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 832 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 833 |
std::string& result); |
| 834 |
|
| 835 |
bool SwitchPosition(const SwitchID switchID, |
| 836 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 837 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 838 |
std::string& result); |
| 839 |
|
| 840 |
bool TextPosition(const TextID textID, |
| 841 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 842 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 843 |
std::string& result); |
| 844 |
|
| 845 |
bool TrackPosition(const TrackID trackID, |
| 846 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 847 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 848 |
std::string& result); |
| 849 |
|
| •850 |
bool CounterPosition(const CounterID counterID, |
| 851 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 852 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 853 |
std::string& result); |
| 854 |
|
| 855 |
bool AccessoryRotate(const AccessoryID accessoryID, |
| 856 |
std::string& result); |
| 857 |
|
| 858 |
bool FeedbackRotate(const FeedbackID feedbackID, |
| 859 |
std::string& result); |
| 860 |
|
| 861 |
bool SignalRotate(const SignalID signalID, |
| 862 |
std::string& result); |
| 863 |
|
| 864 |
bool SwitchRotate(const SwitchID switchID, |
| 865 |
std::string& result); |
| 866 |
|
| 867 |
bool TextRotate(const TextID textID, |
| 868 |
std::string& result); |
| 869 |
|
| 870 |
bool TrackRotate(const TrackID trackID, |
| 871 |
std::string& result); |
| 872 |
|
| •873 |
bool CounterRotate(const CounterID counterID, |
| 874 |
std::string& result); |
| 875 |
|
| 876 |
void AccessorySaveAndPublishSettings(const DataModel::Accessory* const accessory); |
| 877 |
void FeedbackSaveAndPublishSettings(const DataModel::Feedback* const feedback); |
| 878 |
void RouteSaveAndPublishSettings(const DataModel::Route* const route); |
| 879 |
void SignalSaveAndPublishSettings(const DataModel::Signal* const signal); |
| 880 |
void SwitchSaveAndPublishSettings(const DataModel::Switch* const mySwitch); |
| 881 |
void TextSaveAndPublishSettings(const DataModel::Text* const text); |
| 882 |
void TrackSaveAndPublishSettings(const DataModel::Track* const track); |
| •883 |
void CounterSaveAndPublishSettings(const DataModel::Counter* const counter); |
| 884 |
void CounterPublishState(const DataModel::Counter* const counter); |
| 885 |
|
| 886 |
|
| 887 |
bool CheckPositionFree(const DataModel::LayoutItem::LayoutPosition posX, |
| 888 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 889 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 890 |
std::string& result) const; |
| 891 |
bool CheckPositionFree(const DataModel::LayoutItem::LayoutPosition posX, |
| 892 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 893 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 894 |
const DataModel::LayoutItem::LayoutItemSize width, |
| 895 |
const DataModel::LayoutItem::LayoutItemSize height, |
| 896 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 897 |
std::string& result) const; |
| 898 |
|
| 899 |
template<class Type> |
| 900 |
bool CheckLayoutPositionFree(const DataModel::LayoutItem::LayoutPosition posX, |
| 901 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 902 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 903 |
std::string& result, |
| 904 |
const std::map<ObjectID, Type*>& layoutVector, std::mutex& mutex) const; |
| 905 |
|
| 906 |
bool CheckLayoutItemPosition(const DataModel::LayoutItem* layoutItem, |
| 907 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 908 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 909 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 910 |
std::string& result) const; |
| 911 |
|
| 912 |
bool CheckLayoutItemPosition(const DataModel::LayoutItem* item, |
| 913 |
const DataModel::LayoutItem::LayoutPosition posX, |
| 914 |
const DataModel::LayoutItem::LayoutPosition posY, |
| 915 |
const DataModel::LayoutItem::LayoutPosition posZ, |
| 916 |
const DataModel::LayoutItem::LayoutItemSize width, |
| 917 |
const DataModel::LayoutItem::LayoutItemSize height, |
| 918 |
const DataModel::LayoutItem::LayoutRotation rotation, |
| 919 |
std::string& result) const; |
| 920 |
|
| 921 |
bool CheckAddressLoco(const Protocol protocol, const Address address, std::string& result); |
| 922 |
bool CheckAddressAccessory(const Protocol protocol, const Address address, std::string& result); |
| 923 |
|
| 924 |
inline bool CheckControlLocoProtocolAddress(const ControlID controlID, |
| 925 |
const Protocol protocol, |
| 926 |
const Address address, |
| 927 |
std::string& result) |
| 928 |
{ |
| 929 |
return CheckControlProtocolAddress(AddressTypeLoco, controlID, protocol, address, result); |
| 930 |
} |
| 931 |
|
| 932 |
inline bool CheckControlMultipleUnitProtocolAddress(const ControlID controlID, |
| 933 |
const Address address, |
| 934 |
std::string& result) |
| 935 |
{ |
| 936 |
return CheckControlProtocolAddress(AddressTypeMultipleUnit, controlID, ProtocolNone, address, result); |
| 937 |
} |
| 938 |
|
| 939 |
inline bool CheckControlAccessoryProtocolAddress(const ControlID controlID, |
| 940 |
const Protocol protocol, |
| 941 |
const Address address, |
| 942 |
std::string& result) |
| 943 |
{ |
| 944 |
return CheckControlProtocolAddress(AddressTypeAccessory, controlID, protocol, address, result); |
| 945 |
} |
| 946 |
|
| 947 |
bool CheckControlProtocolAddress(const AddressType type, const ControlID controlID, const Protocol protocol, const Address address, std::string& result); |
| 948 |
const std::map<std::string,Protocol> ProtocolsOfControl(const AddressType type, const ControlID) const; |
| 949 |
|
| 950 |
bool LocoBaseReleaseInternal(DataModel::LocoBase* locoBase); |
| 951 |
|
| 952 |
bool LayerHasElements(const DataModel::Layer* layer, |
| 953 |
std::string& result); |
| 954 |
|
| 955 |
template<class Key, class Value> |
| 956 |
void DeleteAllMapEntries(std::map<Key,Value*>& m, std::mutex& x) |
| 957 |
{ |
| 958 |
std::lock_guard<std::mutex> Guard(x); |
| 959 |
while (m.size()) |
| 960 |
{ |
| 961 |
auto it = m.begin(); |
| 962 |
Value* content = it->second; |
| 963 |
m.erase(it); |
| 964 |
if (storage != nullptr) |
| 965 |
{ |
| 966 |
logger->Info(Languages::TextSaving, content->GetName()); |
| 967 |
storage->Save(*content); |
| 968 |
} |
| 969 |
delete content; |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
void DebounceWorker(); |
| 974 |
|
| 975 |
template<class ID, class T> |
| 976 |
T* CreateAndAddObject(std::map<ID,T*>& objects, std::mutex& mutex); |
| 977 |
|
| 978 |
Hardware::HardwareParams* CreateAndAddControl(); |
| 979 |
|
| 980 |
template<class ID, class T> |
| 981 |
bool CheckObjectName(std::map<ID,T*>& objects, const std::string& name) |
| 982 |
{ |
| 983 |
for (auto& object : objects) |
| 984 |
{ |
| 985 |
if (object.second->GetName().compare(name) == 0) |
| 986 |
{ |
| 987 |
return false; |
| 988 |
} |
| 989 |
} |
| 990 |
return true; |
| 991 |
} |
| 992 |
|
| 993 |
inline bool CheckIfNumber(const char& c) |
| 994 |
{ |
| 995 |
return c >= '0' && c <= '9'; |
| 996 |
} |
| 997 |
|
| 998 |
inline bool CheckIfThreeNumbers(const std::string& s) |
| 999 |
{ |
| 1000 |
const size_t sSize = s.size(); |
| 1001 |
return sSize >= 3 |
| 1002 |
&& CheckIfNumber(s.at(sSize - 1)) |
| 1003 |
&& CheckIfNumber(s.at(sSize - 2)) |
| 1004 |
&& CheckIfNumber(s.at(sSize - 3)); |
| 1005 |
} |
| 1006 |
|
| 1007 |
template<class ID, class T> |
| 1008 |
std::string CheckObjectName(std::map<ID,T*>& objects, std::mutex& mutex, const ID objectID, const std::string& name) |
| 1009 |
{ |
| 1010 |
std::lock_guard<std::mutex> Guard(mutex); |
| 1011 |
if (objects.count(objectID) == 1) |
| 1012 |
{ |
| 1013 |
const T* o = objects.at(objectID); |
| 1014 |
const std::string& oldName = o->GetName(); |
| 1015 |
if (oldName.compare(name) == 0) |
| 1016 |
{ |
| 1017 |
return name; |
| 1018 |
} |
| 1019 |
} |
| 1020 |
if (CheckObjectName(objects, name)) |
| 1021 |
{ |
| 1022 |
return name; |
| 1023 |
} |
| 1024 |
unsigned int counter = 0; |
| 1025 |
|
| 1026 |
const std::string baseName = CheckIfThreeNumbers(name) ? name.substr(0, name.size() - 3) : name; |
| 1027 |
|
| 1028 |
while (true) |
| 1029 |
{ |
| 1030 |
++counter; |
| 1031 |
std::stringstream ss; |
| 1032 |
ss << baseName << std::setw(3) << std::setfill('0') << counter; |
| 1033 |
std::string newName = ss.str(); |
| 1034 |
if (CheckObjectName(objects, newName)) |
| 1035 |
{ |
| 1036 |
return newName; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
bool LocoIntoTrack(Logger::Logger *logger, |
| 1042 |
DataModel::Loco* loco, |
| 1043 |
const ObjectType objectType, |
| 1044 |
DataModel::Track* track); |
| 1045 |
|
| 1046 |
void InitLocos(); |
| 1047 |
|
| 1048 |
static inline void InitLocosStatic(Manager* manager) |
| 1049 |
{ |
| 1050 |
manager->InitLocos(); |
| 1051 |
} |
| 1052 |
|
| 1053 |
void ProgramCheckBooster(const ProgramMode mode); |
| 1054 |
|
| 1055 |
bool ObjectIsPartOfRoute(const DataModel::ObjectIdentifier& identifier, |
| 1056 |
const DataModel::Object* object, |
| 1057 |
std::string& result); |
| 1058 |
|
| 1059 |
Logger::Logger* logger; |
| 1060 |
volatile BoosterState boosterState; |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
std::map<ControlID,ControlInterface*> controls; |
| 1066 |
mutable std::mutex controlMutex; |
| 1067 |
|
| 1068 |
|
| 1069 |
std::map<ControlID,Hardware::HardwareParams*> hardwareParams; |
| 1070 |
mutable std::mutex hardwareMutex; |
| 1071 |
|
| 1072 |
|
| 1073 |
std::map<LocoID,DataModel::Loco*> locos; |
| 1074 |
mutable std::mutex locoMutex; |
| 1075 |
|
| 1076 |
|
| 1077 |
std::map<LocoID,DataModel::MultipleUnit*> multipleUnits; |
| 1078 |
mutable std::mutex multipleUnitMutex; |
| 1079 |
|
| 1080 |
|
| 1081 |
std::map<AccessoryID,DataModel::Accessory*> accessories; |
| 1082 |
mutable std::mutex accessoryMutex; |
| 1083 |
|
| 1084 |
|
| 1085 |
std::map<FeedbackID,DataModel::Feedback*> feedbacks; |
| 1086 |
mutable std::mutex feedbackMutex; |
| 1087 |
|
| 1088 |
|
| 1089 |
std::map<TrackID,DataModel::Track*> tracks; |
| 1090 |
mutable std::mutex trackMutex; |
| 1091 |
|
| 1092 |
|
| 1093 |
std::map<SwitchID,DataModel::Switch*> switches; |
| 1094 |
mutable std::mutex switchMutex; |
| 1095 |
|
| 1096 |
|
| 1097 |
std::map<RouteID,DataModel::Route*> routes; |
| 1098 |
mutable std::mutex routeMutex; |
| 1099 |
|
| 1100 |
|
| 1101 |
std::map<LayerID,DataModel::Layer*> layers; |
| 1102 |
mutable std::mutex layerMutex; |
| 1103 |
|
| 1104 |
|
| 1105 |
std::map<SignalID,DataModel::Signal*> signals; |
| 1106 |
mutable std::mutex signalMutex; |
| 1107 |
|
| 1108 |
|
| 1109 |
std::map<SignalID,DataModel::Cluster*> clusters; |
| 1110 |
mutable std::mutex clusterMutex; |
| 1111 |
|
| 1112 |
|
| 1113 |
std::map<TextID,DataModel::Text*> texts; |
| 1114 |
mutable std::mutex textMutex; |
| 1115 |
|
| •1116 |
|
| 1117 |
std::map<CounterID,DataModel::Counter*> counters; |
| 1118 |
mutable std::mutex counterMutex; |
| 1119 |
|
| 1120 |
|
| 1121 |
Storage::StorageHandler* storage; |
| 1122 |
|
| 1123 |
StartupInitLocos startupInitLocos; |
| 1124 |
DataModel::AccessoryPulseDuration defaultAccessoryDuration; |
| 1125 |
bool autoAddFeedback; |
| 1126 |
bool stopOnFeedbackInFreeTrack; |
| 1127 |
bool executeAccessory; |
| 1128 |
DataModel::SelectRouteApproach selectRouteApproach; |
| 1129 |
DataModel::Loco::NrOfTracksToReserve nrOfTracksToReserve; |
| 1130 |
|
| 1131 |
volatile bool run; |
| 1132 |
volatile bool debounceRun; |
| 1133 |
std::thread debounceThread; |
| 1134 |
|
| 1135 |
volatile bool initLocosDone; |
| 1136 |
|
| 1137 |
bool serverEnabled; |
| 1138 |
|
| 1139 |
const std::string unknownControl; |
| 1140 |
const std::string unknownLoco; |
| 1141 |
const std::string unknownMultipleUnit; |
| 1142 |
const std::string unknownAccessory; |
| 1143 |
const std::string unknownFeedback; |
| 1144 |
const std::string unknownTrack; |
| 1145 |
const std::string unknownSwitch; |
| 1146 |
const std::string unknownRoute; |
| 1147 |
const std::string unknownSignal; |
| 1148 |
}; |