You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/01/09 04:46:08 UTC
svn commit: r367180 - /webservices/axis2/trunk/c/include/axis2_stream.h
Author: samisa
Date: Sun Jan 8 19:46:04 2006
New Revision: 367180
URL: http://svn.apache.org/viewcvs?rev=367180&view=rev
Log:
Chenges to the stream abstraction
Modified:
webservices/axis2/trunk/c/include/axis2_stream.h
Modified: webservices/axis2/trunk/c/include/axis2_stream.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_stream.h?rev=367180&r1=367179&r2=367180&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_stream.h (original)
+++ webservices/axis2/trunk/c/include/axis2_stream.h Sun Jan 8 19:46:04 2006
@@ -17,115 +17,151 @@
#ifndef AXIS2_STREAM_H
#define AXIS2_STREAM_H
-#include <axis2_allocator.h>
+#include <axis2.h>
+#include <axis2_defines.h>
+#include <axis2_env.h>
+#include <stdio.h>
#ifdef __cplusplus
extern "C"
{
#endif
- struct axis2_stream;
- struct axis2_stream_ops;
+typedef struct axis2_stream axis2_stream_t;
+typedef struct axis2_stream_ops axis2_stream_ops_t;
+typedef enum axis2_stream_type axis2_stream_type_t;
+#define AXIS2_STREAM_DEFAULT_BUF_SIZE 512
/**
* @defgroup axis2_stream Stream
* @ingroup axis2_util
* @{
*/
- /**
- * \brief Axis2 stream ops struct
- *
- * Encapsulator struct for ops of axis2_stream
- */
- AXIS2_DECLARE_DATA typedef struct axis2_stream_ops
- {
-
- /**
- * deletes the stream
- * @return axis2_status_t AXIS2_SUCCESS on success else AXIS2_FAILURE
- */
-
- axis2_status_t (AXIS2_CALL *free) (struct axis2_stream *stream);
-
- /**
- * reads from stream
- * @param buffer buffer into which the content is to be read
- * @param size size of the buffer
- * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
- */
- axis2_status_t (AXIS2_CALL *read) (void *buffer
- , size_t count);
- /**
- * writes into stream
- * @param buffer buffer to be written
- * @param size size of the buffer
- * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
- */
- axis2_status_t (AXIS2_CALL *write)
- (const void *buffer, size_t count);
-
- /**
- * open a file for read according to the file options given
- * @param file_name file to be opened
- * @param options file options given.
- * @return status code
- */
- void * (AXIS2_CALL *file_open)
- (const char *file_name, const char *options);
-
- /**
- * close a file
- * @param file_ptr file pointer of the file need to be closed
- * @return status code
- */
- axis2_status_t (AXIS2_CALL *file_close)
- (void *file_ptr);
-
- /** reads a once character from a file
- * @param file_ptr pointer to the file to be read from
- * @return char read
- */
- axis2_char_t (AXIS2_CALL *file_get_char)
- (void *file_ptr);
-
- /** write a previously read character back to the file stream
- * @param chr charater to write back
- * @param file_ptr file pointer from which chr is read previously
- * and need to be written back to
- * @return status code
- */
- axis2_status_t (AXIS2_CALL *file_unget_char)
- (const char chr, void *file_ptr);
-
- } axis2_stream_ops_t;
-
- /**
- * \brief Axis2 Stream struct
- *
- * Stream is the encapsulating struct for all stream related ops
- */
- typedef struct axis2_stream
- {
- /** Stream related ops */
- struct axis2_stream_ops *ops;
- int axis2_eof;
- } axis2_stream_t;
-
-#define AXIS2_STREAM_FREE(stream) ((stream->ops)->free(stream))
-
-#define AXIS2_STREAM_READ(stream, buffer, count) \
- ((stream)->ops->read(buffer, count))
-#define AXIS2_STREAM_WRITE(stream, buffer, count) \
- ((stream->ops)->write(buffer, count))
-#define AXIS2_STREAM_FILE_OPEN(stream, file_name, options) \
- ((stream->ops)->file_open(file_name, options))
-#define AXIS2_STREAM_FILE_CLOSE(stream, file_ptr) \
- ((stream->ops)->file_close(file_ptr))
-#define AXIS2_STREAM_FILE_GET_CHAR(stream, file_ptr) \
- ((stream->ops)->file_get_char(file_ptr))
-#define AXIS2_STREAM_FILE_UNGET_CHAR(stream, chr, file_ptr) \
- ((stream->ops)->file_unget_char(chr, file_ptr))
+/**
+* \brief Axis2 stream types
+*
+* This is used to create a stream to correspond to
+* perticular i/o mtd
+*/
+enum axis2_stream_type
+{
+ AXIS2_STREAM_BASIC = 0,
+ AXIS2_STREAM_FILE,
+ AXIS2_STREAM_SOCKET
+};
+
+
+/**
+* \brief Axis2 stream ops struct
+*
+* Encapsulator struct for ops of axis2_stream
+*/
+AXIS2_DECLARE_DATA struct axis2_stream_ops
+{
+
+ /**
+ * Deletes the stream
+ * @return axis2_status_t AXIS2_SUCCESS on success else AXIS2_FAILURE
+ */
+ axis2_status_t (AXIS2_CALL *free)(axis2_stream_t *stream, axis2_env_t **env);
+
+ /**
+ * reads from stream
+ * @param buffer buffer into which the content is to be read
+ * @param count size of the buffer
+ * @return so: of bytes read
+ */
+
+ int (AXIS2_CALL *read) (axis2_stream_t *stream, axis2_env_t **env,
+ void *buffer, size_t count);
+ /**
+ * writes into stream
+ * @param buffer buffer to be written
+ * @param count size of the buffer
+ * @return no: of bytes actually written
+ */
+ int (AXIS2_CALL *write) (axis2_stream_t *stream,
+ axis2_env_t **env, const void *buffer, size_t count);
+ /**
+ * Skips over and discards n bytes of data from this input stream.
+ * @param count number of bytes to be discarded
+ * @return no: of bytes actually skipped
+ */
+ int (AXIS2_CALL *skip) (axis2_stream_t *stream, axis2_env_t **env,
+ int count);
+
+ /**
+ * Reads the next character from stream and returns it as an unsigned char
+ * cast to an int, or EOF on end of file or error.
+ * @return next character in the stream
+ */
+ int (AXIS2_CALL *get_char) (axis2_stream_t *stream, axis2_env_t **env);
+
+ /**
+ * Pushes a character back to stream, cast to unsigned char, where it is
+ * available for subsequent read operations
+ * @param charachter to be pushed
+ * @return the pushed character or EOF if an error
+ */
+ int (AXIS2_CALL *unget_char) (axis2_stream_t *stream, axis2_env_t **env,
+ int ch);
+
+ /**
+ * Returns the length of the stream (applicable only to basic stream)
+ * @return Length of the buffer if its type is basic, else -1
+ * (we can't define a length of a stream unless it is just a buffer)
+ */
+ int (AXIS2_CALL *get_len) (axis2_stream_t *stream, axis2_env_t **env);
+
+};
+
+/**
+* \brief Axis2 Stream struct
+*
+* Stream is the encapsulating struct for all stream related ops
+*/
+AXIS2_DECLARE_DATA struct axis2_stream
+{
+ /** Stream related ops */
+ axis2_stream_ops_t *ops;
+ /** Stream End of File */
+ int axis2_eof;
+};
+
+/** \brief Constructor for creating an in memory stream
+ * @return axis2_stream (in memory)
+ */
+AXIS2_DECLARE(axis2_stream_t *) axis2_stream_create_basic (axis2_env_t **env);
+
+/** \brief Constructor for creating a file stream
+ * @param valid file pointer (opened file)
+ * @return axis2_stream (file)
+ */
+AXIS2_DECLARE(axis2_stream_t *)
+axis2_stream_create_file (axis2_env_t **env, FILE *fp);
+
+/** \brief Constructor for creating a file stream
+ * @param valid socket (opened socket)
+ * @return axis2_stream (socket)
+ */
+AXIS2_DECLARE(axis2_stream_t *)
+axis2_stream_create_socket (axis2_env_t **env, int socket);
+
+#define AXIS2_STREAM_FREE(stream, env) ((stream->ops)->free(stream, env))
+#define AXIS2_STREAM_READ(stream, env, buffer, count) \
+ ((stream)->ops->read(stream, env, buffer, count))
+#define AXIS2_STREAM_WRITE(stream, env, buffer, count) \
+ ((stream)->ops->write(stream, env, buffer, count))
+#define AXIS2_STREAM_SKIP(stream, env, count) \
+ ((stream)->ops->write(stream, env, count))
+#define AXIS2_STREAM_GET_CHAR(stream, env) \
+ ((stream)->ops->get_char(stream, env))
+#define AXIS2_STREAM_UNGET_CHAR(stream, env, ch) \
+ ((stream)->ops->unget_char(stream, env, ch))
+
+#define AXIS2_STREAM_BASIC_GET_LEN(stream, env) \
+ ((stream)->ops->get_len(stream, env))
/** @} */