1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MsgHandlerSynchronized.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Michael Behrisch
13 /// @author  Jakob Erdmann
14 /// @date    Tue, 17 Jun 2003
15 /// @version $Id$
16 ///
17 // Retrieves messages about the process and gives them further to output
18 /****************************************************************************/
19 #ifndef MsgHandlerSynchronized_h
20 #define MsgHandlerSynchronized_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #ifdef HAVE_FOX
29 #include <fx.h>
30 #endif
31 #include <string>
32 #include <vector>
33 #include <iostream>
34 #include <utils/common/MsgHandler.h>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class OutputDevice;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * MsgHandlerSynchronized
48  */
49 class MsgHandlerSynchronized : public MsgHandler {
50 public:
create(MsgType type)51     static MsgHandler* create(MsgType type) {
52         return new MsgHandlerSynchronized(type);
53     }
54 
55     /// @brief adds a new error to the list
56     void inform(std::string msg, bool addType = true);
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     void beginProcessMsg(std::string msg, bool addType = true);
66 
67     /// @brief Ends a process information
68     void endProcessMsg(std::string msg);
69 
70     /// @brief Clears information whether an error occurred previously
71     void clear();
72 
73     /// @brief Adds a further retriever to the instance responsible for a certain msg type
74     void addRetriever(OutputDevice* retriever);
75 
76     /// @brief Removes the retriever from the handler
77     void removeRetriever(OutputDevice* retriever);
78 
79 private:
80     /// @brief standard constructor
81     MsgHandlerSynchronized(MsgType type);
82 
83     /// @brief destructor
84     ~MsgHandlerSynchronized();
85 
86     /// @brief The lock for synchronizing all outputs using handlers of this class
87     static FXMutex myLock;
88 
89 private:
90     /// @brief invalid copy constructor
91     MsgHandlerSynchronized(const MsgHandlerSynchronized& s) = delete;
92 
93     /// @brief invalid assignment operator
94     MsgHandlerSynchronized& operator=(const MsgHandlerSynchronized& s) = delete;
95 };
96 
97 #endif
98 
99 /****************************************************************************/
100