LCOV - code coverage report
Current view: top level - src/MIDI_Interfaces - MIDI_Staller.hpp (source / functions) Hit Total Coverage
Test: 91b605873905a6fcb78324052c97dbac10849539 Lines: 10 10 100.0 %
Date: 2022-11-08 01:34:37 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <Settings/SettingsWrapper.hpp>
       4             : #if !DISABLE_PIPES
       5             : 
       6             : #include <AH/Settings/Warnings.hpp>
       7             : #include <Settings/NamespaceSettings.hpp>
       8             : #include <AH/STL/utility> // std::forward
       9             : 
      10             : AH_DIAGNOSTIC_WERROR()
      11             : 
      12             : BEGIN_CS_NAMESPACE
      13             : 
      14             : /// Struct that can cause a MIDI_Pipe to be stalled.
      15             : struct MIDIStaller {
      16         162 :     virtual ~MIDIStaller() = default;
      17             :     /// Get the staller's name for debugging purposes.
      18           1 :     virtual const char *getName() const { return "<?>"; };
      19             :     /// Call back that should finish any MIDI messages that are in progress, and
      20             :     /// un-stall the pipe or MIDI source as quickly as possible.
      21             :     virtual void handleStall() = 0;
      22             : 
      23             :     /// Get the staller's name for debugging purposes. Correctly deals with
      24             :     /// null pointers or eternal stallers.
      25             :     static const char *getNameNull(MIDIStaller *s);
      26             : };
      27             : 
      28             : /// Allocate a MIDIStaller that executes the given callback and deletes itself
      29             : /// when @ref MIDIStaller::handleStall is called.
      30             : /// @note   Don't lose the pointer! If you never call `handleStall`, the memory
      31             : ///         won't be deallocated.
      32             : template <class Callback>
      33           3 : auto makeMIDIStaller(Callback &&callback) -> MIDIStaller * {
      34             : 
      35             :     struct AutoCleanupMIDIStaller : MIDIStaller {
      36           3 :         AutoCleanupMIDIStaller(Callback &&callback) 
      37           3 :             : callback(std::forward<Callback>(callback)) {}
      38             : 
      39           3 :         void handleStall() override {
      40           3 :             callback(this);
      41           3 :             delete this;
      42           3 :         }
      43             : 
      44             :         Callback callback;
      45             :     };
      46           3 :     return new AutoCleanupMIDIStaller(std::forward<Callback>(callback));
      47             : }
      48             : 
      49             : END_CS_NAMESPACE
      50             : 
      51             : AH_DIAGNOSTIC_POP()
      52             : 
      53             : #else
      54             : 
      55             : BEGIN_CS_NAMESPACE
      56             : 
      57             : struct MIDIStaller {};
      58             : 
      59             : END_CS_NAMESPACE
      60             : 
      61             : #endif

Generated by: LCOV version 1.15