rtop
view2.h
Go to the documentation of this file.
1 #include <ncurses.h>
2 #include <panel.h>
3 #include <menu.h>
4 #include <vector>
5 #include <utility>
6 #include <mutex>
7 
8 #ifndef _VIEW_H_
9 #define _VIEW_H_
10 #include "rtop_logger.h"
11 #include "panel2.h"
12 
13 extern src::severity_logger<severity_level> lg;
14 extern logSpacer log_spacer;
15 
16 namespace rtop
17 {
18 
19  extern MapOfKeyDicts mapKeyDict;
20  extern MemFuncPDict funcPDict;
21 
23 
30  class View
31  {
32  private:
33  int uuid;
35  WINDOW* win;
39  std::vector<SimplePanelData*> panels;
41  std::vector<std::pair<int, int>> panels_yx;
47  bool hidden;
57  std::map<SimplePanelData*, std::pair<SimplePanelData*, SimplePanelData*>> neighbourhood;
59  std::mutex view_mutex;
60  public:
61  View(int);
62  int uUid() const{return uuid;}
63  void resolveKey(int);
64  void refresh();
65  void show();
66  void hide();
67  friend class XMLTree;
68  };
69 
71  View::View(int id): uuid{id}
72  {
73 
74  }
75 
77 
83  void View::resolveKey(int ch)
84  {
86  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"--> View-"<<uuid<<"_resolveKey::";
87  (mapKeyDict.getKeyDict(smKeys.currState())).resolve(ch); // carried out actions may update View's Panel Statemachine and Key StateMachine
88 
89  // if Panel SM report panel change
90  if(smPanels.isChanged())
91  {
93  prev_panel->selectionOff(); // set previous panel's selected item color to basic_color_pair
94  prev_panel->resolveKey(ch); // pass on key input to previous panel for processing
95  curr_panel = funcPDict.getPanel(smPanels.currState()); // update the pointer to current panel
96  curr_panel->selectionOn(); // set new (current) panel's selected item color to selection_color_pair
97  }
98  curr_panel->resolveKey(ch); // pass on key input to current panel (potentially new) for processing
99  refresh(); // refreshes the view, and makes any children panels' changes visible on screen
100  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"<-- View-"<<uuid<<"_resolveKey::";
102  }
103 
105 
110  {
111  log_spacer.addSpace();
112  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"--> View-"<<uuid<<"_refresh::";
113  view_mutex.lock(); // acquire lock
114 
115  // perform actions to hide/show panels contained in the view
116  if (!hidden) // to show
117  {
118  // iterate over all contained panel data strutures
119  for(int i=0; i<panels.size(); i++)
120  {
121  panels[i]->show(); // show the panel
122  panels[i]->moveTo(panels_yx[i].first, panels_yx[i].second); // move panel's window to its location in view's window
123  panels[i]->refresh(); // refresh panel to update menu contents
124 
125  // set panels left/right neighbours in the view
126  for(auto pos: neighbourhood)
127  {
128  (pos.first)->setLeftNbr((pos.second).first);
129  (pos.first)->setRightNbr((pos.second).second);
130  }
131  }
132  // set current panel's to be selected
134  }
135  else // to hide
136  {
137  // iterate over all contained panel data structures
138  for(auto panel: panels)
139  {
140  panel->hide(); // hide the panel
141  panel->selectionOff(); // de-select all the panels
142  panel->Top(); // reset selected item to top of menu
143  }
144  smKeys.reset(); // reset view's Key Statemachine
145  smPanels.reset(); // reset view's Panel Statemachine
146  curr_panel = funcPDict.getPanel(smPanels.currState()); // update the current panel based on start state of Panel statemachine
147  }
148  wrefresh(win); // refresh view's window for changes to take effect in all children windows
149  view_mutex.unlock();
150  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"<-- View-"<<uuid<<"_refresh::";
152  }
153 
155  void View::show()
156  {
158  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"--> View-"<<uuid<<"_show::";
159  hidden = false;
160  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"<-- View-"<<uuid<<"_show::";
162  }
163 
165  void View::hide()
166  {
168  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"--> View-"<<uuid<<"_hide::";
169  hidden = true;
170  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"<-- View-"<<uuid<<"_hide::";
172  }
173 
174 } // namespace rtop
175 
176 #endif // _VIEW_H_
void hide()
sets view to hidden
Definition: view2.h:165
std::mutex view_mutex
mutex for accessing View::refresh
Definition: view2.h:59
int editing_color_pair
index of color_pair used for selected menu item in edit mode
Definition: view2.h:49
MapOfKeyDicts mapKeyDict
global variable for accessing key dictionaries by their uuid
Definition: key_dict.h:175
int uuid
Definition: view2.h:33
WINDOW * win
pointer to window associated with the view, contained panels' windows are derived from it
Definition: view2.h:35
SimplePanelData * curr_panel
pointer to current panel's (Browse/Edit Panel) data structure
Definition: view2.h:37
int uUid() const
Definition: view2.h:62
std::vector< std::pair< int, int > > panels_yx
vector of contained panels' window positions within view window
Definition: view2.h:41
void show()
sets view to visible
Definition: view2.h:155
bool isChanged() const
returns true if prev_state and curr_state are different
Definition: sm.h:52
logSpacer log_spacer
Definition: rtop_logger.h:186
StateMachine smKeys
Keys statemachine.
Definition: view2.h:43
src::severity_logger< severity_level > lg
Definition: rtop_logger.h:108
virtual void selectionOn()
mock
Definition: panel2.h:83
std::vector< SimplePanelData * > panels
vector of pointers to panel data structures corresponding to panels contained in the view
Definition: view2.h:39
int currState() const
returns current state
Definition: sm.h:48
int prevState() const
returns previous state
Definition: sm.h:50
int basic_color_pair
index of color_pair used for non-selected menu items
Definition: view2.h:53
MemFuncPDict funcPDict
Definition: key_dict.h:20
2nd level UI object. Responsible for switching between panels and resolving key input
Definition: view2.h:30
SimplePanelData * getPanel(int)
returns pointer to SimplePanelData object of given uuid
Definition: mem_func.h:199
void refresh()
refreshes view
Definition: view2.h:109
int header_color_pair
index of color_pair used for panel header
Definition: view2.h:55
void delSpace()
deletes one white-space from white-space string corresponding to invoking thread
Definition: rtop_logger.h:151
void addSpace()
adds one white-space to white-space string corresponding to invoking thread
Definition: rtop_logger.h:135
View(int)
View Constructor.
Definition: view2.h:71
KeyDict getKeyDict(int)
Definition: key_dict.h:154
int selection_color_pair
index of color_pair used for selected menu item in non-edit mode
Definition: view2.h:51
bool hidden
indicates if view is hidden/visible
Definition: view2.h:47
void reset()
resets state machine into base state as specified in transition table tuple entry (base_state,...
Definition: sm.h:68
virtual void selectionOff()
mock
Definition: panel2.h:85
enables indentation of logs for easy viewing
Definition: rtop_logger.h:118
StateMachine smPanels
Panel statemachine.
Definition: view2.h:45
std::map< SimplePanelData *, std::pair< SimplePanelData *, SimplePanelData * > > neighbourhood
dictionary storing pair of pointers to panel data structures corresponding to left/right neighbour pa...
Definition: view2.h:57
Base class in heirarchy of UI objects responsible to storing the content associated with a panel and ...
Definition: panel2.h:34
void resolveKey(int)
resolves the key input at View level
Definition: view2.h:83
statemachine that uses integer corresponding to object uuids to represent states
Definition: sm.h:20
parses config file
Definition: fileio.h:28
Definition: action.h:7
virtual void resolveKey(int)
mock
Definition: panel2.h:113