Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2003-2024 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 93924 : static MsgHandler* create(MsgType type) {
49 93924 : return new MsgHandlerSynchronized(type);
50 : }
51 :
52 : /// @brief adds a new error to the list
53 91293 : void inform(std::string msg, bool addType = true) {
54 91293 : FXMutexLock locker(myLock);
55 273879 : MsgHandler::inform(msg, addType);
56 91293 : }
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 20700 : void beginProcessMsg(std::string msg, bool addType = true) {
66 20700 : FXMutexLock locker(myLock);
67 62100 : MsgHandler::beginProcessMsg(msg, addType);
68 20700 : }
69 :
70 : /// @brief Ends a process information
71 20366 : void endProcessMsg(std::string msg) {
72 20366 : FXMutexLock locker(myLock);
73 61098 : MsgHandler::endProcessMsg(msg);
74 20366 : }
75 :
76 : /// @brief Clears information whether an error occurred previously
77 75743 : void clear(bool resetInformed = true) {
78 75743 : FXMutexLock locker(myLock);
79 75743 : MsgHandler::clear(resetInformed);
80 75743 : }
81 :
82 : /// @brief Adds a further retriever to the instance responsible for a certain msg type
83 43626 : void addRetriever(OutputDevice* retriever) {
84 43626 : FXMutexLock locker(myLock);
85 43626 : MsgHandler::addRetriever(retriever);
86 43626 : }
87 :
88 : /// @brief Removes the retriever from the handler
89 314627 : void removeRetriever(OutputDevice* retriever) {
90 314627 : FXMutexLock locker(myLock);
91 314627 : MsgHandler::removeRetriever(retriever);
92 314627 : }
93 :
94 : protected:
95 41286 : bool aggregationThresholdReached(const std::string& format) {
96 41286 : FXMutexLock locker(myLock);
97 82572 : return MsgHandler::aggregationThresholdReached(format);
98 : }
99 :
100 : private:
101 : /// @brief standard constructor
102 93924 : MsgHandlerSynchronized(MsgType type) :
103 93924 : MsgHandler(type), myLock(true) {
104 93924 : }
105 :
106 : /// @brief destructor
107 93898 : ~MsgHandlerSynchronized() {
108 93898 : }
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 : };
|