Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

UnixPipe.cc

Go to the documentation of this file.
00001 /*
00002  * UnixPipe.cc
00003  *
00004  * Smalltalk like class library for C++
00005  * Accessor to unix pipe.
00006  *
00007  * Copyright (c) 2006 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #include <stlib/os/UnixPipe.h>
00025 
00026 #include <stlib/ByteArray.h>
00027 #include <stlib/ExternalReadStream.h>
00028 #include <stlib/ExternalWriteStream.h>
00029 #include <stlib/FileAccessor.h>
00030 #include <stlib/String.h>
00031 
00032 #include <stlib/Error.h>
00033 
00034 #include <stdio.h>
00035 #include <unistd.h>
00036 
00037 namespace OS {
00038 
00039 UnixPipe::UnixPipe(Core::FileAccessor *in, Core::FileAccessor *out)
00040 {
00041     input = in;
00042     output = out;
00043 }
00044 
00045 /* Class-accessing protocol */
00046 String *UnixPipe::className(void) const
00047 {
00048     return new String("UnixPipe");
00049 }
00050 
00051 /* Instance creation protocol */
00052 UnixPipe *UnixPipe::openPair(void)
00053 {
00054     int fds[2];
00055 
00056     if (pipe(fds) < 0) {
00057         perror(__PRETTY_FUNCTION__);
00058         (new Error(new String("Cannot create pipe"),
00059                    new String(__PRETTY_FUNCTION__)))->raise();
00060     }
00061     return new UnixPipe(new FileAccessor(fds[1]), new FileAccessor(fds[0]));
00062 }
00063 
00064 /* Initialize-release protocol */
00065 void UnixPipe::close(void)
00066 {
00067     closeInput();
00068     closeOutput();
00069 }
00070 
00071 void UnixPipe::closeInput(void)
00072 {
00073     input->close();
00074 }
00075 
00076 void UnixPipe::closeOutput(void)
00077 {
00078     output->close();
00079 }
00080 
00081 /* Accessing protocol */
00082 Core::FileAccessor *UnixPipe::inputAccessor(void)
00083 {
00084     return input;
00085 }
00086 
00087 Core::FileAccessor *UnixPipe::outputAccessor(void)
00088 {
00089     return output;
00090 }
00091 
00092 /* Data transfer protocol */
00093 int UnixPipe::readInto(ByteArray *buffer, long startIndex, long count)
00094 {
00095     output->readInto(buffer, startIndex, count);
00096 }
00097 
00098 int UnixPipe::writeFrom(ByteArray *buffer, long startIndex, long count)
00099 {
00100     input->writeFrom(buffer, startIndex, count);
00101 }
00102 
00103 /* Positioning protocol */
00104 void UnixPipe::seekTo(long position)
00105 {
00106     shouldNotImplement(__PRETTY_FUNCTION__);
00107 }
00108 
00109 /* Stream creation protocol */
00110 ExternalReadStream *UnixPipe::readStream(void)
00111 {
00112     return output->readStream();
00113 }
00114 
00115 ExternalWriteStream *UnixPipe::writeStream(void)
00116 {
00117     return input->writeStream();
00118 }
00119 
00120 }; /* namespace OS */

Generated on Mon Nov 27 09:47:56 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2