Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2003-2026 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file MsgHandlerSynchronized.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Jakob Erdmann
18 : /// @date Tue, 17 Jun 2003
19 : ///
20 : // Retrieves messages about the process and gives them further to output
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #ifdef HAVE_FOX
26 : #include "fxheader.h"
27 : #endif
28 : #include <string>
29 : #include <vector>
30 : #include <iostream>
31 : #include <utils/common/MsgHandler.h>
32 :
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class OutputDevice;
38 :
39 :
40 : // ===========================================================================
41 : // class definitions
42 : // ===========================================================================
43 : /**
44 : * MsgHandlerSynchronized
45 : */
46 : class MsgHandlerSynchronized : public MsgHandler {
47 : public:
48 106329 : static MsgHandler* create(MsgType type) {
49 106329 : return new MsgHandlerSynchronized(type);
50 : }
51 :
52 : /// @brief adds a new error to the list
53 110639 : void inform(std::string msg, bool addType = true) {
54 110639 : FXMutexLock locker(myLock);
55 331917 : MsgHandler::inform(msg, addType);
56 110639 : }
57 :
58 : /** @brief Begins a process information
59 : *
60 : * When a longer action is started, this method should be used to inform the user about it.
61 : * There will be no newline printed, but the message handler will be informed that
62 : * a process message has been begun. If an error occurs, a newline will be printed.
63 : * After the action has been performed, use endProcessMsg to inform the user about it.
64 : */
65 23316 : void beginProcessMsg(std::string msg, bool addType = true) {
66 23316 : FXMutexLock locker(myLock);
67 69948 : MsgHandler::beginProcessMsg(msg, addType);
68 23316 : }
69 :
70 : /// @brief Ends a process information
71 22969 : void endProcessMsg(std::string msg) {
72 22969 : FXMutexLock locker(myLock);
73 68907 : MsgHandler::endProcessMsg(msg);
74 22969 : }
75 :
76 : /// @brief Clears information whether an error occurred previously
77 85542 : void clear(bool resetInformed = true) {
78 85542 : FXMutexLock locker(myLock);
79 85542 : MsgHandler::clear(resetInformed);
80 85542 : }
81 :
82 : /// @brief Adds a further retriever to the instance responsible for a certain msg type
83 49598 : void addRetriever(OutputDevice* retriever) {
84 49598 : FXMutexLock locker(myLock);
85 49598 : MsgHandler::addRetriever(retriever);
86 49598 : }
87 :
88 : /// @brief Removes the retriever from the handler
89 356890 : void removeRetriever(OutputDevice* retriever) {
90 356890 : FXMutexLock locker(myLock);
91 356890 : MsgHandler::removeRetriever(retriever);
92 356890 : }
93 :
94 : protected:
95 45902 : bool aggregationThresholdReached(const std::string& format) {
96 45902 : FXMutexLock locker(myLock);
97 91804 : return MsgHandler::aggregationThresholdReached(format);
98 : }
99 :
100 : private:
101 : /// @brief standard constructor
102 106329 : MsgHandlerSynchronized(MsgType type) :
103 106329 : MsgHandler(type), myLock(true) {
104 106329 : }
105 :
106 : /// @brief destructor
107 106271 : ~MsgHandlerSynchronized() {
108 106271 : }
109 :
110 : /// @brief The lock for synchronizing all outputs using handlers of this class
111 : FXMutex myLock;
112 :
113 : private:
114 : /// @brief invalid copy constructor
115 : MsgHandlerSynchronized(const MsgHandlerSynchronized& s) = delete;
116 :
117 : /// @brief invalid assignment operator
118 : MsgHandlerSynchronized& operator=(const MsgHandlerSynchronized& s) = delete;
119 : };
|