Debian Codegraph @

Server/Web/WebServer.cpp

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <algorithm>
22 #include <arpa/inet.h>
23 #include <cstring> //memset
24 #include <ifaddrs.h>
25 #include <netinet/in.h>
26 #include <signal.h>
27 #include <sstream>
28 #include <sys/socket.h>
29 #include <thread>
30 #include <unistd.h>
31
32 #include "ControlInterface.h"
33 #include "DataTypes.h"
34 #include "DataModel/LocoBase.h"
35 #include "DataModel/LocoFunctions.h"
36 #include "DataModel/ObjectIdentifier.h"
37 #include "Languages.h"
38 #include "RailControl.h"
39 #include "Utils/Network.h"
40 #include "Server/Web/WebClient.h"
41 #include "Server/Web/WebServer.h"
42
43 using std::map;
44 using std::thread;
45 using std::string;
46 using std::stringstream;
47 using std::to_string;
48 using std::vector;
49
50 using DataModel::LocoBase;
51 using DataModel::LocoFunctionNr;
52 using DataModel::LocoFunctionState;
53 using DataModel::Route;
54 using DataModel::Track;
55
56 namespace Server { namespace Web
57 {
58 WebServer::WebServer(Manager& manager, const std::string& webserveraddress, const unsigned short port)
59 : ControlInterface(ControlTypeWebServer),
60 Network::TcpServer(webserveraddress, port, "WebServer"),
61 logger(Logger::Logger::GetLogger("WebServer")),
62 lastClientID(0),
63 manager(manager),
64 updateID(1),
65 updateAvailable(false)
66 {
67 AddUpdate(Languages::TextRailControlStarted);
68
69 LogBrowserInfo(webserveraddress, port);
70 }
71
72 WebServer::~WebServer()
73 {
74 // delete all client memory
75 while (clients.size())
76 {
77 WebClient* client = clients.back();
78 clients.pop_back();
79 delete client;
80 }
81 logger->Info(Languages::TextWebServerStopped);
82 }
83
84 void WebServer::Start()
85 {
86 StartTcpServer();
87 logger->Info(Languages::TextWebServerStarted);
88 }
89
90 void WebServer::Stop()
91 {
92 AddUpdate(Languages::TextShutdownRailControl);
93 TerminateTcpServer();
94 // stopping all clients
95 for (auto client : clients)
96 {
97 client->Stop();
98 }
99 }
100
101 void WebServer::LogBrowserInfo(const std::string& webserveraddress, const unsigned short port)
102 {
103 static const string Http("\n http://");
104 static const string Port(to_string(port));
105
106 string localhostInfo(Http);
107 localhostInfo += "localhost:" + Port + "/";
108 string ipv4Info;
109 string ipv6Info;
110
111 struct ifaddrs* ifAddrStruct = nullptr;
112 struct ifaddrs* ifa = nullptr;
113 getifaddrs(&ifAddrStruct);
114
115 if (webserveraddress.compare("localhost") != 0)
116 {
117 for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next)
118 {
119 if (!ifa->ifa_addr)
120 {
121 continue;
122 }
123 if (ifa->ifa_addr->sa_family == AF_INET)
124 {
125 // is a valid IP4 Address
126 void* tmpAddrPtr = &((struct sockaddr_in*) ifa->ifa_addr)->sin_addr;
127 char addressBuffer[INET_ADDRSTRLEN];
128 inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
129 string address(addressBuffer);
130 if (address.compare("0.0.0.0") == 0)
131 {
132 continue;
133 }
134 if (address.substr(0, 8).compare("169.254.") == 0)
135 {
136 continue;
137 }
138 ipv4Info += Http + addressBuffer + ":" + Port + "/";
139 }
140 else if (ifa->ifa_addr->sa_family == AF_INET6)
141 {
142 // is a valid IP6 Address
143 void* tmpAddrPtr = &((struct sockaddr_in6*) ifa->ifa_addr)->sin6_addr;
144 char addressBuffer[INET6_ADDRSTRLEN];
145 inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
146 ipv6Info += Http + "[" + addressBuffer + "]:" + Port + "/";
147 }
148 }
149 }
150
151 if (ifAddrStruct != NULL)
152 {
153 freeifaddrs(ifAddrStruct);
154 }
155
156 logger->Info(Languages::TextBrowserInfo, localhostInfo, ipv4Info, ipv6Info);
157
158 }
159
160 void WebServer::Work(Network::TcpConnection* connection)
161 {
162 clients.push_back(new WebClient(++lastClientID, connection, *this, manager));
163
164 // clean up unused clients
165 for (auto iterator = clients.begin(); iterator != clients.end();)
166 {
167 WebClient* client = *iterator;
168 if (client->IsTerminated())
169 {
170 iterator = clients.erase(iterator);
171 delete client;
172 }
173 else
174 {
175 ++iterator;
176 }
177 }
178 }
179
180 void WebServer::Booster(__attribute__((unused)) const ControlType controlType, const BoosterState status)
181 {
182 if (status)
183 {
184 AddUpdate("booster;on=true", Languages::TextTurningBoosterOn);
185 }
186 else
187 {
188 AddUpdate("booster;on=false", Languages::TextTurningBoosterOff);
189 }
190 }
191
192 void WebServer::LocoBaseSpeed(__attribute__((unused)) const ControlType controlType,
193 const LocoBase* loco,
194 const Speed speed)
195 {
196 const LocoID locoId = loco->GetLocoIdWithPrefix();
197 string command = "locospeed;loco=" + to_string(locoId) + ";speed=" + to_string(speed);
198 AddUpdate(command, Languages::TextLocoSpeedIs, loco->GetName(), speed);
199 }
200
201 void WebServer::LocoBaseOrientation(__attribute__((unused)) const ControlType controlType,
202 const LocoBase* loco,
203 const Orientation orientation)
204 {
205 const LocoID locoId = loco->GetLocoIdWithPrefix();
206 string command = "locoorientation;loco=" + to_string(locoId) + ";orientation=" + (orientation ? "true" : "false");
207 AddUpdate(command, orientation ? Languages::TextLocoDirectionOfTravelIsRight : Languages::TextLocoDirectionOfTravelIsLeft, loco->GetName());
208 }
209
210 void WebServer::LocoBaseFunction(__attribute__((unused)) const ControlType controlType,
211 const LocoBase* loco,
212 const LocoFunctionNr function,
213 const LocoFunctionState state)
214 {
215 const LocoID locoId = loco->GetLocoIdWithPrefix();
216 string command = "locofunction;loco=" + to_string(locoId) + ";function=" + to_string(function) + ";on=" + (state ? "true" : "false");
217 AddUpdate(command, state ? Languages::TextLocoFunctionIsOn : Languages::TextLocoFunctionIsOff, loco->GetName(), function);
218 }
219
220 void WebServer::AccessoryState(__attribute__((unused)) const ControlType controlType, const DataModel::Accessory* accessory)
221 {
222 stringstream command;
223 const DataModel::AccessoryState state = accessory->GetAccessoryState();
224 command << "accessory;accessory=" << accessory->GetID() << ";state=" << (state == DataModel::AccessoryStateOn ? "green" : "red");
225 AddUpdate(command.str(), state ? Languages::TextAccessoryStateIsGreen : Languages::TextAccessoryStateIsRed, accessory->GetName());
226 }
227
228 void WebServer::AccessorySettings(const AccessoryID accessoryID,
229 const std::string& name,
230 __attribute__((unused)) const std::string& matchkey)
231 {
232 stringstream command;
233 command << "accessorysettings;accessory=" << accessoryID;
234 AddUpdate(command.str(), Languages::TextAccessoryUpdated, name);
235 }
236
237 void WebServer::AccessoryDelete(const AccessoryID accessoryID,
238 const std::string& name,
239 __attribute__((unused)) const std::string& matchkey)
240 {
241 stringstream command;
242 command << "accessorydelete;accessory=" << accessoryID;
243 AddUpdate(command.str(), Languages::TextAccessoryDeleted, name);
244 }
245
246 void WebServer::FeedbackState(const std::string& name, const FeedbackID feedbackID, const DataModel::Feedback::FeedbackState state)
247 {
248 stringstream command;
249 command << "feedback;feedback=" << feedbackID << ";state=" << (state ? "on" : "off");
250 AddUpdate(command.str(), state ? Languages::TextFeedbackStateIsOn : Languages::TextFeedbackStateIsOff, name);
251 }
252
253 void WebServer::FeedbackSettings(const FeedbackID feedbackID, const std::string& name)
254 {
255 stringstream command;
256 command << "feedbacksettings;feedback=" << feedbackID;
257 AddUpdate(command.str(), Languages::TextFeedbackUpdated, name);
258 }
259
260 void WebServer::FeedbackDelete(const FeedbackID feedbackID, const std::string& name)
261 {
262 stringstream command;
263 command << "feedbackdelete;feedback=" << feedbackID;
264 AddUpdate(command.str(), Languages::TextFeedbackDeleted, name);
265 }
266
267 void WebServer::RouteSettings(const RouteID routeID, const std::string& name)
268 {
269 stringstream command;
270 command << "routesettings;route=" << routeID;
271 AddUpdate(command.str(), Languages::TextRouteUpdated, name);
272 }
273
274 void WebServer::RouteDelete(const RouteID routeID, const std::string& name)
275 {
276 stringstream command;
277 command << "routedelete;route=" << routeID;
278 AddUpdate(command.str(), Languages::TextRouteDeleted, name);
279 }
280
281 void WebServer::SwitchState(__attribute__((unused)) const ControlType controlType, const DataModel::Switch* mySwitch)
282 {
283 stringstream command;
284 const DataModel::AccessoryState state = mySwitch->GetAccessoryState();
285 command << "switch;switch=" << mySwitch->GetID() << ";state=";
286 Languages::TextSelector text;
287 switch (state)
288 {
289 case DataModel::AccessoryState::SwitchStateTurnout:
290 command << "turnout";
291 text = Languages::TextSwitchStateIsTurnout;
292 break;
293
294 case DataModel::AccessoryState::SwitchStateThird:
295 command << "third";
296 text = Languages::TextSwitchStateIsThird;
297 break;
298
299 case DataModel::AccessoryState::SwitchStateStraight:
300 default:
301 command << "straight";
302 text = Languages::TextSwitchStateIsStraight;
303 break;
304 }
305 AddUpdate(command.str(), text, mySwitch->GetName());
306 }
307
308 void WebServer::SwitchSettings(const SwitchID switchID,
309 const std::string& name,
310 __attribute__((unused)) const std::string& matchKey)
311 {
312 stringstream command;
313 command << "switchsettings;switch=" << switchID;
314 AddUpdate(command.str(), Languages::TextSwitchUpdated, name);
315 }
316
317 void WebServer::SwitchDelete(const SwitchID switchID,
318 const std::string& name,
319 __attribute__((unused)) const std::string& matchkey)
320 {
321 stringstream command;
322 command << "switchdelete;switch=" << switchID;
323 AddUpdate(command.str(), Languages::TextSwitchDeleted, name);
324 }
325
326 void WebServer::TrackState(const DataModel::Track* track)
327 {
328 const LocoBase* locoBase = manager.GetLocoBase(track->GetMainLocoBaseDelayed());
329 const bool reserved = locoBase != nullptr;
330 const string& trackName = track->GetMainName();
331 const string& locoName = reserved ? locoBase->GetName() : "";
332 const bool occupied = track->GetMainStateDelayed() == DataModel::Feedback::FeedbackStateOccupied;
333 const bool blocked = track->GetMainBlocked();
334 const Orientation orientation = track->GetMainLocoOrientation();
335 const string occupiedText = (occupied ? "true" : "false");
336 const string blockedText = (blocked ? "true" : "false");
337 const string reservedText = (reserved ? "true" : "false");
338 const string orientationText = (orientation ? "true" : "false");
339 string command = "trackstate;track="
340 + to_string(track->GetID())
341 + ";occupied=" + occupiedText
342 + ";reserved=" + reservedText
343 + ";blocked=" + blockedText
344 + ";orientation=" + orientationText
345 + ";loconame=" + locoName;
346
347 if (blocked)
348 {
349 if (reserved)
350 {
351 AddUpdate(command, Languages::TextTrackStatusIsBlockedAndReserved, trackName, locoName);
352 }
353 else if (occupied)
354 {
355 AddUpdate(command, Languages::TextTrackStatusIsBlockedAndOccupied, trackName);
356 }
357 else
358 {
359 AddUpdate(command, Languages::TextTrackStatusIsBlocked, trackName);
360 }
361 }
362 else
363 {
364 if (reserved)
365 {
366 AddUpdate(command, Languages::TextTrackStatusIsReserved, trackName, locoName);;
367 }
368 else if (occupied)
369 {
370 AddUpdate(command, Languages::TextTrackStatusIsOccupied, trackName);
371 }
372 else
373 {
374 AddUpdate(command, Languages::TextTrackStatusIsFree, trackName);
375 }
376 }
377 }
378
379 void WebServer::TrackSettings(const TrackID trackID, const std::string& name)
380 {
381 stringstream command;
382 command << "tracksettings;track=" << trackID;
383 AddUpdate(command.str(), Languages::TextTrackUpdated, name);
384 }
385
386 void WebServer::TrackDelete(const TrackID trackID, const std::string& name)
387 {
388 stringstream command;
389 command << "trackdelete;track=" << trackID;
390 AddUpdate(command.str(), Languages::TextTrackDeleted, name);
391 }
392
393 void WebServer::SignalState(__attribute__((unused)) const ControlType controlType, const DataModel::Signal* signal)
394 {
395 const DataModel::AccessoryState state = signal->GetAccessoryState();
396 string stateText;
397 Languages::TextSelector text;
398 switch(state)
399 {
400 case DataModel::SignalStateStop:
401 default:
402 stateText = "stop";
403 text = Languages::TextSignalStateIsStop;
404 break;
405
406 case DataModel::SignalStateClear:
407 stateText = "clear";
408 text = Languages::TextSignalStateIsClear;
409 break;
410
411 case DataModel::SignalStateAspect2:
412 stateText = "aspect2";
413 text = Languages::TextSignalStateIsAspect2;
414 break;
415
416 case DataModel::SignalStateAspect3:
417 stateText = "aspect3";
418 text = Languages::TextSignalStateIsAspect3;
419 break;
420
421 case DataModel::SignalStateAspect4:
422 stateText = "aspect4";
423 text = Languages::TextSignalStateIsAspect4;
424 break;
425
426 case DataModel::SignalStateAspect5:
427 stateText = "aspect5";
428 text = Languages::TextSignalStateIsAspect5;
429 break;
430
431 case DataModel::SignalStateAspect6:
432 stateText = "aspect6";
433 text = Languages::TextSignalStateIsAspect6;
434 break;
435
436 case DataModel::SignalStateAspect7:
437 stateText = "aspect7";
438 text = Languages::TextSignalStateIsAspect7;
439 break;
440
441 case DataModel::SignalStateAspect8:
442 stateText = "aspect8";
443 text = Languages::TextSignalStateIsAspect8;
444 break;
445
446 case DataModel::SignalStateAspect9:
447 stateText = "aspect9";
448 text = Languages::TextSignalStateIsAspect9;
449 break;
450
451 case DataModel::SignalStateAspect10:
452 stateText = "aspect10";
453 text = Languages::TextSignalStateIsAspect10;
454 break;
455
456 case DataModel::SignalStateDark:
457 stateText = "dark";
458 text = Languages::TextSignalStateIsDark;
459 break;
460
461 case DataModel::SignalStateStopExpected:
462 stateText = "stopexpected";
463 text = Languages::TextSignalStateIsStopExpected;
464 break;
465
466 case DataModel::SignalStateClearExpected:
467 stateText = "clearexpected";
468 text = Languages::TextSignalStateIsClearExpected;
469 break;
470
471 case DataModel::SignalStateAspect2Expected:
472 stateText = "aspect2expected";
473 text = Languages::TextSignalStateIsAspect2Expected;
474 break;
475
476 case DataModel::SignalStateAspect3Expected:
477 stateText = "aspect3expected";
478 text = Languages::TextSignalStateIsAspect3Expected;
479 break;
480
481 case DataModel::SignalStateAspect4Expected:
482 stateText = "aspect4expected";
483 text = Languages::TextSignalStateIsAspect4Expected;
484 break;
485
486 case DataModel::SignalStateAspect5Expected:
487 stateText = "aspect5expected";
488 text = Languages::TextSignalStateIsAspect5Expected;
489 break;
490
491 case DataModel::SignalStateAspect6Expected:
492 stateText = "aspect6expected";
493 text = Languages::TextSignalStateIsAspect6Expected;
494 break;
495
496 case DataModel::SignalStateAspect7Expected:
497 stateText = "aspect7expected";
498 text = Languages::TextSignalStateIsAspect7Expected;
499 break;
500
501 case DataModel::SignalStateAspect8Expected:
502 stateText = "aspect8expected";
503 text = Languages::TextSignalStateIsAspect8Expected;
504 break;
505
506 case DataModel::SignalStateAspect9Expected:
507 stateText = "aspect9expected";
508 text = Languages::TextSignalStateIsAspect9Expected;
509 break;
510
511 case DataModel::SignalStateAspect10Expected:
512 stateText = "aspect10expected";
513 text = Languages::TextSignalStateIsAspect10Expected;
514 break;
515 }
516 const string signalIdText(to_string(signal->GetID()));
517 const string command = "signal;signal=" + signalIdText + ";state=" + stateText;
518 AddUpdate(command, text, signal->GetName());
519 }
520
521 void WebServer::SignalSettings(const SignalID signalID,
522 const std::string& name,
523 __attribute__((unused)) const std::string& matchKey)
524 {
525 stringstream command;
526 command << "signalsettings;signal=" << signalID;
527 AddUpdate(command.str(), Languages::TextSignalUpdated, name);
528 }
529
530 void WebServer::SignalDelete(const SignalID signalID,
531 const std::string& name,
532 __attribute__((unused)) const std::string& matchkey)
533 {
534 stringstream command;
535 command << "signaldelete;signal=" << signalID;
536 AddUpdate(command.str(), Languages::TextSignalDeleted, name);
537 }
538
539 void WebServer::ClusterSettings(const ClusterID clusterID, const std::string& name)
540 {
541 stringstream command;
542 command << "clustersettings;cluster=" << clusterID;
543 AddUpdate(command.str(), Languages::TextClusterUpdated, name);
544 }
545
546 void WebServer::ClusterDelete(const ClusterID clusterID, const std::string& name)
547 {
548 stringstream command;
549 command << "clusterdelete;cluster=" << clusterID;
550 AddUpdate(command.str(), Languages::TextClusterDeleted, name);
551 }
552
553 void WebServer::TextSettings(const TextID textID, const std::string& name)
554 {
555 string command = "textsettings;text=" + to_string(textID);
556 AddUpdate(command, Languages::TextTextUpdated, name);
557 }
558
559 void WebServer::TextDelete(const TextID textID, const std::string& name)
560 {
561 string command = "textdelete;text=" + to_string(textID);
562 AddUpdate(command, Languages::TextTextDeleted, name);
563 }
564
•565 void WebServer::CounterSettings(const CounterID counterID, const std::string& name)
566 {
567 const string command = "countersettings;counter=" + to_string(counterID);
568 AddUpdate(command, Languages::TextCounterUpdated, name);
569 }
570
571 void WebServer::CounterDelete(const CounterID counterID, const std::string& name)
572 {
573 const string command = "counterdelete;counter=" + to_string(counterID);
574 AddUpdate(command, Languages::TextCounterDeleted, name);
575 }
576
577 void WebServer::CounterState(const DataModel::Counter* const counter)
578 {
579 const string command ="counterstate;counter=" + to_string(counter->GetID()) + ";count=" + to_string(counter->GetCounter());
580 AddUpdate(command, Languages::TextCounterUpdated, counter->GetName());
581 }
582
583 void WebServer::LocoBaseRelease(const DataModel::LocoBase* loco)
584 {
585 string command("locorelease;loco=");
586 command += loco->GetObjectIdentifier();
587 AddUpdate(command, Languages::TextLocoIsReleased, loco->GetName());
588 }
589
590 void WebServer::RouteRelease(const RouteID routeID)
591 {
592 stringstream command;
593 command << "routeRelease;route=" << routeID;
594 AddUpdate(command.str(), Languages::TextRouteIsReleased, manager.GetRouteName(routeID));
595 }
596
597 void WebServer::LocoBaseDestinationReached(const LocoBase* loco,
598 const Route* route,
599 const Track* track)
600 {
601 string command("locoDestinationReached;loco=");
602 command += loco->GetObjectIdentifier();
603 command += ";route=";
604 command += to_string(route->GetID());
605 command += ";track=";
606 command += to_string(track->GetID());
607 AddUpdate(command, Languages::TextLocoHasReachedDestination, loco->GetName(), track->GetName(), route->GetName());
608 }
609
610 void WebServer::LocoBaseStart(const DataModel::LocoBase* loco)
611 {
612 string command("locoStart;loco=");
613 command += loco->GetObjectIdentifier();
614 AddUpdate(command, Languages::TextLocoIsInAutoMode, loco->GetName());
615 }
616
617 void WebServer::LocoBaseStop(const DataModel::LocoBase* loco)
618 {
619 string command("locoStop;loco=");
620 command += loco->GetObjectIdentifier();
621 AddUpdate(command, Languages::TextLocoIsInManualMode, loco->GetName());
622 }
623
624 void WebServer::LocoSettings(const LocoID locoID,
625 const std::string& name,
626 __attribute__((unused)) const std::string& matchKey)
627 {
628 stringstream command;
629 command << "locosettings;loco=" << locoID;
630 AddUpdate(command.str(), Languages::TextLocoUpdated, name);
631 }
632
633 void WebServer::LocoDelete(const LocoID locoID,
634 const std::string& name,
635 __attribute__((unused)) const std::string& matchkey)
636 {
637 stringstream command;
638 command << "locodelete;loco=" << locoID;
639 AddUpdate(command.str(), Languages::TextLocoDeleted, name);
640 }
641
642 void WebServer::MultipleUnitSettings(const MultipleUnitID multipleUnitID,
643 const std::string& name,
644 __attribute__((unused)) const std::string& matchKey)
645 {
646 stringstream command;
647 command << "multipleunitsettings;loco=" << multipleUnitID;
648 AddUpdate(command.str(), Languages::TextLocoUpdated, name);
649 }
650
651 void WebServer::MultipleUnitDelete(const MultipleUnitID multipleUnitID,
652 const std::string& name,
653 __attribute__((unused)) const std::string& matchkey)
654 {
655 stringstream command;
656 command << "multipleunitdelete;loco=" << multipleUnitID;
657 AddUpdate(command.str(), Languages::TextLocoDeleted, name);
658 }
659
660 void WebServer::LayerSettings(const LayerID layerID, const std::string& name)
661 {
662 stringstream command;
663 command << "layersettings;layer=" << layerID;
664 AddUpdate(command.str(), Languages::TextLayerUpdated, name);
665 }
666
667 void WebServer::LayerDelete(const LayerID layerID, const std::string& name)
668 {
669 stringstream command;
670 command << "layerdelete;layer=" << layerID;
671 AddUpdate(command.str(), Languages::TextLayerDeleted, name);
672 }
673
674 void WebServer::ProgramValue(const CvNumber cv, const CvValue value)
675 {
676 stringstream command;
677 command << "dcccvvalue;cv=" << static_cast<int>(cv) << ";value=" << static_cast<int>(value);
678 AddUpdate(command.str(), Languages::TextProgramReadValue , static_cast<int>(cv), static_cast<int>(value));
679 }
680
681 void WebServer::AddUpdate(const string& data)
682 {
683 std::lock_guard<std::mutex> lock(updateMutex);
684 updates[updateID] = data;
685 ++updateID;
686 updates.erase(updateID - MaxUpdates);
687 }
688
689 bool WebServer::NextUpdate(unsigned int& updateIDClient, string& s)
690 {
691 std::lock_guard<std::mutex> lock(updateMutex);
692
693 if (updateIDClient + MaxUpdates <= updateID)
694 {
695 updateIDClient = updateID - MaxUpdates + 1;
696 }
697
698 if (updates.count(updateIDClient) == 1)
699 {
700 s = updates.at(updateIDClient);
701 return true;
702 }
703
704 return false;
705 }
706
707 }} // namespace Server::Web