diff options
-rw-r--r-- | includes/Handle.h | 1 | ||||
-rw-r--r-- | includes/Input.h | 4 | ||||
-rw-r--r-- | includes/Printer.h | 12 | ||||
-rw-r--r-- | src/Handle.cc | 2 | ||||
-rw-r--r-- | src/Input.cc | 39 | ||||
-rw-r--r-- | tests/test-Handles.cc | 10 | ||||
-rw-r--r-- | tests/test-Sanity.cc | 1 |
7 files changed, 60 insertions, 9 deletions
diff --git a/includes/Handle.h b/includes/Handle.h index d2e1f8c..f2b78ad 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -27,6 +27,7 @@ class Handle { virtual off_t rtell() throw (GeneralException); virtual off_t wtell() throw (GeneralException); virtual off_t getSize(); + virtual time_t getMTime(); protected: Handle() : m_refCount(0) { } private: diff --git a/includes/Input.h b/includes/Input.h index 418b018..7f801f6 100644 --- a/includes/Input.h +++ b/includes/Input.h @@ -10,9 +10,13 @@ class Input : public SeekableHandle { virtual void close() throw (GeneralException); virtual bool isClosed(); virtual const char * getName(); + virtual off_t getSize(); + virtual time_t getMTime(); private: int m_fd; String m_name; + off_t m_size; + time_t m_mtime; }; }; diff --git a/includes/Printer.h b/includes/Printer.h index 20b3b6c..d8ba9cf 100644 --- a/includes/Printer.h +++ b/includes/Printer.h @@ -31,12 +31,12 @@ class Printer { void setLocal(); static Printer * getPrinter(); - static void log(uint32_t level, const String & fmt, ...) { va_list ap; va_start(ap, fmt); log(level, fmt.to_charp(), ap); va_end(ap); } - static void log(uint32_t level, const char * fmt, ...) { va_list ap; va_start(ap, fmt); log(level, fmt, ap); va_end(ap); } - static void log(uint32_t level, const char * fmt, va_list ap) { getPrinter()->_log(level, fmt, ap); } - static void print(const String & fmt, ...) { va_list ap; va_start(ap, fmt); print(fmt.to_charp(), ap); va_end(ap); } - static void print(const char * fmt, ...) { va_list ap; va_start(ap, fmt); print(fmt, ap); va_end(ap); } - static void print(const char * fmt, va_list ap) { getPrinter()->_print(fmt, ap); } + static void log(uint32_t level, const String & fmt, ...) { va_list ap; va_start(ap, fmt); vlog(level, fmt.to_charp(), ap); va_end(ap); } + static void log(uint32_t level, const char * fmt, ...) { va_list ap; va_start(ap, fmt); vlog(level, fmt, ap); va_end(ap); } + static void vlog(uint32_t level, const char * fmt, va_list ap) { getPrinter()->_log(level, fmt, ap); } + static void print(const String & fmt, ...) { va_list ap; va_start(ap, fmt); vprint(fmt.to_charp(), ap); va_end(ap); } + static void print(const char * fmt, ...) { va_list ap; va_start(ap, fmt); vprint(fmt, ap); va_end(ap); } + static void vprint(const char * fmt, va_list ap) { getPrinter()->_print(fmt, ap); } static void enable(uint32_t levels = M_ALL) { getPrinter()->m_verbosity |= levels; } static void disable(uint32_t levels = M_ALL) { getPrinter()->m_verbosity &= ~levels; } diff --git a/src/Handle.cc b/src/Handle.cc index c9e3f57..dc4e257 100644 --- a/src/Handle.cc +++ b/src/Handle.cc @@ -51,6 +51,7 @@ bool Balau::Handle::canSeek() { return false; } bool Balau::Handle::canRead() { return false; } bool Balau::Handle::canWrite() { return false; } off_t Balau::Handle::getSize() { return -1; } +time_t Balau::Handle::getMTime() { return -1; } ssize_t Balau::Handle::read(void * buf, size_t count) throw (GeneralException) { if (canRead()) @@ -149,3 +150,4 @@ off_t Balau::SeekableHandle::wtell() throw (GeneralException) { if (!canWrite()) return rtell(); } + diff --git a/src/Input.cc b/src/Input.cc index 633a1a7..ea078dc 100644 --- a/src/Input.cc +++ b/src/Input.cc @@ -16,11 +16,28 @@ static int eioDone(eio_req * req) { cbResults->result = req->result; cbResults->errorno = req->errorno; cbResults->evt.doSignal(); + return 0; } -Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1) { - cbResults_t cbResults; +struct cbStatsResults_t { + Balau::Events::Custom evt; + int result, errorno; + EIO_STRUCT_STAT statdata; +}; + +static int eioStatsDone(eio_req * req) { + cbStatsResults_t * cbStatsResults = (cbStatsResults_t *) req->data; + cbStatsResults->result = req->result; + cbStatsResults->errorno = req->errorno; + cbStatsResults->statdata = *(EIO_STRUCT_STAT *) req->ptr2; + cbStatsResults->evt.doSignal(); + return 0; +} + +Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1), m_size(-1), m_mtime(-1) { m_name.set("Input(%s)", fname); + + cbResults_t cbResults; eio_req * r = eio_open(fname, O_RDONLY, 0, 0, eioDone, &cbResults); Assert(r != 0); Task::yield(&cbResults.evt); @@ -31,6 +48,16 @@ Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1) { } else { m_fd = cbResults.result; } + + cbStatsResults_t cbStatsResults; + r = eio_fstat(m_fd, 0, eioStatsDone, &cbStatsResults); + Assert(r != 0); + Task::yield(&cbStatsResults.evt); + Assert(cbStatsResults.evt.gotSignal()); + if (cbStatsResults.result == 0) { + m_size = cbStatsResults.statdata.st_size; + m_mtime = cbStatsResults.statdata.st_mtime; + } } void Balau::Input::close() throw (GeneralException) { @@ -58,3 +85,11 @@ bool Balau::Input::isClosed() { const char * Balau::Input::getName() { return m_name.to_charp(); } + +off_t Balau::Input::getSize() { + return m_size; +} + +time_t Balau::Input::getMTime() { + return m_mtime; +} diff --git a/tests/test-Handles.cc b/tests/test-Handles.cc index 38b020b..68d8baa 100644 --- a/tests/test-Handles.cc +++ b/tests/test-Handles.cc @@ -17,6 +17,14 @@ void MainTask::Do() { } Assert(failed); IO i(new Input("Makefile")); - + Printer::log(M_STATUS, "Opened file %s:", i->getName()); + Printer::log(M_STATUS, " - size = %lli", i->getSize()); + char mtimestr[32]; + time_t mtime = i->getMTime(); + ctime_r(&mtime, mtimestr); + char * nl = strrchr(mtimestr, '\n'); + if (nl) + *nl = 0; + Printer::log(M_STATUS, " - mtime = %i (%s)", mtime, mtimestr); Printer::log(M_STATUS, "Test::Handles passed."); } diff --git a/tests/test-Sanity.cc b/tests/test-Sanity.cc index 54fa626..9ed9b4e 100644 --- a/tests/test-Sanity.cc +++ b/tests/test-Sanity.cc @@ -9,6 +9,7 @@ void MainTask::Do() { Assert(sizeof(off_t) == 8); Assert(sizeof(size_t) == 4); + Assert(sizeof(time_t) == 4); Printer::log(M_STATUS, "Test::Sanity passed."); } |