OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
PluginState.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
65
74
75#ifndef OPENSWMM_PLUGIN_STATE_HPP
76#define OPENSWMM_PLUGIN_STATE_HPP
77
78#include <cstdint>
79
80namespace openswmm {
81
86enum class PluginState : std::int32_t {
88 LOADED = 1,
94 CLOSED = 7,
95 ERROR = -1
96};
97
102inline const char* plugin_state_to_string(PluginState state) noexcept {
103 switch (state) {
105 return "UNLOADED";
107 return "LOADED";
109 return "INITIALIZED";
111 return "VALIDATED";
113 return "PREPARED";
115 return "UPDATING";
117 return "FINALIZED";
119 return "CLOSED";
121 return "ERROR";
122 default:
123 return "UNKNOWN";
124 }
125}
126
136 using PS = PluginState;
137 if (to == PS::ERROR)
138 return true; // any state can transition to ERROR
139 switch (from) {
140 case PS::UNLOADED:
141 return to == PS::LOADED;
142 case PS::LOADED:
143 return to == PS::INITIALIZED || to == PS::CLOSED;
144 case PS::INITIALIZED:
145 return to == PS::VALIDATED || to == PS::CLOSED;
146 case PS::VALIDATED:
147 return to == PS::PREPARED || to == PS::CLOSED;
148 case PS::PREPARED:
149 return to == PS::UPDATING || to == PS::FINALIZED;
150 case PS::UPDATING:
151 return to == PS::PREPARED;
152 case PS::FINALIZED:
153 return to == PS::CLOSED;
154 case PS::CLOSED:
155 return false;
156 case PS::ERROR:
157 return to == PS::CLOSED;
158 default:
159 return false;
160 }
161}
162
163} /* namespace openswmm */
164
165#endif /* OPENSWMM_PLUGIN_STATE_HPP */
@ CLOSED
Resources released.
Definition SimulationContext.hpp:278
@ INITIALIZED
Initial conditions applied.
Definition SimulationContext.hpp:273
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:86
@ CLOSED
Library closed and handle released.
Definition PluginState.hpp:94
@ FINALIZED
finalize() returned success; no more update() calls.
Definition PluginState.hpp:93
@ VALIDATED
validate() returned success.
Definition PluginState.hpp:90
@ PREPARED
prepare() returned success; ready to accept update() calls.
Definition PluginState.hpp:91
@ UNLOADED
Library not yet loaded (or was closed).
Definition PluginState.hpp:87
@ LOADED
Shared library opened via dlopen/LoadLibrary.
Definition PluginState.hpp:88
@ ERROR
Plugin is in an error state; not usable.
Definition PluginState.hpp:95
@ UPDATING
Currently executing an update() call (transient; not normally observed).
Definition PluginState.hpp:92
@ INITIALIZED
initialize() returned success.
Definition PluginState.hpp:89
Definition ExchangeLaw.hpp:60
bool plugin_state_transition_valid(PluginState from, PluginState to) noexcept
Query the standalone lifecycle transition policy without applying it.
Definition PluginState.hpp:135
const char * plugin_state_to_string(PluginState state) noexcept
Read the static spelling of one lifecycle enum.
Definition PluginState.hpp:102