rtop
rtop_v0_1.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <thread>
3 #include "rtop_logger.h"
4 #include "columns.h"
5 #include "mem_func.h"
6 #include <stdexcept>
7 #include "fileio.h"
8 
10 extern src::severity_logger< severity_level > lg;
11 extern logSpacer log_spacer;
12 
14 
18 int main(int argc, char* argv[])
19 {
20  // checks for correct number of arguments
21  if (argc <2)
22  {
23  std::cerr<<"error!\n";
24  std::cerr<<"usage: ./out confile_file or ./out config_file log_level\n";
25  return 1;
26  }
27 
28  // initialize logging. using boost_log library for logging
29  // if logging level not provided, set to "fatal"
30  if (argc == 2)
31  {
32  std::cerr<<"setting log level to fatal\n";
33  init_logging("fatal");
34  BOOST_LOG_SEV(lg, debug)<<"logging setup complete, level: "<<"fatal";
35 
36  }
37  if (argc == 3)
38  {
39  init_logging(argv[2]);
40  BOOST_LOG_SEV(lg, debug)<<"logging setup complete, level: "<<argv[2];
41  }
42 
43  try
44  {
45  // initialize system by loading GUI details from the XML config file.
46  rtop::XMLTree object_tree(argv[1]); // 1st pass over XML, creates GUI and non-GUI objects
47  rtop::ScreenManager* screen = object_tree.instantiate(); // 2nd pass over XML, populates objects with information
48  BOOST_LOG_SEV(lg, debug)<<"XML LOADED";
49  rtop::Columns* pclms = rtop::funcPDict.getColumn(303); // TODO: constant should not be here, handle it in getColumn
50  screen->refresh(); /***DO NOT DELETE, REQUIRED FOR FIRST TIME LOADING OF PROCESS PROP FROM ACTIVEPROC PANEL***********/
51 
52  // start key_input thread
53  BOOST_LOG_SEV(lg, debug)<<"Starting key capture";
54  std::thread t_key_input(&rtop::ScreenManager::start, screen);
55 
56  // main loop, responsible for refreshing the screen every POLL_INTVL milliseconds
57  while(1)
58  {
59  if (rtop::EXIT) // if EXIT global has been set to true, exit the loop
60  break;
61  pclms->read(); // read /proc database and store information in ProcDb
62  screen->refresh(); // refreshes screem by forcing ProcViewPanel to important information from ProcDb into ProcViewPanel::columns
63  BOOST_LOG_SEV(lg, debug)<<log_spacer<<"main, Screen refreshed";
64  rtop::milliSleep(rtop::POLL_INTVL); // put main thread to sleep
65  BOOST_LOG_SEV(lg, debug)<<"waking up after "<<rtop::POLL_INTVL<<" msec";
66  }
67  t_key_input.join(); // wait for key input thread to finish running.
68  delete(screen); // invokes ScreenManager destructor
69  }
70  catch(std::runtime_error e)
71  {
72  BOOST_LOG_SEV(lg, error)<<e.what();
73  std::cerr<<e.what()<<std::endl;
74  }
75 
76  return 0;
77 }
78 
79 
src::severity_logger< severity_level > lg
Definition: rtop_logger.h:108
void read()
invokes ProcDb update based on properties currently on display in ProcViewPanel
Definition: columns.h:65
void init_logging(std::string sev_level)
sets up logging using Boost.Log library
Definition: rtop_logger.h:42
void milliSleep(int msec)
makes calling thread sleep for specified milliseconds
Definition: rtop_utils.h:106
stores references to UI and non-UI objects and their callbacks.
Definition: mem_func.h:31
ScreenManager * instantiate()
Definition: fileio.h:103
int main(int argc, char *argv[])
rtop entry point. Invoked as ./rtop config_file.xml [log_level]
Definition: rtop_v0_1.cpp:18
MemFuncPDict funcPDict
Definition: key_dict.h:20
logSpacer log_spacer
Definition: rtop_logger.h:186
Top Level UI object. Responsible to switching between views and capturing key input.
Definition: screen2.h:34
Columns * getColumn(int)
returns pointer to Columns object of given uuid
Definition: mem_func.h:172
enables indentation of logs for easy viewing
Definition: rtop_logger.h:118
int POLL_INTVL
Definition: params.h:8
void refresh()
refreshes screen
Definition: screen2.h:135
bool EXIT
Definition: params.h:9
void start()
Captures key input from screen.
Definition: screen2.h:113
parses config file
Definition: fileio.h:28
responsible for managing the flow of information between ProcViewPanel, ProcDb and ProcInfo
Definition: columns.h:16