From 95462fff10902a15a9ac6964236c08726553c310 Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Wed, 15 Sep 2010 23:04:23 -0400 Subject: [PATCH 1/8] add basic install target --- src/sse-pkg/util/sonataInfoDisplay/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/Makefile b/src/sse-pkg/util/sonataInfoDisplay/Makefile index bd7dfe7..4d43114 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/Makefile +++ b/src/sse-pkg/util/sonataInfoDisplay/Makefile @@ -12,7 +12,6 @@ SOURCES=main.cpp details.cpp utils.cpp screen.cpp components.cpp logfile.cpp OBJECTS1=$(SOURCES:.cpp=.o) OBJECTS=$(OBJECTS1:.c=.o) EXECUTABLE=sonataInfoDisplay -#LIBS = -lnsl -L/usr/lib -lm -lz -lpthread -lrt -lncurses LIBS = -L/usr/lib -lm -lz -lncurses all: $(SOURCES) $(EXECUTABLE) data docs @@ -21,7 +20,8 @@ $(BUILD_BIN)/$(EXECUTABLE): $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CXX) -o $@ $(OBJECTS) $(EXTRA_OBJS) $(LIBS) - # This should be moved to an 'install' target. + +install: $(EXECUTABLE) cp $(EXECUTABLE) $(BUILD_BIN) cp ./displayDemo $(BUILD_BIN) From a9274e10446983e5c8c815d5c5566f6d55842fdc Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Fri, 17 Sep 2010 18:03:57 -0400 Subject: [PATCH 2/8] Revert "add basic install target" This reverts commit 95462fff10902a15a9ac6964236c08726553c310. --- src/sse-pkg/util/sonataInfoDisplay/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/Makefile b/src/sse-pkg/util/sonataInfoDisplay/Makefile index 4d43114..bd7dfe7 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/Makefile +++ b/src/sse-pkg/util/sonataInfoDisplay/Makefile @@ -12,6 +12,7 @@ SOURCES=main.cpp details.cpp utils.cpp screen.cpp components.cpp logfile.cpp OBJECTS1=$(SOURCES:.cpp=.o) OBJECTS=$(OBJECTS1:.c=.o) EXECUTABLE=sonataInfoDisplay +#LIBS = -lnsl -L/usr/lib -lm -lz -lpthread -lrt -lncurses LIBS = -L/usr/lib -lm -lz -lncurses all: $(SOURCES) $(EXECUTABLE) data docs @@ -20,8 +21,7 @@ $(BUILD_BIN)/$(EXECUTABLE): $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CXX) -o $@ $(OBJECTS) $(EXTRA_OBJS) $(LIBS) - -install: $(EXECUTABLE) + # This should be moved to an 'install' target. cp $(EXECUTABLE) $(BUILD_BIN) cp ./displayDemo $(BUILD_BIN) From 895011b5b9ec54678d3927f81d24b4a49dc544af Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Sat, 18 Sep 2010 00:30:59 -0400 Subject: [PATCH 3/8] consolidate logfile processing in Logfile class --- .../util/sonataInfoDisplay/logfile.cpp | 32 ++++++++++++- src/sse-pkg/util/sonataInfoDisplay/logfile.h | 12 ++++- src/sse-pkg/util/sonataInfoDisplay/main.cpp | 47 ++++++++++--------- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp index aea6bd2..26b2c7a 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp @@ -43,10 +43,11 @@ fd_set Logfile::m_rfds; * * @param filename name of file */ -Logfile::Logfile(string filename) +Logfile::Logfile(string filename, Components *details) { m_logfile = filename; openLogfile(m_logfile); + m_details = details; } /* @@ -152,7 +153,8 @@ void Logfile::getLine(char *buf, unsigned long bufsize) * @return the number of file descriptors ready for reading */ -int Logfile::readLogfiles(list logfiles) +int Logfile::readLogfiles(list logfiles, int *linesSinceLastStatus, + time_t *lastStatusTime, Screen *screen) { FD_ZERO(&m_rfds); FD_SET(0, &m_rfds); @@ -176,6 +178,32 @@ int Logfile::readLogfiles(list logfiles) // Consider a delay by e.g. opting out of &m_rfds for n passes when at EOF? retVal = select(Logfile::m_maxFd + 1, &m_rfds, NULL, NULL, &tv); + for(it=logfiles.begin(); it != logfiles.end(); it++) + { + if(it->m_details != NULL) + { + char line[2048]; + + if(FD_ISSET(it->getFd(), &m_rfds)) + { + it->getLine(line, sizeof(line) - 1); + if(line[0] != 0 && it->m_details->addWithFilter(line)) + screen->paint(it->m_details); + (*linesSinceLastStatus)++; + memset(line, 0, sizeof(line)); + } + //FIXME: Hack--move to filter in some way? + if(*linesSinceLastStatus > 0 && + (int)(time(NULL) - *lastStatusTime) > 1) + { + *linesSinceLastStatus = 0; + *lastStatusTime = time(NULL); + it->m_details->addWithFilter("===================================="); + screen->paint(it->m_details); + } + } + } + return retVal; } diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.h b/src/sse-pkg/util/sonataInfoDisplay/logfile.h index 0ac4fae..aa28596 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.h +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.h @@ -40,6 +40,8 @@ #include #include #include +#include "components.h" +#include "screen.h" using namespace std; @@ -58,7 +60,7 @@ using namespace std; * * @param filename name of file */ - Logfile(string filename); + Logfile(string filename, Components *details); /** * Destructor @@ -88,7 +90,10 @@ using namespace std; * * @return the number of file descriptors ready for reading */ - static int readLogfiles(list logfiles); + static int readLogfiles(list logfiles, + int *linesSinceLastStatus, + time_t *lastStatusTime, + Screen *screen); /** * Returns file descriptor set for reads. @@ -117,6 +122,9 @@ using namespace std; /** File-descriptor set used for select() reads */ static fd_set m_rfds; + /** Input-line filter */ + Components *m_details; + /** * Open logfile. * diff --git a/src/sse-pkg/util/sonataInfoDisplay/main.cpp b/src/sse-pkg/util/sonataInfoDisplay/main.cpp index 884b98d..2dd2ef8 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/main.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/main.cpp @@ -44,8 +44,8 @@ #include "details.h" #include "utils.h" -#include "screen.h" -#include "components.h" +//#include "screen.h" +//#include "components.h" #include "logfile.h" #include @@ -70,7 +70,7 @@ int main(int argc, char **argv) string systemLogFileName = ""; string systemErrorFileName = ""; Screen screen; - char line[2048]; + // char line[2048]; list logfiles; Components componentDetails; @@ -90,9 +90,9 @@ int main(int argc, char **argv) systemLogFileName = argv[2]; systemErrorFileName = argv[3]; - Logfile systemStatusFile = Logfile(systemStatusFileName); - Logfile systemLogFile = Logfile(systemLogFileName); - Logfile systemErrorFile = Logfile(systemErrorFileName); + Logfile systemStatusFile = Logfile(systemStatusFileName, &componentDetails); + Logfile systemLogFile = Logfile(systemLogFileName, NULL); + Logfile systemErrorFile = Logfile(systemErrorFileName, NULL); logfiles.push_back(systemStatusFile); logfiles.push_back(systemLogFile); @@ -102,37 +102,38 @@ int main(int argc, char **argv) screen.init(); screen.screenResize(0); - time_t lastStatusTime = time(NULL);; + time_t lastStatusTime = time(NULL); int linesSinceLastStatus = 0; //Loop foever while(1) { - Logfile::readLogfiles(logfiles); + Logfile::readLogfiles(logfiles, &linesSinceLastStatus, &lastStatusTime, + &screen); // FIXME: Move all the stuff below out of main! // (Note the current clumsy use of Logfile::m_rfds.) // Process any data read from the status file. - if(FD_ISSET(systemStatusFile.getFd(), Logfile::getDescriptors())) - { - systemStatusFile.getLine(line, sizeof(line) - 1); - if(line[0] != 0 && componentDetails.addWithFilter(line)) - screen.paint(&componentDetails); - linesSinceLastStatus++; - memset(line, 0, sizeof(line)); - } +// if(FD_ISSET(systemStatusFile.getFd(), Logfile::getDescriptors())) +// { +// systemStatusFile.getLine(line, sizeof(line) - 1); +// if(line[0] != 0 && componentDetails.addWithFilter(line)) +// screen.paint(&componentDetails); +// linesSinceLastStatus++; +// memset(line, 0, sizeof(line)); +// } //The trigger for the end of a status screen paint is "===..." but sometimes //this does not arrive, so we have to force it. - if(linesSinceLastStatus > 0 && (int)(time(NULL) - lastStatusTime) > 1) - { - linesSinceLastStatus = 0; - lastStatusTime = time(NULL); - componentDetails.addWithFilter("===================================="); - screen.paint(&componentDetails); - } +// if(linesSinceLastStatus > 0 && (int)(time(NULL) - lastStatusTime) > 1) +// { +// linesSinceLastStatus = 0; +// lastStatusTime = time(NULL); +// componentDetails.addWithFilter("===================================="); +// screen.paint(&componentDetails); +// } //Process the log file if(FD_ISSET(systemLogFile.getFd(), Logfile::getDescriptors())) From 0e31fa8f9939bad6a39d8f1ad437d80403224c19 Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Wed, 29 Sep 2010 21:18:34 -0400 Subject: [PATCH 4/8] further consolidation into Logfile class --- .../util/sonataInfoDisplay/logfile.cpp | 29 ++++++++++--------- src/sse-pkg/util/sonataInfoDisplay/logfile.h | 7 ++--- src/sse-pkg/util/sonataInfoDisplay/main.cpp | 26 ++++++++--------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp index 26b2c7a..1bd538b 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp @@ -34,6 +34,7 @@ #include "logfile.h" +ino_t Logfile::m_inode = 0; // FIXME: Only static for testing. int Logfile::m_maxFd = 0; fd_set Logfile::m_rfds; @@ -70,7 +71,7 @@ void Logfile::openLogfile(string filename) m_fp = fopen(filename.c_str(), "a+"); if(m_fp == NULL) { - // Change to stderr? + // FIXME: actually exit, send this to stderr. fprintf(stdout," Could not open %s, EXITING.\n", filename.c_str()); } @@ -81,15 +82,14 @@ void Logfile::openLogfile(string filename) } struct stat stbuf; - if(fstat(m_fd, &stbuf) == 0) { - m_inode = stbuf.st_ino; - } - else - { - m_inode = -1; + Logfile::m_inode = stbuf.st_ino; } +// else +// { +// Logfile::m_inode = -1; +// } } /* @@ -105,7 +105,7 @@ void Logfile::checkRefresh() // The most likely reason the inode would be changed is if a new // logfile has been created. // If so, switch to reading the new file. - if (m_inode != stbuf.st_ino) + if (Logfile::m_inode != stbuf.st_ino) { //FIXME: Need exception handling. if(fclose(m_fp) == 0) @@ -153,9 +153,12 @@ void Logfile::getLine(char *buf, unsigned long bufsize) * @return the number of file descriptors ready for reading */ -int Logfile::readLogfiles(list logfiles, int *linesSinceLastStatus, - time_t *lastStatusTime, Screen *screen) +int Logfile::readLogfiles(list logfiles, + time_t *lastStatusTime, + Screen *screen) { + int linesSinceLastStatus = 0; + FD_ZERO(&m_rfds); FD_SET(0, &m_rfds); @@ -189,14 +192,14 @@ int Logfile::readLogfiles(list logfiles, int *linesSinceLastStatus, it->getLine(line, sizeof(line) - 1); if(line[0] != 0 && it->m_details->addWithFilter(line)) screen->paint(it->m_details); - (*linesSinceLastStatus)++; + linesSinceLastStatus++; memset(line, 0, sizeof(line)); } //FIXME: Hack--move to filter in some way? - if(*linesSinceLastStatus > 0 && + if(linesSinceLastStatus > 0 && (int)(time(NULL) - *lastStatusTime) > 1) { - *linesSinceLastStatus = 0; + linesSinceLastStatus = 0; *lastStatusTime = time(NULL); it->m_details->addWithFilter("===================================="); screen->paint(it->m_details); diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.h b/src/sse-pkg/util/sonataInfoDisplay/logfile.h index aa28596..df18844 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.h +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.h @@ -91,7 +91,6 @@ using namespace std; * @return the number of file descriptors ready for reading */ static int readLogfiles(list logfiles, - int *linesSinceLastStatus, time_t *lastStatusTime, Screen *screen); @@ -105,7 +104,6 @@ using namespace std; // handling is removed // from main(). - private: /** Filename of logfile */ @@ -114,13 +112,14 @@ using namespace std; FILE *m_fp; /** File descriptor of open logfile */ int m_fd; - /** Inode of open logfile */ - ino_t m_inode; /** Maximum open logfile descriptor */ static int m_maxFd; /** File-descriptor set used for select() reads */ static fd_set m_rfds; + /** Inode of open logfile */ + static ino_t m_inode; + /** Input-line filter */ Components *m_details; diff --git a/src/sse-pkg/util/sonataInfoDisplay/main.cpp b/src/sse-pkg/util/sonataInfoDisplay/main.cpp index 2dd2ef8..dc029c1 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/main.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/main.cpp @@ -91,25 +91,25 @@ int main(int argc, char **argv) systemErrorFileName = argv[3]; Logfile systemStatusFile = Logfile(systemStatusFileName, &componentDetails); - Logfile systemLogFile = Logfile(systemLogFileName, NULL); - Logfile systemErrorFile = Logfile(systemErrorFileName, NULL); + // Logfile systemLogFile = Logfile(systemLogFileName, NULL); + // Logfile systemErrorFile = Logfile(systemErrorFileName, NULL); logfiles.push_back(systemStatusFile); - logfiles.push_back(systemLogFile); - logfiles.push_back(systemErrorFile); + // logfiles.push_back(systemLogFile); + // logfiles.push_back(systemErrorFile); //Initialize the curses screen. screen.init(); screen.screenResize(0); - time_t lastStatusTime = time(NULL); - int linesSinceLastStatus = 0; + time_t lastStatusTime = time(NULL); // FIXME: move to class? //Loop foever while(1) { - Logfile::readLogfiles(logfiles, &linesSinceLastStatus, &lastStatusTime, + Logfile::readLogfiles(logfiles, + &lastStatusTime, &screen); // FIXME: Move all the stuff below out of main! @@ -136,14 +136,14 @@ int main(int argc, char **argv) // } //Process the log file - if(FD_ISSET(systemLogFile.getFd(), Logfile::getDescriptors())) - { - } +// if(FD_ISSET(systemLogFile.getFd(), Logfile::getDescriptors())) +// { +// } //Process the error file - if(FD_ISSET(systemErrorFile.getFd(), Logfile::getDescriptors())) - { - } +// if(FD_ISSET(systemErrorFile.getFd(), Logfile::getDescriptors())) +// { +// } screen.processKey(&componentDetails); } From 71b14c80733a7e86528659767703d66f8bde33b8 Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Wed, 29 Sep 2010 22:30:10 -0400 Subject: [PATCH 5/8] make Logfile::m_inode non-static --- src/sse-pkg/util/sonataInfoDisplay/logfile.cpp | 7 ++----- src/sse-pkg/util/sonataInfoDisplay/logfile.h | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp index 1bd538b..f400984 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp @@ -34,7 +34,6 @@ #include "logfile.h" -ino_t Logfile::m_inode = 0; // FIXME: Only static for testing. int Logfile::m_maxFd = 0; fd_set Logfile::m_rfds; @@ -80,11 +79,10 @@ void Logfile::openLogfile(string filename) { Logfile::m_maxFd = m_fd; } - struct stat stbuf; if(fstat(m_fd, &stbuf) == 0) { - Logfile::m_inode = stbuf.st_ino; + m_inode = stbuf.st_ino; } // else // { @@ -101,11 +99,10 @@ void Logfile::checkRefresh() if (stat(m_logfile.c_str(), &stbuf) == 0) { - // The most likely reason the inode would be changed is if a new // logfile has been created. // If so, switch to reading the new file. - if (Logfile::m_inode != stbuf.st_ino) + if (m_inode != stbuf.st_ino) { //FIXME: Need exception handling. if(fclose(m_fp) == 0) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.h b/src/sse-pkg/util/sonataInfoDisplay/logfile.h index df18844..d081d1f 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.h +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.h @@ -118,8 +118,7 @@ using namespace std; /** File-descriptor set used for select() reads */ static fd_set m_rfds; /** Inode of open logfile */ - static ino_t m_inode; - + ino_t m_inode; /** Input-line filter */ Components *m_details; From 44da8d943700ee1632a05a3b3c7cd0be7e701c21 Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Thu, 30 Sep 2010 09:08:23 -0400 Subject: [PATCH 6/8] Fix Logfile::m_inode pass-by-ref bug. Code clean-up. --- .../util/sonataInfoDisplay/logfile.cpp | 34 +++-------- src/sse-pkg/util/sonataInfoDisplay/logfile.h | 18 ++---- src/sse-pkg/util/sonataInfoDisplay/main.cpp | 59 +++---------------- 3 files changed, 20 insertions(+), 91 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp index f400984..95ccb59 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp @@ -50,14 +50,6 @@ Logfile::Logfile(string filename, Components *details) m_details = details; } -/* - * Destructor - * Does nothing. - */ -Logfile::~Logfile() -{ -} - /* * Open logfile. * @@ -70,7 +62,7 @@ void Logfile::openLogfile(string filename) m_fp = fopen(filename.c_str(), "a+"); if(m_fp == NULL) { - // FIXME: actually exit, send this to stderr. + // FIXME: actually exit, then send this to stderr. fprintf(stdout," Could not open %s, EXITING.\n", filename.c_str()); } @@ -84,10 +76,10 @@ void Logfile::openLogfile(string filename) { m_inode = stbuf.st_ino; } -// else -// { -// Logfile::m_inode = -1; -// } + else + { + m_inode = -1; + } } /* @@ -104,7 +96,7 @@ void Logfile::checkRefresh() // If so, switch to reading the new file. if (m_inode != stbuf.st_ino) { - //FIXME: Need exception handling. + // FIXME: Needs exception handling. if(fclose(m_fp) == 0) { openLogfile(m_logfile); @@ -150,7 +142,7 @@ void Logfile::getLine(char *buf, unsigned long bufsize) * @return the number of file descriptors ready for reading */ -int Logfile::readLogfiles(list logfiles, +int Logfile::readLogfiles(list& logfiles, time_t *lastStatusTime, Screen *screen) { @@ -168,7 +160,7 @@ int Logfile::readLogfiles(list logfiles, struct timeval tv; tv.tv_sec = 0; - tv.tv_usec = 200000; //1/5 second + tv.tv_usec = 200000; // 1/5 second int retVal = -1; @@ -206,13 +198,3 @@ int Logfile::readLogfiles(list logfiles, return retVal; } - -/* - * Returns file descriptor set for reads. - * - * @return the file descriptor set for reads - */ -fd_set *Logfile::getDescriptors() -{ - return &Logfile::m_rfds; -} diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.h b/src/sse-pkg/util/sonataInfoDisplay/logfile.h index d081d1f..525de73 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.h +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.h @@ -66,7 +66,7 @@ using namespace std; * Destructor * Does nothing. */ - ~Logfile(); + ~Logfile() {}; /** * Returns the logfile's file descriptor. @@ -90,20 +90,10 @@ using namespace std; * * @return the number of file descriptors ready for reading */ - static int readLogfiles(list logfiles, + static int readLogfiles(list& logfiles, time_t *lastStatusTime, Screen *screen); - /** - * Returns file descriptor set for reads. - * - * @return the file descriptor set for reads - */ - static fd_set *getDescriptors(); // FIXME: Will be - // private once all file - // handling is removed - // from main(). - private: /** Filename of logfile */ @@ -112,13 +102,13 @@ using namespace std; FILE *m_fp; /** File descriptor of open logfile */ int m_fd; + /** Inode of open logfile */ + ino_t m_inode; /** Maximum open logfile descriptor */ static int m_maxFd; /** File-descriptor set used for select() reads */ static fd_set m_rfds; - /** Inode of open logfile */ - ino_t m_inode; /** Input-line filter */ Components *m_details; diff --git a/src/sse-pkg/util/sonataInfoDisplay/main.cpp b/src/sse-pkg/util/sonataInfoDisplay/main.cpp index dc029c1..dd1f06f 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/main.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/main.cpp @@ -44,8 +44,6 @@ #include "details.h" #include "utils.h" -//#include "screen.h" -//#include "components.h" #include "logfile.h" #include @@ -70,7 +68,6 @@ int main(int argc, char **argv) string systemLogFileName = ""; string systemErrorFileName = ""; Screen screen; - // char line[2048]; list logfiles; Components componentDetails; @@ -91,64 +88,24 @@ int main(int argc, char **argv) systemErrorFileName = argv[3]; Logfile systemStatusFile = Logfile(systemStatusFileName, &componentDetails); - // Logfile systemLogFile = Logfile(systemLogFileName, NULL); - // Logfile systemErrorFile = Logfile(systemErrorFileName, NULL); + Logfile systemLogFile = Logfile(systemLogFileName, NULL); + Logfile systemErrorFile = Logfile(systemErrorFileName, NULL); logfiles.push_back(systemStatusFile); - // logfiles.push_back(systemLogFile); - // logfiles.push_back(systemErrorFile); + logfiles.push_back(systemLogFile); + logfiles.push_back(systemErrorFile); - //Initialize the curses screen. + // Initialize the curses screen. screen.init(); screen.screenResize(0); - time_t lastStatusTime = time(NULL); // FIXME: move to class? + time_t lastStatusTime = time(NULL); // FIXME: move to class. - //Loop foever + // Loop foever while(1) { - - Logfile::readLogfiles(logfiles, - &lastStatusTime, - &screen); - - // FIXME: Move all the stuff below out of main! - // (Note the current clumsy use of Logfile::m_rfds.) - - // Process any data read from the status file. -// if(FD_ISSET(systemStatusFile.getFd(), Logfile::getDescriptors())) -// { -// systemStatusFile.getLine(line, sizeof(line) - 1); -// if(line[0] != 0 && componentDetails.addWithFilter(line)) -// screen.paint(&componentDetails); -// linesSinceLastStatus++; -// memset(line, 0, sizeof(line)); -// } - - //The trigger for the end of a status screen paint is "===..." but sometimes - //this does not arrive, so we have to force it. -// if(linesSinceLastStatus > 0 && (int)(time(NULL) - lastStatusTime) > 1) -// { -// linesSinceLastStatus = 0; -// lastStatusTime = time(NULL); -// componentDetails.addWithFilter("===================================="); -// screen.paint(&componentDetails); -// } - - //Process the log file -// if(FD_ISSET(systemLogFile.getFd(), Logfile::getDescriptors())) -// { -// } - - //Process the error file -// if(FD_ISSET(systemErrorFile.getFd(), Logfile::getDescriptors())) -// { -// } - + Logfile::readLogfiles(logfiles, &lastStatusTime, &screen); screen.processKey(&componentDetails); } - - return 0; - } From 8fa8dc0cea31e3671cf2853a59f76e186b21d140 Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Sat, 2 Oct 2010 22:23:11 -0400 Subject: [PATCH 7/8] move lastStatusTime to Logfile class --- src/sse-pkg/util/sonataInfoDisplay/logfile.cpp | 13 ++++++++----- src/sse-pkg/util/sonataInfoDisplay/logfile.h | 6 +++--- src/sse-pkg/util/sonataInfoDisplay/main.cpp | 4 +--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp index 95ccb59..508ff3c 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp @@ -36,6 +36,7 @@ int Logfile::m_maxFd = 0; fd_set Logfile::m_rfds; +time_t Logfile::lastStatusTime = -1; /* * Constructor @@ -142,12 +143,14 @@ void Logfile::getLine(char *buf, unsigned long bufsize) * @return the number of file descriptors ready for reading */ -int Logfile::readLogfiles(list& logfiles, - time_t *lastStatusTime, - Screen *screen) +int Logfile::readLogfiles(list& logfiles, Screen *screen) { int linesSinceLastStatus = 0; + if(Logfile::lastStatusTime == -1) + { + Logfile::lastStatusTime = time(NULL); + } FD_ZERO(&m_rfds); FD_SET(0, &m_rfds); @@ -186,10 +189,10 @@ int Logfile::readLogfiles(list& logfiles, } //FIXME: Hack--move to filter in some way? if(linesSinceLastStatus > 0 && - (int)(time(NULL) - *lastStatusTime) > 1) + (int)(time(NULL) - Logfile::lastStatusTime) > 1) { linesSinceLastStatus = 0; - *lastStatusTime = time(NULL); + Logfile::lastStatusTime = time(NULL); it->m_details->addWithFilter("===================================="); screen->paint(it->m_details); } diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.h b/src/sse-pkg/util/sonataInfoDisplay/logfile.h index 525de73..99aa6c3 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.h +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.h @@ -90,9 +90,7 @@ using namespace std; * * @return the number of file descriptors ready for reading */ - static int readLogfiles(list& logfiles, - time_t *lastStatusTime, - Screen *screen); + static int readLogfiles(list& logfiles, Screen *screen); private: @@ -109,6 +107,8 @@ using namespace std; static int m_maxFd; /** File-descriptor set used for select() reads */ static fd_set m_rfds; + /** Timestamp of most recently read status. */ + static time_t lastStatusTime; /** Input-line filter */ Components *m_details; diff --git a/src/sse-pkg/util/sonataInfoDisplay/main.cpp b/src/sse-pkg/util/sonataInfoDisplay/main.cpp index dd1f06f..e4c79d2 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/main.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/main.cpp @@ -99,12 +99,10 @@ int main(int argc, char **argv) screen.init(); screen.screenResize(0); - time_t lastStatusTime = time(NULL); // FIXME: move to class. - // Loop foever while(1) { - Logfile::readLogfiles(logfiles, &lastStatusTime, &screen); + Logfile::readLogfiles(logfiles, &screen); screen.processKey(&componentDetails); } return 0; From 164c20dd944d7f5648ba8ab904fc5f555f0fa6f4 Mon Sep 17 00:00:00 2001 From: Jeff Uphoff Date: Sun, 3 Oct 2010 09:43:07 -0400 Subject: [PATCH 8/8] rename lastStatusTime to m_lastStatusTime to conform to coding standard --- src/sse-pkg/util/sonataInfoDisplay/logfile.cpp | 10 +++++----- src/sse-pkg/util/sonataInfoDisplay/logfile.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp index 508ff3c..00a5b7c 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.cpp @@ -36,7 +36,7 @@ int Logfile::m_maxFd = 0; fd_set Logfile::m_rfds; -time_t Logfile::lastStatusTime = -1; +time_t Logfile::m_lastStatusTime = -1; /* * Constructor @@ -147,9 +147,9 @@ int Logfile::readLogfiles(list& logfiles, Screen *screen) { int linesSinceLastStatus = 0; - if(Logfile::lastStatusTime == -1) + if(Logfile::m_lastStatusTime == -1) { - Logfile::lastStatusTime = time(NULL); + Logfile::m_lastStatusTime = time(NULL); } FD_ZERO(&m_rfds); FD_SET(0, &m_rfds); @@ -189,10 +189,10 @@ int Logfile::readLogfiles(list& logfiles, Screen *screen) } //FIXME: Hack--move to filter in some way? if(linesSinceLastStatus > 0 && - (int)(time(NULL) - Logfile::lastStatusTime) > 1) + (int)(time(NULL) - Logfile::m_lastStatusTime) > 1) { linesSinceLastStatus = 0; - Logfile::lastStatusTime = time(NULL); + Logfile::m_lastStatusTime = time(NULL); it->m_details->addWithFilter("===================================="); screen->paint(it->m_details); } diff --git a/src/sse-pkg/util/sonataInfoDisplay/logfile.h b/src/sse-pkg/util/sonataInfoDisplay/logfile.h index 99aa6c3..1946e1c 100644 --- a/src/sse-pkg/util/sonataInfoDisplay/logfile.h +++ b/src/sse-pkg/util/sonataInfoDisplay/logfile.h @@ -108,7 +108,7 @@ using namespace std; /** File-descriptor set used for select() reads */ static fd_set m_rfds; /** Timestamp of most recently read status. */ - static time_t lastStatusTime; + static time_t m_lastStatusTime; /** Input-line filter */ Components *m_details;