anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, Infosys Ltd. |
| 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 | #include <iostream> |
| 18 | #include "controlBlock.h" |
| 19 | #include "actionTable.h" |
| 20 | #include "state.h" |
| 21 | #include "log.h" |
| 22 | |
| 23 | using namespace std; |
| 24 | |
| 25 | namespace SM |
| 26 | { |
| 27 | |
| 28 | ActionTable::ActionTable() |
| 29 | :nextStatep(NULL) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | ActionTable::~ActionTable() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | ActStatus ActionTable::executeActions(ControlBlock& cb) |
| 38 | { |
| 39 | ActStatus rt = PROCEED; |
| 40 | for(auto it = actionsQ.begin(); it != actionsQ.end(); it++) |
| 41 | { |
| 42 | ActStatus ret = (*it)(cb); |
| 43 | if(PROCEED != ret) |
| 44 | { |
| 45 | // TODO: error handling |
| 46 | break; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if (PROCEED == rt && |
| 51 | nextStatep != NULL) |
| 52 | { |
| 53 | cb.setNextState(nextStatep); |
| 54 | } |
| 55 | |
| 56 | return rt; |
| 57 | } |
| 58 | |
| 59 | void ActionTable::addAction(ActionPointer act) |
| 60 | { |
| 61 | actionsQ.push_back(act); |
| 62 | } |
| 63 | |
| 64 | void ActionTable::setNextState(State* st) |
| 65 | { |
| 66 | nextStatep = st; |
| 67 | } |
| 68 | |
| 69 | void ActionTable::display() |
| 70 | { |
| 71 | if(NULL != nextStatep) |
| 72 | { |
| 73 | log_msg(LOG_DEBUG,"\nnext State : - %d \n",nextStatep->getStateId()); |
| 74 | } |
| 75 | } |
| 76 | } |