Commit 5f1f486a authored by Paul Asmuth's avatar Paul Asmuth
Browse files

outputstream impl WIP

parent 6320e9f1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line


fnordmetric web:
    $ fnordmetric --web 8080   # standalone webserver on port 8080
    $ fnordmetric --cgi        # mount me as cgi script!


rename:
  canvas -> chart
  resultlist -> table
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ project(fnordmetric)
set(FNORDMETRIC_SOURCES
    stage/src/fnordmetric/util/format.cc
    stage/src/fnordmetric/util/inputstream.cc
    stage/src/fnordmetric/util/outputstream.cc
    stage/src/fnordmetric/util/runtimeexception.cc)

set(FNORDMETRIC_UI_SOURCES
+41 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2014 Paul Asmuth, Google Inc.
 *
 * Licensed under the MIT license (see LICENSE).
 */
#include <memory>
#include <unistd.h>
#include <fnordmetric/util/outputstream.h>

namespace fnordmetric {
namespace util {

std::unique_ptr<OutputStream> OutputStream::getStdout() {
  auto stdout_stream = new FileOutputStream(1, false);
  return std::unique_ptr<OutputStream>(stdout_stream);
}

std::unique_ptr<OutputStream> OutputStream::getStderr() {
  auto stderr_stream = new FileOutputStream(2, false);
  return std::unique_ptr<OutputStream>(stderr_stream);
}

FileOutputStream::FileOutputStream(
    int fd,
    bool close_on_destroy /* = false */) :
    fd_(fd),
    close_on_destroy_(close_on_destroy) {}

FileOutputStream::~FileOutputStream() {
  if (fd_ >= 0 && close_on_destroy_) {
    close(fd_);
  }
}

size_t FileOutputStream::write(char* data, size_t size) {
  return 0;
}

}
}
+13 −2
Original line number Diff line number Diff line
@@ -30,15 +30,17 @@ public:

  /**
   * Write the next n bytes to the output stream. This may raise an exception.
   * Returns the number of bytes that have been written.
   *
   * @param data a pointer to the data to be written
   * @param size then number of bytes to be written
   */
  virtual bool write(char* data, size_t size) = 0;
  virtual size_t write(char* data, size_t size) = 0;

};

class FileOutputStream : public OutputStream {
public:

  /**
   * Create a new FileOuputStream instance from the provided filedescriptor. If 
@@ -50,14 +52,23 @@ class FileOutputStream : public OutputStream {
   */
  explicit FileOutputStream(int fd, bool close_on_destroy = false);

  /**
   * Close the fd if close_on_destroy is true
   */
  ~FileOutputStream();

  /**
   * Write the next n bytes to the file. This may raise an exception.
   * Returns the number of bytes that have been written.
   *
   * @param data a pointer to the data to be written
   * @param size then number of bytes to be written
   */
  virtual bool write(char* data, size_t size) = 0;
  size_t write(char* data, size_t size) override;

protected:
  int fd_;
  bool close_on_destroy_;
};

}