FACT++  1.0
void WindowLog::WriteBuffer ( )
private

This is the function which writes the stream physically to a device. If you want to add a new device this must be done here.

If the backlog is enabled, the contents are put into the backlog. if fWindow is NULL the contents are flushed to cout, otherwise to the window defined by fWindow.

In addition the contents are flushed to the log-file if open. If fIsNull is true any output on the screen (cout or fWindow) is suppressed.

Todo:
Truncate the backlog

Definition at line 165 of file WindowLog.cc.

References reset().

166 {
167  // Store the number of characters in the buffer which should be flushed
168  const int len = fPPtr - fBase;
169 
170  // restart writing to the buffer at its first char
171  fPPtr = fBase;
172 
173  // If the is nothing to output, we are done
174  if (len<=0)
175  return;
176 
177  // FIXME: Truncate backlog!
178 
179  // If fWindow is set, output everything to the window, otherwise
180  // to cout
181  if (!fIsNull)
182  {
183  if (fWindow)
184  {
185  fMuxWindow.lock();
186  if (!fIsNull)
187  {
188  const string sout = string(fBase, len);
189  wprintw(fWindow, "%s", sout.c_str());
190  }
191  // If the stream got flushed due to a line break
192  // reset all attributes
193  if (fBase[len-1]=='\n')
194  wattrset(fWindow, 0);
195  fMuxWindow.unlock();
196  }
197  else
198  {
199  fMuxCout.lock();
200  cout.write(fBase, len);// << sout;
201  // If the stream got flushed due to a line break
202  // reset all attributes
203  if (fBase[len-1]=='\n')
204  cout << "\033[0m";
205  cout.flush();
206  fMuxCout.unlock();
207  }
208  }
209 
210  // Add the buffer to the backlog
211  if (fEnableBacklog)
212  {
213  fMuxBacklog.lock();
214  fBacklog.insert(fBacklog.end(), fBase, fBase+len);
215 
216  // If the stream got flushed due to a line break
217  // add the reset of all attributes to the backlog
218  if (fBase[len-1]=='\n')
219  {
220  if (!fWindow)
221  {
222  const char *reset = "\033[0m";
223  fBacklog.insert(fBacklog.end(), reset, reset+4);
224 
225  }
226  else
227  fAttributes[fBacklog.size()] = -1;
228  }
229  fMuxBacklog.unlock();
230  }
231 
232  fQueueFile.emplace(fBase, len);
233  /*
234  // Output everything also to the log-file
235  fMuxFile.lock();
236  fLogFile << sout;
237  //fLogFile.flush();
238  fMuxFile.unlock();
239  */
240  // If we are flushing because of an EOL, we reset also all attributes
241 }
Queue< std::string > fQueueFile
Mutex securing output to fWindow.
Definition: WindowLog.h:78
std::vector< char > fBacklog
Pointer to an ncurses Window.
Definition: WindowLog.h:65
bool fEnableBacklog
Switch to toggle off physical output to the screen.
Definition: WindowLog.h:71
std::mutex fMuxCout
Mutex securing file access.
Definition: WindowLog.h:75
char * fPPtr
Buffer to store the data in.
Definition: WindowLog.h:60
WINDOW * fWindow
Pointer to end of buffer.
Definition: WindowLog.h:63
std::map< int, int > fAttributes
Backlog storage.
Definition: WindowLog.h:66
std::mutex fMuxBacklog
Switch to toggle storage in the backlog on or off.
Definition: WindowLog.h:73
bool fIsNull
Stream for redirection to a log-file.
Definition: WindowLog.h:70
char fBase[fgBufferSize+1]
Definition: WindowLog.h:59
std::mutex fMuxWindow
Mutex securing output to cout.
Definition: WindowLog.h:76
void reset(S &s)
Definition: ByteOrder.h:13

+ Here is the call graph for this function: