LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXThreadEvent.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 1 0.0 %
Date: 2024-04-28 15:39:05 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2004-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    MFXThreadEvent.h
      15             : /// @author  Mathew Robertson
      16             : /// @author  Daniel Krajzewicz
      17             : /// @author  Michael Behrisch
      18             : /// @date    2004-03-19
      19             : ///
      20             : //
      21             : /****************************************************************************/
      22             : #pragma once
      23             : #include <config.h>
      24             : 
      25             : #include "fxexdefs.h"
      26             : #include "MFXBaseObject.h"
      27             : 
      28             : namespace FXEX {
      29             : 
      30             : /**
      31             :  * :Description
      32             :  *
      33             :  *  Interthread communication object
      34             :  *
      35             :  *------------------------------------------------------------------
      36             :  *
      37             :  * Usage:
      38             :  *
      39             :  *  GUI_thread.h:
      40             :  *  ============
      41             :  *
      42             :  *  class MyGUI::FXWhatEver
      43             :  *  {
      44             :  *    // constructor
      45             :  *    MyGUI(...);
      46             :  *
      47             :  *    // message IDs
      48             :  *    enum {
      49             :  *    ID_THREAD_EVENT = FXWhatEver::ID_LAST,
      50             :  *    ID_LAST };
      51             :  *
      52             :  *    // message handler
      53             :  *    long onThreadEvent(FXObject*, FXSelector, void*);
      54             :  *
      55             :  *    // thread event object
      56             :  *   MFXThreadEvent m_threadEvent;
      57             :  *  };
      58             :  *
      59             :  *  GUI_thread.cpp:
      60             :  *  ==============
      61             :  *
      62             :  *  // message map
      63             :  *  FXDEFMAP(MyGUI, FXWhatEver) = {
      64             :  *    FXMAPFUNC(SEL_THREAD_EVENT, MyGUI::ID_THREAD_EVENT, MyGUI::onThreadEvent)
      65             :  *  };
      66             :  *
      67             :  *  // constructor
      68             :  *  MyGUI::MyGUI(...)
      69             :  *  {
      70             :  *    m_threadEvent.setTarget(this),
      71             :  *    m_threadEvent.setSelector(ID_THREAD_EVENT);
      72             :  *  }
      73             :  *
      74             :  *  // message handler
      75             :  *  long onThreadEvent(FXObject*, FXSelector, void*)
      76             :  *  {
      77             :  *    do something with the GUI
      78             :  *  }
      79             :  *
      80             :  *  Worker_thread.cpp:
      81             :  *  =================
      82             :  *
      83             :  *  int threadFunction(...)
      84             :  *  {
      85             :  *    MFXThreadEvent* pThreadEvent = (MFXThreadEvent*)(ptr);
      86             :  *
      87             :  *    while (not_finished) {
      88             :  *      // work hard
      89             :  *      ...
      90             :  *
      91             :  *      // wake up GUI
      92             :  *      if (something_happened_and_the_GUI_needs_to_know_it) {
      93             :  *        pThreadEvent.signal();
      94             :  *      }
      95             :  *    }
      96             :  *
      97             :  *    ...
      98             :  *  }
      99             :  *
     100             :  */
     101             : class /*FXAPI */MFXThreadEvent : public MFXBaseObject {
     102           0 :     FXDECLARE(MFXThreadEvent)
     103             : 
     104             : private:
     105             :     MFXThreadEventHandle event;
     106             : 
     107             : protected:
     108             :     MFXThreadEvent(const MFXThreadEvent&);
     109             :     MFXThreadEvent& operator=(const MFXThreadEvent&);
     110             : 
     111             : public:
     112             :     enum {
     113             :         ID_THREAD_EVENT = MFXBaseObject::ID_LAST,
     114             :         ID_LAST
     115             :     };
     116             : 
     117             : public:
     118             :     long onThreadSignal(FXObject*, FXSelector, void*);
     119             :     long onThreadEvent(FXObject*, FXSelector, void*);
     120             : 
     121             : public:
     122             :     /// Construct an object capable of signaling the main FOX event loop
     123             :     MFXThreadEvent(FXObject* tgt = NULL, FXSelector sel = 0);
     124             : 
     125             :     /**
     126             :      * Signal the event - using the SEL_THREAD FXSelector type
     127             :      *
     128             :      * This is meant to be called from the worker thread - it sends a mesage to
     129             :      * the target, which is in another thread.
     130             :      */
     131             :     void signal();
     132             : 
     133             :     /**
     134             :      * Signal the event - using the specified FXSelector
     135             :      *
     136             :      * This is meant to be called from the worker thread - it sends a mesage to
     137             :      * the target, which is in another thread.
     138             :      */
     139             :     void signal(FXuint seltype);
     140             : 
     141             :     /// destructor
     142             :     virtual ~MFXThreadEvent();
     143             : };
     144             : 
     145             : } // namespace FXEX

Generated by: LCOV version 1.14