summaryrefslogtreecommitdiffstats
path: root/stream.h
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-09 13:27:07 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-09 13:27:07 +0000
commitfd8c6452c8a4d51d39eb511046fca09391138a22 (patch)
treeff95b43b91df5bf2e68c690e38002f30ede5df1c /stream.h
parent2146e340706a9de2be02761b7ad7c28034fb91f3 (diff)
downloadrsyslog-fd8c6452c8a4d51d39eb511046fca09391138a22.tar.gz
rsyslog-fd8c6452c8a4d51d39eb511046fca09391138a22.tar.xz
rsyslog-fd8c6452c8a4d51d39eb511046fca09391138a22.zip
created a generic stream class (for file access)
Diffstat (limited to 'stream.h')
-rw-r--r--stream.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/stream.h b/stream.h
new file mode 100644
index 00000000..5c9451cd
--- /dev/null
+++ b/stream.h
@@ -0,0 +1,83 @@
+/* Definition of serial stream class (strm).
+ *
+ * A serial stream provides serial data access. In theory, serial streams
+ * can be implemented via a number of methods (e.g. files or in-memory
+ * streams). In practice, there currently only exist the file type (aka
+ * "driver").
+ *
+ * In practice, many stream features are bound to files. I have not yet made
+ * any serious effort, except for the naming of this class, to try to make
+ * the interfaces very generic. However, I assume that we could work much
+ * like in the strm class, where some properties are simply ignored when
+ * the wrong strm mode is selected (which would translate here to the wrong
+ * stream mode).
+ *
+ * Most importantly, this class provides generic input and output functions
+ * which can directly be used to work with the strms and file output. It
+ * provides such useful things like a circular file buffer and, hopefully
+ * at a later stage, a lazy writer. The object is also seriazable and thus
+ * can easily be persistet. The bottom line is that it makes much sense to
+ * use this class whereever possible as its features may grow in the future.
+ *
+ * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+
+#ifndef STREAM_H_INCLUDED
+#define STREAM_H_INCLUDED
+
+#include <pthread.h>
+#include "obj.h"
+#include "stream.h"
+
+/* stream types */
+typedef enum {
+ STREAMTYPE_FILE = 0
+} strmType_t;
+
+/* The strm_t data structure */
+typedef struct {
+ BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
+ strmType_t sType;
+ int fd; /* the file descriptor, -1 if closed */
+ uchar *pszCurrFName; /* name of current file (if open) */
+ int iCurrFNum;/* current file number (NOT descriptor, but the number in the file name!) */
+ uchar *pszDir; /* Directory */
+ int lenDir;
+ uchar *pszFilePrefix; /* prefix for generated filenames */
+ int lenFilePrefix;
+ size_t iCurrOffs;/* current offset */
+ uchar *pIOBuf; /* io Buffer */
+ int iBufPtrMax; /* current max Ptr in Buffer (if partial read!) */
+ int iBufPtr; /* pointer into current buffer */
+ int iUngetC; /* char set via UngetChar() call or -1 if none set */
+ int iFlagsOpenOS;
+ int iModeOpenOS;
+ size_t iMaxFileSize;/* maximum size a file may grow to */
+ int bDeleteOnClose; /* set to 1 to auto-delete on close -- be careful with that setting! */
+} strm_t;
+#define STRM_IOBUF_SIZE 4096 /* size of the IO buffer */
+
+/* prototypes */
+rsRetVal strmDestruct(strm_t *pThis);
+rsRetVal strmSetMaxFileSize(strm_t *pThis, size_t iMaxFileSize);
+rsRetVal strmSetFilePrefix(strm_t *pThis, uchar *pszPrefix, size_t iLenPrefix);
+PROTOTYPEObjClassInit(strm);
+
+#endif /* #ifndef STREAM_H_INCLUDED */