Pajdeg  0.2.2
Pajdeg
PDStreamFilter.h
Go to the documentation of this file.
1 //
2 // PDStreamFilter.h
3 //
4 // Copyright (c) 2012 - 2015 Karl-Johan Alm (http://github.com/kallewoof)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 //
24 
96 #ifndef INCLUDED_PDStreamFilter_h
97 #define INCLUDED_PDStreamFilter_h
98 
99 #include "PDDefines.h"
100 
105 
110 
117 
129  void *data;
130  unsigned char *bufIn;
131  unsigned char *bufOut;
140  float growthHint;
141  unsigned char *bufOutOwned;
143 };
144 
158 
165 extern void PDStreamFilterRegisterDualFilter(const char *name, PDStreamDualFilterConstr constr);
166 
178 extern PDStreamFilterRef PDStreamFilterObtain(const char *name, PDBool inputEnd, PDDictionaryRef options);
179 
189 
196 
203 
214 
223 
236 extern PDBool PDStreamFilterApply(PDStreamFilterRef filter, unsigned char *src, unsigned char **dstPtr, PDInteger len, PDInteger *newlenPtr, PDInteger *allocatedlenPtr);
237 
245 
247 // Convert a PDScanner dictionary stack into a stream filter options stack.
248 //
249 // @note The original stack remains untouched.
250 //
251 // @param dictStack The dictionary stack to convert
252 // @return New allocated stack suited for stream filter options.
253 // */
254 //extern pd_stack PDStreamFilterGenerateOptionsFromDictionaryStack(pd_stack dictStack);
255 
262 
266 #define PDStreamFilterPrepare(f, buf_in, len_in, buf_out, len_out) do { \
267  f->bufIn = (unsigned char *)buf_in; \
268  f->bufOut = (unsigned char *)buf_out; \
269  f->bufInAvailable = len_in; \
270  f->bufOutCapacity = len_out; \
271 } while (0)
272 
273 #endif
274 
unsigned char * bufOutOwned
Internal output buffer, that will be freed on destruction. This is used internally for chained filter...
Definition: PDStreamFilter.h:141
PDStreamFilterRef PDStreamFilterAlloc(void)
Definition: PDStreamFilter.c:64
PDBool failing
Whether the filter is failing to handle its input.
Definition: PDStreamFilter.h:127
PDBool PDStreamFilterApply(PDStreamFilterRef filter, unsigned char *src, unsigned char **dstPtr, PDInteger len, PDInteger *newlenPtr, PDInteger *allocatedlenPtr)
Definition: PDStreamFilter.c:89
PDDictionaryRef options
Filter options.
Definition: PDStreamFilter.h:128
long PDInteger
Definition: PDDefines.h:184
unsigned char PDBool
Definition: PDDefines.h:207
PDStreamFilterFunc done
Deinitialization function. Called once after last use.
Definition: PDStreamFilter.h:135
Definition: PDStreamFilter.h:121
PDInteger bufOutCapacity
Output buffer capacity.
Definition: PDStreamFilter.h:133
PDStreamFilterRef PDStreamFilterCreate(PDStreamFilterFunc init, PDStreamFilterFunc done, PDStreamFilterFunc begin, PDStreamFilterFunc proceed, PDStreamFilterPrcs createInversion, PDDictionaryRef options)
Definition: PDStreamFilter.c:69
PDInteger PDStreamFilterBegin(PDStreamFilterRef filter)
Definition: PDStreamFilter.c:163
PDBool finished
Whether the filter is finished.
Definition: PDStreamFilter.h:126
PDInteger(* PDStreamFilterFunc)(PDStreamFilterRef filter)
Definition: PDStreamFilter.h:104
void * data
User info object.
Definition: PDStreamFilter.h:129
PDBool PDStreamFilterInit(PDStreamFilterRef filter)
Definition: PDStreamFilter.c:140
PDBool compatible
If false after initialization, the filter initialized fine but encountered compatibility issues that ...
Definition: PDStreamFilter.h:123
PDInteger bufOutOwnedCapacity
Capacity of internal output buffer.
Definition: PDStreamFilter.h:142
void PDStreamFilterRegisterDualFilter(const char *name, PDStreamDualFilterConstr constr)
Definition: PDStreamFilter.c:32
unsigned char * bufOut
Output buffer.
Definition: PDStreamFilter.h:131
PDStreamFilterFunc init
Initialization function. Called once before first use.
Definition: PDStreamFilter.h:134
unsigned char * bufIn
Input buffer.
Definition: PDStreamFilter.h:130
struct PDStreamFilter * PDStreamFilterRef
Definition: PDDefines.h:841
Definition: pd_internal.h:639
PDStreamFilterRef(* PDStreamDualFilterConstr)(PDBool inputEnd, PDDictionaryRef options)
Definition: PDStreamFilter.h:116
PDInteger bufInAvailable
Available data.
Definition: PDStreamFilter.h:132
PDStreamFilterRef nextFilter
The next filter that should receive the output end of this filter as its input, or NULL if no such re...
Definition: PDStreamFilter.h:139
float growthHint
The growth hint is an indicator for how the filter expects the size of its resulting data to be relat...
Definition: PDStreamFilter.h:140
PDInteger PDStreamFilterProceed(PDStreamFilterRef filter)
Definition: PDStreamFilter.c:201
Definitions for the Pajdeg interface.
PDStreamFilterRef PDStreamFilterCreateInversionForFilter(PDStreamFilterRef filter)
Definition: PDStreamFilter.c:300
PDBool PDStreamFilterDone(PDStreamFilterRef filter)
Definition: PDStreamFilter.c:153
PDStreamFilterRef(* PDStreamFilterPrcs)(PDStreamFilterRef filter)
Definition: PDStreamFilter.h:109
PDStreamFilterFunc proceed
Proceed function. Called any number of times to request more output from last begin call...
Definition: PDStreamFilter.h:137
PDBool initialized
Determines if filter was set up or not.
Definition: PDStreamFilter.h:122
void PDStreamFilterAppendFilter(PDStreamFilterRef filter, PDStreamFilterRef next)
Definition: PDStreamFilter.c:83
PDStreamFilterFunc begin
Processing function. Called any number of times, at most once per new input buffer.
Definition: PDStreamFilter.h:136
PDBool needsInput
Whether the filter needs data. If true, its input buffer must not be modified.
Definition: PDStreamFilter.h:124
PDBool hasInput
Whether the filter has pending input that, for capacity reasons, has not been added to the buffer yet...
Definition: PDStreamFilter.h:125
PDStreamFilterPrcs createInversion
Inversion function. Returns, if possible, a filter chain that reverts the current filter...
Definition: PDStreamFilter.h:138
PDStreamFilterRef PDStreamFilterObtain(const char *name, PDBool inputEnd, PDDictionaryRef options)
Definition: PDStreamFilter.c:38