ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RealTime2.cxx
Go to the documentation of this file.
1 
5 #include "RealTime2.h"
6 
8 
9 // cannot make a namespace ?? unamed to try
10 // unamed bad idea, make global better like this, not sure
11 bool RealTime2::status_rt = false;
12 RealTime2* RealTime2::frealtime = NULL;
13 
14 RealTime2* RealTime2::getInstance()
15 {
16 #ifdef DEBUG_CONT_FRAME
17  std::cout << "RealTime2::getInstance() " << std::endl;
18 #endif
19  if ( status_rt )
20  return frealtime;
21  else {
22  frealtime = new RealTime2();
23  status_rt = true;
24  return frealtime;
25  }
26 }
27 
29 {
30  if ( !status_rt ) {
31  std::cout << "RealTime::killInstance, but has not been run, nothing to do " << std::endl;
32  return;
33  }
34  else {
35  delete frealtime;
36  frealtime = 0;
37  status_rt = false;
38  }
39 }
40 
41 void RealTime2::SetMessage( std::vector<std::string> & message ) {
42 #ifdef DEBUG_CONT_FRAME
43  std::cout << "RealTime2::ListMessages push back a new message " << std::endl;
44 #endif
45  // insert new element at the end
46  //need to protect here ?
47  //boost::lock_guard automatically calls lock() and unlock() inside its constructor and destructor, respectively.
48  // destructed automatically on exit of the function
49  boost::lock_guard<boost::mutex> lock(mutex);
50  ListMessages.push_back( message );
51 #ifdef DEBUG_CONT_FRAME
52  std::cout << "Size of the list " << ListMessages.size() << std::endl;
53 #endif
54 }
55 
56 std::vector<std::string> RealTime2::GetMessage() {
57 /*
58 #ifdef DEBUG_CONT_FRAME
59  std::cout << "RealTime2::GetMessage " << std::endl;
60 #endif
61 */
62  std::vector<std::string> message;
63  // if the list is empty return
64  if (! ListMessages.size() ) {
65 /*
66 #ifdef DEBUG_CONT_FRAME
67  std::cout << "The list is empty return" << std::endl;
68 #endif
69 */
70  return message;
71  }
72 
73  boost::lock_guard<boost::mutex> lock(mutex);
74  // access first element
75  message = ListMessages.front();
76  // remove the first element from the list
77  // need lock here as well
78  ListMessages.erase ( ListMessages.begin() );
79 #ifdef DEBUG_CONT_FRAME
80  std::cout << "return a non-empty message" << std::endl;
81 #endif
82  return message;
83 }
84 
85 //not needed should in controller or main/indicator frame
86 /*
87 void RealTime2::ConnectToGUI()
88 {
89 #ifdef DEBUG_CONT_FRAME
90  std::cout << "\n\t RealTime2::ConnectToGUI RealTime2 not used !!!! " << std::endl;
91 #endif
92  //Connect("Timeout()", "RealTime", 0, "UpdateStock()");
93  //Start(10000);
94  Start(100);
95 }
96 */
97 
98 // works, but still bound to thread
99 /*
100 void RealTime2::GetUpdate()
101 {
102 #ifdef DEBUG_CONT_FRAME
103  std::cout << "\n\t RealTime2::GetUpdate Emit TimeOut()" << std::endl;
104 #endif
105 
106  Timeout();
107  //Emit("TimeOut()");
108 }
109 */
boost::mutex mutex
Definition: RealTime2.h:66
void SetMessage(std::vector< std::string > &message)
deal with the list, fill and remove, protected by lock_guard
Definition: RealTime2.cxx:41
RealTime2 derives from TTimer.
ClassImp(CanvasStock) CanvasStock
Definition: CanvasStock.cxx:15
static RealTime2 * frealtime
private pointer to the real object
Definition: RealTime2.h:52
static bool status_rt
static variable for switching on/off the real time
Definition: RealTime2.h:50
static void killInstance()
public destructor
Definition: RealTime2.cxx:28
std::vector< std::string > GetMessage()
Definition: RealTime2.cxx:56
std::list< std::vector< std::string > > ListMessages
vector to conserve the messages, producer/consumer between SM and Main-Loop maybe to protect when wri...
Definition: RealTime2.h:62