1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3 
4   This file is part of SOPE.
5 
6   SOPE is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10 
11   SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15 
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 
22 #ifndef __NGStreams_NGStreamProtocols_H__
23 #define __NGStreams_NGStreamProtocols_H__
24 
25 #import <Foundation/NSObject.h>
26 
27 #if !(MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED)
28 #  define USE_SERIALIZER 1
29 #  import <Foundation/NSSerialization.h>
30 #endif
31 
32 @class NSException;
33 
34 typedef enum {
35   NGStreamMode_undefined = 0,
36   NGStreamMode_readOnly  = 1,
37   NGStreamMode_writeOnly = 2,
38   NGStreamMode_readWrite = 4
39 } NGStreamMode;
40 
41 /* if this value is returned by -read, -lastException is set ... */
42 enum {NGStreamError = 0x7fffffff};
43 
44 typedef unsigned (*NGIOReadMethodType )(id, SEL, void *, unsigned);
45 typedef unsigned (*NGIOWriteMethodType)(id, SEL, const void *, unsigned);
46 typedef BOOL (*NGIOSafeReadMethodType )(id, SEL, void *, unsigned);
47 typedef BOOL (*NGIOSafeWriteMethodType)(id, SEL, const void *, unsigned);
48 
49 @protocol NGInputStream < NSObject >
50 
51 - (unsigned)readBytes:(void *)_buf count:(unsigned)_len;
52 - (BOOL)safeReadBytes:(void *)_buf count:(unsigned)_len;
53 - (BOOL)close;
54 
55 // marks
56 
57 - (BOOL)mark;
58 - (BOOL)rewind;
59 - (BOOL)markSupported;
60 
61 @end
62 
63 @protocol NGOutputStream < NSObject >
64 
65 - (unsigned)writeBytes:(const void *)_buf count:(unsigned)_len;
66 - (BOOL)safeWriteBytes:(const void *)_buf count:(unsigned)_len;
67 
68 - (BOOL)flush;
69 - (BOOL)close;
70 
71 @end
72 
73 @protocol NGPositionableStream < NSObject >
74 
75 - (BOOL)moveToLocation:(unsigned)_location;
76 - (BOOL)moveByOffset:(int)_delta;
77 
78 @end
79 
80 @protocol NGStream < NGInputStream, NGOutputStream >
81 
82 - (BOOL)close;
83 - (NGStreamMode)mode;
84 - (NSException *)lastException;
85 
86 @end
87 
88 @protocol NGByteSequenceStream < NGInputStream >
89 
90 - (int)readByte; // Java semantics (-1 on EOF)
91 
92 @end
93 
94 typedef int (*NGSequenceReadByteMethod)(id<NGByteSequenceStream> self, SEL _cmd);
95 
96 // push streams
97 
98 @class NSData;
99 
100 @protocol NGPushStream < NSObject >
101 
102 - (void)pushChar:(char)_c;
103 - (void)pushCString:(const char *)_cstr;
104 - (void)pushData:(NSData *)_block;
105 - (void)pushBytes:(const void *)_buffer count:(unsigned)_len;
106 - (void)abort;
107 
108 @end
109 
110 // serializer
111 
112 @protocol NGSerializer < NSObject >
113 
114 - (void)serializeChar:(char)_value;
115 - (void)serializeShort:(short)_value;
116 - (void)serializeInt:(int)_value;
117 - (void)serializeLong:(long)_value;
118 - (void)serializeFloat:(float)_value;
119 - (void)serializeDouble:(double)_value;
120 - (void)serializeLongLong:(long long)_value;
121 
122 - (char)deserializeChar;
123 - (short)deserializeShort;
124 - (int)deserializeInt;
125 - (long)deserializeLong;
126 - (float)deserializeFloat;
127 - (double)deserializeDouble;
128 - (long long)deserializeLongLong;
129 
130 - (void)serializeCString:(const char *)_value;
131 - (char *)deserializeCString;
132 
133 #if USE_SERIALIZER
134 - (void)serializeDataAt:(const void*)data ofObjCType:(const char*)type
135   context:(id<NSObjCTypeSerializationCallBack>)_callback;
136 - (void)deserializeDataAt:(const void*)data ofObjCType:(const char*)type
137   context:(id<NSObjCTypeSerializationCallBack>)_callback;
138 #endif
139 
140 @end
141 
142 #endif /* __NGStreams_NGStreamProtocols_H__ */
143