LCOV - code coverage report
Current view: top level - src/utils/foxtools - MsgHandlerSynchronized.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 34 34 100.0 %
Date: 2024-04-27 15:34:54 Functions: 10 11 90.9 %

          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       90025 :     static MsgHandler* create(MsgType type) {
      49       90025 :         return new MsgHandlerSynchronized(type);
      50             :     }
      51             : 
      52             :     /// @brief adds a new error to the list
      53       80409 :     void inform(std::string msg, bool addType = true) {
      54       80409 :         FXMutexLock locker(myLock);
      55      241227 :         MsgHandler::inform(msg, addType);
      56       80409 :     }
      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       19986 :     void beginProcessMsg(std::string msg, bool addType = true) {
      66       19986 :         FXMutexLock locker(myLock);
      67       59958 :         MsgHandler::beginProcessMsg(msg, addType);
      68       19986 :     }
      69             : 
      70             :     /// @brief Ends a process information
      71       19659 :     void endProcessMsg(std::string msg) {
      72       19659 :         FXMutexLock locker(myLock);
      73       58977 :         MsgHandler::endProcessMsg(msg);
      74       19659 :     }
      75             : 
      76             :     /// @brief Clears information whether an error occurred previously
      77       72514 :     void clear(bool resetInformed = true) {
      78       72514 :         FXMutexLock locker(myLock);
      79       72514 :         MsgHandler::clear(resetInformed);
      80       72514 :     }
      81             : 
      82             :     /// @brief Adds a further retriever to the instance responsible for a certain msg type
      83       41780 :     void addRetriever(OutputDevice* retriever) {
      84       41780 :         FXMutexLock locker(myLock);
      85       41780 :         MsgHandler::addRetriever(retriever);
      86       41780 :     }
      87             : 
      88             :     /// @brief Removes the retriever from the handler
      89      301116 :     void removeRetriever(OutputDevice* retriever) {
      90      301116 :         FXMutexLock locker(myLock);
      91      301116 :         MsgHandler::removeRetriever(retriever);
      92      301116 :     }
      93             : 
      94             : protected:
      95       30897 :     bool aggregationThresholdReached(const std::string& format) {
      96       30897 :         FXMutexLock locker(myLock);
      97       61794 :         return MsgHandler::aggregationThresholdReached(format);
      98             :     }
      99             : 
     100             : private:
     101             :     /// @brief standard constructor
     102       90025 :     MsgHandlerSynchronized(MsgType type) :
     103       90025 :         MsgHandler(type), myLock(true) {
     104       90025 :     }
     105             : 
     106             :     /// @brief destructor
     107       89993 :     ~MsgHandlerSynchronized() {
     108       89993 :     }
     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             : };

Generated by: LCOV version 1.14