The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
FSMCallbackHolder.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
15#include <GaudiKernel/extends.h>
16#include <algorithm>
17#include <map>
18#include <vector>
19
20namespace Gaudi {
21
36 template <class BASE>
37 class FSMCallbackHolder : public extends<BASE, IFSMCallbackHolder> {
38
39 public:
42
44 m_callbacks[s].push_back( std::move( c ) );
45 }
46
48 return Parent::sysInitialize().andThen( [&]() { handleCallBacks( StateMachine::INITIALIZE ); } );
49 }
50 StatusCode sysStart() override {
51 return Parent::sysStart().andThen( [&]() { handleCallBacks( StateMachine::START ); } );
52 }
53 StatusCode sysStop() override {
54 return Parent::sysStop().andThen( [&]() { handleCallBacks( StateMachine::STOP ); } );
55 }
57 return Parent::sysFinalize().andThen( [&]() { handleCallBacks( StateMachine::FINALIZE ); } );
58 }
59
60 private:
62 std::for_each( m_callbacks[state].begin(), m_callbacks[state].end(),
63 []( IFSMCallbackHolder::CallBack const& c ) { c(); } );
64 }
65
66 std::map<StateMachine::Transition, std::vector<IFSMCallbackHolder::CallBack>> m_callbacks;
67 };
68
69} // namespace Gaudi
Helper class to implement the IFSMCallbackHolder interface.
StatusCode sysStop() override
extends< BASE, IFSMCallbackHolder > Parent
StatusCode sysFinalize() override
StatusCode sysInitialize() override
void registerCallBack(StateMachine::Transition s, IFSMCallbackHolder::CallBack c) override
std::map< StateMachine::Transition, std::vector< IFSMCallbackHolder::CallBack > > m_callbacks
void handleCallBacks(StateMachine::Transition state)
StatusCode sysStart() override
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
Transition
Allowed transitions between states.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
Interface defining a CallBack registration functionality based on the State Machine of Gaudi.
std::function< void()> CallBack