]> git.saurik.com Git - apple/cf.git/blob - AppServices.subproj/CFStreamPriv.h
CF-368.1.tar.gz
[apple/cf.git] / AppServices.subproj / CFStreamPriv.h
1 /*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* CFStreamPriv.h
24 Copyright (c) 2000-2005, Apple, Inc. All rights reserved.
25 */
26
27 #if !defined(__COREFOUNDATION_CFSTREAMPRIV__)
28 #define __COREFOUNDATION_CFSTREAMPRIV__ 1
29
30 #include <CoreFoundation/CFBase.h>
31 #include <CoreFoundation/CFRuntime.h>
32 #include <CoreFoundation/CFStream.h>
33 #include <CoreFoundation/CFStreamAbstract.h>
34 #include <CoreFoundation/CFRunLoop.h>
35
36 #if defined(__cplusplus)
37 extern "C" {
38 #endif
39
40 struct _CFStream;
41 struct _CFStreamClient {
42 CFStreamClientContext cbContext;
43 void (*cb)(struct _CFStream *, CFStreamEventType, void *);
44 CFOptionFlags when;
45 CFRunLoopSourceRef rlSource;
46 CFMutableArrayRef runLoopsAndModes;
47 CFOptionFlags whatToSignal;
48 };
49
50 // A unified set of callbacks so we can use a single structure for all struct _CFStreams.
51 struct _CFStreamCallBacks {
52 CFIndex version;
53 void *(*create)(struct _CFStream *stream, void *info);
54 void (*finalize)(struct _CFStream *stream, void *info);
55 CFStringRef (*copyDescription)(struct _CFStream *stream, void *info);
56 Boolean (*open)(struct _CFStream *stream, CFStreamError *error, Boolean *openComplete, void *info);
57 Boolean (*openCompleted)(struct _CFStream *stream, CFStreamError *error, void *info);
58 CFIndex (*read)(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLength, CFStreamError *error, Boolean *atEOF, void *info);
59 const UInt8 *(*getBuffer)(CFReadStreamRef sream, CFIndex maxBytesToRead, CFIndex *numBytesRead, CFStreamError *error, Boolean *atEOF, void *info);
60 Boolean (*canRead)(CFReadStreamRef, void *info);
61 CFIndex (*write)(CFWriteStreamRef, const UInt8 *buffer, CFIndex bufferLength, CFStreamError *error, void *info);
62 Boolean (*canWrite)(CFWriteStreamRef, void *info);
63 void (*close)(struct _CFStream *stream, void *info);
64 CFTypeRef (*copyProperty)(struct _CFStream *stream, CFStringRef propertyName, void *info);
65 Boolean (*setProperty)(struct _CFStream *stream, CFStringRef propertyName, CFTypeRef propertyValue, void *info);
66 void (*requestEvents)(struct _CFStream *stream, CFOptionFlags events, void *info);
67 void (*schedule)(struct _CFStream *stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void *info);
68 void (*unschedule)(struct _CFStream *stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void *info);
69 };
70
71 struct _CFStream {
72 CFRuntimeBase _cfBase;
73 CFOptionFlags flags;
74 CFStreamError error;
75 struct _CFStreamClient *client;
76 void *info;
77 const struct _CFStreamCallBacks *callBacks; // This will not exist (will not be allocated) if the callbacks are from our known, "blessed" set.
78 void *_reserved1;
79 };
80
81 CF_INLINE void *_CFStreamGetInfoPointer(struct _CFStream *stream) {
82 return stream->info;
83 }
84
85 // cb version must be 1
86 CF_EXPORT struct _CFStream *_CFStreamCreateWithConstantCallbacks(CFAllocatorRef alloc, void *info, const struct _CFStreamCallBacks *cb, Boolean isReading);
87
88 // Only available for streams created with _CFStreamCreateWithConstantCallbacks, above. cb's version must be 1
89 CF_EXPORT void _CFStreamSetInfoPointer(struct _CFStream *stream, void *info, const struct _CFStreamCallBacks *cb);
90
91
92 /*
93 ** _CFStreamSourceScheduleWithRunLoop
94 **
95 ** Schedules the given run loop source on the given run loop and mode. It then
96 ** adds the loop and mode pair to the runLoopsAndModes list. The list is
97 ** simply a linear list of a loop reference followed by a mode reference.
98 **
99 ** source Run loop source to be scheduled
100 **
101 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
102 **
103 ** runLoop Run loop on which the source is being scheduled
104 **
105 ** runLoopMode Run loop mode on which the source is being scheduled
106 */
107 CF_EXPORT
108 void _CFStreamSourceScheduleWithRunLoop(CFRunLoopSourceRef source, CFMutableArrayRef runLoopsAndModes, CFRunLoopRef runLoop, CFStringRef runLoopMode);
109
110
111 /*
112 ** _CFStreamSourceUnscheduleFromRunLoop
113 **
114 ** Unschedule the given source from the given run loop and mode. It then will
115 ** guarantee that the source remains scheduled on the list of run loop and mode
116 ** pairs in the runLoopsAndModes list. The list is simply a linear list of a
117 ** loop reference followed by a mode reference.
118 **
119 ** source Run loop source to be unscheduled
120 **
121 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
122 **
123 ** runLoop Run loop from which the source is being unscheduled
124 **
125 ** runLoopMode Run loop mode from which the source is being unscheduled
126 */
127 CF_EXPORT
128 void _CFStreamSourceUnscheduleFromRunLoop(CFRunLoopSourceRef source, CFMutableArrayRef runLoopsAndModes, CFRunLoopRef runLoop, CFStringRef runLoopMode);
129
130
131 /*
132 ** _CFStreamSourceScheduleWithAllRunLoops
133 **
134 ** Schedules the given run loop source on all the run loops and modes in the list.
135 ** The list is simply a linear list of a loop reference followed by a mode reference.
136 **
137 ** source Run loop source to be unscheduled
138 **
139 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
140 */
141 CF_EXPORT
142 void _CFStreamSourceScheduleWithAllRunLoops(CFRunLoopSourceRef source, CFArrayRef runLoopsAndModes);
143
144
145 /*
146 ** _CFStreamSourceUnscheduleFromRunLoop
147 **
148 ** Unschedule the given source from all the run loops and modes in the list.
149 ** The list is simply a linear list of a loop reference followed by a mode
150 ** reference.
151 **
152 ** source Run loop source to be unscheduled
153 **
154 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
155 */
156 CF_EXPORT
157 void _CFStreamSourceUncheduleFromAllRunLoops(CFRunLoopSourceRef source, CFArrayRef runLoopsAndModes);
158
159
160 #define SECURITY_NONE (0)
161 #define SECURITY_SSLv2 (1)
162 #define SECURITY_SSLv3 (2)
163 #define SECURITY_SSLv32 (3)
164 #define SECURITY_TLS (4)
165
166 extern const int kCFStreamErrorDomainSSL;
167
168 #if defined(__cplusplus)
169 }
170 #endif
171
172 #endif /* ! __COREFOUNDATION_CFSTREAMPRIV__ */
173