Line data Source code
1 : // 2 : // Copyright 2024 OpenModelViewer Authors 3 : // 4 : // Licensed under the Apache License, Version 2.0 (the "License"); 5 : // you may not use this file except in compliance with the License. 6 : // You may obtain a copy of the License at 7 : // 8 : // http://www.apache.org/licenses/LICENSE-2.0 9 : // 10 : // Unless required by applicable law or agreed to in writing, software 11 : // distributed under the License is distributed on an "AS IS" BASIS, 12 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : // See the License for the specific language governing permissions and 14 : // limitations under the License. 15 : // 16 : 17 : #pragma once 18 : 19 : #include "openmodelviewer/core/lifecycle/istartable.hpp" 20 : #include "openmodelviewer/core/lifecycle/istoppable.hpp" 21 : 22 : namespace openmodelviewer::core::lifecycle 23 : { 24 : /** 25 : * @brief Interface for autonomous runtime components. 26 : * 27 : * Represents a component that can be started and stopped independently, 28 : * and maintains its own execution flow � typically on a dedicated thread. 29 : * 30 : * IRunnable abstracts away how the component works internally: once started, 31 : * it is expected to operate asynchronously or autonomously until stopped. 32 : * 33 : * This interface is purely behavioral and does not imply any resource allocation responsibility. 34 : */ 35 : class IRunnable : public IStartable, public IStoppable 36 : { 37 : public: 38 181 : virtual ~IRunnable() = default; 39 : 40 : /** 41 : * @brief Starts the component. 42 : * 43 : * @return true if the component started successfully. 44 : */ 45 : virtual bool start() override = 0; 46 : 47 : /** 48 : * @brief Stops the runtime behavior of the component. 49 : */ 50 : virtual void stop() override = 0; 51 : 52 : /** 53 : * @brief Returns whether the component is currently running. 54 : * 55 : * @return true if the component has been started and is still active. 56 : */ 57 : virtual bool isRunning() const noexcept = 0; 58 : }; 59 : } // namespace openmodelviewer::core::lifecycle