blob: 7591a1a6e312d8fa2ac27eed17e41e307e7f89d4 [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#ifndef CONTROLBLOCK_H_
18#define CONTROLBLOCK_H_
19
20#include <mutex>
21#include <queue>
22#include <deque>
23#include <stdint.h>
24#include <time.h>
25#include "permDataBlock.h"
26#include <smTypes.h>
27#include "tempDataBlock.h"
28
29class Event;
30class State;
31
32using namespace std;
33
34namespace SM
35{
36 typedef struct debugEventInfo
37 {
38 Event_e event;
39 State_e state;
40 time_t evt_time;
41
42 debugEventInfo(Event_e evt, State_e st, time_t t)
43 {
44 event = evt;
45 state = st;
46 evt_time = t;
47 }
48
49 }debugEventInfo;
50
51 class Event;
52 class State;
53 class ControlBlock
54 {
55 public:
56 static const unsigned short MAX_FAST_BLOCK_IDX = 5;
57 static uint32_t controlBlockArrayIdx;
58
59 ControlBlock();
60 virtual ~ControlBlock();
61
62 void reset();
63
64 uint32_t getCBIndex();
65
66 void addEventToProcQ(Event &event);
67 bool getCurrentEvent(Event &evt);
68
69 State* getCurrentState();
70 void setNextState(State* state);
71
72 PermDataBlock* getFastAccessBlock(unsigned short idx) const;
73 void setFastAccessBlock(PermDataBlock* pdb_p, unsigned short idx);
74
75 PermDataBlock* getPermDataBlock() const;
76 void setPermDataBlock(PermDataBlock* pdb_p);
77
78 TempDataBlock* getTempDataBlock() const;
79 void setTempDataBlock(TempDataBlock* tdb_p);
80 void setCurrentTempDataBlock(TempDataBlock* tdb_p);
81
82 void addDebugInfo(debugEventInfo& eventInfo);
83 inline deque<debugEventInfo> getDebugInfoQueue()const
84 {
85 return debugEventInfoQ;
86 }
87
88 void* getMsgData()
89 {
90 return data_p;
91 }
92
93 void setMsgData(void* ptr)
94 {
95 data_p = ptr;
96 }
97
98 void setControlBlockState(ControlBlockState state);
99 ControlBlockState getControlBlockState();
100
101 bool isInProcQueue();
102 void setProcQueueFlag(bool flag);
103
104 virtual void display();
105
106 private:
107 std::mutex mutex_m;
108 const uint32_t cbIndex_m;
109 ControlBlockState cbState_m;
110
111 // deallocated once the event is processed
112 void* data_p;
113
114 PermDataBlock* pdb_mp;
115 PermDataBlock* fadb_mpa[MAX_FAST_BLOCK_IDX];
116 TempDataBlock* tdb_mp;
117
118 queue<Event> eventQ;
119
120 deque<debugEventInfo> debugEventInfoQ;
121 bool inProcQueue_m;
122 };
123}
124#endif /* CONTROLBLOCK_H_ */