summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-07-28 23:17:07 +0000
committerrandomdan <randomdan@localhost>2010-07-28 23:17:07 +0000
commit7fa007189841b6de90ac54e6c042e601c0b9d56a (patch)
tree777214cb0970fc50b7e4b996757fdd02d026d2e3
parentTidy up no longer required parameters passed to execute (diff)
downloadproject2-7fa007189841b6de90ac54e6c042e601c0b9d56a.tar.bz2
project2-7fa007189841b6de90ac54e6c042e601c0b9d56a.tar.xz
project2-7fa007189841b6de90ac54e6c042e601c0b9d56a.zip
Fix typo in class name
Add file channel suitable for processes
-rw-r--r--project2/fileRows.cpp2
-rw-r--r--project2/fileStarGlibIoChannel.cpp43
-rw-r--r--project2/fileStarGlibIoChannel.h15
3 files changed, 47 insertions, 13 deletions
diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp
index 57ff8e5..c2a3a09 100644
--- a/project2/fileRows.cpp
+++ b/project2/fileRows.cpp
@@ -40,7 +40,7 @@ _FileRows::execute() const
if (!f) {
throw std::runtime_error("Could not open file");
}
- FileStrChannel c(f);
+ FileStarChannel c(f);
c.set_encoding(encoding);
c.set_line_term(newline);
Glib::ustring line;
diff --git a/project2/fileStarGlibIoChannel.cpp b/project2/fileStarGlibIoChannel.cpp
index 551763d..72c379f 100644
--- a/project2/fileStarGlibIoChannel.cpp
+++ b/project2/fileStarGlibIoChannel.cpp
@@ -1,7 +1,10 @@
#include "fileStarGlibIoChannel.h"
#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdexcept>
-FileStrChannel::FileStrChannel(FILE * f) :
+FileStarChannel::FileStarChannel(FILE * f) :
Glib::IOChannel(),
file(f)
{
@@ -10,33 +13,56 @@ FileStrChannel::FileStrChannel(FILE * f) :
gobj()->is_writeable = 0;
}
-FileStrChannel::~FileStrChannel()
+ProcessStarChannel::ProcessStarChannel(FILE * f) :
+ FileStarChannel(f)
+{
+ gobj()->is_seekable = 0;
+ gobj()->is_readable = 1;
+ gobj()->is_writeable = 0;
+}
+
+FileStarChannel::~FileStarChannel()
+{
+ close_vfunc();
+}
+
+Glib::IOStatus
+FileStarChannel::close_vfunc()
{
if (file) {
fclose(file);
+ file = NULL;
}
+ return Glib::IO_STATUS_NORMAL;
}
-Glib::IOStatus FileStrChannel::close_vfunc()
+Glib::IOStatus
+ProcessStarChannel::close_vfunc()
{
if (file) {
- fclose(file);
+ if (pclose(file)) {
+ file = NULL;
+ throw std::runtime_error(strerror(errno));
+ }
file = NULL;
}
return Glib::IO_STATUS_NORMAL;
}
-Glib::IOStatus FileStrChannel::set_flags_vfunc(Glib::IOFlags flags)
+Glib::IOStatus
+FileStarChannel::set_flags_vfunc(Glib::IOFlags flags)
{
return Glib::IO_STATUS_NORMAL;
}
-Glib::IOFlags FileStrChannel::get_flags_vfunc()
+Glib::IOFlags
+FileStarChannel::get_flags_vfunc()
{
return Glib::IO_FLAG_IS_SEEKABLE | Glib::IO_FLAG_IS_READABLE;
}
-Glib::IOStatus FileStrChannel::seek_vfunc(gint64 offset, Glib::SeekType type)
+Glib::IOStatus
+FileStarChannel::seek_vfunc(gint64 offset, Glib::SeekType type)
{
if (fseek(file, offset, type)) {
return Glib::IO_STATUS_ERROR;
@@ -44,7 +70,8 @@ Glib::IOStatus FileStrChannel::seek_vfunc(gint64 offset, Glib::SeekType type)
return Glib::IO_STATUS_NORMAL;
}
-Glib::IOStatus FileStrChannel::read_vfunc(char* buf, gsize count, gsize& bytes_read)
+Glib::IOStatus
+FileStarChannel::read_vfunc(char* buf, gsize count, gsize& bytes_read)
{
bytes_read = fread(buf, 1, count, file);
if (bytes_read == 0) {
diff --git a/project2/fileStarGlibIoChannel.h b/project2/fileStarGlibIoChannel.h
index 69f09ac..2980a3c 100644
--- a/project2/fileStarGlibIoChannel.h
+++ b/project2/fileStarGlibIoChannel.h
@@ -3,19 +3,26 @@
#include <glibmm/iochannel.h>
-class FileStrChannel : public Glib::IOChannel {
+class FileStarChannel : public Glib::IOChannel {
public:
- FileStrChannel(FILE * f);
- virtual ~FileStrChannel();
+ FileStarChannel(FILE * f);
+ virtual ~FileStarChannel();
virtual Glib::IOStatus close_vfunc();
virtual Glib::IOStatus set_flags_vfunc(Glib::IOFlags flags);
virtual Glib::IOFlags get_flags_vfunc();
virtual Glib::IOStatus seek_vfunc(gint64 offset, Glib::SeekType type);
virtual Glib::IOStatus read_vfunc(char* buf, gsize count, gsize& bytes_read);
- private:
+ protected:
FILE * file;
};
+class ProcessStarChannel : public FileStarChannel {
+ public:
+ ProcessStarChannel(FILE * f);
+
+ virtual Glib::IOStatus close_vfunc();
+};
+
#endif