/[svn]/qsampler/trunk/src/qsamplerMessages.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMessages.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2582 by capela, Fri May 30 20:58:26 2014 UTC revision 3357 by capela, Tue Oct 17 21:44:20 2017 UTC
# Line 1  Line 1 
1  // qsamplerMessages.cpp  // qsamplerMessages.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2017, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 34  Line 34 
34  #include <QDateTime>  #include <QDateTime>
35  #include <QIcon>  #include <QIcon>
36    
37  #if !defined(WIN32)  #if !defined(_WIN32)
38  #include <unistd.h>  #include <unistd.h>
39    #include <fcntl.h>
40  #endif  #endif
41    
42    
# Line 112  Messages::~Messages (void) Line 113  Messages::~Messages (void)
113  }  }
114    
115    
116    // Set stdout/stderr blocking mode.
117    bool Messages::stdoutBlock ( int fd, bool bBlock ) const
118    {
119    #if !defined(_WIN32)
120            const int iFlags = ::fcntl(fd, F_GETFL, 0);
121            const bool bNonBlock = bool(iFlags & O_NONBLOCK);
122            if (bBlock && bNonBlock)
123                    bBlock = (::fcntl(fd, F_SETFL, iFlags & ~O_NONBLOCK) == 0);
124            else
125            if (!bBlock && !bNonBlock)
126                    bBlock = (::fcntl(fd, F_SETFL, iFlags |  O_NONBLOCK) != 0);
127    #endif
128            return bBlock;
129    }
130    
131    
132  // Own stdout/stderr socket notifier slot.  // Own stdout/stderr socket notifier slot.
133  void Messages::stdoutNotify ( int fd )  void Messages::stdoutNotify ( int fd )
134  {  {
135  #if !defined(WIN32)  #if !defined(_WIN32)
136            // Set non-blocking reads, if not already...
137            const bool bBlock = stdoutBlock(fd, false);
138            // Read as much as is available...
139            QString sTemp;
140          char achBuffer[1024];          char achBuffer[1024];
141          const int cchBuffer = ::read(fd, achBuffer, sizeof(achBuffer) - 1);          const int cchBuffer = sizeof(achBuffer) - 1;
142          if (cchBuffer > 0) {          int cchRead = ::read(fd, achBuffer, cchBuffer);
143                  achBuffer[cchBuffer] = (char) 0;          while (cchRead > 0) {
144                  appendStdoutBuffer(achBuffer);                  achBuffer[cchRead] = (char) 0;
145                    sTemp.append(achBuffer);
146                    cchRead = (bBlock ? 0 : ::read(fd, achBuffer, cchBuffer));
147          }          }
148            // Needs to be non-empty...
149            if (!sTemp.isEmpty())
150                    appendStdoutBuffer(sTemp);
151  #endif  #endif
152  }  }
153    
# Line 148  void Messages::flushStdoutBuffer (void) Line 174  void Messages::flushStdoutBuffer (void)
174  {  {
175          if (!m_sStdoutBuffer.isEmpty()) {          if (!m_sStdoutBuffer.isEmpty()) {
176                  appendMessagesText(m_sStdoutBuffer);                  appendMessagesText(m_sStdoutBuffer);
177                  m_sStdoutBuffer.truncate(0);                  m_sStdoutBuffer.clear();
178          }          }
179  }  }
180    
# Line 164  void Messages::setCaptureEnabled ( bool Line 190  void Messages::setCaptureEnabled ( bool
190          // Flush current buffer.          // Flush current buffer.
191          flushStdoutBuffer();          flushStdoutBuffer();
192    
193  #if !defined(WIN32)  #if !defined(_WIN32)
194          // Destroy if already enabled.          // Destroy if already enabled.
195          if (!bCapture && m_pStdoutNotifier) {          if (!bCapture && m_pStdoutNotifier) {
196                  delete m_pStdoutNotifier;                  delete m_pStdoutNotifier;
# Line 283  void Messages::appendMessages ( const QS Line 309  void Messages::appendMessages ( const QS
309    
310  void Messages::appendMessagesColor ( const QString& s, const QString &c )  void Messages::appendMessagesColor ( const QString& s, const QString &c )
311  {  {
312          const QString& sText = QTime::currentTime().toString("hh:mm:ss.zzz") + ' ' + s;          const QString& sText
313                    = QTime::currentTime().toString("hh:mm:ss.zzz") + ' ' + s;
314          appendMessagesLine("<font color=\"" + c + "\">" + sText + "</font>");          appendMessagesLine("<font color=\"" + c + "\">" + sText + "</font>");
315          appendMessagesLog(sText);          appendMessagesLog(sText);
316  }  }

Legend:
Removed from v.2582  
changed lines
  Added in v.3357

  ViewVC Help
Powered by ViewVC