From: Mikko Rasa Date: Wed, 30 May 2012 19:02:30 +0000 (+0000) Subject: Implement get_handle in File and Pipe X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f041a31f9a6e19da86a63912e5a8050f216e5bc5;p=libs%2Fcore.git Implement get_handle in File and Pipe --- diff --git a/source/io/file.cpp b/source/io/file.cpp index dacc5d7..862b607 100644 --- a/source/io/file.cpp +++ b/source/io/file.cpp @@ -153,5 +153,11 @@ SeekOffset File::tell() const return sys_seek(const_cast(handle), 0, S_CUR); } +const Handle &File::get_handle(Mode m) +{ + check_access(m); + return handle; +} + } // namespace IO } // namespace Msp diff --git a/source/io/file.h b/source/io/file.h index 6c71697..430571f 100644 --- a/source/io/file.h +++ b/source/io/file.h @@ -54,6 +54,8 @@ public: virtual SeekOffset seek(SeekOffset, SeekType); virtual SeekOffset tell() const; + + virtual const Handle &get_handle(Mode); }; inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n) diff --git a/source/io/pipe.cpp b/source/io/pipe.cpp index 3b74a0f..639743f 100644 --- a/source/io/pipe.cpp +++ b/source/io/pipe.cpp @@ -86,5 +86,15 @@ unsigned Pipe::do_read(char *buf, unsigned size) return ret; } +const Handle &Pipe::get_handle(Mode m) +{ + if(m==M_READ) + return read_handle; + else if(m==M_WRITE) + return write_handle; + else + throw invalid_argument("Pipe::get_handle"); +} + } // namespace IO } // namespace Msp diff --git a/source/io/pipe.h b/source/io/pipe.h index 6d65a9a..d1508b2 100644 --- a/source/io/pipe.h +++ b/source/io/pipe.h @@ -26,6 +26,7 @@ protected: virtual unsigned do_read(char *, unsigned); public: + virtual const Handle &get_handle(Mode); virtual const Handle &get_event_handle() { return reader.get_event(); } };