1#ifndef BUF_H
2/*
3 * buf.h --
4 *
5 *	Definitions for buffer objects.
6 *
7 * Copyright (C) 2000 Andreas Kupries (a.kupries@westend.com)
8 * All rights reserved.
9 *
10 * Permission is hereby granted, without written agreement and without
11 * license or royalty fees, to use, copy, modify, and distribute this
12 * software and its documentation for any purpose, provided that the
13 * above copyright notice and the following two paragraphs appear in
14 * all copies of this software.
15 *
16 * IN NO EVENT SHALL I BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
17 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
18 * SOFTWARE AND ITS DOCUMENTATION, EVEN IF I HAVE BEEN ADVISED OF THE
19 * POSSIBILITY OF SUCH DAMAGE.
20 *
21 * I SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
24 * I HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
25 * ENHANCEMENTS, OR MODIFICATIONS.
26 *
27 * CVS: $Id: buf.h,v 1.3 2002/08/23 18:04:40 andreas_kupries Exp $
28 */
29
30
31#include <errno.h>
32#include <tcl.h>
33
34/*
35 * Windows needs to know which symbols to export.  Unix does not.
36 * BUILD_Memchan should be undefined for Unix.
37 */
38
39#ifdef BUILD_Memchan
40#undef TCL_STORAGE_CLASS
41#define TCL_STORAGE_CLASS DLLEXPORT
42#endif /* BUILD_Memchan */
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/*
49 * The definitions in this header and the accompanying code define a
50 * generic buffer object.
51 *
52 * The code here is partially based upon the buffer structures used by
53 * the tcl core and uponconcepts laid out in the STREAMS paper at
54 * http://cm.bell-labs.com/cm/cs/who/dmr/st.html
55 *
56 * I hope that it can and will be used in a future reorganization of
57 * the core I/O system.
58 */
59
60/* Basis:
61 *	Refcounted buffers. The structures actually holding
62 *	information. Buffers are typed to allow differentation
63 *	between simple data and special control blocks.
64 *
65 *	To the outside they are opaque tokens.
66 *	All access to them have to go through the public API.
67 */
68
69typedef struct Buf_Buffer_* Buf_Buffer;
70
71/*
72 * Definition of the type for variables referencing a position
73 * in a buffer. Opaque token.
74 */
75
76typedef struct Buf_BufferPosition_* Buf_BufferPosition;
77
78/*
79 * Another opaque structure: Queues of buffers.
80 * The queues defined here are thread-safe !
81 */
82
83typedef struct Buf_BufferQueue_* Buf_BufferQueue;
84
85
86
87/* The structure for a buffer type.
88 * Before that the interfaces of the procedures used by buffer types.
89 */
90
91typedef int (Buf_ReadProc) _ANSI_ARGS_ ((Buf_Buffer buf, ClientData clientData,
92					VOID* outbuf, int size));
93
94typedef int (Buf_WriteProc) _ANSI_ARGS_ ((Buf_Buffer buf, ClientData clientData,
95					 CONST VOID* inbuf, int size));
96
97typedef Buf_Buffer (Buf_DuplicateProc) _ANSI_ARGS_ ((Buf_Buffer buf,
98						    ClientData clientData));
99
100typedef void (Buf_FreeProc) _ANSI_ARGS_ ((Buf_Buffer buf,
101					 ClientData clientData));
102
103typedef int (Buf_SizeProc) _ANSI_ARGS_ ((Buf_Buffer buf,
104					ClientData clientData));
105
106typedef int (Buf_TellProc) _ANSI_ARGS_ ((Buf_Buffer buf,
107					ClientData clientData));
108
109typedef char* (Buf_DataProc) _ANSI_ARGS_ ((Buf_Buffer buf,
110					  ClientData clientData));
111
112typedef struct Buf_BufferType_ {
113  char* typeName;               /* The name of the buffer type.
114				 * Statically allocated.
115				 * Not touched by the system */
116  Buf_ReadProc*      readProc;  /* Procedure called to read data
117				 * from a buffer of this type. */
118  Buf_WriteProc*     writeProc; /* Procedure called to write data
119				 * into a buffer of this type. */
120  Buf_DuplicateProc* dupProc;   /* Procedure called to duplicate
121				 * a buffer of this type. */
122  Buf_FreeProc*      freeProc;  /* Procedure called to free
123				 * a buffer of this type. */
124  Buf_SizeProc*      sizeProc;  /* Procedure called to ask for the
125				 * size of a buffer of this type. */
126  Buf_TellProc*      tellProc;  /* Procedure called to ask for the
127				 * offset of the read location. */
128  Buf_DataProc*      dataProc;  /* Procedure called to ask for a
129				 * pointer to the data area of a
130				 * buffer. */
131} Buf_BufferType;
132
133
134#include "bufDecls.h"
135
136
137#ifdef __cplusplus
138}
139#endif /* C++ */
140
141#undef TCL_STORAGE_CLASS
142#define TCL_STORAGE_CLASS DLLIMPORT
143
144#endif /* BUF_H */
145