]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Rename SyslogStreambuf -> DoutStreambuf
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 6 Dec 2010 23:50:44 +0000 (15:50 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 6 Dec 2010 23:57:56 +0000 (15:57 -0800)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/Makefile.am
src/common/DoutStreambuf.cc [new file with mode: 0644]
src/common/DoutStreambuf.h [new file with mode: 0644]
src/common/SyslogStreambuf.cc [deleted file]
src/common/SyslogStreambuf.h [deleted file]
src/test/TestDoutStreambuf.cc [new file with mode: 0644]
src/test/TestSyslogStreambuf.cc [deleted file]

index d0d650a35cac5cf4ecc61b93726f30b1e3cf6d4d..94982ca0e2d1acdedecc32bbd6e0825004b9e252 100644 (file)
@@ -193,9 +193,9 @@ testencoding_SOURCES = test/TestEncoding.cc
 testencoding_LDADD = libceph.la libcrush.la -lpthread -lm -lcrypto
 bin_PROGRAMS += testencoding
 
-testsyslog_streambuf_SOURCES = test/TestSyslogStreambuf.cc
-testsyslog_streambuf_LDADD = libceph.la libcrush.la -lpthread
-bin_PROGRAMS += testsyslog_streambuf
+testdout_streambuf_SOURCES = test/TestDoutStreambuf.cc
+testdout_streambuf_LDADD = libceph.la libcrush.la -lpthread
+bin_PROGRAMS += testdout_streambuf
 
 endif
 
@@ -452,7 +452,7 @@ libcommon_files = \
        config.cc \
        common/page.cc \
        common/lockdep.cc \
-       common/SyslogStreambuf.cc
+       common/DoutStreambuf.cc
 
 libcrush_a_SOURCES = \
        crush/builder.c \
@@ -585,7 +585,7 @@ noinst_HEADERS = \
         common/Mutex.h\
         common/RWLock.h\
         common/Semaphore.h\
-       common/SyslogStreambuf.h\
+       common/DoutStreambuf.h\
         common/Thread.h\
         common/Throttle.h\
         common/Timer.h\
diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc
new file mode 100644 (file)
index 0000000..ca75af1
--- /dev/null
@@ -0,0 +1,98 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "common/DoutStreambuf.h"
+
+#include <assert.h>
+#include <fstream>
+#include <iostream>
+#include <streambuf>
+#include <syslog.h>
+#include <string.h>
+
+template <typename charT, typename traits>
+DoutStreambuf<charT, traits>::DoutStreambuf()
+{
+  // Initialize get pointer to zero so that underflow is called on the first read.
+  this->setg(0, 0, 0);
+
+  // Set up the put pointer.
+  // Overflow is called when this buffer is filled
+  this->setp(obuf, obuf + OBUF_SZ - 2);
+
+  // Zero the output buffer
+  memset(obuf, 0, OBUF_SZ);
+}
+
+// This function is called when the output buffer is filled.
+// In this function, the buffer should be written to wherever it should
+// be written to (in this case, the streambuf object that this is controlling).
+template <typename charT, typename traits>
+typename DoutStreambuf<charT, traits>::int_type
+DoutStreambuf<charT, traits>::overflow(DoutStreambuf<charT, traits>::int_type c)
+{
+  charT* end = this->pptr();
+
+  // Add an eof character to the buffer if we need to.
+  if(!traits_ty::eq_int_type(c, traits_ty::eof())) {
+    *end++ = traits_ty::to_char_type(c);
+  }
+  *end++ = '\0';
+
+  //std::cout << "overflow with '" << obuf << "'" << std::endl;
+
+  // int_type ilen = end - obuf; // Compute the write length.
+  syslog(LOG_USER | LOG_NOTICE, "%s", obuf);
+
+  // Reset put pointers
+  setp(obuf, obuf + OBUF_SZ - 1);
+  obuf[0] = '\0';
+
+  // A value different than EOF (or traits::eof() for other traits) signals success.
+  // If the function fails, either EOF (or traits::eof() for other traits) is returned or an
+  // exception is thrown.
+  return traits_ty::not_eof(c);
+}
+
+// This is called to flush the buffer.
+// This is called when we're done with the file stream (or when .flush() is called).
+template <typename charT, typename traits>
+typename DoutStreambuf<charT, traits>::int_type
+DoutStreambuf<charT, traits>::sync()
+{
+  //std::cout << "flush!" << std::endl;
+
+  // Don't bother calling overflow if there's nothing to syslog
+  if (obuf[0] == '\0')
+    return 0;
+
+  typename DoutStreambuf<charT, traits>::int_type
+    ret(this->overflow(traits_ty::eof()));
+  if (ret == traits_ty::eof())
+    return -1;
+
+  return 0;
+}
+
+template <typename charT, typename traits>
+typename DoutStreambuf<charT, traits>::int_type
+DoutStreambuf<charT, traits>::underflow()
+{
+  // We can't read from this
+  // TODO: some more elegant way of preventing callers from trying to get input from this stream
+  assert(0);
+}
+
+// Explicit template instantiation
+template class DoutStreambuf <char>;
diff --git a/src/common/DoutStreambuf.h b/src/common/DoutStreambuf.h
new file mode 100644 (file)
index 0000000..c808b1b
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+/*
+ * DoutStreambuf
+ *
+ * The stream buffer used by dout
+ */
+#ifndef CEPH_DOUT_STREAMBUF_H
+#define CEPH_DOUT_STREAMBUF_H
+
+#include <iosfwd>
+
+template <typename charT, typename traits = std::char_traits<charT> >
+class DoutStreambuf : public std::basic_streambuf<charT, traits>
+{
+public:
+  typedef traits traits_ty;
+  typedef typename traits_ty::int_type int_type;
+  typedef typename traits_ty::pos_type pos_type;
+  typedef typename traits_ty::off_type off_type;
+
+  // The size of the input and output buffers.
+  static const size_t OBUF_SZ = 32000;
+
+  DoutStreambuf();
+
+protected:
+  // Called when the buffer fills up
+  virtual int_type overflow(int_type c);
+
+  // Called when the buffer is flushed
+  virtual int_type sync();
+
+  // Called when we try to read, but there are no more chars in the buffer
+  virtual int_type underflow();
+
+private:
+  // Output buffer
+  charT obuf[OBUF_SZ];
+};
+
+#endif
diff --git a/src/common/SyslogStreambuf.cc b/src/common/SyslogStreambuf.cc
deleted file mode 100644 (file)
index 7c30c4f..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2010 Dreamhost
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-#include "common/SyslogStreambuf.h"
-
-#include <assert.h>
-#include <fstream>
-#include <iostream>
-#include <streambuf>
-#include <syslog.h>
-#include <string.h>
-
-template <typename charT, typename traits>
-SyslogStreambuf<charT, traits>::SyslogStreambuf()
-{
-  // Initialize get pointer to zero so that underflow is called on the first read.
-  this->setg(0, 0, 0);
-
-  // Set up the put pointer.
-  // Overflow is called when this buffer is filled
-  this->setp(obuf, obuf + OBUF_SZ - 2);
-
-  // Zero the output buffer
-  memset(obuf, 0, OBUF_SZ);
-}
-
-// This function is called when the output buffer is filled.
-// In this function, the buffer should be written to wherever it should
-// be written to (in this case, the streambuf object that this is controlling).
-template <typename charT, typename traits>
-typename SyslogStreambuf<charT, traits>::int_type
-SyslogStreambuf<charT, traits>::overflow(SyslogStreambuf<charT, traits>::int_type c)
-{
-  charT* end = this->pptr();
-
-  // Add an eof character to the buffer if we need to.
-  if(!traits_ty::eq_int_type(c, traits_ty::eof())) {
-    *end++ = traits_ty::to_char_type(c);
-  }
-  *end++ = '\0';
-
-  //std::cout << "overflow with '" << obuf << "'" << std::endl;
-
-  // int_type ilen = end - obuf; // Compute the write length.
-  syslog(LOG_USER | LOG_NOTICE, "%s", obuf);
-
-  // Reset put pointers
-  setp(obuf, obuf + OBUF_SZ - 1);
-  obuf[0] = '\0';
-
-  // A value different than EOF (or traits::eof() for other traits) signals success.
-  // If the function fails, either EOF (or traits::eof() for other traits) is returned or an
-  // exception is thrown.
-  return traits_ty::not_eof(c);
-}
-
-// This is called to flush the buffer.
-// This is called when we're done with the file stream (or when .flush() is called).
-template <typename charT, typename traits>
-typename SyslogStreambuf<charT, traits>::int_type
-SyslogStreambuf<charT, traits>::sync()
-{
-  //std::cout << "flush!" << std::endl;
-
-  // Don't bother calling overflow if there's nothing to syslog
-  if (obuf[0] == '\0')
-    return 0;
-
-  typename SyslogStreambuf<charT, traits>::int_type
-    ret(this->overflow(traits_ty::eof()));
-  if (ret == traits_ty::eof())
-    return -1;
-
-  return 0;
-}
-
-template <typename charT, typename traits>
-typename SyslogStreambuf<charT, traits>::int_type
-SyslogStreambuf<charT, traits>::underflow()
-{
-  // We can't read from this
-  // TODO: some more elegant way of preventing callers from trying to get input from this stream
-  assert(0);
-}
-
-// Explicit template instantiation
-template class SyslogStreambuf <char>;
diff --git a/src/common/SyslogStreambuf.h b/src/common/SyslogStreambuf.h
deleted file mode 100644 (file)
index c55db5c..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2010 Dreamhost
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-/*
- * SyslogStreambuf
- *
- * A stream buffer that writes its output to syslog.
- */
-#ifndef CEPH_SYSLOG_STREAMBUF_H
-#define CEPH_SYSLOG_STREAMBUF_H
-
-#include <iosfwd>
-
-template <typename charT, typename traits = std::char_traits<charT> >
-class SyslogStreambuf : public std::basic_streambuf<charT, traits>
-{
-public:
-  typedef traits traits_ty;
-  typedef typename traits_ty::int_type int_type;
-  typedef typename traits_ty::pos_type pos_type;
-  typedef typename traits_ty::off_type off_type;
-
-  // The size of the input and output buffers.
-  static const size_t OBUF_SZ = 32000;
-
-  SyslogStreambuf();
-
-protected:
-  // Called when the buffer fills up
-  virtual int_type overflow(int_type c);
-
-  // Called when the buffer is flushed
-  virtual int_type sync();
-
-  // Called when we try to read, but there are no more chars in the buffer
-  virtual int_type underflow();
-
-private:
-  // Output buffer
-  charT obuf[OBUF_SZ];
-};
-
-#endif
diff --git a/src/test/TestDoutStreambuf.cc b/src/test/TestDoutStreambuf.cc
new file mode 100644 (file)
index 0000000..758c3cf
--- /dev/null
@@ -0,0 +1,70 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+/*
+ * TestDoutStreambuf
+ *
+ * Puts some output into the DoutStreambuf class.
+ * Check your syslog to see what it did.
+ */
+#include "common/DoutStreambuf.h"
+#include "common/common_init.h"
+#include "config.h"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+using std::cout;
+using std::cerr;
+using std::string;
+
+int main(int argc, const char **argv)
+{
+  vector<const char*> args;
+  argv_to_vec(argc, argv, args);
+  env_to_vec(args);
+
+  ceph_set_default_id("admin");
+  common_set_defaults(false);
+  common_init(args, "ceph", true);
+
+  std::ostream oss(new DoutStreambuf<char>);
+
+  oss << "I am logging to dout now!" << std::endl;
+
+  oss << "And here is another line!" << std::endl;
+
+  oss.flush();
+
+  oss << "Stuff ";
+  oss << "that ";
+  oss << "will ";
+  oss << "all ";
+  oss << "be ";
+  oss << "on ";
+  oss << "one ";
+  oss << "line.";
+  oss.flush();
+
+  oss << "There will be no blank lines here." << std::endl;
+  oss.flush();
+  oss.flush();
+  oss.flush();
+
+  oss << "But here is a blank line:" << std::endl;
+  oss << std::endl;
+
+  return 0;
+}
diff --git a/src/test/TestSyslogStreambuf.cc b/src/test/TestSyslogStreambuf.cc
deleted file mode 100644 (file)
index cd6469d..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2010 Dreamhost
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-/*
- * TestSyslogStreambuf
- *
- * Puts some output into the SyslogStreambuf class.
- * Check your syslog to see what it did.
- */
-#include "common/SyslogStreambuf.h"
-#include "common/common_init.h"
-#include "config.h"
-
-#include <iostream>
-#include <sstream>
-#include <string>
-
-using std::cout;
-using std::cerr;
-using std::string;
-
-int main(int argc, const char **argv)
-{
-  vector<const char*> args;
-  argv_to_vec(argc, argv, args);
-  env_to_vec(args);
-
-  ceph_set_default_id("admin");
-  common_set_defaults(false);
-  common_init(args, "ceph", true);
-
-  std::ostream oss(new SyslogStreambuf<char>);
-
-  oss << "I am logging to syslog now!" << std::endl;
-
-  oss << "And here is another line!" << std::endl;
-
-  oss.flush();
-
-  oss << "Stuff ";
-  oss << "that ";
-  oss << "will ";
-  oss << "all ";
-  oss << "be ";
-  oss << "on ";
-  oss << "one ";
-  oss << "line.";
-  oss.flush();
-
-  oss << "There will be no blank lines here." << std::endl;
-  oss.flush();
-  oss.flush();
-  oss.flush();
-
-  oss << "But here is a blank line:" << std::endl;
-  oss << std::endl;
-
-  return 0;
-}