blob: 007ba4399d57ff0a7f3548f513a63a76542b03fa [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
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 <string>
18#include <iostream>
19#include "state.h"
20#include "actionTable.h"
21#include "smTypes.h"
22#include "log.h"
23
24using namespace std;
25
26
27namespace SM
28{
29 State::State(State_e sID)
30 :stateID(sID),
31 eventToActionsMap()
32 {
33 }
34
35 State::~State()
36 {
37 }
38
39 void State::display()
40 {
41 for(auto& eventToActionsMapEntry : eventToActionsMap)
42 {
43 log_msg(LOG_DEBUG, "Event Id = %d \n", eventToActionsMapEntry.first);
44 ActionTable& act = eventToActionsMapEntry.second;
45 act.display();
46 }
47 }
48
49 ActStatus State::executeActions(Event_e evt,ControlBlock& cb)
50 {
51 EventToActionTableMap::iterator itr = eventToActionsMap.find(evt);
52
53 if (itr != eventToActionsMap.end())
54 {
55 ActionTable& actions_r = itr->second;
56 return actions_r.executeActions(cb);
57 }
58 else
59 return ActStatus::HALT;
60 }
61}