Line data Source code
1 : /* 2 : * This file is part of PTN Engine 3 : * 4 : * Copyright (c) 2017 Eduardo Valgôde 5 : * Copyright (c) 2021 Kale Evans 6 : * Copyright (c) 2023-2024 Eduardo Valgôde 7 : * 8 : * Licensed under the Apache License, Version 2.0 (the "License"); 9 : * you may not use this file except in compliance with the License. 10 : * You may obtain a copy of the License at 11 : * 12 : * http://www.apache.org/licenses/LICENSE-2.0 13 : * 14 : * Unless required by applicable law or agreed to in writing, software 15 : * distributed under the License is distributed on an "AS IS" BASIS, 16 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 : * See the License for the specific language governing permissions and 18 : * limitations under the License. 19 : */ 20 : 21 : #include "PTN_Engine/PTN_EngineImpProxy.h" 22 : 23 : namespace ptne 24 : { 25 : using namespace std; 26 : 27 56 : PTN_Engine::PTN_EngineImpProxy::PTN_EngineImpProxy(ACTIONS_THREAD_OPTION actionsThreadOption) 28 56 : : m_ptnEngineImp(actionsThreadOption) 29 : { 30 56 : setActionsThreadOption(actionsThreadOption); 31 56 : } 32 : 33 56 : PTN_Engine::PTN_EngineImpProxy::~PTN_EngineImpProxy() 34 : { 35 56 : m_ptnEngineImp.stop(); 36 56 : } 37 : 38 1 : void PTN_Engine::PTN_EngineImpProxy::setEventLoopSleepDuration(const EventLoopSleepDuration sleepDuration) 39 : { 40 1 : unique_lock guard(m_mutex); 41 1 : m_ptnEngineImp.setEventLoopSleepDuration(sleepDuration); 42 1 : } 43 : 44 2 : PTN_Engine::EventLoopSleepDuration PTN_Engine::PTN_EngineImpProxy::getEventLoopSleepDuration() const 45 : { 46 2 : shared_lock guard(m_mutex); 47 4 : return m_ptnEngineImp.getEventLoopSleepDuration(); 48 2 : } 49 : 50 10 : void PTN_Engine::PTN_EngineImpProxy::addArc(const ArcProperties &arcProperties) 51 : { 52 10 : unique_lock guard(m_mutex); 53 10 : m_ptnEngineImp.addArc(arcProperties); 54 10 : } 55 : 56 2 : void PTN_Engine::PTN_EngineImpProxy::removeArc(const ArcProperties &arcProperties) 57 : { 58 2 : unique_lock guard(m_mutex); 59 2 : m_ptnEngineImp.removeArc(arcProperties); 60 2 : } 61 : 62 1 : void PTN_Engine::PTN_EngineImpProxy::clearNet() 63 : { 64 1 : unique_lock guard(m_mutex); 65 1 : m_ptnEngineImp.clearNet(); 66 1 : } 67 : 68 12 : vector<PlaceProperties> PTN_Engine::PTN_EngineImpProxy::getPlacesProperties() const 69 : { 70 12 : shared_lock guard(m_mutex); 71 24 : return m_ptnEngineImp.getPlacesProperties(); 72 12 : } 73 : 74 13 : vector<TransitionProperties> PTN_Engine::PTN_EngineImpProxy::getTransitionsProperties() const 75 : { 76 13 : shared_lock guard(m_mutex); 77 26 : return m_ptnEngineImp.getTransitionsProperties(); 78 13 : } 79 : 80 133 : void PTN_Engine::PTN_EngineImpProxy::createTransition(const TransitionProperties &transitionProperties) 81 : { 82 133 : unique_lock guard(m_mutex); 83 133 : m_ptnEngineImp.createTransition(transitionProperties); 84 133 : } 85 : 86 180 : void PTN_Engine::PTN_EngineImpProxy::createPlace(const PlaceProperties &placeProperties) 87 : { 88 180 : unique_lock guard(m_mutex); 89 183 : m_ptnEngineImp.createPlace(placeProperties); 90 180 : } 91 : 92 11 : void PTN_Engine::PTN_EngineImpProxy::registerAction(const string &name, const ActionFunction &action) 93 : { 94 11 : unique_lock guard(m_mutex); 95 11 : m_ptnEngineImp.registerAction(name, action); 96 11 : } 97 : 98 12 : void PTN_Engine::PTN_EngineImpProxy::registerCondition(const string &name, const ConditionFunction &condition) 99 : { 100 12 : unique_lock guard(m_mutex); 101 12 : m_ptnEngineImp.registerCondition(name, condition); 102 12 : } 103 : 104 38 : void PTN_Engine::PTN_EngineImpProxy::execute(const bool log, ostream &o) 105 : { 106 38 : unique_lock guard(m_mutex); 107 38 : m_ptnEngineImp.execute(log, o); 108 38 : } 109 : 110 41 : void PTN_Engine::PTN_EngineImpProxy::stop() 111 : { 112 41 : unique_lock guard(m_mutex); 113 41 : m_ptnEngineImp.stop(); 114 41 : } 115 : 116 179 : size_t PTN_Engine::PTN_EngineImpProxy::getNumberOfTokens(const string &place) const 117 : { 118 179 : shared_lock guard(m_mutex); 119 357 : return m_ptnEngineImp.getNumberOfTokens(place); 120 179 : } 121 : 122 2468 : void PTN_Engine::PTN_EngineImpProxy::incrementInputPlace(const string &place) 123 : { 124 2468 : unique_lock guard(m_mutex); 125 2468 : m_ptnEngineImp.incrementInputPlace(place); 126 2468 : } 127 : 128 0 : void PTN_Engine::PTN_EngineImpProxy::printState(ostream &o) const 129 : { 130 0 : shared_lock guard(m_mutex); 131 0 : m_ptnEngineImp.printState(o); 132 0 : } 133 : 134 12 : bool PTN_Engine::PTN_EngineImpProxy::isEventLoopRunning() const 135 : { 136 12 : shared_lock guard(m_mutex); 137 24 : return m_ptnEngineImp.isEventLoopRunning(); 138 12 : } 139 : 140 63 : void PTN_Engine::PTN_EngineImpProxy::setActionsThreadOption(const ACTIONS_THREAD_OPTION actionsThreadOption) 141 : { 142 63 : unique_lock guard(m_mutex); 143 63 : m_ptnEngineImp.setActionsThreadOption(actionsThreadOption); 144 63 : } 145 : 146 4 : PTN_Engine::ACTIONS_THREAD_OPTION PTN_Engine::PTN_EngineImpProxy::getActionsThreadOption() const 147 : { 148 4 : shared_lock guard(m_mutex); 149 8 : return m_ptnEngineImp.getActionsThreadOption(); 150 4 : } 151 : 152 : } // namespace ptne